Redis Internal: Hash Types

The Generic Hash Implementation Code Path: src/t_hash.c The generic hash type is a wrapper around listpack and dict, it will switch between two different implementation and call the routines accordingly. Listpack Implementation Code Path: src/listpack.c Listpack is a densed storage of a series of keys and values, it supports storing both integers and strings. If the hash size is lower than hash_max_listpack_value, it will be saved as a listpack. If the hash size is higher than hash_max_listpack_value, it will create a dict and copy the data from listpack to the dict. ...

November 26, 2022

Redis Architecture

Start-Up Procedures spt_init: This procedure initializes the process’s name and deep copy command-line arguments & environments. tzset. zmalloc_set_oom_handler init_genrand64 with timestamp and pid number. Code Path: mt19937-64.c crc64_init. Code Path: crc64.c umask dictSetHashFunctionSeed with a random 16-byte seed. Code Path: dict.c initServerConfig ACLInit. Code Path: acl.c moduleInitModulesSystem. Code Path: module.c connTypeInitialize. Code Path: connection.c initSentinelConfig and initSentinel if the server was started in sentinel mode. Code Path: sentinel.c Run redis_check_aof_main or redis_check_rdb_main and exit. Code Path: redis-check-aof.c, redis-check-rdb.c Parse command-line options and loadServerConfig. Code Path: config.c. sentinelCheckConfigFile if it’s in sentinel mode. Code Path: sentinel.c Check whether the server is supervised by upstart or systemd. daemonize if required. initServer. It initializes the global redisServer structure. createPidFile if required. redisSetProcTitle if required. checkTcpBacklogSettings. clusterInit if it’s in cluster mode. Code Path: cluster.c moduleLoadFromQueue. Code Path: module.c. ACLLoadUsersAtStartup, Code path: acl.c. initListeners. Redis supports multiple types of listeners, and each one has its own accept handling logic. The listeners will be registered by aeCreateFileEvent clusterInitListeners if it’s in cluster mode. Code Path: cluster.c bioInit initializes the redis’s background I/O. Code Path: bio.c initThreadedIO initializes the threaded I/O. Code Path: networking.c set_jemalloc_bg_thread. If it’s not sentinel mode: aofLoadManifestFromDisk. Code Path: aof.c loadDataFromDisk. It will either load the AOF file with loadAppendOnlyFiles, or load the RDB file with rdbLoad and initialize the replication backlog with createReplicationBacklog. RDB Code Path: rdb.c aofOpenIfNeededOnServerStart to open the AOF file on disk. Code Path: aof.c aofDelHistoryFiles to clear the history_aof_list. Code Path: aof.c verifyClusterConfigWithData check the cluster slots. Note that cluster mode only allows data in db 0. Code Path: cluster.c Else, do sentinelIsRunning. redisSetCpuAffinity setOOMScoreAdj will update the value in /proc/self/oom_score_adj aeMain starts the event loop. aeDeleteEventLoop after the event loop is finished. Code Path: ae.c Event Loop server.el got initialized during initServer. The main event loop is created, serverCron and module_pipe events are registered. beforeSleep and afterSleep are also configured on the event loop. ...

November 10, 2022