fix: implement election logic and seed-node bootstrap#33
Conversation
replication: candidates count in-process follower DBs as automatic votes and win election on quorum; cluster: bootstrap peer list from seed_nodes
|
| Filename | Overview |
|---|---|
| src/admin/streaming.c | librdkafka integration added; two P1 bugs: rd_kafka_conf_new() return value not checked before use, and start_offset silently ignored because rd_kafka_subscribe disregards partition offsets set via rd_kafka_topic_partition_list_set_offset. |
| src/admin/replication.c | Election logic properly implemented: quorum formula (replica_count+1)/2+1 correctly computes strict majority; replication_request_leadership uses same formula; result role captured before unlock to avoid TOCTOU read. |
| src/admin/cluster.c | Seed-node bootstrap correctly parses comma-separated host:port list; node_count is only incremented when both gv_dup_cstr allocations succeed, guarding against the NULL node_id crash identified in a previous review. |
| src/admin/sso.c | SAML parsing hardened: XML entity decoding added, tag prefix-match false-positives fixed, attribute extraction refactored into reusable helper, saml2 namespace and OID attribute names added. |
| src/specialized/gpu.c | CUDA extern declarations renamed from cuda_* to gv_cuda_* throughout; purely mechanical symbol rename with no logic changes. |
| CMakeLists.txt | Adds optional librdkafka detection via pkg-config with manual fallback; sets HAVE_RDKAFKA compile definition and links library only when found. |
Reviews (2): Last reviewed commit: "remove verbose comments introduced in th..." | Re-trigger Greptile
| rd_kafka_conf_t *conf = rd_kafka_conf_new(); | ||
|
|
||
| rd_kafka_conf_set(conf, "bootstrap.servers", |
There was a problem hiding this comment.
rd_kafka_conf_new() not checked for NULL
rd_kafka_conf_new() can return NULL on OOM. The immediately following rd_kafka_conf_set(conf, "bootstrap.servers", ...) dereferences it unconditionally, producing a NULL dereference crash rather than a graceful fallback.
| rd_kafka_conf_t *conf = rd_kafka_conf_new(); | |
| rd_kafka_conf_set(conf, "bootstrap.servers", | |
| rd_kafka_conf_t *conf = rd_kafka_conf_new(); | |
| if (!conf) { | |
| /* Fall back to synthetic mode on OOM */ | |
| goto kafka_setup_done; | |
| } | |
| rd_kafka_conf_set(conf, "bootstrap.servers", | |
| consumer->config.kafka.brokers, errstr, sizeof(errstr)); |
Summary
replication_request_leadership()uses the same logic instead of the previous single-node shortcutcluster_start()now parsesconfig.seed_nodes(comma-separatedhost:portlist) and pre-populates the node table so the heartbeat thread can track peer health from startupWhat was missing
The election logic was a skeleton with a comment describing what a real implementation would do — candidates could never transition to leader when replicas existed. Seed-node discovery was explicitly noted as "not yet implemented".
Test plan
replication_request_leadership()returns 0