summaryrefslogtreecommitdiff
path: root/src/mongo/db/storage/remove_saver.h
diff options
context:
space:
mode:
authorRandolph Tan <randolph@10gen.com>2018-12-17 15:15:43 -0500
committerRandolph Tan <randolph@10gen.com>2019-01-11 14:32:51 -0500
commit891ca0c23f979268fa0b9403500a8a582646613b (patch)
tree36040158a601bd52385ff01effb78f4deeb9d56b /src/mongo/db/storage/remove_saver.h
parent3b028cfc6f5ced60c180c340a46d4d06f7ac9815 (diff)
downloadmongo-891ca0c23f979268fa0b9403500a8a582646613b.tar.gz
SERVER-38179 Refactor RemoveSaver out of dbhelpers
Diffstat (limited to 'src/mongo/db/storage/remove_saver.h')
-rw-r--r--src/mongo/db/storage/remove_saver.h85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/mongo/db/storage/remove_saver.h b/src/mongo/db/storage/remove_saver.h
new file mode 100644
index 00000000000..78057622444
--- /dev/null
+++ b/src/mongo/db/storage/remove_saver.h
@@ -0,0 +1,85 @@
+
+/**
+ * Copyright (C) 2018-present MongoDB, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the Server Side Public License, version 1,
+ * as published by MongoDB, Inc.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Server Side Public License for more details.
+ *
+ * You should have received a copy of the Server Side Public License
+ * along with this program. If not, see
+ * <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the Server Side Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#pragma once
+
+#include <boost/filesystem/path.hpp>
+#include <memory>
+#include <ostream>
+#include <string>
+
+#include "mongo/base/disallow_copying.h"
+#include "mongo/base/status.h"
+#include "mongo/db/jsobj.h"
+#include "mongo/db/storage/data_protector.h"
+
+namespace mongo {
+
+/**
+ * for saving deleted bson objects to a flat file
+ */
+class RemoveSaver {
+ MONGO_DISALLOW_COPYING(RemoveSaver);
+
+public:
+ RemoveSaver(const std::string& type, const std::string& ns, const std::string& why);
+ ~RemoveSaver();
+
+ /**
+ * Writes document to file. File is created lazily before writing the first document.
+ * Returns error status if the file could not be created or if there were errors writing
+ * to the file.
+ */
+ Status goingToDelete(const BSONObj& o);
+
+ /**
+ * A path object describing the directory containing the file with deleted documents.
+ */
+ const auto& root() const& {
+ return _root;
+ }
+ void root() && = delete;
+
+ /**
+ * A path object describing the actual file containing BSON documents.
+ */
+ const auto& file() const& {
+ return _file;
+ }
+ void file() && = delete;
+
+private:
+ boost::filesystem::path _root;
+ boost::filesystem::path _file;
+ std::unique_ptr<DataProtector> _protector;
+ std::unique_ptr<std::ostream> _out;
+};
+
+} // namespace mongo