Files
zeekay 5b2e5fe98e fix: revert the -X ours upstream merge, which left the tree uncompilable
`merge: upstream/unstable (-X ours, brand preserved)` resolved every conflicting
hunk in our favour. That is right for brand strings and wrong for code: it kept
our old server.h beside their new module.c, so module.c calls
commandResultSuccessListeners and reads from_call_argv off a struct that has
neither, and zslFreeLexRange lost the declarations it still has call sites for.
kvReaderFeed got a newer body calling kvReaderGetReadBuf/CommitRead grafted onto
older locals — an sds newbuf and an oom: label the new body never uses. Across
398 files nothing downstream noticed, because main has not compiled since.

That is what the Dockerfile was working around. Pulling valkey/valkey and copying
binaries out of it produced an image no matter what the source did, so a tree
that cannot build looked like a tree that builds. Now the image compiles this
source, so the build breaking is visible the moment it breaks.

src, deps and tests return to the last coherent commit. Carried forward on top:

  - Two identical rdbIsVersionAccepted definitions, differing only in a
    parameter name. The rename pass copied the function instead of editing it,
    so this never compiled either.
  - kv_strtod.h lost the #ifdef USE_FAST_FLOAT that separated its two
    implementations, leaving both definitions and a stray #endif.
  - extended-redis-compatibility is deleted, not defaulted off. It made the
    server answer HELLO with "redis" and name itself Redis in five error
    strings. A server that can be configured to lie about what it is has one
    setting too many. HELLO now reports kv unconditionally.
  - The redis-server and redis-cli install symlinks, on by default via
    USE_REDIS_SYMLINKS?=yes. This is why a running instance answered to
    redis-cli at all.
  - valkeymodule.h and redismodule.h, 3094 lines of adapters mapping old
    prefixes onto KVMODULE_*, included by nothing. kvmodule.h is the header.
  - deps/libvalkey, one documentation file the rename stranded.

Wire contract is untouched. INFO still reports redis_version, redis_git_sha1,
redis_git_dirty and redis_build_id, and the Lua sandbox still exports
REDIS_VERSION — clients parse those field names, so they are protocol, not
branding. What we choose is what the server calls itself, and it calls itself kv.

Verified: builds clean, and a live instance answers HELLO with "server kv",
reports server_name:kv, has no extended-redis-compatibility directive, and
serves strings and lists.
2026-07-26 15:04:44 -07:00

121 lines
4.2 KiB
C

#include "kvmodule.h"
#include <string.h>
#define UNUSED(x) (void)(x)
void cluster_timer_handler(KVModuleCtx *ctx, void *data) {
KVMODULE_NOT_USED(data);
KVModuleCallReply *rep = KVModule_Call(ctx, "CLUSTER", "c", "SLOTS");
if (rep) {
if (KVModule_CallReplyType(rep) == KVMODULE_REPLY_ARRAY) {
KVModule_Log(ctx, "notice", "Timer: CLUSTER SLOTS success");
} else {
KVModule_Log(ctx, "notice",
"Timer: CLUSTER SLOTS unexpected reply type %d",
KVModule_CallReplyType(rep));
}
KVModule_FreeCallReply(rep);
} else {
KVModule_Log(ctx, "warning", "Timer: CLUSTER SLOTS failed");
}
}
int test_start_cluster_timer(KVModuleCtx *ctx, KVModuleString **argv, int argc) {
KVMODULE_NOT_USED(argv);
KVMODULE_NOT_USED(argc);
KVModule_CreateTimer(ctx, 1, cluster_timer_handler, NULL);
return KVModule_ReplyWithSimpleString(ctx, "OK");
}
int test_cluster_slots(KVModuleCtx *ctx, KVModuleString **argv, int argc) {
UNUSED(argv);
if (argc != 1) return KVModule_WrongArity(ctx);
KVModuleCallReply *rep = KVModule_Call(ctx, "CLUSTER", "c", "SLOTS");
if (!rep) {
KVModule_ReplyWithError(ctx, "ERR NULL reply returned");
} else {
KVModule_ReplyWithCallReply(ctx, rep);
KVModule_FreeCallReply(rep);
}
return KVMODULE_OK;
}
int test_cluster_shards(KVModuleCtx *ctx, KVModuleString **argv, int argc) {
UNUSED(argv);
if (argc != 1) return KVModule_WrongArity(ctx);
KVModuleCallReply *rep = KVModule_Call(ctx, "CLUSTER", "c", "SHARDS");
if (!rep) {
KVModule_ReplyWithError(ctx, "ERR NULL reply returned");
} else {
KVModule_ReplyWithCallReply(ctx, rep);
KVModule_FreeCallReply(rep);
}
return KVMODULE_OK;
}
#define MSGTYPE_DING 1
#define MSGTYPE_DONG 2
/* test.pingall */
int PingallCommand(KVModuleCtx *ctx, KVModuleString **argv, int argc) {
KVMODULE_NOT_USED(argv);
KVMODULE_NOT_USED(argc);
KVModule_SendClusterMessage(ctx, NULL, MSGTYPE_DING, "Hey", 3);
return KVModule_ReplyWithSimpleString(ctx, "OK");
}
void DingReceiver(KVModuleCtx *ctx, const char *sender_id, uint8_t type, const unsigned char *payload, uint32_t len) {
KVModule_Log(ctx, "notice", "DING (type %d) RECEIVED from %.*s: '%.*s'", type, KVMODULE_NODE_ID_LEN, sender_id, (int)len, payload);
/* Ensure sender_id is null-terminated for cross-version compatibility */
char null_terminated_sender_id[KVMODULE_NODE_ID_LEN + 1];
memcpy(null_terminated_sender_id, sender_id, KVMODULE_NODE_ID_LEN);
null_terminated_sender_id[KVMODULE_NODE_ID_LEN] = '\0';
KVModule_SendClusterMessage(ctx, null_terminated_sender_id, MSGTYPE_DONG, "Message Received!", 17);
}
void DongReceiver(KVModuleCtx *ctx, const char *sender_id, uint8_t type, const unsigned char *payload, uint32_t len) {
KVModule_Log(ctx, "notice", "DONG (type %d) RECEIVED from %.*s: '%.*s'", type, KVMODULE_NODE_ID_LEN, sender_id, (int)len, payload);
}
int KVModule_OnLoad(KVModuleCtx *ctx, KVModuleString **argv, int argc) {
KVMODULE_NOT_USED(argv);
KVMODULE_NOT_USED(argc);
if (KVModule_Init(ctx, "cluster", 1, KVMODULE_APIVER_1)== KVMODULE_ERR)
return KVMODULE_ERR;
if (KVModule_CreateCommand(ctx, "test.pingall", PingallCommand, "readonly", 0, 0, 0) ==
KVMODULE_ERR)
return KVMODULE_ERR;
if (KVModule_CreateCommand(ctx, "test.cluster_slots", test_cluster_slots, "", 0, 0, 0) == KVMODULE_ERR)
return KVMODULE_ERR;
if (KVModule_CreateCommand(ctx, "test.cluster_shards", test_cluster_shards, "", 0, 0, 0) == KVMODULE_ERR)
return KVMODULE_ERR;
if (KVModule_CreateCommand(ctx, "test.start_cluster_timer", test_start_cluster_timer, "", 0, 0, 0) == KVMODULE_ERR)
return KVMODULE_ERR;
if (ValkeyModule_CreateCommand(ctx, "test.start_cluster_timer", test_start_cluster_timer, "", 0, 0, 0) == VALKEYMODULE_ERR)
return VALKEYMODULE_ERR;
/* Register our handlers for different message types. */
KVModule_RegisterClusterMessageReceiver(ctx, MSGTYPE_DING, DingReceiver);
KVModule_RegisterClusterMessageReceiver(ctx, MSGTYPE_DONG, DongReceiver);
return KVMODULE_OK;
}