Skip to content

Commit

Permalink
fixup! kvs: add date to kvs-primary checkpoint
Browse files Browse the repository at this point in the history
refactor, move log output into checkpoint_get()
  • Loading branch information
chu11 committed Feb 17, 2022
1 parent e99110f commit db3f6fa
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions src/modules/kvs/kvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2757,11 +2757,12 @@ static int checkpoint_get_version1 (const char *value,
* Return 0 on success, -1 on failure,
*/
static int checkpoint_get (flux_t *h, const char *key,
char *buf, size_t len,
double *timestamp)
char *buf, size_t len)
{
flux_future_t *f = NULL;
const char *value = NULL;
double timestamp = 0.;
char datestr[128];
int rv = -1;

if (!(f = flux_rpc_pack (h,
Expand All @@ -2775,11 +2776,23 @@ static int checkpoint_get (flux_t *h, const char *key,
if (flux_rpc_get_unpack (f, "{s:s}", "value", &value) < 0)
goto error;

if (checkpoint_get_version1 (value, buf, len, timestamp) < 0
if (checkpoint_get_version1 (value, buf, len, &timestamp) < 0
&& checkpoint_get_version0 (value, buf, len) < 0) {
errno = EINVAL;
goto error;
}

if (timestamp > 0.) {
time_t sec = timestamp;
struct tm tm;
gmtime_r (&sec, &tm);
strftime (datestr, sizeof (datestr), "%FT%T", &tm);
}
else
snprintf (datestr, sizeof (datestr), "N/A");

flux_log (h, LOG_INFO,
"restored kvs-primary from checkpoint on %s", datestr);
rv = 0;
error:
flux_future_destroy (f);
Expand Down Expand Up @@ -2923,27 +2936,12 @@ int mod_main (flux_t *h, int argc, char **argv)
if (ctx->rank == 0) {
struct kvsroot *root;
char rootref[BLOBREF_MAX_STRING_SIZE];
double timestamp = 0.;
uint32_t owner = getuid ();

/* Look for a checkpoint and use it if found.
* Otherwise start the primary root namespace with an empty directory.
*/
if (checkpoint_get (h, "kvs-primary",
rootref, sizeof (rootref), &timestamp) == 0) {
char datestr[128];
time_t sec = timestamp;
struct tm tm;
if (timestamp > 0.) {
gmtime_r (&sec, &tm);
strftime (datestr, sizeof (datestr), "%FT%T", &tm);
}
else
snprintf (datestr, sizeof (datestr), "N/A");
flux_log (h, LOG_INFO,
"restored kvs-primary from checkpoint on %s", datestr);
}
else {
if (checkpoint_get (h, "kvs-primary", rootref, sizeof (rootref)) < 0) {
if (store_initial_rootdir (ctx, rootref, sizeof (rootref)) < 0) {
flux_log_error (h, "storing initial root object");
goto done;
Expand Down

0 comments on commit db3f6fa

Please sign in to comment.