Skip to content

Commit 1fd480e

Browse files
chu11mergify[bot]
authored andcommitted
flux-kvs: support sync command
Problem: The only way to perform a sync is through the `flux kvs put` command, which inherently requires the user to also write data at the same time. This isn't necessarily always desired. Support a new `flux kvs sync` command. It is largely identical to `flux kvs put --sync`, but does not require additional data to be written. Fixes #6814
1 parent 16f72c4 commit 1fd480e

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/cmd/flux-kvs.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ int cmd_move (optparse_t *p, int argc, char **argv);
4747
int cmd_dir (optparse_t *p, int argc, char **argv);
4848
int cmd_ls (optparse_t *p, int argc, char **argv);
4949
int cmd_getroot (optparse_t *p, int argc, char **argv);
50+
int cmd_sync (optparse_t *p, int argc, char **argv);
5051
int cmd_eventlog (optparse_t *p, int argc, char **argv);
5152

5253
static int get_window_width (optparse_t *p, int fd);
@@ -373,6 +374,13 @@ static struct optparse_subcommand subcommands[] = {
373374
0,
374375
getroot_opts
375376
},
377+
{ "sync",
378+
NULL,
379+
"sync content and checkpoint to disk",
380+
cmd_sync,
381+
0,
382+
NULL
383+
},
376384
{ "eventlog",
377385
NULL,
378386
"Manipulate a KVS eventlog",
@@ -1828,6 +1836,37 @@ int cmd_getroot (optparse_t *p, int argc, char **argv)
18281836
return (0);
18291837
}
18301838

1839+
/* We could call kvs_checkpoint_commit() for syncing, however we
1840+
* choose to go with FLUX_KVS_SYNC and an empty transaction. That way
1841+
* this "transaction" goes into the same queue as other KVS
1842+
* transactions and syncs after all previously submitted KVS
1843+
* transactions. In contrast, kvs_checkpoint_commit() operates
1844+
* outside of the KVS transaction queue.
1845+
*/
1846+
int cmd_sync (optparse_t *p, int argc, char **argv)
1847+
{
1848+
flux_t *h;
1849+
int optindex = optparse_option_index (p);
1850+
flux_kvs_txn_t *txn;
1851+
flux_future_t *f;
1852+
1853+
if (optindex != argc) {
1854+
optparse_print_usage (p);
1855+
exit (1);
1856+
}
1857+
if (!(h = flux_open (NULL, 0)))
1858+
log_err_exit ("flux_open");
1859+
if (!(txn = flux_kvs_txn_create ()))
1860+
log_err_exit ("flux_kvs_txn_create");
1861+
if (!(f = flux_kvs_commit (h, NULL, FLUX_KVS_SYNC, txn))
1862+
|| flux_future_get (f, NULL) < 0)
1863+
log_err_exit ("flux_kvs_commit");
1864+
flux_future_destroy (f);
1865+
flux_kvs_txn_destroy (txn);
1866+
flux_close (h);
1867+
return (0);
1868+
}
1869+
18311870
/* combine 'argv' elements into one space-separated string (caller must free).
18321871
* assumes 'argv' is NULL terminated.
18331872
*/

0 commit comments

Comments
 (0)