Skip to content

Commit c50e2d4

Browse files
committed
Fix fastsync test failures caused by closing due to repl buffer size too soon
1 parent e580a8e commit c50e2d4

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/replication.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -1158,10 +1158,23 @@ class replicationBuffer {
11581158
}
11591159

11601160
void putSlavesOnline() {
1161+
for (auto replica : replicas) {
1162+
std::unique_lock<fastlock> ul(replica->lock);
1163+
// If we put the replica online before the output is drained then it will get immediately closed
1164+
while (checkClientOutputBufferLimits(replica)
1165+
&& (replica->flags.load(std::memory_order_relaxed) & CLIENT_CLOSE_ASAP) == 0) {
1166+
ul.unlock();
1167+
usleep(1000); // give 1ms for the I/O before we poll again
1168+
ul.lock();
1169+
}
1170+
}
1171+
1172+
aeAcquireLock();
11611173
for (auto replica : replicas) {
11621174
replica->replstate = SLAVE_STATE_FASTSYNC_DONE;
11631175
replica->repl_put_online_on_ack = 1;
11641176
}
1177+
aeReleaseLock();
11651178
}
11661179

11671180
void abort() {
@@ -1282,9 +1295,7 @@ int rdbSaveSnapshotForReplication(rdbSaveInfo *rsi) {
12821295
auto usec = ustime() - timeStart;
12831296
serverLog(LL_NOTICE, "Transferred %zuMB total (%zuMB data) in %.2f seconds. (%.2fGbit/s)", spreplBuf->cbWritten()/1024/1024, cbData/1024/1024, usec/1000000.0, (spreplBuf->cbWritten()*8.0)/(usec/1000000.0)/1000000000.0);
12841297
if (retval == C_OK) {
1285-
aeAcquireLock();
12861298
replBuf.putSlavesOnline();
1287-
aeReleaseLock();
12881299
}
12891300
});
12901301

0 commit comments

Comments
 (0)