From fe7d79098e08d4b1bf0249f123cadacbb50b5429 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Feb 2026 14:18:30 +0000 Subject: [PATCH] Move CEIL macro to basic.h and remove unnecessary heartbeat reset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Move the CEIL macro from config.h to basic.h alongside MIN/MAX, and use it in deadline_to_timeout for the rounding-up division - Remove the heartbeat reset in complete_view_change_and_become_primary since it was not needed — heartbeat is already set when the node enters STATUS_CHANGE_VIEW, which is close enough in time https://claude.ai/code/session_0184gHjra7fsmSPZ4kppaGhC --- src/basic.c | 2 +- src/basic.h | 1 + src/config.h | 1 - src/server.c | 1 - 4 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/basic.c b/src/basic.c index 3974344..b1f706f 100644 --- a/src/basic.c +++ b/src/basic.c @@ -74,7 +74,7 @@ int deadline_to_timeout(Time deadline, Time current_time) if (deadline <= current_time) return 0; // Round up so sub-millisecond deadlines become 1ms, not 0 - return (deadline - current_time + 999999) / 1000000; + return CEIL(deadline - current_time, 1000000); } bool getargb(int argc, char **argv, char *name) diff --git a/src/basic.h b/src/basic.h index dfb641f..7ab2fa2 100644 --- a/src/basic.h +++ b/src/basic.h @@ -37,6 +37,7 @@ typedef uint64_t Time; #define MIN(X, Y) ((X) < (Y) ? (X) : (Y)) #define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) +#define CEIL(X, Y) (((X) + (Y) - 1) / (Y)) #define UNREACHABLE __builtin_trap(); diff --git a/src/config.h b/src/config.h index 2e2a80f..f997aee 100644 --- a/src/config.h +++ b/src/config.h @@ -12,6 +12,5 @@ #define REPLICATION_FACTOR 2 #define CHUNK_SIZE 32 #define MAX_TRANSFERS (META_CHUNKS_MAX * REPLICATION_FACTOR) -#define CEIL(X, Y) (((X) + (Y) - 1) / (Y)) #endif // CONFIG_INCLUDED \ No newline at end of file diff --git a/src/server.c b/src/server.c index 0091bdd..18de29f 100644 --- a/src/server.c +++ b/src/server.c @@ -517,7 +517,6 @@ complete_view_change_and_become_primary(ServerState *state) broadcast_to_peers_ex(state, &begin_view_message.base, state->log.entries, state->log.count * sizeof(LogEntry)); clear_view_change_fields(state); - state->heartbeat = state->now; return HR_OK; }