Skip to content

Commit

Permalink
Remove support for splitting multi-key commands per slot
Browse files Browse the repository at this point in the history
Signed-off-by: Björn Svensson <[email protected]>
  • Loading branch information
bjosv committed Jun 22, 2024
1 parent f3776bd commit e3431b6
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 782 deletions.
29 changes: 14 additions & 15 deletions libvalkeycluster/tests/ct_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,23 @@

void test_exists(valkeyClusterContext *cc) {
valkeyReply *reply;
reply = (valkeyReply *)valkeyClusterCommand(cc, "SET key1 Hello");
reply = valkeyClusterCommand(cc, "SET {key}1 Hello");
CHECK_REPLY_OK(cc, reply);
freeReplyObject(reply);

reply = (valkeyReply *)valkeyClusterCommand(cc, "EXISTS key1");
reply = valkeyClusterCommand(cc, "EXISTS {key}1");
CHECK_REPLY_INT(cc, reply, 1);
freeReplyObject(reply);

reply = (valkeyReply *)valkeyClusterCommand(cc, "EXISTS nosuchkey");
reply = valkeyClusterCommand(cc, "EXISTS nosuch{key}");
CHECK_REPLY_INT(cc, reply, 0);
freeReplyObject(reply);

reply = (valkeyReply *)valkeyClusterCommand(cc, "SET key2 World");
reply = valkeyClusterCommand(cc, "SET {key}2 World");
CHECK_REPLY_OK(cc, reply);
freeReplyObject(reply);

reply =
(valkeyReply *)valkeyClusterCommand(cc, "EXISTS key1 key2 nosuchkey");
reply = valkeyClusterCommand(cc, "EXISTS {key}1 {key}2 nosuch{key}");
CHECK_REPLY_INT(cc, reply, 2);
freeReplyObject(reply);
}
Expand Down Expand Up @@ -61,39 +60,39 @@ void test_bitfield_ro(valkeyClusterContext *cc) {

void test_mset(valkeyClusterContext *cc) {
valkeyReply *reply;
reply = (valkeyReply *)valkeyClusterCommand(
cc, "MSET key1 mset1 key2 mset2 key3 mset3");
reply =
valkeyClusterCommand(cc, "MSET {key}1 mset1 {key}2 mset2 {key}3 mset3");
CHECK_REPLY_OK(cc, reply);
freeReplyObject(reply);

reply = (valkeyReply *)valkeyClusterCommand(cc, "GET key1");
reply = valkeyClusterCommand(cc, "GET {key}1");
CHECK_REPLY_STR(cc, reply, "mset1");
freeReplyObject(reply);

reply = (valkeyReply *)valkeyClusterCommand(cc, "GET key2");
reply = valkeyClusterCommand(cc, "GET {key}2");
CHECK_REPLY_STR(cc, reply, "mset2");
freeReplyObject(reply);

reply = (valkeyReply *)valkeyClusterCommand(cc, "GET key3");
reply = valkeyClusterCommand(cc, "GET {key}3");
CHECK_REPLY_STR(cc, reply, "mset3");
freeReplyObject(reply);
}

void test_mget(valkeyClusterContext *cc) {
valkeyReply *reply;
reply = (valkeyReply *)valkeyClusterCommand(cc, "SET key1 mget1");
reply = valkeyClusterCommand(cc, "SET {key}1 mget1");
CHECK_REPLY_OK(cc, reply);
freeReplyObject(reply);

reply = (valkeyReply *)valkeyClusterCommand(cc, "SET key2 mget2");
reply = valkeyClusterCommand(cc, "SET {key}2 mget2");
CHECK_REPLY_OK(cc, reply);
freeReplyObject(reply);

reply = (valkeyReply *)valkeyClusterCommand(cc, "SET key3 mget3");
reply = valkeyClusterCommand(cc, "SET {key}3 mget3");
CHECK_REPLY_OK(cc, reply);
freeReplyObject(reply);

reply = (valkeyReply *)valkeyClusterCommand(cc, "MGET key1 key2 key3");
reply = valkeyClusterCommand(cc, "MGET {key}1 {key}2 {key}3");
CHECK_REPLY_ARRAY(cc, reply, 3);
CHECK_REPLY_STR(cc, reply->element[0], "mget1");
CHECK_REPLY_STR(cc, reply->element[1], "mget2");
Expand Down
87 changes: 15 additions & 72 deletions libvalkeycluster/tests/ct_out_of_memory_handling.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,33 +185,14 @@ void test_alloc_failure_handling(void) {
valkeyReply *reply;
const char *cmd = "SET key value";

for (int i = 0; i < 36; ++i) {
for (int i = 0; i < 35; ++i) {
prepare_allocation_test(cc, i);
reply = (valkeyReply *)valkeyClusterCommand(cc, cmd);
assert(reply == NULL);
ASSERT_STR_EQ(cc->errstr, "Out of memory");
}

prepare_allocation_test(cc, 36);
reply = (valkeyReply *)valkeyClusterCommand(cc, cmd);
CHECK_REPLY_OK(cc, reply);
freeReplyObject(reply);
}

// Multi key command
{
valkeyReply *reply;
const char *cmd = "MSET key1 v1 key2 v2 key3 v3";

for (int i = 0; i < 77; ++i) {
prepare_allocation_test(cc, i);
reply = (valkeyReply *)valkeyClusterCommand(cc, cmd);
assert(reply == NULL);
ASSERT_STR_EQ(cc->errstr, "Out of memory");
}

// Multi-key commands
prepare_allocation_test(cc, 77);
prepare_allocation_test(cc, 35);
reply = (valkeyReply *)valkeyClusterCommand(cc, cmd);
CHECK_REPLY_OK(cc, reply);
freeReplyObject(reply);
Expand Down Expand Up @@ -245,7 +226,7 @@ void test_alloc_failure_handling(void) {
valkeyReply *reply;
const char *cmd = "SET foo one";

for (int i = 0; i < 37; ++i) {
for (int i = 0; i < 36; ++i) {
prepare_allocation_test(cc, i);
result = valkeyClusterAppendCommand(cc, cmd);
assert(result == VALKEY_ERR);
Expand All @@ -257,7 +238,7 @@ void test_alloc_failure_handling(void) {
for (int i = 0; i < 4; ++i) {
// Appended command lost when receiving error from valkey
// during a GetReply, needs a new append for each test loop
prepare_allocation_test(cc, 37);
prepare_allocation_test(cc, 36);
result = valkeyClusterAppendCommand(cc, cmd);
assert(result == VALKEY_OK);

Expand All @@ -269,7 +250,7 @@ void test_alloc_failure_handling(void) {
valkeyClusterReset(cc);
}

prepare_allocation_test(cc, 37);
prepare_allocation_test(cc, 36);
result = valkeyClusterAppendCommand(cc, cmd);
assert(result == VALKEY_OK);

Expand All @@ -280,44 +261,6 @@ void test_alloc_failure_handling(void) {
freeReplyObject(reply);
}

// Append multi-key command
{
valkeyReply *reply;
const char *cmd = "MSET key1 val1 key2 val2 key3 val3";

for (int i = 0; i < 90; ++i) {
prepare_allocation_test(cc, i);
result = valkeyClusterAppendCommand(cc, cmd);
assert(result == VALKEY_ERR);
ASSERT_STR_EQ(cc->errstr, "Out of memory");

valkeyClusterReset(cc);
}

for (int i = 0; i < 12; ++i) {
prepare_allocation_test(cc, 90);
result = valkeyClusterAppendCommand(cc, cmd);
assert(result == VALKEY_OK);

prepare_allocation_test(cc, i);
result = valkeyClusterGetReply(cc, (void *)&reply);
assert(result == VALKEY_ERR);
ASSERT_STR_EQ(cc->errstr, "Out of memory");

valkeyClusterReset(cc);
}

prepare_allocation_test(cc, 90);
result = valkeyClusterAppendCommand(cc, cmd);
assert(result == VALKEY_OK);

prepare_allocation_test(cc, 12);
result = valkeyClusterGetReply(cc, (void *)&reply);
assert(result == VALKEY_OK);
CHECK_REPLY_OK(cc, reply);
freeReplyObject(reply);
}

// Append command to node
{
valkeyReply *reply;
Expand Down Expand Up @@ -412,15 +355,15 @@ void test_alloc_failure_handling(void) {
freeReplyObject(reply);

/* Test ASK reply handling with OOM */
for (int i = 0; i < 50; ++i) {
for (int i = 0; i < 49; ++i) {
prepare_allocation_test(cc, i);
reply = valkeyClusterCommand(cc, "GET foo");
assert(reply == NULL);
ASSERT_STR_EQ(cc->errstr, "Out of memory");
}

/* Test ASK reply handling without OOM */
prepare_allocation_test(cc, 50);
prepare_allocation_test(cc, 49);
reply = valkeyClusterCommand(cc, "GET foo");
CHECK_REPLY_STR(cc, reply, "one");
freeReplyObject(reply);
Expand All @@ -441,15 +384,15 @@ void test_alloc_failure_handling(void) {
freeReplyObject(reply);

/* Test MOVED reply handling with OOM */
for (int i = 0; i < 34; ++i) {
for (int i = 0; i < 33; ++i) {
prepare_allocation_test(cc, i);
reply = valkeyClusterCommand(cc, "GET foo");
assert(reply == NULL);
ASSERT_STR_EQ(cc->errstr, "Out of memory");
}

/* Test MOVED reply handling without OOM */
prepare_allocation_test(cc, 34);
prepare_allocation_test(cc, 33);
reply = valkeyClusterCommand(cc, "GET foo");
CHECK_REPLY_STR(cc, reply, "one");
freeReplyObject(reply);
Expand Down Expand Up @@ -597,18 +540,18 @@ void test_alloc_failure_handling_async(void) {
{
const char *cmd1 = "SET foo one";

for (int i = 0; i < 38; ++i) {
for (int i = 0; i < 37; ++i) {
prepare_allocation_test_async(acc, i);
result = valkeyClusterAsyncCommand(acc, commandCallback, &r1, cmd1);
assert(result == VALKEY_ERR);
if (i != 36) {
if (i != 35) {
ASSERT_STR_EQ(acc->errstr, "Out of memory");
} else {
ASSERT_STR_EQ(acc->errstr, "Failed to attach event adapter");
}
}

prepare_allocation_test_async(acc, 38);
prepare_allocation_test_async(acc, 37);
result = valkeyClusterAsyncCommand(acc, commandCallback, &r1, cmd1);
ASSERT_MSG(result == VALKEY_OK, acc->errstr);
}
Expand All @@ -619,16 +562,16 @@ void test_alloc_failure_handling_async(void) {
{
const char *cmd2 = "GET foo";

for (int i = 0; i < 15; ++i) {
for (int i = 0; i < 14; ++i) {
prepare_allocation_test_async(acc, i);
result = valkeyClusterAsyncCommand(acc, commandCallback, &r2, cmd2);
assert(result == VALKEY_ERR);
ASSERT_STR_EQ(acc->errstr, "Out of memory");
}

/* Skip iteration 15, errstr not set by libvalkey when valkeyFormatSdsCommandArgv() fails. */
/* Skip iteration 14, errstr not set by libvalkey when valkeyFormatSdsCommandArgv() fails. */

prepare_allocation_test_async(acc, 16);
prepare_allocation_test_async(acc, 15);
result = valkeyClusterAsyncCommand(acc, commandCallback, &r2, cmd2);
ASSERT_MSG(result == VALKEY_OK, acc->errstr);
}
Expand Down
36 changes: 0 additions & 36 deletions libvalkeycluster/tests/ct_pipeline.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,40 +57,6 @@ void test_pipeline(void) {
valkeyClusterFree(cc);
}

// Test of pipelines containing multi-node commands
void test_pipeline_with_multinode_commands(void) {
valkeyClusterContext *cc = valkeyClusterContextInit();
assert(cc);

int status;
status = valkeyClusterSetOptionAddNodes(cc, CLUSTER_NODE);
ASSERT_MSG(status == VALKEY_OK, cc->errstr);

status = valkeyClusterConnect2(cc);
ASSERT_MSG(status == VALKEY_OK, cc->errstr);

status =
valkeyClusterAppendCommand(cc, "MSET key1 Hello key2 World key3 !");
ASSERT_MSG(status == VALKEY_OK, cc->errstr);

status = valkeyClusterAppendCommand(cc, "MGET key1 key2 key3");
ASSERT_MSG(status == VALKEY_OK, cc->errstr);

valkeyReply *reply;
valkeyClusterGetReply(cc, (void *)&reply);
CHECK_REPLY_OK(cc, reply);
freeReplyObject(reply);

valkeyClusterGetReply(cc, (void *)&reply);
CHECK_REPLY_ARRAY(cc, reply, 3);
CHECK_REPLY_STR(cc, reply->element[0], "Hello");
CHECK_REPLY_STR(cc, reply->element[1], "World");
CHECK_REPLY_STR(cc, reply->element[2], "!");
freeReplyObject(reply);

valkeyClusterFree(cc);
}

//------------------------------------------------------------------------------
// Async API
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -173,10 +139,8 @@ void test_async_pipeline(void) {
int main(void) {

test_pipeline();
test_pipeline_with_multinode_commands();

test_async_pipeline();
// Asynchronous API does not support multi-key commands

return 0;
}
2 changes: 1 addition & 1 deletion libvalkeycluster/tests/ut_parse_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void test_valkey_parse_cmd_mset(void) {
c->clen = len;
valkey_parse_cmd(c);
ASSERT_MSG(c->result == CMD_PARSE_OK, "Parse not OK");
ASSERT_KEYS(c, "foo", "bar");
ASSERT_KEYS(c, "foo");
command_destroy(c);
}

Expand Down
Loading

0 comments on commit e3431b6

Please sign in to comment.