MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / sendChildInfoGeneric

Function sendChildInfoGeneric

src/childinfo.cpp:71–113  ·  view source on GitHub ↗

Send save data to parent. */

Source from the content-addressed store, hash-verified

69
70/* Send save data to parent. */
71void sendChildInfoGeneric(childInfoType info_type, size_t keys, double progress, const char *pname) {
72 if (g_pserver->child_info_pipe[1] == -1) return;
73 if (g_pserver->rdbThreadVars.fRdbThreadActive && g_pserver->rdbThreadVars.fRdbThreadCancel) return;
74
75 static monotime cow_updated = 0;
76 static uint64_t cow_update_cost = 0;
77 static size_t cow = 0;
78
79 child_info_data data = {0}; /* zero everything, including padding to satisfy valgrind */
80
81 /* When called to report current info, we need to throttle down CoW updates as they
82 * can be very expensive. To do that, we measure the time it takes to get a reading
83 * and schedule the next reading to happen not before time*CHILD_COW_COST_FACTOR
84 * passes. */
85
86 monotime now = getMonotonicUs();
87 if (info_type != CHILD_INFO_TYPE_CURRENT_INFO ||
88 !cow_updated ||
89 now - cow_updated > cow_update_cost * CHILD_COW_DUTY_CYCLE)
90 {
91 cow = zmalloc_get_private_dirty(-1);
92 cow_updated = getMonotonicUs();
93 cow_update_cost = cow_updated - now;
94
95 if (cow) {
96 serverLog((info_type == CHILD_INFO_TYPE_CURRENT_INFO) ? LL_VERBOSE : LL_NOTICE,
97 "%s: %zu MB of memory used by copy-on-write",
98 pname, cow / (1024 * 1024));
99 }
100 }
101
102 data.information_type = info_type;
103 data.keys = keys;
104 data.cow = cow;
105 data.cow_updated = cow_updated;
106 data.progress = progress;
107
108 ssize_t wlen = sizeof(data);
109
110 if (write(g_pserver->child_info_pipe[1], &data, wlen) != wlen) {
111 /* Nothing to do on error, this will be detected by the other side. */
112 }
113}
114
115/* Update Child info. */
116void updateChildInfo(childInfoType information_type, size_t cow, monotime cow_updated, size_t keys, double progress) {

Callers 3

sendChildCowInfoFunction · 0.85
sendChildInfoFunction · 0.85
RM_SendChildHeartbeatFunction · 0.85

Calls 2

serverLogFunction · 0.85

Tested by

no test coverage detected