1
0
Fork 0

[3.4] Updates to collection versioning. (#7260)

This commit is contained in:
Dan Larkin-York 2018-11-19 03:45:09 -05:00 committed by Jan
parent 4362137ba4
commit 4210d9eab6
4 changed files with 61 additions and 34 deletions

View File

@ -1922,21 +1922,10 @@ void MMFilesCollection::open(bool ignoreErrors) {
} }
// successfully opened collection. now adjust version number // successfully opened collection. now adjust version number
if (LogicalCollection::VERSION_33 != _logicalCollection.version()) { if (LogicalCollection::currentVersion() != _logicalCollection.version()
_logicalCollection.setVersion(LogicalCollection::VERSION_33); && !engine->upgrading()) {
setCurrentVersion();
bool const doSync = // updates have already happened elsewhere, it is safe to bump the number
application_features::ApplicationServer::getFeature<DatabaseFeature>(
"Database")
->forceSyncProperties();
StorageEngine* engine = EngineSelectorFeature::ENGINE;
engine->changeCollection(
_logicalCollection.vocbase(),
_logicalCollection.id(),
_logicalCollection,
doSync
);
} }
} }
@ -3140,6 +3129,13 @@ void MMFilesCollection::removeLocalDocumentId(LocalDocumentId const& documentId,
} }
} }
bool MMFilesCollection::hasAllPersistentLocalIds() const {
TRI_ASSERT(_hasAllPersistentLocalIds.load() !=
(_logicalCollection.version() <
LogicalCollection::CollectionVersions::VERSION_34));
return _hasAllPersistentLocalIds.load();
}
Result MMFilesCollection::persistLocalDocumentIdsForDatafile( Result MMFilesCollection::persistLocalDocumentIdsForDatafile(
MMFilesCollection& collection, MMFilesDatafile& file) { MMFilesCollection& collection, MMFilesDatafile& file) {
Result res; Result res;
@ -3185,6 +3181,12 @@ Result MMFilesCollection::persistLocalDocumentIdsForDatafile(
} }
Result MMFilesCollection::persistLocalDocumentIds() { Result MMFilesCollection::persistLocalDocumentIds() {
if (_logicalCollection.version() >=
LogicalCollection::CollectionVersions::VERSION_34) {
// already good, just continue
return Result();
}
WRITE_LOCKER(dataLocker, _dataLock); WRITE_LOCKER(dataLocker, _dataLock);
TRI_ASSERT(_compactors.empty()); TRI_ASSERT(_compactors.empty());
@ -3210,9 +3212,27 @@ Result MMFilesCollection::persistLocalDocumentIds() {
TRI_ASSERT(_compactors.empty()); TRI_ASSERT(_compactors.empty());
TRI_ASSERT(_journals.empty()); TRI_ASSERT(_journals.empty());
// mark collection as upgraded so we can avoid re-checking
setCurrentVersion();
return Result(); return Result();
} }
void MMFilesCollection::setCurrentVersion() {
_logicalCollection.setVersion(
static_cast<LogicalCollection::CollectionVersions>(
LogicalCollection::currentVersion()));
bool const doSync =
application_features::ApplicationServer::getFeature<DatabaseFeature>(
"Database")
->forceSyncProperties();
StorageEngine* engine = EngineSelectorFeature::ENGINE;
engine->changeCollection(_logicalCollection.vocbase(),
_logicalCollection.id(), _logicalCollection, doSync);
}
/// @brief creates a new entry in the primary index /// @brief creates a new entry in the primary index
Result MMFilesCollection::insertPrimaryIndex(transaction::Methods* trx, Result MMFilesCollection::insertPrimaryIndex(transaction::Methods* trx,
LocalDocumentId const& documentId, LocalDocumentId const& documentId,

View File

@ -535,10 +535,12 @@ class MMFilesCollection final : public PhysicalCollection {
LocalDocumentId reuseOrCreateLocalDocumentId(OperationOptions const& options) const; LocalDocumentId reuseOrCreateLocalDocumentId(OperationOptions const& options) const;
bool hasAllPersistentLocalIds() const { return _hasAllPersistentLocalIds.load(); } bool hasAllPersistentLocalIds() const;
static Result persistLocalDocumentIdsForDatafile( static Result persistLocalDocumentIdsForDatafile(
MMFilesCollection& collection, MMFilesDatafile& file); MMFilesCollection& collection, MMFilesDatafile& file);
void setCurrentVersion();
private: private:
mutable arangodb::MMFilesDitches _ditches; mutable arangodb::MMFilesDitches _ditches;

View File

@ -89,7 +89,12 @@ class LogicalCollection : public LogicalDataSource {
LogicalCollection& operator=(LogicalCollection const&) = delete; LogicalCollection& operator=(LogicalCollection const&) = delete;
virtual ~LogicalCollection(); virtual ~LogicalCollection();
enum CollectionVersions { VERSION_30 = 5, VERSION_31 = 6, VERSION_33 = 7 }; enum CollectionVersions {
VERSION_30 = 5,
VERSION_31 = 6,
VERSION_33 = 7,
VERSION_34 = 8
};
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
/// @brief the category representing a logical collection /// @brief the category representing a logical collection
@ -99,7 +104,7 @@ class LogicalCollection : public LogicalDataSource {
/// @brief hard-coded minimum version number for collections /// @brief hard-coded minimum version number for collections
static constexpr uint32_t minimumVersion() { return VERSION_30; } static constexpr uint32_t minimumVersion() { return VERSION_30; }
/// @brief current version for collections /// @brief current version for collections
static constexpr uint32_t currentVersion() { return VERSION_33; } static constexpr uint32_t currentVersion() { return VERSION_34; }
// SECTION: Meta Information // SECTION: Meta Information
uint32_t version() const { return _version; } uint32_t version() const { return _version; }

View File

@ -23,7 +23,7 @@ const anonymize = function(doc) {
} }
if (doc === null || typeof doc === 'number' || typeof doc === 'boolean') { if (doc === null || typeof doc === 'number' || typeof doc === 'boolean') {
return doc; return doc;
} }
if (typeof doc === 'object') { if (typeof doc === 'object') {
let result = {}; let result = {};
Object.keys(doc).forEach(function(key) { Object.keys(doc).forEach(function(key) {
@ -248,8 +248,8 @@ function printStats (stats) {
stats.executionTime = stats.executionTime.toFixed(5); stats.executionTime = stats.executionTime.toFixed(5);
stringBuilder.appendLine(' ' + header('Writes Exec') + ' ' + header('Writes Ign') + ' ' + header('Scan Full') + ' ' + stringBuilder.appendLine(' ' + header('Writes Exec') + ' ' + header('Writes Ign') + ' ' + header('Scan Full') + ' ' +
header('Scan Index') + ' ' + header('Filtered') + ' ' + header('Exec Time [s]')); header('Scan Index') + ' ' + header('Filtered') + ' ' + header('Exec Time [s]'));
stringBuilder.appendLine(' ' + pad(1 + maxWELen - String(stats.writesExecuted).length) + value(stats.writesExecuted) + ' ' + stringBuilder.appendLine(' ' + pad(1 + maxWELen - String(stats.writesExecuted).length) + value(stats.writesExecuted) + ' ' +
pad(1 + maxWILen - String(stats.writesIgnored).length) + value(stats.writesIgnored) + ' ' + pad(1 + maxWILen - String(stats.writesIgnored).length) + value(stats.writesIgnored) + ' ' +
pad(1 + maxSFLen - String(stats.scannedFull).length) + value(stats.scannedFull) + ' ' + pad(1 + maxSFLen - String(stats.scannedFull).length) + value(stats.scannedFull) + ' ' +
pad(1 + maxSILen - String(stats.scannedIndex).length) + value(stats.scannedIndex) + ' ' + pad(1 + maxSILen - String(stats.scannedIndex).length) + value(stats.scannedIndex) + ' ' +
@ -335,7 +335,7 @@ function printIndexes (indexes) {
var ranges; var ranges;
if (indexes[i].hasOwnProperty('condition')) { if (indexes[i].hasOwnProperty('condition')) {
ranges = indexes[i].condition; ranges = indexes[i].condition;
} else { } else {
ranges = '[ ' + indexes[i].ranges + ' ]'; ranges = '[ ' + indexes[i].ranges + ' ]';
} }
@ -382,7 +382,7 @@ function printFunctions (functions) {
maxNameLen = l; maxNameLen = l;
} }
}); });
let line = ' ' + let line = ' ' +
header('Name') + pad(1 + maxNameLen - 'Name'.length) + ' ' + header('Name') + pad(1 + maxNameLen - 'Name'.length) + ' ' +
header('Deterministic') + pad(1 + maxDeterministicLen - 'Deterministic'.length) + ' ' + header('Deterministic') + pad(1 + maxDeterministicLen - 'Deterministic'.length) + ' ' +
header('Cacheable') + pad(1 + maxCacheableLen - 'Cacheable'.length) + ' ' + header('Cacheable') + pad(1 + maxCacheableLen - 'Cacheable'.length) + ' ' +
@ -974,7 +974,7 @@ function processQuery (query, explain) {
} }
return ''; return '';
}; };
var iterateIndexes = function (idx, i, node, types, variable) { var iterateIndexes = function (idx, i, node, types, variable) {
var what = (node.reverse ? 'reverse ' : '') + idx.type + ' index scan' + ((node.producesResult || !node.hasOwnProperty('producesResult')) ? (node.indexCoversProjections ? ', index only' : '') : ', scan only'); var what = (node.reverse ? 'reverse ' : '') + idx.type + ' index scan' + ((node.producesResult || !node.hasOwnProperty('producesResult')) ? (node.indexCoversProjections ? ', index only' : '') : ', scan only');
if (types.length === 0 || what !== types[types.length - 1]) { if (types.length === 0 || what !== types[types.length - 1]) {
@ -1720,8 +1720,8 @@ function debug(query, bindVars, options) {
if (v === null) { if (v === null) {
return; return;
} }
result.views[collection.name] = { result.views[collection.name] = {
type: v.type(), type: v.type(),
properties: v.properties() properties: v.properties()
}; };
@ -1730,7 +1730,7 @@ function debug(query, bindVars, options) {
let examples; let examples;
if (input.options.examples) { if (input.options.examples) {
// include example data from collections // include example data from collections
let max = 10; // default number of documents let max = 10; // default number of documents
if (typeof input.options.examples === 'number') { if (typeof input.options.examples === 'number') {
max = input.options.examples; max = input.options.examples;
} }
@ -1744,7 +1744,7 @@ function debug(query, bindVars, options) {
examples = examples.map(anonymize); examples = examples.map(anonymize);
} }
} }
result.collections[collection.name] = { result.collections[collection.name] = {
type: c.type(), type: c.type(),
properties: c.properties(), properties: c.properties(),
indexes: c.getIndexes(true), indexes: c.getIndexes(true),
@ -1754,7 +1754,7 @@ function debug(query, bindVars, options) {
}; };
} }
}); });
result.graphs = graphs; result.graphs = graphs;
return result; return result;
} }
@ -1809,7 +1809,7 @@ function inspectDump(filename, outfile) {
print(); print();
}); });
print(); print();
// insert example data // insert example data
print("/* example data */"); print("/* example data */");
Object.keys(data.collections).forEach(function(collection) { Object.keys(data.collections).forEach(function(collection) {
@ -1838,12 +1838,12 @@ function inspectDump(filename, outfile) {
print("db._createView(" + JSON.stringify(view) + ", " + JSON.stringify(details.type) + ", " + JSON.stringify(details.properties) + ");"); print("db._createView(" + JSON.stringify(view) + ", " + JSON.stringify(details.type) + ", " + JSON.stringify(details.properties) + ");");
}); });
print(); print();
print("/* explain result */"); print("/* explain result */");
print(data.fancy.trim().split(/\n/).map(function(line) { return "// " + line; }).join("\n")); print(data.fancy.trim().split(/\n/).map(function(line) { return "// " + line; }).join("\n"));
print(); print();
print("/* explain command */"); print("/* explain command */");
if (data.query.options) { if (data.query.options) {
delete data.query.options.anonymize; delete data.query.options.anonymize;
delete data.query.options.colors; delete data.query.options.colors;