Skip to content

Commit 98c8c5e

Browse files
committed
MINOR: cli: implement wait on be-removable
Implement be-removable argument to CLI wait. This is implemented via be_check_for_deletion() invokation, also used by "del backend" handler. The objective is to test whether a backend instance can be removed. If this is not the case, the command may returns immediately if the target proxy is incompatible with dynamic removal or if a user action is required. Else, the command will wait until the temporary restriction is lifted.
1 parent 5ddfbd4 commit 98c8c5e

3 files changed

Lines changed: 31 additions & 4 deletions

File tree

doc/management.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2129,7 +2129,8 @@ del backend <name>
21292129

21302130
This operation is only possible for TCP or HTTP proxies. To succeed, the
21312131
backend instance must have been first unpublished. Also, all of its servers
2132-
must first be removed (via "del server" CLI).
2132+
must first be removed (via "del server" CLI). Finally, no stream must still
2133+
be attached to the backend instance.
21332134

21342135
There is additional restrictions which prevent backend removal. First, a
21352136
backend cannot be removed if it is explicitely referenced by config elements,
@@ -2139,6 +2140,10 @@ del backend <name>
21392140
cannot be removed if there is a stick-table declared in it. Finally, it is
21402141
impossible for now to remove a backend if QUIC servers were present in it.
21412142

2143+
It can be useful to use "wait be-removable" prior to this command to check
2144+
for the aformentioned requisites. This also provides a methode to wait for
2145+
the final closure of the streams attached to the target backend.
2146+
21422147
This command is restricted and can only be issued on sockets configured for
21432148
level "admin". Moreover, this feature is still considered in development so it
21442149
also requires experimental mode (see "experimental-mode on").
@@ -4545,6 +4550,13 @@ wait { -h | <delay> } [<condition> [<args>...]]
45454550
specified condition to be satisfied, to unrecoverably fail, or to remain
45464551
unsatisfied for the whole <delay> duration. The supported conditions are:
45474552

4553+
- be-removable <proxy> : this will wait for the specified proxy backend to be
4554+
removable by the "del backend" command. Some conditions will never be
4555+
accepted (e.g. backend not yet unpublished or with servers in it) and will
4556+
cause the report of a specific error message indicating what condition is
4557+
not met. If everything is OK before the delay, a success is returned and
4558+
the operation is terminated.
4559+
45484560
- srv-removable <proxy>/<server> : this will wait for the specified server to
45494561
be removable by the "del server" command, i.e. be in maintenance and no
45504562
longer have any connection on it (neither active or idle). Some conditions

include/haproxy/cli-t.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ enum cli_wait_err {
100100
enum cli_wait_cond {
101101
CLI_WAIT_COND_NONE, // no condition to wait on
102102
CLI_WAIT_COND_SRV_UNUSED,// wait for server to become unused
103+
CLI_WAIT_COND_BE_UNUSED, // wait for backend to become unused
103104
};
104105

105106
struct cli_wait_ctx {

src/cli.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,6 +2120,14 @@ static int cli_parse_wait(char **args, char *payload, struct appctx *appctx, voi
21202120
ctx->args[1] = ist0(sv_name);
21212121
ctx->cond = CLI_WAIT_COND_SRV_UNUSED;
21222122
}
2123+
else if (strcmp(args[2], "be-removable") == 0) {
2124+
if (!*args[3])
2125+
return cli_err(appctx, "Missing backend name.\n");
2126+
ctx->args[0] = strdup(args[3]);
2127+
if (!ctx->args[0])
2128+
return cli_err(appctx, "Out of memory trying to clone the backend name.\n");
2129+
ctx->cond = CLI_WAIT_COND_BE_UNUSED;
2130+
}
21232131
else if (*args[2]) {
21242132
/* show the command's help either upon request (-h) or error */
21252133
err = "Usage: wait {-h|<duration>} [condition [args...]]\n"
@@ -2165,9 +2173,15 @@ static int cli_io_handler_wait(struct appctx *appctx)
21652173

21662174
/* here we should evaluate our waiting conditions, if any */
21672175

2168-
if (ctx->cond == CLI_WAIT_COND_SRV_UNUSED) {
2169-
/* check if the server in args[0]/args[1] can be released now */
2170-
ret = srv_check_for_deletion(ctx->args[0], ctx->args[1], NULL, NULL, &ctx->msg);
2176+
if (ctx->cond == CLI_WAIT_COND_SRV_UNUSED ||
2177+
ctx->cond == CLI_WAIT_COND_BE_UNUSED) {
2178+
if (ctx->cond == CLI_WAIT_COND_SRV_UNUSED) {
2179+
/* check if the server in args[0]/args[1] can be released now */
2180+
ret = srv_check_for_deletion(ctx->args[0], ctx->args[1], NULL, NULL, &ctx->msg);
2181+
}
2182+
else {
2183+
ret = be_check_for_deletion(ctx->args[0], NULL, &ctx->msg);
2184+
}
21712185

21722186
if (ret < 0) {
21732187
/* unrecoverable failure */

0 commit comments

Comments
 (0)