diff options
Diffstat (limited to 'src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp')
-rw-r--r-- | src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp | 677 |
1 files changed, 334 insertions, 343 deletions
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp index f123ff1fffd..291797c11a8 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp @@ -57,426 +57,417 @@ namespace mongo { - using std::set; - using std::string; - - - WiredTigerKVEngine::WiredTigerKVEngine( const std::string& path, - const std::string& extraOpenOptions, - bool durable, - bool repair ) - : _eventHandler(WiredTigerUtil::defaultEventHandlers()), - _path( path ), - _durable( durable ), - _sizeStorerSyncTracker( 100000, 60 * 1000 ) { - - size_t cacheSizeGB = wiredTigerGlobalOptions.cacheSizeGB; - if (cacheSizeGB == 0) { - // Since the user didn't provide a cache size, choose a reasonable default value. - ProcessInfo pi; - unsigned long long memSizeMB = pi.getMemSizeMB(); - if ( memSizeMB > 0 ) { - double cacheMB = memSizeMB / 2; - cacheSizeGB = static_cast<size_t>( cacheMB / 1024 ); - if ( cacheSizeGB < 1 ) - cacheSizeGB = 1; - } +using std::set; +using std::string; + + +WiredTigerKVEngine::WiredTigerKVEngine(const std::string& path, + const std::string& extraOpenOptions, + bool durable, + bool repair) + : _eventHandler(WiredTigerUtil::defaultEventHandlers()), + _path(path), + _durable(durable), + _sizeStorerSyncTracker(100000, 60 * 1000) { + size_t cacheSizeGB = wiredTigerGlobalOptions.cacheSizeGB; + if (cacheSizeGB == 0) { + // Since the user didn't provide a cache size, choose a reasonable default value. + ProcessInfo pi; + unsigned long long memSizeMB = pi.getMemSizeMB(); + if (memSizeMB > 0) { + double cacheMB = memSizeMB / 2; + cacheSizeGB = static_cast<size_t>(cacheMB / 1024); + if (cacheSizeGB < 1) + cacheSizeGB = 1; } + } - if ( _durable ) { - boost::filesystem::path journalPath = path; - journalPath /= "journal"; - if ( !boost::filesystem::exists( journalPath ) ) { - try { - boost::filesystem::create_directory( journalPath ); - } - catch( std::exception& e) { - log() << "error creating journal dir " << journalPath.string() << ' ' << e.what(); - throw; - } + if (_durable) { + boost::filesystem::path journalPath = path; + journalPath /= "journal"; + if (!boost::filesystem::exists(journalPath)) { + try { + boost::filesystem::create_directory(journalPath); + } catch (std::exception& e) { + log() << "error creating journal dir " << journalPath.string() << ' ' << e.what(); + throw; } } + } - std::stringstream ss; - ss << "create,"; - ss << "cache_size=" << cacheSizeGB << "G,"; - ss << "session_max=20000,"; - ss << "eviction=(threads_max=4),"; - ss << "statistics=(fast),"; - if ( _durable ) { - ss << "log=(enabled=true,archive=true,path=journal,compressor="; - ss << wiredTigerGlobalOptions.journalCompressor << "),"; - } - ss << "file_manager=(close_idle_time=100000),"; //~28 hours, will put better fix in 3.1.x - ss << "checkpoint=(wait=" << wiredTigerGlobalOptions.checkpointDelaySecs; - ss << ",log_size=2GB),"; - ss << "statistics_log=(wait=" << wiredTigerGlobalOptions.statisticsLogDelaySecs << "),"; - ss << WiredTigerCustomizationHooks::get( - getGlobalServiceContext())->getOpenConfig("metadata"); - ss << extraOpenOptions; - string config = ss.str(); - log() << "wiredtiger_open config: " << config; - int ret = wiredtiger_open(path.c_str(), &_eventHandler, config.c_str(), &_conn); - // Invalid argument (EINVAL) is usually caused by invalid configuration string. - // We still fassert() but without a stack trace. - if (ret == EINVAL) { - fassertFailedNoTrace(28561); - } - else if (ret != 0) { - Status s(wtRCToStatus(ret)); - msgassertedNoTrace(28595, s.reason()); - } + std::stringstream ss; + ss << "create,"; + ss << "cache_size=" << cacheSizeGB << "G,"; + ss << "session_max=20000,"; + ss << "eviction=(threads_max=4),"; + ss << "statistics=(fast),"; + if (_durable) { + ss << "log=(enabled=true,archive=true,path=journal,compressor="; + ss << wiredTigerGlobalOptions.journalCompressor << "),"; + } + ss << "file_manager=(close_idle_time=100000),"; //~28 hours, will put better fix in 3.1.x + ss << "checkpoint=(wait=" << wiredTigerGlobalOptions.checkpointDelaySecs; + ss << ",log_size=2GB),"; + ss << "statistics_log=(wait=" << wiredTigerGlobalOptions.statisticsLogDelaySecs << "),"; + ss << WiredTigerCustomizationHooks::get(getGlobalServiceContext())->getOpenConfig("metadata"); + ss << extraOpenOptions; + string config = ss.str(); + log() << "wiredtiger_open config: " << config; + int ret = wiredtiger_open(path.c_str(), &_eventHandler, config.c_str(), &_conn); + // Invalid argument (EINVAL) is usually caused by invalid configuration string. + // We still fassert() but without a stack trace. + if (ret == EINVAL) { + fassertFailedNoTrace(28561); + } else if (ret != 0) { + Status s(wtRCToStatus(ret)); + msgassertedNoTrace(28595, s.reason()); + } - _sessionCache.reset( new WiredTigerSessionCache( this ) ); + _sessionCache.reset(new WiredTigerSessionCache(this)); - _sizeStorerUri = "table:sizeStorer"; - { - WiredTigerSession session(_conn); - if (repair && _hasUri(session.getSession(), _sizeStorerUri)) { - log() << "Repairing size cache"; - fassertNoTrace(28577, _salvageIfNeeded(_sizeStorerUri.c_str())); - } - _sizeStorer.reset(new WiredTigerSizeStorer(_conn, _sizeStorerUri)); - _sizeStorer->fillCache(); + _sizeStorerUri = "table:sizeStorer"; + { + WiredTigerSession session(_conn); + if (repair && _hasUri(session.getSession(), _sizeStorerUri)) { + log() << "Repairing size cache"; + fassertNoTrace(28577, _salvageIfNeeded(_sizeStorerUri.c_str())); } + _sizeStorer.reset(new WiredTigerSizeStorer(_conn, _sizeStorerUri)); + _sizeStorer->fillCache(); } +} - WiredTigerKVEngine::~WiredTigerKVEngine() { - if (_conn) { - cleanShutdown(); - } - - _sessionCache.reset( NULL ); +WiredTigerKVEngine::~WiredTigerKVEngine() { + if (_conn) { + cleanShutdown(); } - void WiredTigerKVEngine::cleanShutdown() { - log() << "WiredTigerKVEngine shutting down"; - syncSizeInfo(true); - if (_conn) { - // these must be the last things we do before _conn->close(); - _sizeStorer.reset( NULL ); - _sessionCache->shuttingDown(); + _sessionCache.reset(NULL); +} + +void WiredTigerKVEngine::cleanShutdown() { + log() << "WiredTigerKVEngine shutting down"; + syncSizeInfo(true); + if (_conn) { + // these must be the last things we do before _conn->close(); + _sizeStorer.reset(NULL); + _sessionCache->shuttingDown(); #if !__has_feature(address_sanitizer) - const char* config = "leak_memory=true"; + const char* config = "leak_memory=true"; #else - const char* config = NULL; + const char* config = NULL; #endif - invariantWTOK( _conn->close(_conn, config) ); - _conn = NULL; - } - } - - Status WiredTigerKVEngine::okToRename( OperationContext* opCtx, - StringData fromNS, - StringData toNS, - StringData ident, - const RecordStore* originalRecordStore ) const { - _sizeStorer->storeToCache(_uri( ident ), - originalRecordStore->numRecords( opCtx ), - originalRecordStore->dataSize( opCtx ) ); - syncSizeInfo(true); - return Status::OK(); + invariantWTOK(_conn->close(_conn, config)); + _conn = NULL; } +} - int64_t WiredTigerKVEngine::getIdentSize( OperationContext* opCtx, - StringData ident ) { - WiredTigerSession* session = WiredTigerRecoveryUnit::get(opCtx)->getSession(opCtx); - return WiredTigerUtil::getIdentSize(session->getSession(), _uri(ident) ); - } +Status WiredTigerKVEngine::okToRename(OperationContext* opCtx, + StringData fromNS, + StringData toNS, + StringData ident, + const RecordStore* originalRecordStore) const { + _sizeStorer->storeToCache( + _uri(ident), originalRecordStore->numRecords(opCtx), originalRecordStore->dataSize(opCtx)); + syncSizeInfo(true); + return Status::OK(); +} - Status WiredTigerKVEngine::repairIdent( OperationContext* opCtx, - StringData ident ) { - WiredTigerSession* session = WiredTigerRecoveryUnit::get(opCtx)->getSession(opCtx); - session->closeAllCursors(); - string uri = _uri(ident); - return _salvageIfNeeded(uri.c_str()); - } +int64_t WiredTigerKVEngine::getIdentSize(OperationContext* opCtx, StringData ident) { + WiredTigerSession* session = WiredTigerRecoveryUnit::get(opCtx)->getSession(opCtx); + return WiredTigerUtil::getIdentSize(session->getSession(), _uri(ident)); +} - Status WiredTigerKVEngine::_salvageIfNeeded(const char* uri) { - // Using a side session to avoid transactional issues - WiredTigerSession sessionWrapper(_conn); - WT_SESSION* session = sessionWrapper.getSession(); +Status WiredTigerKVEngine::repairIdent(OperationContext* opCtx, StringData ident) { + WiredTigerSession* session = WiredTigerRecoveryUnit::get(opCtx)->getSession(opCtx); + session->closeAllCursors(); + string uri = _uri(ident); + return _salvageIfNeeded(uri.c_str()); +} - int rc = (session->verify)(session, uri, NULL); - if (rc == 0) { - log() << "Verify succeeded on uri " << uri << ". Not salvaging."; - return Status::OK(); - } +Status WiredTigerKVEngine::_salvageIfNeeded(const char* uri) { + // Using a side session to avoid transactional issues + WiredTigerSession sessionWrapper(_conn); + WT_SESSION* session = sessionWrapper.getSession(); - if (rc == EBUSY) { - // SERVER-16457: verify and salvage are occasionally failing with EBUSY. For now we - // lie and return OK to avoid breaking tests. This block should go away when that ticket - // is resolved. - error() << "Verify on " << uri << " failed with EBUSY. Assuming no salvage is needed."; - return Status::OK(); - } + int rc = (session->verify)(session, uri, NULL); + if (rc == 0) { + log() << "Verify succeeded on uri " << uri << ". Not salvaging."; + return Status::OK(); + } - // TODO need to cleanup the sizeStorer cache after salvaging. - log() << "Verify failed on uri " << uri << ". Running a salvage operation."; - return wtRCToStatus(session->salvage(session, uri, NULL), "Salvage failed:"); + if (rc == EBUSY) { + // SERVER-16457: verify and salvage are occasionally failing with EBUSY. For now we + // lie and return OK to avoid breaking tests. This block should go away when that ticket + // is resolved. + error() << "Verify on " << uri << " failed with EBUSY. Assuming no salvage is needed."; + return Status::OK(); } - int WiredTigerKVEngine::flushAllFiles( bool sync ) { - LOG(1) << "WiredTigerKVEngine::flushAllFiles"; - syncSizeInfo(true); + // TODO need to cleanup the sizeStorer cache after salvaging. + log() << "Verify failed on uri " << uri << ". Running a salvage operation."; + return wtRCToStatus(session->salvage(session, uri, NULL), "Salvage failed:"); +} - WiredTigerSession session(_conn); - WT_SESSION* s = session.getSession(); - invariantWTOK( s->checkpoint(s, NULL ) ); +int WiredTigerKVEngine::flushAllFiles(bool sync) { + LOG(1) << "WiredTigerKVEngine::flushAllFiles"; + syncSizeInfo(true); - return 1; - } + WiredTigerSession session(_conn); + WT_SESSION* s = session.getSession(); + invariantWTOK(s->checkpoint(s, NULL)); - void WiredTigerKVEngine::syncSizeInfo( bool sync ) const { - if ( !_sizeStorer ) - return; + return 1; +} - try { - _sizeStorer->syncCache(sync); - } - catch (const WriteConflictException&) { - // ignore, we'll try again later. - } - } +void WiredTigerKVEngine::syncSizeInfo(bool sync) const { + if (!_sizeStorer) + return; - RecoveryUnit* WiredTigerKVEngine::newRecoveryUnit() { - return new WiredTigerRecoveryUnit( _sessionCache.get() ); + try { + _sizeStorer->syncCache(sync); + } catch (const WriteConflictException&) { + // ignore, we'll try again later. } +} - void WiredTigerKVEngine::setRecordStoreExtraOptions( const std::string& options ) { - _rsOptions = options; - } +RecoveryUnit* WiredTigerKVEngine::newRecoveryUnit() { + return new WiredTigerRecoveryUnit(_sessionCache.get()); +} - void WiredTigerKVEngine::setSortedDataInterfaceExtraOptions( const std::string& options ) { - _indexOptions = options; - } +void WiredTigerKVEngine::setRecordStoreExtraOptions(const std::string& options) { + _rsOptions = options; +} - Status WiredTigerKVEngine::createRecordStore( OperationContext* opCtx, - StringData ns, - StringData ident, - const CollectionOptions& options ) { - _checkIdentPath( ident ); - WiredTigerSession session(_conn); +void WiredTigerKVEngine::setSortedDataInterfaceExtraOptions(const std::string& options) { + _indexOptions = options; +} - StatusWith<std::string> result = - WiredTigerRecordStore::generateCreateString(ns, options, _rsOptions); - if (!result.isOK()) { - return result.getStatus(); - } - std::string config = result.getValue(); +Status WiredTigerKVEngine::createRecordStore(OperationContext* opCtx, + StringData ns, + StringData ident, + const CollectionOptions& options) { + _checkIdentPath(ident); + WiredTigerSession session(_conn); + + StatusWith<std::string> result = + WiredTigerRecordStore::generateCreateString(ns, options, _rsOptions); + if (!result.isOK()) { + return result.getStatus(); + } + std::string config = result.getValue(); + + string uri = _uri(ident); + WT_SESSION* s = session.getSession(); + LOG(2) << "WiredTigerKVEngine::createRecordStore uri: " << uri << " config: " << config; + return wtRCToStatus(s->create(s, uri.c_str(), config.c_str())); +} - string uri = _uri( ident ); - WT_SESSION* s = session.getSession(); - LOG(2) << "WiredTigerKVEngine::createRecordStore uri: " << uri << " config: " << config; - return wtRCToStatus( s->create( s, uri.c_str(), config.c_str() ) ); +RecordStore* WiredTigerKVEngine::getRecordStore(OperationContext* opCtx, + StringData ns, + StringData ident, + const CollectionOptions& options) { + if (options.capped) { + return new WiredTigerRecordStore(opCtx, + ns, + _uri(ident), + options.capped, + options.cappedSize ? options.cappedSize : 4096, + options.cappedMaxDocs ? options.cappedMaxDocs : -1, + NULL, + _sizeStorer.get()); + } else { + return new WiredTigerRecordStore( + opCtx, ns, _uri(ident), false, -1, -1, NULL, _sizeStorer.get()); } +} + +string WiredTigerKVEngine::_uri(StringData ident) const { + return string("table:") + ident.toString(); +} - RecordStore* WiredTigerKVEngine::getRecordStore( OperationContext* opCtx, - StringData ns, +Status WiredTigerKVEngine::createSortedDataInterface(OperationContext* opCtx, StringData ident, - const CollectionOptions& options ) { - - if (options.capped) { - return new WiredTigerRecordStore(opCtx, ns, _uri(ident), options.capped, - options.cappedSize ? options.cappedSize : 4096, - options.cappedMaxDocs ? options.cappedMaxDocs : -1, - NULL, - _sizeStorer.get() ); - } - else { - return new WiredTigerRecordStore(opCtx, ns, _uri(ident), - false, -1, -1, NULL, _sizeStorer.get() ); - } + const IndexDescriptor* desc) { + _checkIdentPath(ident); + StatusWith<std::string> result = WiredTigerIndex::generateCreateString(_indexOptions, *desc); + if (!result.isOK()) { + return result.getStatus(); } - string WiredTigerKVEngine::_uri( StringData ident ) const { - return string("table:") + ident.toString(); - } + std::string config = result.getValue(); - Status WiredTigerKVEngine::createSortedDataInterface( OperationContext* opCtx, - StringData ident, - const IndexDescriptor* desc ) { - _checkIdentPath( ident ); - StatusWith<std::string> result = - WiredTigerIndex::generateCreateString(_indexOptions, *desc); - if (!result.isOK()) { - return result.getStatus(); - } - - std::string config = result.getValue(); + LOG(2) << "WiredTigerKVEngine::createSortedDataInterface ident: " << ident + << " config: " << config; + return wtRCToStatus(WiredTigerIndex::Create(opCtx, _uri(ident), config)); +} - LOG(2) << "WiredTigerKVEngine::createSortedDataInterface ident: " << ident - << " config: " << config; - return wtRCToStatus(WiredTigerIndex::Create(opCtx, _uri(ident), config)); - } +SortedDataInterface* WiredTigerKVEngine::getSortedDataInterface(OperationContext* opCtx, + StringData ident, + const IndexDescriptor* desc) { + if (desc->unique()) + return new WiredTigerIndexUnique(opCtx, _uri(ident), desc); + return new WiredTigerIndexStandard(opCtx, _uri(ident), desc); +} - SortedDataInterface* WiredTigerKVEngine::getSortedDataInterface( OperationContext* opCtx, - StringData ident, - const IndexDescriptor* desc ) { - if ( desc->unique() ) - return new WiredTigerIndexUnique( opCtx, _uri( ident ), desc ); - return new WiredTigerIndexStandard( opCtx, _uri( ident ), desc ); - } +Status WiredTigerKVEngine::dropIdent(OperationContext* opCtx, StringData ident) { + _drop(ident); + return Status::OK(); +} - Status WiredTigerKVEngine::dropIdent( OperationContext* opCtx, - StringData ident ) { - _drop( ident ); - return Status::OK(); - } +bool WiredTigerKVEngine::_drop(StringData ident) { + string uri = _uri(ident); - bool WiredTigerKVEngine::_drop( StringData ident ) { - string uri = _uri( ident ); + WiredTigerSession session(_conn); - WiredTigerSession session(_conn); + int ret = session.getSession()->drop(session.getSession(), uri.c_str(), "force"); + LOG(1) << "WT drop of " << uri << " res " << ret; - int ret = session.getSession()->drop( session.getSession(), uri.c_str(), "force" ); - LOG(1) << "WT drop of " << uri << " res " << ret; + if (ret == 0) { + // yay, it worked + return true; + } - if ( ret == 0 ) { - // yay, it worked - return true; + if (ret == EBUSY) { + // this is expected, queue it up + { + stdx::lock_guard<stdx::mutex> lk(_identToDropMutex); + _identToDrop.insert(uri); } + _sessionCache->closeAll(); + return false; + } - if ( ret == EBUSY ) { - // this is expected, queue it up - { - stdx::lock_guard<stdx::mutex> lk( _identToDropMutex ); - _identToDrop.insert( uri ); - } - _sessionCache->closeAll(); - return false; - } + invariantWTOK(ret); + return false; +} - invariantWTOK( ret ); - return false; +bool WiredTigerKVEngine::haveDropsQueued() const { + if (_sizeStorerSyncTracker.intervalHasElapsed()) { + _sizeStorerSyncTracker.resetLastTime(); + syncSizeInfo(false); } + stdx::lock_guard<stdx::mutex> lk(_identToDropMutex); + return !_identToDrop.empty(); +} - bool WiredTigerKVEngine::haveDropsQueued() const { - if ( _sizeStorerSyncTracker.intervalHasElapsed() ) { - _sizeStorerSyncTracker.resetLastTime(); - syncSizeInfo(false); - } - stdx::lock_guard<stdx::mutex> lk( _identToDropMutex ); - return !_identToDrop.empty(); +void WiredTigerKVEngine::dropAllQueued() { + set<string> mine; + { + stdx::lock_guard<stdx::mutex> lk(_identToDropMutex); + mine = _identToDrop; } - void WiredTigerKVEngine::dropAllQueued() { - set<string> mine; - { - stdx::lock_guard<stdx::mutex> lk( _identToDropMutex ); - mine = _identToDrop; - } + set<string> deleted; - set<string> deleted; + { + WiredTigerSession session(_conn); + for (set<string>::const_iterator it = mine.begin(); it != mine.end(); ++it) { + string uri = *it; + int ret = session.getSession()->drop(session.getSession(), uri.c_str(), "force"); + LOG(1) << "WT queued drop of " << uri << " res " << ret; - { - WiredTigerSession session(_conn); - for ( set<string>::const_iterator it = mine.begin(); it != mine.end(); ++it ) { - string uri = *it; - int ret = session.getSession()->drop( session.getSession(), uri.c_str(), "force" ); - LOG(1) << "WT queued drop of " << uri << " res " << ret; - - if ( ret == 0 ) { - deleted.insert( uri ); - continue; - } - - if ( ret == EBUSY ) { - // leave in qeuue - continue; - } - - invariantWTOK( ret ); + if (ret == 0) { + deleted.insert(uri); + continue; } - } - { - stdx::lock_guard<stdx::mutex> lk( _identToDropMutex ); - for ( set<string>::const_iterator it = deleted.begin(); it != deleted.end(); ++it ) { - _identToDrop.erase( *it ); + if (ret == EBUSY) { + // leave in qeuue + continue; } - } - } - bool WiredTigerKVEngine::supportsDocLocking() const { - return true; - } - - bool WiredTigerKVEngine::supportsDirectoryPerDB() const { - return true; + invariantWTOK(ret); + } } - bool WiredTigerKVEngine::hasIdent(OperationContext* opCtx, StringData ident) const { - return _hasUri(WiredTigerRecoveryUnit::get(opCtx)->getSession(opCtx)->getSession(), - _uri(ident)); + { + stdx::lock_guard<stdx::mutex> lk(_identToDropMutex); + for (set<string>::const_iterator it = deleted.begin(); it != deleted.end(); ++it) { + _identToDrop.erase(*it); + } } +} - bool WiredTigerKVEngine::_hasUri(WT_SESSION* session, const std::string& uri) const { - // can't use WiredTigerCursor since this is called from constructor. - WT_CURSOR* c = NULL; - int ret = session->open_cursor(session, "metadata:", NULL, NULL, &c); - if (ret == ENOENT) return false; - invariantWTOK(ret); - ON_BLOCK_EXIT(c->close, c); +bool WiredTigerKVEngine::supportsDocLocking() const { + return true; +} - c->set_key(c, uri.c_str()); - return c->search(c) == 0; - } +bool WiredTigerKVEngine::supportsDirectoryPerDB() const { + return true; +} - std::vector<std::string> WiredTigerKVEngine::getAllIdents( OperationContext* opCtx ) const { - std::vector<std::string> all; - WiredTigerCursor cursor( "metadata:", WiredTigerSession::kMetadataCursorId, false, opCtx ); - WT_CURSOR* c = cursor.get(); - if ( !c ) - return all; - - while ( c->next(c) == 0 ) { - const char* raw; - c->get_key(c, &raw ); - StringData key(raw); - size_t idx = key.find( ':' ); - if ( idx == string::npos ) - continue; - StringData type = key.substr( 0, idx ); - if ( type != "table" ) - continue; +bool WiredTigerKVEngine::hasIdent(OperationContext* opCtx, StringData ident) const { + return _hasUri(WiredTigerRecoveryUnit::get(opCtx)->getSession(opCtx)->getSession(), + _uri(ident)); +} - StringData ident = key.substr(idx+1); - if ( ident == "sizeStorer" ) - continue; +bool WiredTigerKVEngine::_hasUri(WT_SESSION* session, const std::string& uri) const { + // can't use WiredTigerCursor since this is called from constructor. + WT_CURSOR* c = NULL; + int ret = session->open_cursor(session, "metadata:", NULL, NULL, &c); + if (ret == ENOENT) + return false; + invariantWTOK(ret); + ON_BLOCK_EXIT(c->close, c); - all.push_back( ident.toString() ); - } + c->set_key(c, uri.c_str()); + return c->search(c) == 0; +} +std::vector<std::string> WiredTigerKVEngine::getAllIdents(OperationContext* opCtx) const { + std::vector<std::string> all; + WiredTigerCursor cursor("metadata:", WiredTigerSession::kMetadataCursorId, false, opCtx); + WT_CURSOR* c = cursor.get(); + if (!c) return all; - } - int WiredTigerKVEngine::reconfigure(const char* str) { - return _conn->reconfigure(_conn, str); + while (c->next(c) == 0) { + const char* raw; + c->get_key(c, &raw); + StringData key(raw); + size_t idx = key.find(':'); + if (idx == string::npos) + continue; + StringData type = key.substr(0, idx); + if (type != "table") + continue; + + StringData ident = key.substr(idx + 1); + if (ident == "sizeStorer") + continue; + + all.push_back(ident.toString()); } - void WiredTigerKVEngine::_checkIdentPath( StringData ident ) { - size_t start = 0; - size_t idx; - while ( ( idx = ident.find( '/', start ) ) != string::npos ) { - StringData dir = ident.substr( 0, idx ); - - boost::filesystem::path subdir = _path; - subdir /= dir.toString(); - if ( !boost::filesystem::exists( subdir ) ) { - LOG(1) << "creating subdirectory: " << dir; - try { - boost::filesystem::create_directory( subdir ); - } - catch (const std::exception& e) { - error() << "error creating path " << subdir.string() << ' ' << e.what(); - throw; - } - } + return all; +} + +int WiredTigerKVEngine::reconfigure(const char* str) { + return _conn->reconfigure(_conn, str); +} - start = idx + 1; +void WiredTigerKVEngine::_checkIdentPath(StringData ident) { + size_t start = 0; + size_t idx; + while ((idx = ident.find('/', start)) != string::npos) { + StringData dir = ident.substr(0, idx); + + boost::filesystem::path subdir = _path; + subdir /= dir.toString(); + if (!boost::filesystem::exists(subdir)) { + LOG(1) << "creating subdirectory: " << dir; + try { + boost::filesystem::create_directory(subdir); + } catch (const std::exception& e) { + error() << "error creating path " << subdir.string() << ' ' << e.what(); + throw; + } } + + start = idx + 1; } } +} |