forked from lei.chen/myxce
feat(ha-convergence-recovery): self-restart primitive + demotion convergence (task 2.2)
This commit is contained in:
parent
c8e55947c2
commit
09103a3141
7 changed files with 337 additions and 43 deletions
|
|
@ -1597,6 +1597,30 @@ int persist_truncate_wal_above(persist_t* p, uint64_t cutoff_lsn)
|
|||
}
|
||||
|
||||
if (cutoff_seg_idx < 0) {
|
||||
/* cutoff_lsn is below the oldest retained segment's start LSN, so EVERY
|
||||
* on-disk entry has LSN > cutoff_lsn and must be removed (the function's
|
||||
* contract: "remove all entries with LSN > cutoff_lsn"). This is the
|
||||
* demotion-convergence case (ha-convergence-recovery Req 1.2): a demoted
|
||||
* ex-primary whose committed boundary sits below its entire retained log
|
||||
* must discard all of it and collapse the tip to cutoff_lsn + 1. Delete
|
||||
* every segment, close the active fd, and reset the in-memory tip. */
|
||||
for (int i = 0; i < nseg; i++) {
|
||||
char del_path[4096];
|
||||
snprintf(del_path, sizeof(del_path),
|
||||
WAL_SEG_FMT, p->wal_path, seg_lsns[i]);
|
||||
unlink(del_path);
|
||||
}
|
||||
if (p->wal_fd >= 0) {
|
||||
fdatasync(p->wal_fd);
|
||||
close(p->wal_fd);
|
||||
p->wal_fd = -1;
|
||||
}
|
||||
p->seg_offset = 0;
|
||||
p->seg_path[0] = '\0';
|
||||
p->current_lsn = cutoff_lsn + 1;
|
||||
p->last_crc = WAL_CRC_NONE;
|
||||
atomic_store_explicit(&p->committed_lsn, cutoff_lsn,
|
||||
memory_order_release);
|
||||
pthread_mutex_unlock(&p->lock);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue