Skip to content

Commit b7141c4

Browse files
authored
Merge pull request #6627 from chu11/kvs_cleanup4
kvs: more misc cleanups
2 parents 27f4390 + 0b8a577 commit b7141c4

File tree

7 files changed

+264
-164
lines changed

7 files changed

+264
-164
lines changed

src/modules/kvs-watch/kvs-watch.c

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ struct ns_monitor {
8181
struct watch_ctx {
8282
flux_t *h;
8383
flux_msg_handler_t **handlers;
84-
zhash_t *namespaces; // hash of monitored namespaces
84+
zhashx_t *namespaces; // hash of monitored namespaces
8585
};
8686

8787
static void watcher_destroy (struct watcher *w)
@@ -164,9 +164,10 @@ static struct commit *commit_create (const char *rootref,
164164
return commit;
165165
}
166166

167-
static void namespace_destroy (struct ns_monitor *nsm)
167+
static void namespace_destroy (void **data)
168168
{
169-
if (nsm) {
169+
if (data) {
170+
struct ns_monitor *nsm = *data;
170171
int saved_errno = errno;
171172
commit_destroy (nsm->commit);
172173
zlistx_destroy (&nsm->watchers);
@@ -227,7 +228,7 @@ static struct ns_monitor *namespace_create (struct watch_ctx *ctx,
227228
nsm->subscribed = true;
228229
return nsm;
229230
error:
230-
namespace_destroy (nsm);
231+
namespace_destroy ((void **)&nsm);
231232
return NULL;
232233
}
233234

@@ -249,7 +250,7 @@ static void watcher_cleanup (struct ns_monitor *nsm, struct watcher *w)
249250
/* if nsm->getrootf, destroy when getroot_continuation completes */
250251
if (zlistx_size (nsm->watchers) == 0
251252
&& !nsm->getrootf)
252-
zhash_delete (nsm->ctx->namespaces, nsm->ns_name);
253+
zhashx_delete (nsm->ctx->namespaces, nsm->ns_name);
253254
}
254255

255256
static void handle_load_response (flux_future_t *f, struct watcher *w)
@@ -1072,7 +1073,7 @@ static void watcher_cancel_all (struct watch_ctx *ctx,
10721073
const flux_msg_t *msg,
10731074
bool cancel)
10741075
{
1075-
zlist_t *l;
1076+
zlistx_t *l;
10761077
char *name;
10771078
struct ns_monitor *nsm;
10781079
uint32_t matchtag = FLUX_MATCHTAG_NONE;
@@ -1083,14 +1084,14 @@ static void watcher_cancel_all (struct watch_ctx *ctx,
10831084
return;
10841085
}
10851086

1086-
if ((l = zhash_keys (ctx->namespaces))) {
1087-
name = zlist_first (l);
1087+
if ((l = zhashx_keys (ctx->namespaces))) {
1088+
name = zlistx_first (l);
10881089
while (name) {
1089-
nsm = zhash_lookup (ctx->namespaces, name);
1090+
nsm = zhashx_lookup (ctx->namespaces, name);
10901091
watcher_cancel_ns (nsm, msg, matchtag, cancel);
1091-
name = zlist_next (l);
1092+
name = zlistx_next (l);
10921093
}
1093-
zlist_destroy (&l);
1094+
zlistx_destroy (&l);
10941095
}
10951096
else
10961097
flux_log_error (ctx->h, "%s: zhash_keys", __FUNCTION__);
@@ -1112,7 +1113,7 @@ static void removed_cb (flux_t *h,
11121113
flux_log_error (h, "%s: flux_event_unpack", __FUNCTION__);
11131114
return;
11141115
}
1115-
if ((nsm = zhash_lookup (ctx->namespaces, ns))) {
1116+
if ((nsm = zhashx_lookup (ctx->namespaces, ns))) {
11161117
nsm->fatal_errnum = ENOTSUP;
11171118
watcher_respond_ns (nsm);
11181119
}
@@ -1145,7 +1146,7 @@ static void namespace_created_cb (flux_t *h,
11451146
flux_log_error (h, "%s: flux_event_unpack", __FUNCTION__);
11461147
return;
11471148
}
1148-
if (!(nsm = zhash_lookup (ctx->namespaces, ns))
1149+
if (!(nsm = zhashx_lookup (ctx->namespaces, ns))
11491150
|| nsm->commit)
11501151
return;
11511152
if (!(commit = commit_create (rootref, rootseq, NULL))) {
@@ -1189,7 +1190,7 @@ static void setroot_cb (flux_t *h,
11891190
flux_log_error (h, "%s: flux_event_unpack", __FUNCTION__);
11901191
return;
11911192
}
1192-
if (!(nsm = zhash_lookup (ctx->namespaces, ns))
1193+
if (!(nsm = zhashx_lookup (ctx->namespaces, ns))
11931194
|| (nsm->commit && rootseq <= nsm->commit->rootseq))
11941195
return;
11951196
if (!(commit = commit_create (rootref, rootseq, keys))) {
@@ -1219,7 +1220,7 @@ static void namespace_getroot_continuation (flux_future_t *f, void *arg)
12191220

12201221
/* small racy chance watcher canceled before getroot completes */
12211222
if (zlistx_size (nsm->watchers) == 0) {
1222-
zhash_delete (nsm->ctx->namespaces, nsm->ns_name);
1223+
zhashx_delete (nsm->ctx->namespaces, nsm->ns_name);
12231224
return;
12241225
}
12251226
if (nsm->commit) {
@@ -1260,21 +1261,19 @@ struct ns_monitor *namespace_monitor (struct watch_ctx *ctx,
12601261
{
12611262
struct ns_monitor *nsm;
12621263

1263-
if (!(nsm = zhash_lookup (ctx->namespaces, ns))) {
1264+
if (!(nsm = zhashx_lookup (ctx->namespaces, ns))) {
12641265
if (!(nsm = namespace_create (ctx, ns)))
12651266
return NULL;
1266-
(void)zhash_insert (ctx->namespaces, ns, nsm);
1267-
zhash_freefn (ctx->namespaces, ns,
1268-
(zhash_free_fn *)namespace_destroy);
1267+
(void)zhashx_insert (ctx->namespaces, ns, nsm);
12691268
/* store future in namespace, so namespace can be destroyed
12701269
* appropriately to avoid matchtag leak */
12711270
if (!(nsm->getrootf = flux_kvs_getroot (ctx->h, ns, 0))) {
1272-
zhash_delete (ctx->namespaces, ns);
1271+
zhashx_delete (ctx->namespaces, ns);
12731272
return NULL;
12741273
}
12751274
if (flux_future_then (nsm->getrootf, -1.,
12761275
namespace_getroot_continuation, nsm) < 0) {
1277-
zhash_delete (ctx->namespaces, ns);
1276+
zhashx_delete (ctx->namespaces, ns);
12781277
return NULL;
12791278
}
12801279
}
@@ -1380,7 +1379,7 @@ static void stats_cb (flux_t *h,
13801379

13811380
if (!(stats = json_object()))
13821381
goto nomem;
1383-
nsm = zhash_first (ctx->namespaces);
1382+
nsm = zhashx_first (ctx->namespaces);
13841383
while (nsm) {
13851384
json_t *o = json_pack ("{s:i s:i s:s s:i}",
13861385
"owner", (int)nsm->owner,
@@ -1396,13 +1395,13 @@ static void stats_cb (flux_t *h,
13961395
goto nomem;
13971396
}
13981397
watchers += zlistx_size (nsm->watchers);
1399-
nsm = zhash_next (ctx->namespaces);
1398+
nsm = zhashx_next (ctx->namespaces);
14001399
}
14011400
if (flux_respond_pack (h,
14021401
msg,
14031402
"{s:i s:i s:O}",
14041403
"watchers", watchers,
1405-
"namespace-count", (int)zhash_size (ctx->namespaces),
1404+
"namespace-count", (int)zhashx_size (ctx->namespaces),
14061405
"namespaces", stats) < 0)
14071406
flux_log_error (h,
14081407
"%s: failed to respond to kvs-watch.stats-get",
@@ -1460,7 +1459,7 @@ static void watch_ctx_destroy (struct watch_ctx *ctx)
14601459
{
14611460
if (ctx) {
14621461
int saved_errno = errno;
1463-
zhash_destroy (&ctx->namespaces);
1462+
zhashx_destroy (&ctx->namespaces);
14641463
flux_msg_handler_delvec (ctx->handlers);
14651464
free (ctx);
14661465
errno = saved_errno;
@@ -1475,8 +1474,10 @@ static struct watch_ctx *watch_ctx_create (flux_t *h)
14751474
ctx->h = h;
14761475
if (flux_msg_handler_addvec (h, htab, ctx, &ctx->handlers) < 0)
14771476
goto error;
1478-
if (!(ctx->namespaces = zhash_new ()))
1477+
if (!(ctx->namespaces = zhashx_new ()))
14791478
goto error;
1479+
zhashx_set_destructor (ctx->namespaces,
1480+
(zhashx_destructor_fn *)namespace_destroy);
14801481
return ctx;
14811482
error:
14821483
watch_ctx_destroy (ctx);

src/modules/kvs/kvs.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ static int heartbeat_root_cb (struct kvsroot *root, void *arg)
12341234

12351235
if (root->remove) {
12361236
if (!zlist_size (root->wait_version_list)
1237-
&& !zhash_size (root->transaction_requests)
1237+
&& !zhashx_size (root->transaction_requests)
12381238
&& !kvstxn_mgr_ready_transaction_count (root->ktm)) {
12391239

12401240
if (event_unsubscribe (ctx, root->ns_name) < 0)
@@ -1252,7 +1252,7 @@ static int heartbeat_root_cb (struct kvsroot *root, void *arg)
12521252
&& !root->is_primary
12531253
&& (now - root->last_update_time) > max_namespace_age
12541254
&& !zlist_size (root->wait_version_list)
1255-
&& !zhash_size (root->transaction_requests)
1255+
&& !zhashx_size (root->transaction_requests)
12561256
&& !kvstxn_mgr_ready_transaction_count (root->ktm)) {
12571257
/* remove a root if it not the primary one, has timed out
12581258
* on a follower node, and it does not have any watchers,
@@ -1602,9 +1602,9 @@ static void finalize_transaction_bynames (struct kvs_ctx *ctx,
16021602
return;
16031603
}
16041604
nameval = json_string_value (name);
1605-
if ((msg = zhash_lookup (root->transaction_requests, nameval))) {
1605+
if ((msg = zhashx_lookup (root->transaction_requests, nameval))) {
16061606
finalize_transaction_req (msg, &cbd);
1607-
zhash_delete (root->transaction_requests, nameval);
1607+
zhashx_delete (root->transaction_requests, nameval);
16081608
}
16091609
}
16101610
}
@@ -2060,7 +2060,7 @@ static int stats_get_root_cb (struct kvsroot *root, void *arg)
20602060
"#no-op stores",
20612061
kvstxn_mgr_get_noop_stores (root->ktm),
20622062
"#transactions",
2063-
zhash_size (root->transaction_requests),
2063+
zhashx_size (root->transaction_requests),
20642064
"#readytransactions",
20652065
kvstxn_mgr_ready_transaction_count (root->ktm),
20662066
"store revision", root->seq))) {

src/modules/kvs/kvs_wait_version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ static void kvs_wait_version_destroy (void *data)
5050
{
5151
struct kvs_wait_version *ks = data;
5252
if (ks) {
53+
int save_errno = errno;
5354
flux_msg_decref (ks->msg);
5455
free (ks);
56+
errno = save_errno;
5557
}
5658
}
5759

0 commit comments

Comments
 (0)