Skip to content

Commit

Permalink
Reduce memory allocations
Browse files Browse the repository at this point in the history
Signed-off-by: Ping Xie <pingxie@google.com>
  • Loading branch information
PingXie committed May 1, 2024
1 parent f910041 commit dc97cc3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
17 changes: 4 additions & 13 deletions src/cluster_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -6898,22 +6898,17 @@ void clusterReplicateOpenSlots(void)
int argc = 5;
robj **argv = zmalloc(sizeof(robj*)*argc);

robj *cmd_obj = createObject(OBJ_STRING, sdsnew("CLUSTER"));
robj *subcmd_obj = createObject(OBJ_STRING, sdsnew("SETSLOT"));
robj *imp_obj = createObject(OBJ_STRING, sdsnew("IMPORTING"));
robj *mig_obj = createObject(OBJ_STRING, sdsnew("MIGRATING"));

argv[0] = cmd_obj;
argv[1] = subcmd_obj;
argv[0] =shared.cluster;
argv[1] = shared.setslot;

for (int i = 0; i < 2; i++) {
clusterNode **nodes_ptr = NULL;
if (i == 0) {
nodes_ptr = server.cluster->importing_slots_from;
argv[3] = imp_obj;
argv[3] = shared.importing;
} else {
nodes_ptr = server.cluster->migrating_slots_to;
argv[3] = mig_obj;
argv[3] = shared.migrating;
}

for (int j = 0; j < CLUSTER_SLOTS; j++) {
Expand All @@ -6930,9 +6925,5 @@ void clusterReplicateOpenSlots(void)
}
}

decrRefCount(mig_obj);
decrRefCount(imp_obj);
decrRefCount(subcmd_obj);
decrRefCount(cmd_obj);
zfree(argv);
}
4 changes: 4 additions & 0 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1999,6 +1999,10 @@ void createSharedObjects(void) {
shared.special_asterick = createStringObject("*",1);
shared.special_equals = createStringObject("=",1);
shared.redacted = makeObjectShared(createStringObject("(redacted)",10));
shared.cluster = createStringObject("CLUSTER", 7);
shared.setslot = createStringObject("SETSLOT", 7);
shared.importing = createStringObject("IMPORTING", 9);
shared.migrating = createStringObject("MIGRATING", 9);

for (j = 0; j < OBJ_SHARED_INTEGERS; j++) {
shared.integers[j] =
Expand Down
2 changes: 1 addition & 1 deletion src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,7 @@ struct sharedObjectsStruct {
*time, *pxat, *absttl, *retrycount, *force, *justid, *entriesread,
*lastid, *ping, *setid, *keepttl, *load, *createconsumer,
*getack, *special_asterick, *special_equals, *default_username, *redacted,
*ssubscribebulk,*sunsubscribebulk, *smessagebulk,
*ssubscribebulk,*sunsubscribebulk, *smessagebulk, *cluster, *setslot, *importing, *migrating,
*select[PROTO_SHARED_SELECT_CMDS],
*integers[OBJ_SHARED_INTEGERS],
*mbulkhdr[OBJ_SHARED_BULKHDR_LEN], /* "*<value>\r\n" */
Expand Down

0 comments on commit dc97cc3

Please sign in to comment.