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

news/2024/10/5 22:35:36/

三、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/news/1473761.html

相关文章

CountDownLatch简介

引言 在多线程编程中,线程之间的协调和同步是一个常见的需求。Java 提供了多种工具来实现这一目标,其中 CountDownLatch 是一种简单而强大的同步机制。本文将详细介绍 CountDownLatch 的概念、使用方法和实际应用场景。 1. CountDownLatch 概述 Count…

Python 函数递归

以下是一个使用递归计算阶乘的 Python 函数示例 : 应用场景: 1. 动态规划问题:在一些需要逐步求解子问题并利用其结果的动态规划场景中,递归可以帮助直观地表达问题的分解和求解过程。 2. 遍历具有递归结构的数据:如递…

vector模拟实现【C++】

文章目录 全部的实现代码放在了文章末尾准备工作包含头文件定义命名空间和类类的成员变量 迭代器迭代器获取函数 构造函数默认构造使用n个值构造迭代器区间构造解决迭代器区间构造和用n个值构造的冲突拷贝构造 析构函数swap【交换函数】赋值运算符重载emptysize和capacityopera…

使用kali Linux启动盘轻松破解Windows电脑密码

破解分析文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。谢谢!! 效果展示: 使用kali Linux可以轻松破解Windows用户及密码 准备阶段: &#xff08…

架构师应该在团队中发挥怎样的作用?

架构师分为5种: 1.企业架构师EA(Enterprise Architect) EA的职责是决定整个公司的技术路线和技术发展方向。 2.基础结构架构师IA(Infrastructure Architect) IA的工作就是提炼和优化技术方面积累和沉淀形成的基础性的、公共的、可复用的框架和组件,这…

【学习笔记】程序设计竞赛

程序设计竞赛 文章目录 程序设计竞赛0x00 基本操作指南0x01 算法分析0x02 STL和基本数据结构栈队列集合map 0x03 排序插入排序归并排序(Merge Sort)快速排序 0x04 搜索技术BFSDFS回溯与剪枝 深度迭代ID A*A star双向广搜 0x05 递推方程0x06 高级数据结构并查集二叉树…

基于Vue,mysql,JavaEE的简单投票与投票管理系统

项目介绍 ​ 本项目,基于Vue2.6,mysql,JavaEE 实现简单的投票与投票管理系统 项目地址 VotingSystem: 投票系统1.0 管理员和普通用户 (gitee.com) 有问题请评论私聊哦 项目分类 数据库 创建投票人,被投票人,投票关系(追踪谁…

Python中异步事件触发

1、问题背景 在Python中,我想创建一个由事件生成控制流程的类结构。为此,我做了以下工作: class MyEvent: EventName_FunctionName {}classmethoddef setup(cls, notificationname, functionname):if notificationname in MyEvent.EventN…