diff options
author | Igor Canadi <icanadi@fb.com> | 2015-01-30 10:08:26 -0800 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2015-02-03 18:32:13 -0500 |
commit | 6015a7b55ce7216ed9d511cf3b363dc8af5d96be (patch) | |
tree | 90be18343b5c75347f24f9f7330087e2a6af5341 | |
parent | 51fdd6114daa0cfb5c27a2d0116f05ceae8ad211 (diff) | |
download | mongo-6015a7b55ce7216ed9d511cf3b363dc8af5d96be.tar.gz |
SERVER-17133 Fail verbosely when RocksDB's disk format changes
Signed-off-by: Benety Goh <benety@mongodb.com>
-rw-r--r-- | src/mongo/db/storage/rocks/rocks_init.cpp | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/mongo/db/storage/rocks/rocks_init.cpp b/src/mongo/db/storage/rocks/rocks_init.cpp index 0feef149ce1..9442d5c30d5 100644 --- a/src/mongo/db/storage/rocks/rocks_init.cpp +++ b/src/mongo/db/storage/rocks/rocks_init.cpp @@ -35,6 +35,8 @@ #include "mongo/db/global_environment_experiment.h" #include "mongo/db/storage_options.h" #include "mongo/db/storage/kv/kv_storage_engine.h" +#include "mongo/db/storage/storage_engine_metadata.h" +#include "mongo/util/mongoutils/str.h" namespace mongo { @@ -67,12 +69,38 @@ namespace mongo { virtual Status validateMetadata(const StorageEngineMetadata& metadata, const StorageGlobalParams& params) const { + const BSONObj& options = metadata.getStorageEngineOptions(); + BSONElement element = options.getField(kRocksFormatVersionString); + if (element.eoo() || !element.isNumber()) { + return Status(ErrorCodes::UnsupportedFormat, + "Storage engine metadata format not recognized. If you created " + "this database with older version of mongo, please reload the " + "database using mongodump and mongorestore"); + } + if (element.numberInt() != kRocksFormatVersion) { + return Status( + ErrorCodes::UnsupportedFormat, + str::stream() + << "Database created with format version " << element.numberInt() + << " and this version only supports format version " + << kRocksFormatVersion + << ". Please reload the database using mongodump and mongorestore"); + } return Status::OK(); } virtual BSONObj createMetadataOptions(const StorageGlobalParams& params) const { - return BSONObj(); + BSONObjBuilder builder; + builder.append(kRocksFormatVersionString, kRocksFormatVersion); + return builder.obj(); } + + private: + // Current disk format. We bump this number when we change the disk format. MongoDB will + // fail to start if the versions don't match. In that case a user needs to run mongodump + // and mongorestore. + const int kRocksFormatVersion = 1; + const std::string kRocksFormatVersionString = "rocksFormatVersion"; }; } // namespace |