深入刨析Redis存储技术设计艺术(二)

server/2024/10/21 5:48:32/

三、Redis主存储

3.1、存储相关结构体

redisServer:服务器

server.h

struct redisServer {   /* General */   pid_t pid;                  /* Main process pid. */   pthread_t main_thread_id;         /* Main thread id */   char *configfile;           /* Absolute config file path, or NULL */   char *executable;           /* Absolute executable file path. */   char **exec_argv;           /* Executable argv vector (copy). */   int dynamic_hz;             /* Change hz value depending on # of clients. */   int config_hz;              /* Configured HZ value. May be different than                                  the actual 'hz' field value if dynamic-hz                                  is enabled. */   mode_t umask;               /* The umask value of the process on startup */   int hz;                     /* serverCron() calls frequency in hertz */   int in_fork_child;          /* indication that this is a fork child */   redisDb *db;   dict *commands;             /* Command table */   dict *orig_commands;        /* Command table before command renaming. */   aeEventLoop *el;   rax *errors;                /* Errors table */   redisAtomic unsigned int lruclock; /* Clock for LRU eviction */   volatile sig_atomic_t shutdown_asap; /* SHUTDOWN needed ASAP */   int activerehashing;        /* Incremental rehash in serverCron() */   int active_defrag_running;  /* Active defragmentation running (holds current scan aggressiveness) */   char *pidfile;              /* PID file path */   int arch_bits;              /* 32 or 64 depending on sizeof(long) */   int cronloops;              /* Number of times the cron function run */   char runid[CONFIG_RUN_ID_SIZE+1];  /* ID always different at every exec. */   int sentinel_mode;          /* True if this instance is a Sentinel. */   size_t initial_memory_usage; /* Bytes used after initialization. */   int always_show_logo;       /* Show logo even for non-stdout logging. */   int in_eval;                /* Are we inside EVAL? */   int in_exec;                /* Are we inside EXEC? */   int propagate_in_transaction;  /* Make sure we don't propagate nested MULTI/EXEC */   char *ignore_warnings;      /* Config: warnings that should be ignored. */   int client_pause_in_transaction; /* Was a client pause executed during this Exec? */   /* Modules */   dict *moduleapi;            /* Exported core APIs dictionary for modules. */   dict *sharedapi;            /* Like moduleapi but containing the APIs that                                  modules share with each other. */   list *loadmodule_queue;     /* List of modules to load at startup. */   int module_blocked_pipe[2]; /* Pipe used to awake the event loop if a                                  client blocked on a module command needs                                  to be processed. */   pid_t child_pid;            /* PID of current child */   int child_type;             /* Type of current child */   client *module_client;      /* "Fake" client to call Redis from modules */   /* Networking */   int port;                   /* TCP listening port */   int tls_port;               /* TLS listening port */   int tcp_backlog;            /* TCP listen() backlog */   char *bindaddr[CONFIG_BINDADDR_MAX]; /* Addresses we should bind to */   int bindaddr_count;         /* Number of addresses in server.bindaddr[] */   char *unixsocket;           /* UNIX socket path */   mode_t unixsocketperm;      /* UNIX socket permission */   socketFds ipfd;             /* TCP socket file descriptors */   socketFds tlsfd;            /* TLS socket file descriptors */   int sofd;                   /* Unix socket file descriptor */   socketFds cfd;              /* Cluster bus listening socket */   list *clients;              /* List of active clients */   list *clients_to_close;     /* Clients to close asynchronously */   list *clients_pending_write; /* There is to write or install handler. */   list *clients_pending_read;  /* Client has pending read socket buffers. */   list *slaves, *monitors;    /* List of slaves and MONITORs */   client *current_client;     /* Current client executing the command. */   rax *clients_timeout_table; /* Radix tree for blocked clients timeouts. */   long fixed_time_expire;     /* If > 0, expire keys against server.mstime. */   rax *clients_index;         /* Active clients dictionary by client ID. */   pause_type client_pause_type;      /* True if clients are currently paused */   list *paused_clients;       /* List of pause clients */   mstime_t client_pause_end_time;    /* Time when we undo clients_paused */   char neterr[ANET_ERR_LEN];   /* Error buffer for anet.c */   dict *migrate_cached_sockets;/* MIGRATE cached sockets */   redisAtomic uint64_t next_client_id; /* Next client unique ID. Incremental. */   int protected_mode;         /* Don't accept external connections. */   int gopher_enabled;         /* If true the server will reply to gopher                                  queries. Will still serve RESP2 queries. */   int io_threads_num;         /* Number of IO threads to use. */   int io_threads_do_reads;    /* Read and parse from IO threads? */   int io_threads_active;      /* Is IO threads currently active? */   long long events_processed_while_blocked; /* processEventsWhileBlocked() */
​   /* RDB / AOF loading information */   volatile sig_atomic_t loading; /* We are loading data from disk if true */   off_t loading_total_bytes;   off_t loading_rdb_used_mem;   off_t loading_loaded_bytes;   time_t loading_start_time;   off_t loading_process_events_interval_bytes;   /* Fast pointers to often looked up command */   struct redisCommand *delCommand, *multiCommand, *lpushCommand,                       *lpopCommand, *rpopCommand, *zpopminCommand,                       *zpopmaxCommand, *sremCommand, *execCommand,                       *expireCommand, *pexpireCommand, *xclaimCommand,                       *xgroupCommand, *rpoplpushCommand, *lmoveCommand;   /* Fields used only for stats */   time_t stat_starttime;          /* Server start time */   long long stat_numcommands;     /* Number of processed commands */   long long stat_numconnections;  /* Number of connections received */   long long stat_expiredkeys;     /* Number of expired keys */   double stat_expired_stale_perc; /* Percentage of keys probably expired */   long long stat_expired_time_cap_reached_count; /* Early expire cylce stops.*/   long long stat_expire_cycle_time_used; /* Cumulative microseconds used. */   long long stat_evictedkeys;     /* Number of evicted keys (maxmemory) */   long long stat_keyspace_hits;   /* Number of successful lookups of keys */   long long stat_keyspace_misses; /* Number of failed lookups of keys */   long long stat_active_defrag_hits;      /* number of allocations moved */   long long stat_active_defrag_misses;    /* number of allocations scanned but not moved */   long long stat_active_defrag_key_hits;  /* number of keys with moved allocations */   long long stat_active_defrag_key_misses;/* number of keys scanned and not moved */   long long stat_active_defrag_scanned;   /* number of dictEntries scanned */   size_t stat_peak_memory;        /* Max used memory record */   long long stat_fork_time;       /* Time needed to perform latest fork() */   double stat_fork_rate;          /* Fork rate in GB/sec. */   long long stat_total_forks;     /* Total count of fork. */   long long stat_rejected_conn;   /* Clients rejected because of maxclients */   long long stat_sync_full;       /* Number of full resyncs with slaves. */   long long stat_sync_partial_ok; /* Number of accepted PSYNC requests. */   long long stat_sync_partial_err;/* Number of unaccepted PSYNC requests. */   list *slowlog;                  /* SLOWLOG list of commands */   long long slowlog_entry_id;     /* SLOWLOG current entry ID */   long long slowlog_log_slower_than; /* SLOWLOG time limit (to get logged) */   unsigned long slowlog_max_len;     /* SLOWLOG max number of items logged */   struct malloc_stats cron_malloc_stats; /* sampled in serverCron(). */   redisAtomic long long stat_net_input_bytes; /* Bytes read from network. */   redisAtomic long long stat_net_output_bytes; /* Bytes written to network. */   size_t stat_current_cow_bytes;  /* Copy on write bytes while child is active. */   monotime stat_current_cow_updated;  /* Last update time of stat_current_cow_bytes */   size_t stat_current_save_keys_processed;  /* Processed keys while child is active. */   size_t stat_current_save_keys_total;  /* Number of keys when child started. */   size_t stat_rdb_cow_bytes;      /* Copy on write bytes during RDB saving. */ 

http://www.ppmy.cn/server/55882.html

相关文章

SwinTransformer的相对位置索引的原理以及源码分析

文章目录 1. 理论分析2. 完整代码 引用:参考博客链接 1. 理论分析 根据论文中提供的公式可知是在 Q Q Q和 K K K进行匹配并除以 d \sqrt d d ​ 后加上了相对位置偏执 B B B。 A t t e n t i o n ( Q , K , V ) S o f t m a x ( Q K T d B ) V \begin{aligned} &…

TQ15EG开发板教程:MPSOC创建fmcomms8工程

链接:https://pan.baidu.com/s/1jbuYs9alP2SaqnV5fpNgyg 提取码:r00c 本例程需要实现在hdl加no-OS系统中,通过修改fmcomms8/zcu102项目,实现在MPSOC两个fmc口上运行fmcomms8项目。 目录 1 下载文件与切换版本 2 编译fmcomms8项…

软考中级数据库系统工程师备考经验分享

前几天软考成绩出了,赶紧查询了一下发现自己顺利通过啦(上午63,下午67,开心),因此本文记录一下我的备考经验分享给大家。因为工作中项目管理类的知识没有系统学习过,本来想直接报名软考高级证书…

python读取写入txt文本文件

读取 txt 文件 def read_txt_file(file_path):"""读取文本文件的内容:param file_path: 文本文件的路径:return: 文件内容"""try:with open(file_path, r, encodingutf-8) as file:content file.read()return contentexcept FileNotFoundError…

机器学习原理之 -- XGboost原理详解

XGBoost(eXtreme Gradient Boosting)是近年来在数据科学和机器学习领域中广受欢迎的集成学习算法。它在多个数据科学竞赛中表现出色,被广泛应用于各种机器学习任务。本文将详细介绍XGBoost的由来、基本原理、算法细节、优缺点及应用场景。 X…

Shell Expect自动化交互(示例)

Shell Expect自动化交互 日常linux运维时,经常需要远程登录到服务器,登录过程中需要交互的过程,可能需要输入yes/no等信息,所以就用到expect来实现交互。 关键语法 ❶[#!/usr/bin/expect] 这一行告诉操…

苍穹外卖--sky-take-out(四)10-12

苍穹外卖--sky-take-out(一) 苍穹外卖--sky-take-out(一)-CSDN博客​编辑https://blog.csdn.net/kussm_/article/details/138614737?spm1001.2014.3001.5501https://blog.csdn.net/kussm_/article/details/138614737?spm1001.2…

【Gin】项目搭建 一

环境准备 首先确保自己电脑安装了Golang 开始项目 1、初始化项目 mkdir gin-hello; # 创建文件夹 cd gin-hello; # 需要到刚创建的文件夹里操作 go mod init goserver; # 初始化项目,项目名称:goserver go get -u github.com/gin-gonic/gin; # 下载…