"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/childinfo.c" between
redis-6.2-rc3.tar.gz and redis-6.2.0.tar.gz

About: redis is an advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

childinfo.c  (redis-6.2-rc3):childinfo.c  (redis-6.2.0)
skipping to change at line 34 skipping to change at line 34
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "server.h" #include "server.h"
#include <unistd.h> #include <unistd.h>
typedef struct { typedef struct {
int process_type; /* AOF or RDB child? */ size_t keys;
int on_exit; /* COW size of active or exited child */ size_t cow;
size_t cow_size; /* Copy on write size. */ double progress;
childInfoType information_type; /* Type of information */
} child_info_data; } child_info_data;
/* Open a child-parent channel used in order to move information about the /* 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 * RDB / AOF saving process from the child to the parent (for instance
* the amount of copy on write memory used) */ * the amount of copy on write memory used) */
void openChildInfoPipe(void) { void openChildInfoPipe(void) {
if (pipe(server.child_info_pipe) == -1) { if (pipe(server.child_info_pipe) == -1) {
/* On error our two file descriptors should be still set to -1, /* On error our two file descriptors should be still set to -1,
* but we call anyway closeChildInfoPipe() since can't hurt. */ * but we call anyway closeChildInfoPipe() since can't hurt. */
closeChildInfoPipe(); closeChildInfoPipe();
skipping to change at line 67 skipping to change at line 68
server.child_info_pipe[1] != -1) server.child_info_pipe[1] != -1)
{ {
close(server.child_info_pipe[0]); close(server.child_info_pipe[0]);
close(server.child_info_pipe[1]); close(server.child_info_pipe[1]);
server.child_info_pipe[0] = -1; server.child_info_pipe[0] = -1;
server.child_info_pipe[1] = -1; server.child_info_pipe[1] = -1;
server.child_info_nread = 0; server.child_info_nread = 0;
} }
} }
/* Send COW data to parent. */ /* Send save data to parent. */
void sendChildInfo(int process_type, int on_exit, size_t cow_size) { void sendChildInfoGeneric(childInfoType info_type, size_t keys, double progress,
char *pname) {
if (server.child_info_pipe[1] == -1) return; if (server.child_info_pipe[1] == -1) return;
child_info_data buffer = {.process_type = process_type, .on_exit = on_exit, child_info_data data = {0}; /* zero everything, including padding to sattisf
.cow_size = cow_size}; y valgrind */
ssize_t wlen = sizeof(buffer); data.information_type = info_type;
data.keys = keys;
data.cow = zmalloc_get_private_dirty(-1);
data.progress = progress;
if (write(server.child_info_pipe[1],&buffer,wlen) != wlen) { if (data.cow) {
/* Nothing to do on error, this will be detected by the other side. */ serverLog((info_type == CHILD_INFO_TYPE_CURRENT_INFO) ? LL_VERBOSE : LL_
NOTICE,
"%s: %zu MB of memory used by copy-on-write",
pname, data.cow/(1024*1024));
} }
}
/* Update COW data. */ ssize_t wlen = sizeof(data);
void updateChildInfo(int process_type, int on_exit, size_t cow_size) {
if (!on_exit) { if (write(server.child_info_pipe[1], &data, wlen) != wlen) {
server.stat_current_cow_bytes = cow_size; /* Nothing to do on error, this will be detected by the other side. */
return;
} }
}
if (process_type == CHILD_TYPE_RDB) { /* Update Child info. */
server.stat_rdb_cow_bytes = cow_size; void updateChildInfo(childInfoType information_type, size_t cow, size_t keys, do
} else if (process_type == CHILD_TYPE_AOF) { uble progress) {
server.stat_aof_cow_bytes = cow_size; if (information_type == CHILD_INFO_TYPE_CURRENT_INFO) {
} else if (process_type == CHILD_TYPE_MODULE) { server.stat_current_cow_bytes = cow;
server.stat_module_cow_bytes = cow_size; 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 COW info data from the pipe. /* Read child info data from the pipe.
* if complete data read into the buffer, process type, copy-on-write type and c * if complete data read into the buffer,
opy-on-write size * data is stored into *buffer, and returns 1.
* are stored into *process_type, *on_exit and *cow_size respectively and return
s 1.
* otherwise, the partial data is left in the buffer, waiting for the next read, and returns 0. */ * otherwise, the partial data is left in the buffer, waiting for the next read, and returns 0. */
int readChildInfo(int *process_type, int *on_exit, size_t *cow_size) { int readChildInfo(childInfoType *information_type, size_t *cow, size_t *keys, do uble* progress) {
/* We are using here a static buffer in combination with the server.child_in fo_nread to handle short reads */ /* We are using here a static buffer in combination with the server.child_in fo_nread to handle short reads */
static child_info_data buffer; static child_info_data buffer;
ssize_t wlen = sizeof(buffer); ssize_t wlen = sizeof(buffer);
/* Do not overlap */ /* Do not overlap */
if (server.child_info_nread == wlen) server.child_info_nread = 0; if (server.child_info_nread == wlen) server.child_info_nread = 0;
int nread = read(server.child_info_pipe[0], (char *)&buffer + server.child_i nfo_nread, wlen - server.child_info_nread); int nread = read(server.child_info_pipe[0], (char *)&buffer + server.child_i nfo_nread, wlen - server.child_info_nread);
if (nread > 0) { if (nread > 0) {
server.child_info_nread += nread; server.child_info_nread += nread;
} }
/* We have complete child info */ /* We have complete child info */
if (server.child_info_nread == wlen) { if (server.child_info_nread == wlen) {
*process_type = buffer.process_type; *information_type = buffer.information_type;
*on_exit = buffer.on_exit; *cow = buffer.cow;
*cow_size = buffer.cow_size; *keys = buffer.keys;
*progress = buffer.progress;
return 1; return 1;
} else { } else {
return 0; return 0;
} }
} }
/* Receive COW data from child. */ /* Receive info data from child. */
void receiveChildInfo(void) { void receiveChildInfo(void) {
if (server.child_info_pipe[0] == -1) return; if (server.child_info_pipe[0] == -1) return;
int process_type; size_t cow;
int on_exit; size_t keys;
size_t cow_size; double progress;
childInfoType information_type;
/* Drain the pipe and update child info so that we get the final message. */ /* Drain the pipe and update child info so that we get the final message. */
while (readChildInfo(&process_type, &on_exit, &cow_size)) { while (readChildInfo(&information_type, &cow, &keys, &progress)) {
updateChildInfo(process_type, on_exit, cow_size); updateChildInfo(information_type, cow, keys, progress);
} }
} }
 End of changes. 14 change blocks. 
37 lines changed or deleted 51 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)