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; }
// 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.

View File

@ -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<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()

View File

@ -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)