summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/chunk_splitter.h
diff options
context:
space:
mode:
authorJoanna Huang <joannahuang@Joannas-MacBook-Pro.local>2017-07-18 13:31:11 -0400
committerJoanna Huang <joannahuang@Joannas-MacBook-Pro.local>2017-07-27 11:00:00 -0400
commit029669a994f92a2f0fe57c5ed06edec871d372ab (patch)
treef769e8cf305faee1175e565f8d71a2706332904c /src/mongo/db/s/chunk_splitter.h
parent74c6b215bc40e1229368cf26434c512ec2e0d433 (diff)
downloadmongo-029669a994f92a2f0fe57c5ed06edec871d372ab.tar.gz
SERVER-30096 Add stepdown/stepup logic to ChunkSplitter
Diffstat (limited to 'src/mongo/db/s/chunk_splitter.h')
-rw-r--r--src/mongo/db/s/chunk_splitter.h42
1 files changed, 35 insertions, 7 deletions
diff --git a/src/mongo/db/s/chunk_splitter.h b/src/mongo/db/s/chunk_splitter.h
index 5f6b62affc3..ee86b4bc4ad 100644
--- a/src/mongo/db/s/chunk_splitter.h
+++ b/src/mongo/db/s/chunk_splitter.h
@@ -32,27 +32,55 @@
namespace mongo {
-class ChunkRange;
class NamespaceString;
-class OperationContext;
-class ThreadPool;
/**
* Handles asynchronous auto-splitting of chunks.
*/
class ChunkSplitter {
+ MONGO_DISALLOW_COPYING(ChunkSplitter);
+
public:
ChunkSplitter();
~ChunkSplitter();
/**
- * Schedules an autosplit task. Returns whether or not the task was successfully scheduled.
+ * Sets the mode of the ChunkSplitter to either primary or secondary.
+ * The ChunkSplitter is only active when primary.
+ */
+ void setReplicaSetMode(bool isPrimary);
+
+ /**
+ * Invoked when the shard server primary enters the 'PRIMARY' state to set up the ChunkSplitter
+ * to begin accepting split requests.
*/
- bool trySplitting(OperationContext* opCtx,
- const NamespaceString& nss,
- const ChunkRange& chunkRange);
+ void initiateChunkSplitter();
+
+ /**
+ * Invoked when this node which is currently serving as a 'PRIMARY' steps down.
+ *
+ * This method might be called multiple times in succession, which is what happens as a result
+ * of incomplete transition to primary so it is resilient to that.
+ */
+ void interruptChunkSplitter();
+
+ /**
+ * Schedules an autosplit task. This function throws on scheduling failure.
+ */
+ void trySplitting(const NamespaceString& nss, const BSONObj& min, const BSONObj& max);
private:
+ /**
+ * Determines if the specified chunk should be split and then performs any necessary split.
+ */
+ void _runAutosplit(const NamespaceString& nss, const BSONObj& min, const BSONObj& max);
+
+ // Protects the state below.
+ stdx::mutex _mutex;
+
+ // The ChunkSplitter is only active on a primary node.
+ bool _isPrimary;
+
// Thread pool for parallelizing splits.
ThreadPool _threadPool;
};