Skip to content

Commit 712055f

Browse files
committed
MEDIUM: proxy: implement backend deletion
This patch finalizes "del backend" handler by implementing the proper proxy deletion. After ensuring backend deletion can be performed, several steps are executed. First, any watcher elements are updated to point on the next proxy instance. The backend is then removed from ID and name global trees and is finally detached from proxies_list. Once the backend instance is removed from proxies_list, the backend cannot be found by new elements. Thread isolation is lifted and proxy_drop() is called, which will purge the proxy if its refcount is null. Thanks to recently introduced PROXIES_DEL_LOCK, proxy_drop() is thread safe.
1 parent 6145f52 commit 712055f

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/proxy.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5098,7 +5098,8 @@ int be_check_for_deletion(const char *bename, struct proxy **pb, const char **pm
50985098
/* Handler for "delete backend". Runs under thread isolation. Always returns 1. */
50995099
static int cli_parse_delete_backend(char **args, char *payload, struct appctx *appctx, void *private)
51005100
{
5101-
struct proxy *px;
5101+
struct watcher *px_watch;
5102+
struct proxy *px, *prev;
51025103
const char *msg;
51035104
char *be_name;
51045105
int ret;
@@ -5120,11 +5121,32 @@ static int cli_parse_delete_backend(char **args, char *payload, struct appctx *a
51205121
goto out;
51215122
}
51225123

5124+
while (!MT_LIST_ISEMPTY(&px->watcher_list)) {
5125+
px_watch = MT_LIST_NEXT(&px->watcher_list, struct watcher *, el);
5126+
watcher_next(px_watch, px->next);
5127+
}
5128+
5129+
ceb32_item_delete(&used_proxy_id, conf.uuid_node, uuid, px);
5130+
cebis_item_delete(&proxy_by_name, conf.name_node, id, px);
5131+
5132+
/* Detach backend from global proxies_list. */
5133+
if (proxies_list == px) {
5134+
proxies_list = px->next;
5135+
}
5136+
else {
5137+
for (prev = proxies_list->next; prev && prev->next != px; prev = prev->next)
5138+
;
5139+
BUG_ON(!prev); /* Proxy instance not found in global list ? */
5140+
prev->next = px->next;
5141+
}
5142+
51235143
px->flags |= PR_FL_DELETED;
51245144

51255145
thread_release();
51265146

51275147
ha_notice("Backend deleted.\n");
5148+
proxy_drop(px);
5149+
51285150
cli_umsg(appctx, LOG_INFO);
51295151
return 1;
51305152

0 commit comments

Comments
 (0)