Fixed bug that mmap won't work if MultiDiskAdaptor is used

This commit is contained in:
Tatsuhiro Tsujikawa 2012-10-08 19:13:01 +09:00
parent 71620854c7
commit 5367c34de3
3 changed files with 15 additions and 7 deletions

View File

@ -90,6 +90,8 @@ public:
virtual bool isReadOnlyEnabled() const { return false; } 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() {} virtual void enableMmap() {}
// Assumed each file length is stored in fileEntries or DiskAdaptor knows it. // Assumed each file length is stored in fileEntries or DiskAdaptor knows it.

View File

@ -119,8 +119,7 @@ bool DiskWriterEntry::operator<(const DiskWriterEntry& entry) const
MultiDiskAdaptor::MultiDiskAdaptor() MultiDiskAdaptor::MultiDiskAdaptor()
: pieceLength_(0), : pieceLength_(0),
maxOpenFiles_(DEFAULT_MAX_OPEN_FILES), maxOpenFiles_(DEFAULT_MAX_OPEN_FILES),
readOnly_(false), readOnly_(false)
enableMmap_(false)
{} {}
MultiDiskAdaptor::~MultiDiskAdaptor() {} MultiDiskAdaptor::~MultiDiskAdaptor() {}
@ -230,9 +229,8 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
if(readOnly_) { if(readOnly_) {
(*i)->getDiskWriter()->enableReadOnly(); (*i)->getDiskWriter()->enableReadOnly();
} }
if(enableMmap_) { // TODO mmap is not enabled at this moment. Call enableMmap()
(*i)->getDiskWriter()->enableMmap(); // after this function call.
}
} }
} }
} }
@ -456,7 +454,14 @@ void MultiDiskAdaptor::disableReadOnly()
void MultiDiskAdaptor::enableMmap() void MultiDiskAdaptor::enableMmap()
{ {
enableMmap_ = true; for(std::vector<SharedHandle<DiskWriterEntry> >::const_iterator i =
diskWriterEntries_.begin(), eoi = diskWriterEntries_.end();
i != eoi; ++i) {
const SharedHandle<DiskWriter>& dw = (*i)->getDiskWriter();
if(dw) {
dw->enableMmap();
}
}
} }
void MultiDiskAdaptor::cutTrailingGarbage() void MultiDiskAdaptor::cutTrailingGarbage()

View File

@ -110,7 +110,6 @@ private:
int maxOpenFiles_; int maxOpenFiles_;
bool readOnly_; bool readOnly_;
bool enableMmap_;
void resetDiskWriterEntries(); void resetDiskWriterEntries();
@ -148,6 +147,8 @@ public:
virtual bool isReadOnlyEnabled() const { return readOnly_; } virtual bool isReadOnlyEnabled() const { return readOnly_; }
// Enables mmap feature. This method must be called after files are
// opened.
virtual void enableMmap(); virtual void enableMmap();
void setPieceLength(int32_t pieceLength) void setPieceLength(int32_t pieceLength)