Move CEIL macro to basic.h and remove unnecessary heartbeat reset

- 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
This commit is contained in:
Claude
2026-02-21 14:18:30 +00:00
parent 8233392871
commit fe7d79098e
4 changed files with 2 additions and 3 deletions
+1 -1
View File
@@ -74,7 +74,7 @@ int deadline_to_timeout(Time deadline, Time current_time)
if (deadline <= current_time) if (deadline <= current_time)
return 0; return 0;
// Round up so sub-millisecond deadlines become 1ms, not 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) bool getargb(int argc, char **argv, char *name)
+1
View File
@@ -37,6 +37,7 @@ typedef uint64_t Time;
#define MIN(X, Y) ((X) < (Y) ? (X) : (Y)) #define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
#define MAX(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(); #define UNREACHABLE __builtin_trap();
-1
View File
@@ -12,6 +12,5 @@
#define REPLICATION_FACTOR 2 #define REPLICATION_FACTOR 2
#define CHUNK_SIZE 32 #define CHUNK_SIZE 32
#define MAX_TRANSFERS (META_CHUNKS_MAX * REPLICATION_FACTOR) #define MAX_TRANSFERS (META_CHUNKS_MAX * REPLICATION_FACTOR)
#define CEIL(X, Y) (((X) + (Y) - 1) / (Y))
#endif // CONFIG_INCLUDED #endif // CONFIG_INCLUDED
-1
View File
@@ -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)); broadcast_to_peers_ex(state, &begin_view_message.base, state->log.entries, state->log.count * sizeof(LogEntry));
clear_view_change_fields(state); clear_view_change_fields(state);
state->heartbeat = state->now;
return HR_OK; return HR_OK;
} }