Skip to content

Commit 41df35c

Browse files
committed
kvs: use zhashx for transaction_requests
Problem: In the kvsroot data structure, a zhash_t is used for transaction requests. A zhashx_t is preferred in flux-core nowadays because it does not have as large of a initial memory footprint. Convert transaction_requests from a zhash_t to zhashx_t.
1 parent 5318770 commit 41df35c

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

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/kvsroot.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static void kvsroot_destroy (void *data)
8888
if (root->ktm)
8989
kvstxn_mgr_destroy (root->ktm);
9090
if (root->transaction_requests)
91-
zhash_destroy (&(root->transaction_requests));
91+
zhashx_destroy (&(root->transaction_requests));
9292
if (root->wait_version_list)
9393
zlist_destroy (&root->wait_version_list);
9494
if (root->setroot_queue)
@@ -98,6 +98,13 @@ static void kvsroot_destroy (void *data)
9898
}
9999
}
100100

101+
/* zhashx_destructor_fn */
102+
static void flux_msg_decref_wrapper (void **item)
103+
{
104+
flux_msg_t *msg = *item;
105+
flux_msg_decref (msg);
106+
}
107+
101108
struct kvsroot *kvsroot_mgr_create_root (kvsroot_mgr_t *krm,
102109
struct cache *cache,
103110
const char *hash_name,
@@ -136,11 +143,17 @@ struct kvsroot *kvsroot_mgr_create_root (kvsroot_mgr_t *krm,
136143
goto error;
137144
}
138145

139-
if (!(root->transaction_requests = zhash_new ())) {
140-
flux_log_error (krm->h, "zhash_new");
146+
if (!(root->transaction_requests = zhashx_new ())) {
147+
flux_log_error (krm->h, "zhashx_new");
141148
goto error;
142149
}
143150

151+
zhashx_set_duplicator (root->transaction_requests,
152+
(zhashx_duplicator_fn *)flux_msg_incref);
153+
154+
zhashx_set_destructor (root->transaction_requests,
155+
(zhashx_destructor_fn *)flux_msg_decref_wrapper);
156+
144157
if (!(root->wait_version_list = zlist_new ())) {
145158
flux_log_error (krm->h, "zlist_new");
146159
goto error;
@@ -261,17 +274,13 @@ int kvsroot_save_transaction_request (struct kvsroot *root,
261274
return -1;
262275
}
263276

264-
if (zhash_insert (root->transaction_requests,
265-
name,
266-
(void *)flux_msg_incref (request)) < 0) {
267-
flux_msg_decref (request);
277+
if (zhashx_insert (root->transaction_requests,
278+
name,
279+
(void *)request) < 0) {
268280
errno = EEXIST;
269281
return -1;
270282
}
271283

272-
zhash_freefn (root->transaction_requests,
273-
name,
274-
(zhash_free_fn *)flux_msg_decref);
275284
return 0;
276285
}
277286

src/modules/kvs/kvsroot.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct kvsroot {
3030
int seq;
3131
char ref[BLOBREF_MAX_STRING_SIZE];
3232
kvstxn_mgr_t *ktm;
33-
zhash_t *transaction_requests;
33+
zhashx_t *transaction_requests;
3434
zlist_t *wait_version_list;
3535
double last_update_time;
3636
int flags;

src/modules/kvs/test/kvsroot.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ void basic_transaction_request_tests (void)
305305
0)) != NULL,
306306
"kvsroot_mgr_create_root works");
307307

308-
ok (zhash_size (root->transaction_requests) == 0,
308+
ok (zhashx_size (root->transaction_requests) == 0,
309309
"before saving transaction, no transaction_requests in hash");
310310

311311
if (!(request = flux_request_encode ("mytopic", "{ bar : 1 }")))
@@ -320,7 +320,7 @@ void basic_transaction_request_tests (void)
320320

321321
flux_msg_destroy (request);
322322

323-
ok (zhash_size (root->transaction_requests) == 1,
323+
ok (zhashx_size (root->transaction_requests) == 1,
324324
"after saving transaction, one transaction_requests in hash");
325325

326326
kvsroot_mgr_destroy (krm);

0 commit comments

Comments
 (0)