当前位置:网站首页>Gossip about redis source code 75
Gossip about redis source code 75
2022-07-03 23:23:00 【Tao song remains the same】
Here is the control code related to the pipeline , Just have a brief look :
#include "server.h"
#include <unistd.h>
typedef struct {
size_t keys;
size_t cow;
monotime cow_updated;
double progress;
childInfoType information_type; /* Type of information */
} child_info_data;
/* Open a child-parent channel used in order to move information about the
* RDB / AOF saving process from the child to the parent (for instance
* the amount of copy on write memory used) */
void openChildInfoPipe(void) {
if (pipe(server.child_info_pipe) == -1) {
/* On error our two file descriptors should be still set to -1,
* but we call anyway closeChildInfoPipe() since can't hurt. */
closeChildInfoPipe();
} else if (anetNonBlock(NULL,server.child_info_pipe[0]) != ANET_OK) {
closeChildInfoPipe();
} else {
server.child_info_nread = 0;
}
}
/* Close the pipes opened with openChildInfoPipe(). */
void closeChildInfoPipe(void) {
if (server.child_info_pipe[0] != -1 ||
server.child_info_pipe[1] != -1)
{
close(server.child_info_pipe[0]);
close(server.child_info_pipe[1]);
server.child_info_pipe[0] = -1;
server.child_info_pipe[1] = -1;
server.child_info_nread = 0;
}
}
/* Send save data to parent. */
void sendChildInfoGeneric(childInfoType info_type, size_t keys, double progress, char *pname) {
if (server.child_info_pipe[1] == -1) return;
static monotime cow_updated = 0;
static uint64_t cow_update_cost = 0;
static size_t cow = 0;
child_info_data data = {0}; /* zero everything, including padding to satisfy valgrind */
/* When called to report current info, we need to throttle down CoW updates as they
* can be very expensive. To do that, we measure the time it takes to get a reading
* and schedule the next reading to happen not before time*CHILD_COW_COST_FACTOR
* passes. */
monotime now = getMonotonicUs();
if (info_type != CHILD_INFO_TYPE_CURRENT_INFO ||
!cow_updated ||
now - cow_updated > cow_update_cost * CHILD_COW_DUTY_CYCLE)
{
cow = zmalloc_get_private_dirty(-1);
cow_updated = getMonotonicUs();
cow_update_cost = cow_updated - now;
if (cow) {
serverLog((info_type == CHILD_INFO_TYPE_CURRENT_INFO) ? LL_VERBOSE : LL_NOTICE,
"%s: %zu MB of memory used by copy-on-write",
pname, cow / (1024 * 1024));
}
}
data.information_type = info_type;
data.keys = keys;
data.cow = cow;
data.cow_updated = cow_updated;
data.progress = progress;
ssize_t wlen = sizeof(data);
if (write(server.child_info_pipe[1], &data, wlen) != wlen) {
/* Nothing to do on error, this will be detected by the other side. */
}
}
/* Update Child info. */
void updateChildInfo(childInfoType information_type, size_t cow, monotime cow_updated, size_t keys, double progress) {
if (information_type == CHILD_INFO_TYPE_CURRENT_INFO) {
server.stat_current_cow_bytes = cow;
server.stat_current_cow_updated = cow_updated;
server.stat_current_save_keys_processed = keys;
if (progress != -1) server.stat_module_progress = progress;
} else if (information_type == CHILD_INFO_TYPE_AOF_COW_SIZE) {
server.stat_aof_cow_bytes = cow;
} else if (information_type == CHILD_INFO_TYPE_RDB_COW_SIZE) {
server.stat_rdb_cow_bytes = cow;
} else if (information_type == CHILD_INFO_TYPE_MODULE_COW_SIZE) {
server.stat_module_cow_bytes = cow;
}
}
/* Read child info data from the pipe.
* if complete data read into the buffer,
* data is stored into *buffer, and returns 1.
* otherwise, the partial data is left in the buffer, waiting for the next read, and returns 0. */
int readChildInfo(childInfoType *information_type, size_t *cow, monotime *cow_updated, size_t *keys, double* progress) {
/* We are using here a static buffer in combination with the server.child_info_nread to handle short reads */
static child_info_data buffer;
ssize_t wlen = sizeof(buffer);
/* Do not overlap */
if (server.child_info_nread == wlen) server.child_info_nread = 0;
int nread = read(server.child_info_pipe[0], (char *)&buffer + server.child_info_nread, wlen - server.child_info_nread);
if (nread > 0) {
server.child_info_nread += nread;
}
/* We have complete child info */
if (server.child_info_nread == wlen) {
*information_type = buffer.information_type;
*cow = buffer.cow;
*cow_updated = buffer.cow_updated;
*keys = buffer.keys;
*progress = buffer.progress;
return 1;
} else {
return 0;
}
}
/* Receive info data from child. */
void receiveChildInfo(void) {
if (server.child_info_pipe[0] == -1) return;
size_t cow;
monotime cow_updated;
size_t keys;
double progress;
childInfoType information_type;
/* Drain the pipe and update child info so that we get the final message. */
while (readChildInfo(&information_type, &cow, &cow_updated, &keys, &progress)) {
updateChildInfo(information_type, cow, cow_updated, keys, progress);
}
}
边栏推荐
- Get current JVM data
- Arc135 partial solution
- The 2022 global software R & D technology conference was released, and world-class masters such as Turing prize winners attended
- [note] IPC traditional interprocess communication and binder interprocess communication principle
- D28:maximum sum (maximum sum, translation)
- 2022 a special equipment related management (elevator) examination questions and a special equipment related management (elevator) examination contents
- 2.14 summary
- [15th issue] Tencent PCG background development internship I, II and III (OC)
- How to quickly build high availability of service discovery
- [MySQL] sql99 syntax to realize multi table query
猜你喜欢

What are the common computer problems and solutions

Hcip day 14 notes

Apple released a supplementary update to MacOS Catalina 10.15.5, which mainly fixes security vulnerabilities

Ppt image processing

Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?

Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?

Learning notes of raspberry pie 4B - IO communication (SPI)

Meta metauniverse female safety problems occur frequently, how to solve the relevant problems in the metauniverse?

The interviewer's biggest lie to deceive you, bypassing three years of less struggle

How to connect a laptop to a projector
随机推荐
How to solve the problem of requiring a password when accessing your network neighborhood on your computer
Is the controller a single instance or multiple instances? How to ensure the safety of concurrency
How to quickly build high availability of service discovery
Open 2022 efficient office, starting from project management
Fashion cloud interview questions series - JS high-frequency handwritten code questions
Hcip 13th day notes
A treasure open source software, cross platform terminal artifact tabby
D29:post Office (post office, translation)
[note] glide process and source code analysis
ADB related commands
File copy method
In 2022, 6G development has indeed warmed up
What are the securities companies with the lowest Commission for stock account opening? Would you recommend it? Is it safe to open an account on your mobile phone
The difference between single power amplifier and dual power amplifier
Programming language (1)
Interpretation of corolla sub low configuration, three cylinder power configuration, CVT fuel saving and smooth, safety configuration is in place
Druids connect to mysql8.0.11
The reason why the computer runs slowly and how to solve it
2022 a special equipment related management (elevator) examination questions and a special equipment related management (elevator) examination contents
To rotate 90 degrees clockwise and modify the video format