fix: resolve probe_ctx_t type tag, add DEFAULT_MAX_WAL_RECORDS macro, fix atomic type consistency, move ha_seed_jitter to ha.c, add API doc comments
This commit is contained in:
parent
8a9fce1be4
commit
1c4a103a66
5 changed files with 67 additions and 37 deletions
|
|
@ -2,18 +2,47 @@
|
|||
#include "ha.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <stdatomic.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Circular-include safety: cluster_def.h includes ha.h (include-guarded),
|
||||
* and ha.h only forward-declares cluster_t — no cycle. */
|
||||
#include "xce/cluster_def.h"
|
||||
#include "persist.h"
|
||||
|
||||
/* ── PRNG seeding ───────────────────────────────────────────── */
|
||||
|
||||
void ha_seed_jitter(uint64_t *seed, int my_priority)
|
||||
{
|
||||
uint8_t buf[8] = {0};
|
||||
int fd = open("/dev/urandom", O_RDONLY);
|
||||
if (fd >= 0) {
|
||||
ssize_t n = 0;
|
||||
while (n < 8) {
|
||||
ssize_t r = read(fd, buf + n, (size_t)(8 - n));
|
||||
if (r <= 0) break;
|
||||
n += r;
|
||||
}
|
||||
close(fd);
|
||||
if (n == 8) {
|
||||
memcpy(seed, buf, 8);
|
||||
if (*seed != 0) return;
|
||||
}
|
||||
}
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
*seed = (uint64_t)ts.tv_nsec
|
||||
^ ((uint64_t)my_priority << 56)
|
||||
^ ((uint64_t)getpid() << 16);
|
||||
}
|
||||
|
||||
int ha_init(ha_state_t *ha, const ha_config_t *cfg, int my_priority)
|
||||
{
|
||||
if (!ha || !cfg)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue