diff --git a/src/DiskAdaptor.h b/src/DiskAdaptor.h index a1ba1c76..eef6950b 100644 --- a/src/DiskAdaptor.h +++ b/src/DiskAdaptor.h @@ -90,6 +90,8 @@ public: virtual bool isReadOnlyEnabled() const { return false; } + // Enables mmap feature. Some derived classes may require that files + // have been opened before this method call. virtual void enableMmap() {} // Assumed each file length is stored in fileEntries or DiskAdaptor knows it. diff --git a/src/MultiDiskAdaptor.cc b/src/MultiDiskAdaptor.cc index a9ea7172..bdfa72a0 100644 --- a/src/MultiDiskAdaptor.cc +++ b/src/MultiDiskAdaptor.cc @@ -119,8 +119,7 @@ bool DiskWriterEntry::operator<(const DiskWriterEntry& entry) const MultiDiskAdaptor::MultiDiskAdaptor() : pieceLength_(0), maxOpenFiles_(DEFAULT_MAX_OPEN_FILES), - readOnly_(false), - enableMmap_(false) + readOnly_(false) {} MultiDiskAdaptor::~MultiDiskAdaptor() {} @@ -230,9 +229,8 @@ void MultiDiskAdaptor::resetDiskWriterEntries() if(readOnly_) { (*i)->getDiskWriter()->enableReadOnly(); } - if(enableMmap_) { - (*i)->getDiskWriter()->enableMmap(); - } + // TODO mmap is not enabled at this moment. Call enableMmap() + // after this function call. } } } @@ -456,7 +454,14 @@ void MultiDiskAdaptor::disableReadOnly() void MultiDiskAdaptor::enableMmap() { - enableMmap_ = true; + for(std::vector >::const_iterator i = + diskWriterEntries_.begin(), eoi = diskWriterEntries_.end(); + i != eoi; ++i) { + const SharedHandle& dw = (*i)->getDiskWriter(); + if(dw) { + dw->enableMmap(); + } + } } void MultiDiskAdaptor::cutTrailingGarbage() diff --git a/src/MultiDiskAdaptor.h b/src/MultiDiskAdaptor.h index 392b97bf..bd8d8025 100644 --- a/src/MultiDiskAdaptor.h +++ b/src/MultiDiskAdaptor.h @@ -110,7 +110,6 @@ private: int maxOpenFiles_; bool readOnly_; - bool enableMmap_; void resetDiskWriterEntries(); @@ -148,6 +147,8 @@ public: virtual bool isReadOnlyEnabled() const { return readOnly_; } + // Enables mmap feature. This method must be called after files are + // opened. virtual void enableMmap(); void setPieceLength(int32_t pieceLength)