Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix memory leak when load list from rdb #48

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# redis-migrate-tool

**redis-migrate-tool** is a convenient and useful tool for migrating data between [redis](https://github.com/antirez/redis).
**redis-migrate-tool** is a convenient and useful tool for migrating data between [redis](https://github.com/antirez/redis). it has supported redis 5.0 rdb format v9.

## [中文介绍](http://www.oschina.net/p/redis-migrate-tool)

Expand Down
4 changes: 3 additions & 1 deletion src/rmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,9 @@ int main(int argc,char *argv[])
if (rmt_ctx == NULL) {
return RMT_ERROR;
}


set_rate_limiting(rmti.rate_limiting);

core_core(rmt_ctx);

destroy_context(rmt_ctx);
Expand Down
5 changes: 2 additions & 3 deletions src/rmt_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ static int writeThreadCron(struct aeEventLoop *eventLoop, long long id, void *cl

if (trgroup->password) {
sds reply;
reply = rmt_send_sync_cmd_read_line(tc->sd, "auth", trgroup->password, NULL);
reply = rmt_send_sync_auth(tc->sd, trgroup->password);
if (sdslen(reply) == 0 || reply[0] == '-') {
log_error("ERROR: password to %s is wrong", trnode->addr);
sdsfree(reply);
Expand Down Expand Up @@ -1597,11 +1597,10 @@ int prepare_send_msg(redis_node *srnode, struct msg *msg, redis_node *trnode)

if (trgroup->password) {
sds reply;
reply = rmt_send_sync_cmd_read_line(tc->sd, "auth", trgroup->password, NULL);
reply = rmt_send_sync_auth(tc->sd, trgroup->password);
if (sdslen(reply) == 0 || reply[0] == '-') {
log_error("ERROR: password to %s is wrong", trnode->addr);
sdsfree(reply);
return RMT_ERROR;
}
sdsfree(reply);
}
Expand Down
3 changes: 3 additions & 0 deletions src/rmt_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ struct instance {

char *listen;
int max_clients;
int rate_limiting;
};

typedef struct rmtContext {
Expand Down Expand Up @@ -291,6 +292,8 @@ void source_group_destroy(redis_group *srgroup);
redis_group *target_group_create(rmtContext *ctx);
void target_group_destroy(redis_group *trgroup);

void set_rate_limiting(int rl);

void redis_migrate(rmtContext *ctx, int type);
void redis_check_data(rmtContext *ctx, int type);
void redis_testinsert_data(rmtContext *ctx, int type);
Expand Down
19 changes: 16 additions & 3 deletions src/rmt_option.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#define RMT_OPTION_LISTEN_DEFAULT "127.0.0.1:8888"
#define RMT_OPTION_MAX_CLIENTS_DEFAULT 100

#define RMT_OPTION_RATE_LIMITING_DEFAULT 0

static struct option long_options[] = {
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
Expand All @@ -52,10 +54,11 @@ static struct option long_options[] = {
{ "from", required_argument, NULL, 'f' },
{ "to", required_argument, NULL, 't' },
{ "step", required_argument, NULL, 's' },
{ "rate-limiting", required_argument, NULL, 'l' },
{ NULL, 0, NULL, 0 }
};

static char short_options[] = "hVdnIo:v:c:p:m:C:r:R:T:b:S:f:t:s:";
static char short_options[] = "hVdnIo:v:c:p:m:C:r:R:T:b:S:f:t:s:l:";

void
rmt_show_usage(void)
Expand Down Expand Up @@ -88,6 +91,7 @@ rmt_show_usage(void)
" -f, --from=S : set source redis address (default: %s)" CRLF
" -t, --to=S : set target redis group address (default: %s)" CRLF
" -s, --step=N : set step (default: %d)" CRLF
" -l, --rate-limiting : rate limit of payload to backend server (default %d)" CRLF
"",
RMT_LOG_DEFAULT, RMT_LOG_MIN, RMT_LOG_MAX,
RMT_LOG_PATH != NULL ? RMT_LOG_PATH : "stderr",
Expand All @@ -101,7 +105,8 @@ rmt_show_usage(void)
RMT_OPTION_BUFFER_DEFAULT,
RMT_SOURCE_ADDR,
RMT_TARGET_ADDR,
RMT_OPTION_STEP_DEFAULT);
RMT_OPTION_STEP_DEFAULT,
RMT_OPTION_RATE_LIMITING_DEFAULT);

rmt_show_command_usage();
}
Expand Down Expand Up @@ -139,6 +144,7 @@ rmt_set_default_options(struct instance *nci)

nci->listen = RMT_OPTION_LISTEN_DEFAULT;
nci->max_clients = RMT_OPTION_MAX_CLIENTS_DEFAULT;
nci->rate_limiting = RMT_OPTION_RATE_LIMITING_DEFAULT;
}

r_status
Expand Down Expand Up @@ -307,7 +313,14 @@ rmt_get_options(int argc, char **argv, struct instance *nci)

nci->step = value;
break;

case 'l':
value = rmt_atoi(optarg, rmt_strlen(optarg));
if (value < 0) {
log_stderr("redis-migrate-tool: option -s requires a number >=0");
return RMT_ERROR;
}
nci->rate_limiting = value;
break;
case '?':
switch (optopt) {
case 'o':
Expand Down
Loading