diff options
author | Randolph Tan <randolph@10gen.com> | 2018-12-17 15:15:43 -0500 |
---|---|---|
committer | Randolph Tan <randolph@10gen.com> | 2019-01-11 14:32:51 -0500 |
commit | 891ca0c23f979268fa0b9403500a8a582646613b (patch) | |
tree | 36040158a601bd52385ff01effb78f4deeb9d56b /src/mongo/db/dbhelpers.cpp | |
parent | 3b028cfc6f5ced60c180c340a46d4d06f7ac9815 (diff) | |
download | mongo-891ca0c23f979268fa0b9403500a8a582646613b.tar.gz |
SERVER-38179 Refactor RemoveSaver out of dbhelpers
Diffstat (limited to 'src/mongo/db/dbhelpers.cpp')
-rw-r--r-- | src/mongo/db/dbhelpers.cpp | 128 |
1 files changed, 0 insertions, 128 deletions
diff --git a/src/mongo/db/dbhelpers.cpp b/src/mongo/db/dbhelpers.cpp index d1b5b9518fa..6598b445dcc 100644 --- a/src/mongo/db/dbhelpers.cpp +++ b/src/mongo/db/dbhelpers.cpp @@ -34,9 +34,6 @@ #include "mongo/db/dbhelpers.h" -#include <boost/filesystem/operations.hpp> -#include <fstream> - #include "mongo/db/db_raii.h" #include "mongo/db/exec/working_set_common.h" #include "mongo/db/index/btree_access_method.h" @@ -55,9 +52,6 @@ #include "mongo/db/repl/repl_client_info.h" #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/service_context.h" -#include "mongo/db/storage/data_protector.h" -#include "mongo/db/storage/encryption_hooks.h" -#include "mongo/db/storage/storage_options.h" #include "mongo/db/write_concern.h" #include "mongo/db/write_concern_options.h" #include "mongo/util/log.h" @@ -67,11 +61,8 @@ namespace mongo { using std::unique_ptr; -using std::ios_base; -using std::ofstream; using std::set; using std::string; -using std::stringstream; /* fetch a single object from collection ns that matches query set your db SavedContext first @@ -276,123 +267,4 @@ void Helpers::emptyCollection(OperationContext* opCtx, const NamespaceString& ns deleteObjects(opCtx, collection, nss, BSONObj(), false); } -Helpers::RemoveSaver::RemoveSaver(const string& a, const string& b, const string& why) { - static int NUM = 0; - - _root = storageGlobalParams.dbpath; - if (a.size()) - _root /= a; - if (b.size()) - _root /= b; - verify(a.size() || b.size()); - - _file = _root; - - stringstream ss; - ss << why << "." << terseCurrentTime(false) << "." << NUM++ << ".bson"; - _file /= ss.str(); - - auto encryptionHooks = EncryptionHooks::get(getGlobalServiceContext()); - if (encryptionHooks->enabled()) { - _protector = encryptionHooks->getDataProtector(); - _file += encryptionHooks->getProtectedPathSuffix(); - } -} - -Helpers::RemoveSaver::~RemoveSaver() { - if (_protector && _out) { - auto encryptionHooks = EncryptionHooks::get(getGlobalServiceContext()); - invariant(encryptionHooks->enabled()); - - size_t protectedSizeMax = encryptionHooks->additionalBytesForProtectedBuffer(); - std::unique_ptr<uint8_t[]> protectedBuffer(new uint8_t[protectedSizeMax]); - - size_t resultLen; - Status status = _protector->finalize(protectedBuffer.get(), protectedSizeMax, &resultLen); - if (!status.isOK()) { - severe() << "Unable to finalize DataProtector while closing RemoveSaver: " - << redact(status); - fassertFailed(34350); - } - - _out->write(reinterpret_cast<const char*>(protectedBuffer.get()), resultLen); - if (_out->fail()) { - severe() << "Couldn't write finalized DataProtector data to: " << _file.string() - << " for remove saving: " << redact(errnoWithDescription()); - fassertFailed(34351); - } - - protectedBuffer.reset(new uint8_t[protectedSizeMax]); - status = _protector->finalizeTag(protectedBuffer.get(), protectedSizeMax, &resultLen); - if (!status.isOK()) { - severe() << "Unable to get finalizeTag from DataProtector while closing RemoveSaver: " - << redact(status); - fassertFailed(34352); - } - if (resultLen != _protector->getNumberOfBytesReservedForTag()) { - severe() << "Attempted to write tag of size " << resultLen - << " when DataProtector only reserved " - << _protector->getNumberOfBytesReservedForTag() << " bytes"; - fassertFailed(34353); - } - _out->seekp(0); - _out->write(reinterpret_cast<const char*>(protectedBuffer.get()), resultLen); - if (_out->fail()) { - severe() << "Couldn't write finalizeTag from DataProtector to: " << _file.string() - << " for remove saving: " << redact(errnoWithDescription()); - fassertFailed(34354); - } - } -} - -Status Helpers::RemoveSaver::goingToDelete(const BSONObj& o) { - if (!_out) { - // We don't expect to ever pass "" to create_directories below, but catch - // this anyway as per SERVER-26412. - invariant(!_root.empty()); - boost::filesystem::create_directories(_root); - _out.reset(new ofstream(_file.string().c_str(), ios_base::out | ios_base::binary)); - if (_out->fail()) { - string msg = str::stream() << "couldn't create file: " << _file.string() - << " for remove saving: " << redact(errnoWithDescription()); - error() << msg; - _out.reset(); - _out = 0; - return Status(ErrorCodes::FileNotOpen, msg); - } - } - - const uint8_t* data = reinterpret_cast<const uint8_t*>(o.objdata()); - size_t dataSize = o.objsize(); - - std::unique_ptr<uint8_t[]> protectedBuffer; - if (_protector) { - auto encryptionHooks = EncryptionHooks::get(getGlobalServiceContext()); - invariant(encryptionHooks->enabled()); - - size_t protectedSizeMax = dataSize + encryptionHooks->additionalBytesForProtectedBuffer(); - protectedBuffer.reset(new uint8_t[protectedSizeMax]); - - size_t resultLen; - Status status = _protector->protect( - data, dataSize, protectedBuffer.get(), protectedSizeMax, &resultLen); - if (!status.isOK()) { - return status; - } - - data = protectedBuffer.get(); - dataSize = resultLen; - } - - _out->write(reinterpret_cast<const char*>(data), dataSize); - if (_out->fail()) { - string msg = str::stream() << "couldn't write document to file: " << _file.string() - << " for remove saving: " << redact(errnoWithDescription()); - error() << msg; - return Status(ErrorCodes::OperationFailed, msg); - } - return Status::OK(); -} - - } // namespace mongo |