summaryrefslogtreecommitdiff
path: root/src/mongo/db/server_recovery.h
diff options
context:
space:
mode:
authorKyle Suarez <kyle.suarez@mongodb.com>2018-04-07 10:52:37 -0400
committerKyle Suarez <kyle.suarez@mongodb.com>2018-04-07 10:52:37 -0400
commitfae36f1444627d28bd18e7395962078a729b940a (patch)
treef6a9a94ec8e528eef5c4bb2d404a5997e40c2966 /src/mongo/db/server_recovery.h
parent47e4b6b791cce13a36ea499a9311d54f100412ee (diff)
downloadmongo-fae36f1444627d28bd18e7395962078a729b940a.tar.gz
SERVER-33488 conditionally update WT size metadata during startup recovery
Diffstat (limited to 'src/mongo/db/server_recovery.h')
-rw-r--r--src/mongo/db/server_recovery.h90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/mongo/db/server_recovery.h b/src/mongo/db/server_recovery.h
new file mode 100644
index 00000000000..0fcd6ebc55d
--- /dev/null
+++ b/src/mongo/db/server_recovery.h
@@ -0,0 +1,90 @@
+/**
+ * Copyright (C) 2018 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * 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
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * 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 GNU Affero General 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 <set>
+#include <string>
+
+#include "mongo/db/service_context.h"
+#include "mongo/stdx/mutex.h"
+
+namespace mongo {
+/**
+ * This class is for use with non-MMAPv1 storage engines that track record store sizes in catalog
+ * metadata.
+ *
+ * During normal server operation, we adjust the size metadata for all record stores. But when
+ * performing replication recovery, we avoid doing so, as we trust that the size metadata on disk is
+ * already correct with respect to the end state of recovery.
+ *
+ * However, there may be exceptions that require the server to adjust size metadata even during
+ * recovery. One such case is the oplog: during rollback, the oplog is truncated, and then recovery
+ * occurs using oplog entries after the common point from the sync source. The server will need to
+ * adjust the size metadata for the oplog namespace to ensure that the count of oplog entries is
+ * correct after rollback recovery.
+ *
+ * This class is responsible for keeping track of namespaces that require this special
+ * count adjustment.
+ */
+class SizeRecoveryState {
+public:
+ /**
+ * If replication recovery is ongoing, returns false unless 'ns' is the oplog namespace or has
+ * been specifically marked as requiring adjustment even during recovery.
+ *
+ * If the system is not currently undergoing replication recovery, always returns true.
+ */
+ bool collectionNeedsSizeAdjustment(const std::string& ns) const;
+
+ /**
+ * Mark 'ns' as always requiring size adjustment, even if replication recovery is ongoing.
+ */
+ void markCollectionAsAlwaysNeedsSizeAdjustment(const std::string& ns);
+
+ /**
+ * Clears all internal state. This method should be called when replication recovery ends.
+ */
+ void clearStateAfterRecovery();
+
+private:
+ mutable stdx::mutex _mutex;
+ std::set<std::string> _collectionsAlwaysNeedingSizeAdjustment;
+};
+
+/**
+ * Returns a mutable reference to the single SizeRecoveryState associated with 'serviceCtx'.
+ */
+SizeRecoveryState& sizeRecoveryState(ServiceContext* serviceCtx);
+
+/**
+ * Returns a mutable reference to a boolean decoration on 'serviceCtx', which indicates whether or
+ * not the server is currently undergoing replication recovery.
+ */
+bool& inReplicationRecovery(ServiceContext* serviceCtx);
+} // namespace mongo