summaryrefslogtreecommitdiff
path: root/src/sentinel.c
diff options
context:
space:
mode:
authoryoav-steinberg <yoav@monfort.co.il>2021-08-05 08:25:58 +0300
committerGitHub <noreply@github.com>2021-08-05 08:25:58 +0300
commit5e908a290ccbe9c4a7bea9356faf3b837df62793 (patch)
treeee8c2008ef1c18653203245dd40d3befb2cd364f /src/sentinel.c
parent1c59567a7fe207997eef6197eefa7d508d7fbf9f (diff)
downloadredis-5e908a290ccbe9c4a7bea9356faf3b837df62793.tar.gz
dict struct memory optimizations (#9228)
Reduce dict struct memory overhead on 64bit dict size goes down from jemalloc's 96 byte bin to its 56 byte bin. summary of changes: - Remove `privdata` from callbacks and dict creation. (this affects many files, see "Interface change" below). - Meld `dictht` struct into the `dict` struct to eliminate struct padding. (this affects just dict.c and defrag.c) - Eliminate the `sizemask` field, can be calculated from size when needed. - Convert the `size` field into `size_exp` (exponent), utilizes one byte instead of 8. Interface change: pass dict pointer to dict type call back functions. This is instead of passing the removed privdata field. In the future if we'd like to have private data in the callbacks we can extract it from the dict type. We can extend dictType to include a custom dict struct allocator and use it to allocate more data at the end of the dict struct. This data can then be used to store private data later acccessed by the callbacks.
Diffstat (limited to 'src/sentinel.c')
-rw-r--r--src/sentinel.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/sentinel.c b/src/sentinel.c
index 40f9a2ac4..f8e1e607d 100644
--- a/src/sentinel.c
+++ b/src/sentinel.c
@@ -406,8 +406,8 @@ void sentinelSimFailureCrash(void);
void releaseSentinelRedisInstance(sentinelRedisInstance *ri);
-void dictInstancesValDestructor (void *privdata, void *obj) {
- UNUSED(privdata);
+void dictInstancesValDestructor (dict *d, void *obj) {
+ UNUSED(d);
releaseSentinelRedisInstance(obj);
}
@@ -527,7 +527,7 @@ void initSentinel(void) {
/* Initialize various data structures. */
sentinel.current_epoch = 0;
- sentinel.masters = dictCreate(&instancesDictType,NULL);
+ sentinel.masters = dictCreate(&instancesDictType);
sentinel.tilt = 0;
sentinel.tilt_start_time = 0;
sentinel.previous_time = mstime();
@@ -1346,13 +1346,13 @@ sentinelRedisInstance *createSentinelRedisInstance(char *name, int flags, char *
ri->slave_master_port = 0;
ri->slave_master_link_status = SENTINEL_MASTER_LINK_STATUS_DOWN;
ri->slave_repl_offset = 0;
- ri->sentinels = dictCreate(&instancesDictType,NULL);
+ ri->sentinels = dictCreate(&instancesDictType);
ri->quorum = quorum;
ri->parallel_syncs = SENTINEL_DEFAULT_PARALLEL_SYNCS;
ri->master = master;
- ri->slaves = dictCreate(&instancesDictType,NULL);
+ ri->slaves = dictCreate(&instancesDictType);
ri->info_refresh = 0;
- ri->renamed_commands = dictCreate(&renamedCommandsDictType,NULL);
+ ri->renamed_commands = dictCreate(&renamedCommandsDictType);
/* Failover state. */
ri->leader = NULL;
@@ -1563,10 +1563,10 @@ void sentinelDelFlagsToDictOfRedisInstances(dict *instances, int flags) {
void sentinelResetMaster(sentinelRedisInstance *ri, int flags) {
serverAssert(ri->flags & SRI_MASTER);
dictRelease(ri->slaves);
- ri->slaves = dictCreate(&instancesDictType,NULL);
+ ri->slaves = dictCreate(&instancesDictType);
if (!(flags & SENTINEL_RESET_NO_SENTINELS)) {
dictRelease(ri->sentinels);
- ri->sentinels = dictCreate(&instancesDictType,NULL);
+ ri->sentinels = dictCreate(&instancesDictType);
}
instanceLinkCloseConnection(ri->link,ri->link->cc);
instanceLinkCloseConnection(ri->link,ri->link->pc);
@@ -3789,7 +3789,7 @@ NULL
copy_keeper.valDestructor = NULL;
dict *masters_local = sentinel.masters;
if (c->argc > 2) {
- masters_local = dictCreate(&copy_keeper, NULL);
+ masters_local = dictCreate(&copy_keeper);
for (int i = 2; i < c->argc; i++) {
sentinelRedisInstance *ri;
@@ -4094,7 +4094,7 @@ void sentinelSetCommand(client *c) {
/* If the target name is the same as the source name there
* is no need to add an entry mapping to itself. */
- if (!dictSdsKeyCaseCompare(NULL,oldname,newname)) {
+ if (!dictSdsKeyCaseCompare(ri->renamed_commands,oldname,newname)) {
oldname = sdsdup(oldname);
newname = sdsdup(newname);
dictAdd(ri->renamed_commands,oldname,newname);
@@ -4431,7 +4431,7 @@ char *sentinelGetLeader(sentinelRedisInstance *master, uint64_t epoch) {
uint64_t max_votes = 0;
serverAssert(master->flags & (SRI_O_DOWN|SRI_FAILOVER_IN_PROGRESS));
- counters = dictCreate(&leaderVotesDictType,NULL);
+ counters = dictCreate(&leaderVotesDictType);
voters = dictSize(master->sentinels)+1; /* All the other sentinels and me.*/