Skip to content

Commit

Permalink
doveadm director flush: Added --max-parallel parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen committed Oct 25, 2016
1 parent 4a9870f commit 2e52280
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions src/doveadm/doveadm-director.c
Expand Up @@ -33,6 +33,7 @@ struct director_context {
struct istream *input;
bool explicit_socket_path;
bool hash_map, user_map, force_flush;
int64_t max_parallel;
};

struct user_list {
Expand Down Expand Up @@ -128,6 +129,8 @@ cmd_director_init(struct doveadm_cmd_context *cctx)
ctx->vhost_count = NULL;
if (!doveadm_cmd_param_str(cctx, "passdb-field", &(ctx->passdb_field)))
ctx->passdb_field = NULL;
if (!doveadm_cmd_param_int64(cctx, "max-parallel", &(ctx->max_parallel)))
ctx->max_parallel = 0;
if (!ctx->user_map)
director_connect(ctx);
return ctx;
Expand Down Expand Up @@ -629,8 +632,15 @@ static void cmd_director_flush_all(struct director_context *ctx)
{
const char *line;

director_send(ctx, ctx->force_flush ?
"HOST-FLUSH\n" : "HOST-RESET-USERS\n");
if (ctx->force_flush)
line = "HOST-FLUSH\n";
else if (ctx->max_parallel > 0) {
line = t_strdup_printf("HOST-RESET-USERS\t\t%lld\n",
(long long)ctx->max_parallel);
} else {
line = "HOST-RESET-USERS\n";
}
director_send(ctx, line);

line = i_stream_read_next_line(ctx->input);
if (line == NULL) {
Expand All @@ -651,6 +661,7 @@ static void cmd_director_flush(struct doveadm_cmd_context *cctx)
unsigned int i, ips_count;
struct ip_addr ip;
const char *line;
string_t *cmd;

ctx = cmd_director_init(cctx);
if (ctx->host == NULL) {
Expand All @@ -669,10 +680,20 @@ static void cmd_director_flush(struct doveadm_cmd_context *cctx)
if (director_get_host(ctx->host, &ips, &ips_count) != 0) return;
}

cmd = t_str_new(64);
for (i = 0; i < ips_count; i++) {
director_send(ctx, t_strdup_printf("%s\t%s\n",
ctx->force_flush ? "HOST-FLUSH" : "HOST-RESET-USERS",
net_ip2addr(&ip)));
str_truncate(cmd, 0);
if (ctx->force_flush)
str_printfa(cmd, "HOST-FLUSH\t%s\n", net_ip2addr(&ip));
else {
str_printfa(cmd, "HOST-RESET-USERS\t%s", net_ip2addr(&ip));
if (ctx->max_parallel > 0) {
str_printfa(cmd, "\t%lld",
(long long)ctx->max_parallel);
}
str_append_c(cmd, '\n');
}
director_send(ctx, str_c(cmd));
}
for (i = 0; i < ips_count; i++) {
line = i_stream_read_next_line(ctx->input);
Expand Down Expand Up @@ -942,10 +963,11 @@ DOVEADM_CMD_PARAMS_END
{
.name = "director flush",
.cmd = cmd_director_flush,
.usage = "[-a <director socket path>] [-F] <host>|all",
.usage = "[-a <director socket path>] [-F] [--max-parallel <n>] <host>|all",
DOVEADM_CMD_PARAMS_START
DOVEADM_CMD_PARAM('a', "socket-path", CMD_PARAM_STR, 0)
DOVEADM_CMD_PARAM('F', "force-flush", CMD_PARAM_BOOL, 0)
DOVEADM_CMD_PARAM('\0', "max-parallel", CMD_PARAM_INT64, 0)
DOVEADM_CMD_PARAM('\0', "host", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
DOVEADM_CMD_PARAMS_END
},
Expand Down

0 comments on commit 2e52280

Please sign in to comment.