Skip to content

Commit fc88e6f

Browse files
committed
unsolo and tweak recovery
1 parent 2b3262f commit fc88e6f

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

lib/session-state.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,12 +583,20 @@ class SessionState {
583583
continue
584584
}
585585

586-
await new Promise((resolve) => setTimeout(resolve, 8000))
586+
let restart = false
587587

588-
peers = getRecoveryPeers(replicator.peers)
588+
for (let i = 0; i < 32; i++) {
589+
await new Promise((resolve) => setTimeout(resolve, 250))
589590

590-
if (peers.length < 1 || this.closing) continue
591-
if (peers[0].remoteLength > this.length) continue
591+
peers = getRecoveryPeers(replicator.peers)
592+
593+
if (this.closing || !validateRecoveryPeers(peers, this.length)) {
594+
restart = true
595+
break
596+
}
597+
}
598+
599+
if (restart) continue
592600

593601
if (this.length !== length) {
594602
throw SESSION_NOT_WRITABLE('core recovered during append')
@@ -1310,3 +1318,19 @@ function getRecoveryPeers(peers) {
13101318

13111319
return actual
13121320
}
1321+
1322+
function validateRecoveryPeers(peers, length) {
1323+
if (peers.length < 1) return false
1324+
1325+
for (const p of peers) {
1326+
if (p.remoteLength > length) return false
1327+
}
1328+
1329+
let all = true
1330+
1331+
for (const p of peers) {
1332+
if (p.remoteLength === 0) all = false
1333+
}
1334+
1335+
return all
1336+
}

test/replicate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2887,7 +2887,7 @@ test('local writable caught up by remote', async function (t) {
28872887
t.is(b.length, a.length)
28882888
})
28892889

2890-
test.solo('local recovering from remote', async function (t) {
2890+
test('local recovering from remote', async function (t) {
28912891
const a = await create(t)
28922892

28932893
await a.append(['a', 'b', 'c', 'd', 'e'])

0 commit comments

Comments
 (0)