fix(ha-repl-hardening): wire snapshot production path (task 3.5b)

- SEND_SNAPSHOT uses checkpoint_lsn (not committed_lsn) for file lookup
- ha_send_snapshot_to_standby stats file for actual total_size
- ha_compute_oldest_wal_lsn scans WAL dir for min segment LSN
- Removed hardcoded 131072 and oldest_wal_lsn=0 placeholders
This commit is contained in:
Rongsong Shen 2026-06-05 01:25:00 +00:00
parent 834ab4d5e7
commit 318098c727
5 changed files with 43 additions and 18 deletions

View file

@ -1740,16 +1740,21 @@ int (*xce_snapshot_chunk_hook)(endpoint_t *ep, xce_request_t *req) = NULL;
#define SNAPSHOT_CHUNK_SIZE 65536
int ha_send_snapshot_to_standby(endpoint_t *ep, const char *snap_dir,
uint64_t checkpoint_lsn, uint64_t total_size)
uint64_t checkpoint_lsn)
{
if (!snap_dir)
return -EINVAL;
/* Find the snapshot file by naming convention */
char snap_path[4096];
snprintf(snap_path, sizeof(snap_path),
"%s/snap-%016" PRIx64 ".capnp", snap_dir, checkpoint_lsn);
/* Stat the snapshot file to get total_size */
struct stat st;
if (stat(snap_path, &st) != 0)
return -errno;
uint64_t total_size = (uint64_t)st.st_size;
FILE *f = fopen(snap_path, "rb");
if (!f)
return -errno;
@ -1813,3 +1818,22 @@ int ha_send_snapshot_to_standby(endpoint_t *ep, const char *snap_dir,
fclose(f);
return rc;
}
uint64_t ha_compute_oldest_wal_lsn(const char *wal_path)
{
DIR *d = opendir(wal_path);
if (!d)
return 0;
uint64_t oldest = UINT64_MAX;
struct dirent *ent;
while ((ent = readdir(d)) != NULL) {
uint64_t seg_lsn = 0;
if (sscanf(ent->d_name, "seg-%" SCNx64 ".wal", &seg_lsn) != 1)
continue;
if (seg_lsn < oldest)
oldest = seg_lsn;
}
closedir(d);
return (oldest == UINT64_MAX) ? 0 : oldest;
}