1
0
Fork 0

Moved the entire logic of open() to the Physical collection. It is different for each StorageEngine.

This commit is contained in:
Michael Hackstein 2017-02-15 16:21:53 +01:00
parent d82e72f7fc
commit 94fbfaa453
4 changed files with 136 additions and 144 deletions

View File

@ -1142,7 +1142,139 @@ void MMFilesCollection::finishCompaction() {
_compactionLock.unlock();
}
/// @brief opens an existing collection
int MMFilesCollection::openWorker(bool ignoreErrors) {
StorageEngine* engine = EngineSelectorFeature::ENGINE;
double start = TRI_microtime();
auto vocbase = _logicalCollection->vocbase();
LOG_TOPIC(TRACE, Logger::PERFORMANCE)
<< "open-collection { collection: " << vocbase->name() << "/" << _logicalCollection->name()
<< " }";
try {
// check for journals and datafiles
int res = engine->openCollection(vocbase, _logicalCollection, ignoreErrors);
if (res != TRI_ERROR_NO_ERROR) {
LOG_TOPIC(DEBUG, arangodb::Logger::FIXME) << "cannot open '" << path() << "', check failed";
return res;
}
LOG_TOPIC(TRACE, Logger::PERFORMANCE)
<< "[timer] " << Logger::FIXED(TRI_microtime() - start)
<< " s, open-collection { collection: " << vocbase->name() << "/"
<< _logicalCollection->name() << " }";
return TRI_ERROR_NO_ERROR;
} catch (basics::Exception const& ex) {
LOG_TOPIC(ERR, arangodb::Logger::FIXME) << "cannot load collection parameter file '" << path()
<< "': " << ex.what();
return ex.code();
} catch (std::exception const& ex) {
LOG_TOPIC(ERR, arangodb::Logger::FIXME) << "cannot load collection parameter file '" << path()
<< "': " << ex.what();
return TRI_ERROR_INTERNAL;
}
}
void MMFilesCollection::open(bool ignoreErrors) {
VPackBuilder builder;
StorageEngine* engine = EngineSelectorFeature::ENGINE;
auto vocbase = _logicalCollection->vocbase();
auto cid = _logicalCollection->cid();
engine->getCollectionInfo(vocbase, cid, builder, true, 0);
VPackSlice initialCount =
builder.slice().get(std::vector<std::string>({"parameters", "count"}));
if (initialCount.isNumber()) {
int64_t count = initialCount.getNumber<int64_t>();
if (count > 0) {
updateCount(count);
}
}
double start = TRI_microtime();
LOG_TOPIC(TRACE, Logger::PERFORMANCE)
<< "open-document-collection { collection: " << vocbase->name() << "/"
<< _logicalCollection->name() << " }";
int res = openWorker(ignoreErrors);
if (res != TRI_ERROR_NO_ERROR) {
THROW_ARANGO_EXCEPTION_MESSAGE(
res,
std::string("cannot open document collection from path '") + path() +
"': " + TRI_errno_string(res));
}
arangodb::SingleCollectionTransaction trx(
arangodb::StandaloneTransactionContext::Create(vocbase), cid,
AccessMode::Type::WRITE);
// build the primary index
double startIterate = TRI_microtime();
LOG_TOPIC(TRACE, Logger::PERFORMANCE)
<< "iterate-markers { collection: " << vocbase->name() << "/" << _logicalCollection->name()
<< " }";
// iterate over all markers of the collection
res = iterateMarkersOnLoad(&trx);
LOG_TOPIC(TRACE, Logger::PERFORMANCE)
<< "[timer] " << Logger::FIXED(TRI_microtime() - startIterate)
<< " s, iterate-markers { collection: " << vocbase->name() << "/"
<< _logicalCollection->name() << " }";
if (res != TRI_ERROR_NO_ERROR) {
THROW_ARANGO_EXCEPTION_MESSAGE(
res,
std::string("cannot iterate data of document collection: ") +
TRI_errno_string(res));
}
// build the indexes meta-data, but do not fill the indexes yet
{
auto old = _logicalCollection->useSecondaryIndexes();
// turn filling of secondary indexes off. we're now only interested in
// getting
// the indexes' definition. we'll fill them below ourselves.
_logicalCollection->useSecondaryIndexes(false);
try {
_logicalCollection->detectIndexes(&trx);
_logicalCollection->useSecondaryIndexes(old);
} catch (basics::Exception const& ex) {
_logicalCollection->useSecondaryIndexes(old);
THROW_ARANGO_EXCEPTION_MESSAGE(
ex.code(),
std::string("cannot initialize collection indexes: ") + ex.what());
} catch (std::exception const& ex) {
_logicalCollection->useSecondaryIndexes(old);
THROW_ARANGO_EXCEPTION_MESSAGE(
TRI_ERROR_INTERNAL,
std::string("cannot initialize collection indexes: ") + ex.what());
} catch (...) {
_logicalCollection->useSecondaryIndexes(old);
THROW_ARANGO_EXCEPTION_MESSAGE(
TRI_ERROR_INTERNAL,
"cannot initialize collection indexes: unknown exception");
}
}
if (!engine->inRecovery()) {
// build the index structures, and fill the indexes
_logicalCollection->fillIndexes(&trx, *(_logicalCollection->indexList()));
}
LOG_TOPIC(TRACE, Logger::PERFORMANCE)
<< "[timer] " << Logger::FIXED(TRI_microtime() - start)
<< " s, open-document-collection { collection: " << vocbase->name()
<< "/" << _logicalCollection->name() << " }";
// successfully opened collection. now adjust version number
if (_logicalCollection->version() != LogicalCollection::VERSION_31 && !_revisionError &&
application_features::ApplicationServer::server

View File

@ -294,6 +294,8 @@ class MMFilesCollection final : public PhysicalCollection {
private:
int openWorker(bool ignoreErrors);
int removeFastPath(arangodb::transaction::Methods* trx,
TRI_voc_rid_t oldRevisionId,
arangodb::velocypack::Slice const oldDoc,

View File

@ -226,8 +226,7 @@ LogicalCollection::LogicalCollection(LogicalCollection const& other)
_physical(EngineSelectorFeature::ENGINE->createPhysicalCollection(this)),
_useSecondaryIndexes(true),
_maxTick(0),
_keyGenerator(),
_isInitialIteration(false) {
_keyGenerator() {
_keyGenerator.reset(KeyGenerator::factory(other.keyOptions()));
if (ServerState::instance()->isDBServer() ||
@ -284,8 +283,7 @@ LogicalCollection::LogicalCollection(TRI_vocbase_t* vocbase,
_physical(EngineSelectorFeature::ENGINE->createPhysicalCollection(this)),
_useSecondaryIndexes(true),
_maxTick(0),
_keyGenerator(),
_isInitialIteration(false) {
_keyGenerator() {
getPhysical()->setPath(ReadStringValue(info, "path", ""));
if (!IsAllowedName(info)) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_ILLEGAL_NAME);
@ -1189,142 +1187,10 @@ std::shared_ptr<arangodb::velocypack::Builder> LogicalCollection::figures() {
/// @brief opens an existing collection
void LogicalCollection::open(bool ignoreErrors) {
VPackBuilder builder;
StorageEngine* engine = EngineSelectorFeature::ENGINE;
engine->getCollectionInfo(_vocbase, cid(), builder, true, 0);
VPackSlice initialCount =
builder.slice().get(std::vector<std::string>({"parameters", "count"}));
if (initialCount.isNumber()) {
int64_t count = initialCount.getNumber<int64_t>();
if (count > 0) {
_physical->updateCount(count);
}
}
double start = TRI_microtime();
LOG_TOPIC(TRACE, Logger::PERFORMANCE)
<< "open-document-collection { collection: " << _vocbase->name() << "/"
<< _name << " }";
int res = openWorker(ignoreErrors);
if (res != TRI_ERROR_NO_ERROR) {
THROW_ARANGO_EXCEPTION_MESSAGE(
res,
std::string("cannot open document collection from path '") + getPhysical()->path() +
"': " + TRI_errno_string(res));
}
arangodb::SingleCollectionTransaction trx(
arangodb::StandaloneTransactionContext::Create(_vocbase), cid(),
AccessMode::Type::WRITE);
// build the primary index
double startIterate = TRI_microtime();
LOG_TOPIC(TRACE, Logger::PERFORMANCE)
<< "iterate-markers { collection: " << _vocbase->name() << "/" << _name
<< " }";
_isInitialIteration = true;
// iterate over all markers of the collection
res = getPhysical()->iterateMarkersOnLoad(&trx);
LOG_TOPIC(TRACE, Logger::PERFORMANCE)
<< "[timer] " << Logger::FIXED(TRI_microtime() - startIterate)
<< " s, iterate-markers { collection: " << _vocbase->name() << "/"
<< _name << " }";
if (res != TRI_ERROR_NO_ERROR) {
THROW_ARANGO_EXCEPTION_MESSAGE(
res,
std::string("cannot iterate data of document collection: ") +
TRI_errno_string(res));
}
_isInitialIteration = false;
// build the indexes meta-data, but do not fill the indexes yet
{
auto old = useSecondaryIndexes();
// turn filling of secondary indexes off. we're now only interested in
// getting
// the indexes' definition. we'll fill them below ourselves.
useSecondaryIndexes(false);
try {
detectIndexes(&trx);
useSecondaryIndexes(old);
} catch (basics::Exception const& ex) {
useSecondaryIndexes(old);
THROW_ARANGO_EXCEPTION_MESSAGE(
ex.code(),
std::string("cannot initialize collection indexes: ") + ex.what());
} catch (std::exception const& ex) {
useSecondaryIndexes(old);
THROW_ARANGO_EXCEPTION_MESSAGE(
TRI_ERROR_INTERNAL,
std::string("cannot initialize collection indexes: ") + ex.what());
} catch (...) {
useSecondaryIndexes(old);
THROW_ARANGO_EXCEPTION_MESSAGE(
TRI_ERROR_INTERNAL,
"cannot initialize collection indexes: unknown exception");
}
}
if (!engine->inRecovery()) {
// build the index structures, and fill the indexes
fillIndexes(&trx, *(indexList()));
}
LOG_TOPIC(TRACE, Logger::PERFORMANCE)
<< "[timer] " << Logger::FIXED(TRI_microtime() - start)
<< " s, open-document-collection { collection: " << _vocbase->name()
<< "/" << _name << " }";
getPhysical()->open(ignoreErrors);
TRI_UpdateTickServer(_cid);
}
/// @brief opens an existing collection
int LogicalCollection::openWorker(bool ignoreErrors) {
StorageEngine* engine = EngineSelectorFeature::ENGINE;
double start = TRI_microtime();
LOG_TOPIC(TRACE, Logger::PERFORMANCE)
<< "open-collection { collection: " << _vocbase->name() << "/" << name()
<< " }";
try {
// check for journals and datafiles
int res = engine->openCollection(_vocbase, this, ignoreErrors);
if (res != TRI_ERROR_NO_ERROR) {
LOG_TOPIC(DEBUG, arangodb::Logger::FIXME) << "cannot open '" << getPhysical()->path() << "', check failed";
return res;
}
LOG_TOPIC(TRACE, Logger::PERFORMANCE)
<< "[timer] " << Logger::FIXED(TRI_microtime() - start)
<< " s, open-collection { collection: " << _vocbase->name() << "/"
<< name() << " }";
return TRI_ERROR_NO_ERROR;
} catch (basics::Exception const& ex) {
LOG_TOPIC(ERR, arangodb::Logger::FIXME) << "cannot load collection parameter file '" << getPhysical()->path()
<< "': " << ex.what();
return ex.code();
} catch (std::exception const& ex) {
LOG_TOPIC(ERR, arangodb::Logger::FIXME) << "cannot load collection parameter file '" << getPhysical()->path()
<< "': " << ex.what();
return TRI_ERROR_INTERNAL;
}
}
/// SECTION Indexes
std::shared_ptr<Index> LogicalCollection::lookupIndex(

View File

@ -106,8 +106,6 @@ class LogicalCollection {
static bool IsAllowedName(velocypack::Slice parameters);
static bool IsAllowedName(bool isSystem, std::string const& name);
void isInitialIteration(bool value) { _isInitialIteration = value; }
// TODO: MOVE TO PHYSICAL?
bool isFullyCollected(); //should not be exposed
@ -363,8 +361,6 @@ class LogicalCollection {
/// @brief creates the initial indexes for the collection
void createInitialIndexes();
int openWorker(bool ignoreErrors);
bool removeIndex(TRI_idx_iid_t iid);
void addIndex(std::shared_ptr<Index>);
@ -496,10 +492,6 @@ class LogicalCollection {
mutable basics::ReadWriteLock
_infoLock; // lock protecting the info
/// @brief: flag that is set to true when the documents are
/// initial enumerated and the primary index is built
bool _isInitialIteration;
};
} // namespace arangodb