summaryrefslogtreecommitdiff
path: root/src/replication.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/replication.c')
-rw-r--r--src/replication.c65
1 files changed, 28 insertions, 37 deletions
diff --git a/src/replication.c b/src/replication.c
index 99f233380..12500c0af 100644
--- a/src/replication.c
+++ b/src/replication.c
@@ -39,7 +39,6 @@
#include <sys/socket.h>
#include <sys/stat.h>
-long long adjustMeaningfulReplOffset();
void replicationDiscardCachedMaster(void);
void replicationResurrectCachedMaster(connection *conn);
void replicationSendAck(void);
@@ -2755,10 +2754,6 @@ void replicationCacheMaster(client *c) {
* pending outputs to the master. */
sdsclear(server.master->querybuf);
sdsclear(server.master->pending_querybuf);
-
- /* Adjust reploff and read_reploff to the last meaningful offset we
- * executed. This is the offset the replica will use for future PSYNC. */
- server.master->reploff = adjustMeaningfulReplOffset();
server.master->read_reploff = server.master->reploff;
if (c->flags & CLIENT_MULTI) discardTransaction(c);
listEmpty(c->reply);
@@ -2783,15 +2778,33 @@ void replicationCacheMaster(client *c) {
replicationHandleMasterDisconnection();
}
-/* If the "meaningful" offset, that is the offset without the final PINGs
- * in the stream, is different than the last offset, use it instead:
- * often when the master is no longer reachable, replicas will never
- * receive the PINGs, however the master will end with an incremented
- * offset because of the PINGs and will not be able to incrementally
- * PSYNC with the new master.
- * This function trims the replication backlog when needed, and returns
- * the offset to be used for future partial sync. */
-long long adjustMeaningfulReplOffset() {
+/* This function is called when a master is turend into a slave, in order to
+ * create from scratch a cached master for the new client, that will allow
+ * to PSYNC with the slave that was promoted as the new master after a
+ * failover.
+ *
+ * Assuming this instance was previously the master instance of the new master,
+ * the new master will accept its replication ID, and potentiall also the
+ * current offset if no data was lost during the failover. So we use our
+ * current replication ID and offset in order to synthesize a cached master. */
+void replicationCacheMasterUsingMyself(void) {
+ serverLog(LL_NOTICE,
+ "Before turning into a replica, using my own master parameters "
+ "to synthesize a cached master: I may be able to synchronize with "
+ "the new master with just a partial transfer.");
+
+ /* This will be used to populate the field server.master->reploff
+ * by replicationCreateMasterClient(). We'll later set the created
+ * master as server.cached_master, so the replica will use such
+ * offset for PSYNC. */
+ server.master_initial_offset = server.master_repl_offset;
+
+ /* However if the "meaningful" offset, that is the offset without
+ * the final PINGs in the stream, is different, use this instead:
+ * often when the master is no longer reachable, replicas will never
+ * receive the PINGs, however the master will end with an incremented
+ * offset because of the PINGs and will not be able to incrementally
+ * PSYNC with the new master. */
if (server.master_repl_offset > server.master_repl_meaningful_offset) {
long long delta = server.master_repl_offset -
server.master_repl_meaningful_offset;
@@ -2801,6 +2814,7 @@ long long adjustMeaningfulReplOffset() {
server.master_repl_meaningful_offset,
server.master_repl_offset,
delta);
+ server.master_initial_offset = server.master_repl_meaningful_offset;
server.master_repl_offset = server.master_repl_meaningful_offset;
if (server.repl_backlog_histlen <= delta) {
server.repl_backlog_histlen = 0;
@@ -2812,29 +2826,6 @@ long long adjustMeaningfulReplOffset() {
server.repl_backlog_size;
}
}
- return server.master_repl_offset;
-}
-
-/* This function is called when a master is turend into a slave, in order to
- * create from scratch a cached master for the new client, that will allow
- * to PSYNC with the slave that was promoted as the new master after a
- * failover.
- *
- * Assuming this instance was previously the master instance of the new master,
- * the new master will accept its replication ID, and potentiall also the
- * current offset if no data was lost during the failover. So we use our
- * current replication ID and offset in order to synthesize a cached master. */
-void replicationCacheMasterUsingMyself(void) {
- serverLog(LL_NOTICE,
- "Before turning into a replica, using my own master parameters "
- "to synthesize a cached master: I may be able to synchronize with "
- "the new master with just a partial transfer.");
-
- /* This will be used to populate the field server.master->reploff
- * by replicationCreateMasterClient(). We'll later set the created
- * master as server.cached_master, so the replica will use such
- * offset for PSYNC. */
- server.master_initial_offset = adjustMeaningfulReplOffset();
/* The master client we create can be set to any DBID, because
* the new master will start its replication stream with SELECT. */