summaryrefslogtreecommitdiff
path: root/util/mmap_posix.cpp
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2009-04-15 11:58:38 -0400
committerAaron <aaron@10gen.com>2009-04-15 11:58:38 -0400
commit0033bd91dfd8846e7f53e4a58c91714fa5b6d99e (patch)
tree85ba5c70ea5cae665323d2ede7201e8c5c0360f8 /util/mmap_posix.cpp
parentae6ea342423e7bc73f1d4632d51a0f261f24600e (diff)
downloadmongo-0033bd91dfd8846e7f53e4a58c91714fa5b6d99e.tar.gz
allocate files in background
Diffstat (limited to 'util/mmap_posix.cpp')
-rw-r--r--util/mmap_posix.cpp40
1 files changed, 4 insertions, 36 deletions
diff --git a/util/mmap_posix.cpp b/util/mmap_posix.cpp
index 360484554a0..b351b02392f 100644
--- a/util/mmap_posix.cpp
+++ b/util/mmap_posix.cpp
@@ -18,6 +18,7 @@
#include "stdafx.h"
#include "mmap.h"
+#include "file_allocator.h"
#include <errno.h>
#include <sys/mman.h>
@@ -53,47 +54,14 @@ namespace mongo {
updateLength( filename, length );
len = length;
- fd = open(filename, O_CREAT | O_RDWR | O_NOATIME, S_IRUSR | S_IWUSR);
+ theFileAllocator().allocateAsap( filename, length );
+
+ fd = open(filename, O_RDWR | O_NOATIME);
if ( fd <= 0 ) {
out() << "couldn't open " << filename << ' ' << errno << endl;
return 0;
}
- /* make sure the file is the full desired length */
- off_t filelen = lseek(fd, 0, SEEK_END);
- if ( filelen < length ) {
- // log() << "map: file length=" << (unsigned) filelen << " want:"
- // << length
- // << endl;
- if ( filelen != 0 ) {
- problem() << "failure mapping new file " << filename << " length:" << length << endl;
- return 0;
- }
- // Check for end of disk.
- massert( "Unable to allocate file of desired size",
- length - 1 == lseek(fd, length - 1, SEEK_SET) );
- massert( "Unable to allocate file of desired size",
- 1 == write(fd, "", 1) );
- lseek(fd, 0, SEEK_SET);
- Nullstream &l = log();
- l << "new datafile " << filename << " filling with zeroes...";
- l.flush();
- Timer t;
- int z = 8192;
- char buf[z];
- memset(buf, 0, z);
- int left = length;
- while ( 1 ) {
- if ( left <= z ) {
- write(fd, buf, left);
- break;
- }
- write(fd, buf, z);
- left -= z;
- }
- l << "done " << ((double)t.millis())/1000.0 << " secs" << endl;
- }
-
view = mmap(NULL, length, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if ( view == MAP_FAILED ) {
out() << " mmap() failed for " << filename << " len:" << length << " errno:" << errno << endl;