From 5324a6bbe82646ad815c4b11877243824ff3ba2c Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Tue, 8 Nov 2016 10:29:53 +0100 Subject: [PATCH] fix _rev handling when creating collections --- arangod/StorageEngine/MMFilesCollection.cpp | 2 +- arangod/VocBase/LogicalCollection.cpp | 5 ++++- arangod/VocBase/LogicalCollection.h | 2 ++ arangod/VocBase/vocbase.cpp | 4 +++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/arangod/StorageEngine/MMFilesCollection.cpp b/arangod/StorageEngine/MMFilesCollection.cpp index 68909e179e..43f6194d09 100644 --- a/arangod/StorageEngine/MMFilesCollection.cpp +++ b/arangod/StorageEngine/MMFilesCollection.cpp @@ -1086,7 +1086,7 @@ int MMFilesCollection::iterateMarkersOnLoad(arangodb::Transaction* trx) { << openState._deletions << " deletion markers for collection '" << _logicalCollection->name() << "'"; if (_logicalCollection->version() <= LogicalCollection::VERSION_30 && - _lastRevision >= static_cast(2016 - 1970) * 1000 * 60 * 60 * 24 * 365 && + _lastRevision >= static_cast(2016ULL - 1970ULL) * 1000ULL * 60ULL * 60ULL * 24ULL * 365ULL && application_features::ApplicationServer::server->getFeature("Database")->check30Revisions()) { // a collection from 3.0 or earlier with a _rev value that is higher than we can handle safely _logicalCollection->setRevisionError(); diff --git a/arangod/VocBase/LogicalCollection.cpp b/arangod/VocBase/LogicalCollection.cpp index 5db5a3eb57..fd5e233e9b 100644 --- a/arangod/VocBase/LogicalCollection.cpp +++ b/arangod/VocBase/LogicalCollection.cpp @@ -398,7 +398,7 @@ LogicalCollection::LogicalCollection(TRI_vocbase_t* vocbase, _lastCompactionStamp(0.0), _uncollectedLogfileEntries(0), _revisionError(false) { - + if (!IsAllowedName(info)) { THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_ILLEGAL_NAME); } @@ -410,6 +410,9 @@ LogicalCollection::LogicalCollection(TRI_vocbase_t* vocbase, "with the --database.auto-upgrade option."); THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_FAILED, errorMsg); + } else if (info.hasKey("indexes") && _version == VERSION_30) { + // already a 3.1 collection. upgrade the _version data + setVersion(VERSION_31); } if (_isVolatile && _waitForSync) { diff --git a/arangod/VocBase/LogicalCollection.h b/arangod/VocBase/LogicalCollection.h index e831c6a9e4..a686bae06b 100644 --- a/arangod/VocBase/LogicalCollection.h +++ b/arangod/VocBase/LogicalCollection.h @@ -134,6 +134,8 @@ class LogicalCollection { uint32_t version() const { return _version; } + + void setVersion(CollectionVersions version) { _version = version; } uint32_t internalVersion() const; diff --git a/arangod/VocBase/vocbase.cpp b/arangod/VocBase/vocbase.cpp index 6ba1e9964d..8aba9b5e50 100644 --- a/arangod/VocBase/vocbase.cpp +++ b/arangod/VocBase/vocbase.cpp @@ -308,6 +308,8 @@ arangodb::LogicalCollection* TRI_vocbase_t::createCollectionWorker( cid = collection->cid(); collection->setStatus(TRI_VOC_COL_STATUS_LOADED); + // set collection version to 3.1, as the collection is just created + collection->setVersion(LogicalCollection::VERSION_31); if (writeMarker) { collection->toVelocyPack(builder, false); @@ -1302,7 +1304,7 @@ void TRI_SanitizeObjectWithEdges(VPackSlice const slice, VPackBuilder& builder) /// @brief Convert a revision ID to a string constexpr static TRI_voc_rid_t tickLimit - = static_cast(2016 - 1970) * 1000 * 60 * 60 * 24 * 365; + = static_cast(2016ULL - 1970ULL) * 1000ULL * 60ULL * 60ULL * 24ULL * 365ULL; std::string TRI_RidToString(TRI_voc_rid_t rid) { if (rid <= tickLimit) {