示例#1
0
        void flush() {
            if ( _view == NULL || _fd == 0 )
                return;

            if ( msync(_view, _len, MS_SYNC ) == 0 )
                return;

            if ( errno == EBADF ) {
                // ok, we were unlocked, so this file was closed
                return;
            }

            // some error, lets see if we're supposed to exist
            LockMongoFilesShared mmfilesLock;
            if ( MongoFile::getAllFiles().count( _theFile ) == 0 ) {
                log() << "msync failed with: " << errnoWithDescription()
                      << " but file doesn't exist anymore, so ignoring";
                // this was deleted while we were unlocked
                return;
            }

            // we got an error, and we still exist, so this is bad, we fail
            problem() << "msync " << errnoWithDescription() << endl;
            dataSyncFailedHandler();
        }
示例#2
0
        void flush() {
            if ( _view == NULL || _fd == 0 )
                return;

            if ( msync(_view, _len, MS_SYNC ) == 0 )
                return;

            if ( errno == EBADF ) {
                // ok, we were unlocked, so this file was closed
                return;
            }

            // some error, lets see if we're supposed to exist
            LockMongoFilesShared mmfilesLock;
            std::set<MongoFile*> mmfs = MongoFile::getAllFiles();
            std::set<MongoFile*>::const_iterator it = mmfs.find(_theFile);
            if ( (it == mmfs.end()) || ((*it)->getUniqueId() != _id) ) {
                log() << "msync failed with: " << errnoWithDescription()
                      << " but file doesn't exist anymore, so ignoring";
                // this was deleted while we were unlocked
                return;
            }

            // we got an error, and we still exist, so this is bad, we fail
            problem() << "msync " << errnoWithDescription() << endl;
            dataSyncFailedHandler();
        }
示例#3
0
 void MemoryMappedFile::flush(bool sync) {
     if ( views.empty() || fd == 0 )
         return;
     if ( msync(viewForFlushing(), len, sync ? MS_SYNC : MS_ASYNC) ) {
         // msync failed, this is very bad
         problem() << "msync failed: " << errnoWithDescription();
         dataSyncFailedHandler();
     }
 }
示例#4
0
    void flush() {
        if (!_view || !_fd)
            return;

        {
            LockMongoFilesShared mmfilesLock;

            std::set<MongoFile*> mmfs = MongoFile::getAllFiles();
            std::set<MongoFile*>::const_iterator it = mmfs.find(_theFile);
            if (it == mmfs.end() || (*it)->getUniqueId() != _id) {
                // this was deleted while we were unlocked
                return;
            }

            // Hold the flush mutex to ensure the file is not closed during flush
            _flushMutex.lock();
        }

        stdx::lock_guard<stdx::mutex> lk(_flushMutex, stdx::adopt_lock);

        int loopCount = 0;
        bool success = false;
        bool timeout = false;
        int dosError = ERROR_SUCCESS;
        const int maximumTimeInSeconds = 60 * 15;
        Timer t;
        while (!success && !timeout) {
            ++loopCount;
            success = FALSE != FlushViewOfFile(_view, 0);
            if (!success) {
                dosError = GetLastError();
                if (dosError != ERROR_LOCK_VIOLATION) {
                    break;
                }
                timeout = t.seconds() > maximumTimeInSeconds;
            }
        }
        if (success && loopCount > 1) {
            log() << "FlushViewOfFile for " << _filename << " succeeded after " << loopCount
                  << " attempts taking " << t.millis() << "ms" << endl;
        } else if (!success) {
            log() << "FlushViewOfFile for " << _filename << " failed with error " << dosError
                  << " after " << loopCount << " attempts taking " << t.millis() << "ms" << endl;
            // Abort here to avoid data corruption
            fassert(16387, false);
        }

        success = FALSE != FlushFileBuffers(_fd);
        if (!success) {
            int err = GetLastError();
            log() << "FlushFileBuffers failed: " << errnoWithDescription(err)
                  << " file: " << _filename << endl;
            dataSyncFailedHandler();
        }
    }
示例#5
0
        void flush() {
            if (!_view || !_fd)
                return;

            LockMongoFilesShared mmfilesLock;
            if ( MongoFile::getAllFiles().count( _theFile ) == 0 ) {
                // this was deleted while we were unlocked
                return;
            }

            SimpleMutex::scoped_lock _globalFlushMutex(globalFlushMutex);
            scoped_lock lk(*_flushMutex);

            int loopCount = 0;
            bool success = false;
            bool timeout = false;
            int dosError = ERROR_SUCCESS;
            const int maximumTimeInSeconds = 60 * 15;
            Timer t;
            while ( !success && !timeout ) {
                ++loopCount;
                success = FALSE != FlushViewOfFile( _view, 0 );
                if ( !success ) {
                    dosError = GetLastError();
                    if ( dosError != ERROR_LOCK_VIOLATION ) {
                        break;
                    }
                    timeout = t.seconds() > maximumTimeInSeconds;
                }
            }
            if ( success && loopCount > 1 ) {
                log() << "FlushViewOfFile for " << _filename
                        << " succeeded after " << loopCount
                        << " attempts taking " << t.millis()
                        << "ms" << endl;
            }
            else if ( !success ) {
                log() << "FlushViewOfFile for " << _filename
                        << " failed with error " << dosError
                        << " after " << loopCount
                        << " attempts taking " << t.millis()
                        << "ms" << endl;
                // Abort here to avoid data corruption
                fassert(16387, false);
            }

            success = FALSE != FlushFileBuffers(_fd);
            if (!success) {
                int err = GetLastError();
                out() << "FlushFileBuffers failed: " << errnoWithDescription( err )
                      << " file: " << _filename << endl;
                dataSyncFailedHandler();
            }
        }
示例#6
0
void MemoryMappedFile::flush(bool sync) {
    if (views.empty() || fd == 0)
        return;

    bool useFsync = sync && !ProcessInfo::preferMsyncOverFSync();

    if (useFsync ? fsync(fd) != 0 : msync(viewForFlushing(), len, sync ? MS_SYNC : MS_ASYNC)) {
        // msync failed, this is very bad
        log() << (useFsync ? "fsync failed: " : "msync failed: ") << errnoWithDescription()
              << " file: " << filename() << endl;
        dataSyncFailedHandler();
    }
}