void rpctest_begin_cb (flux_t h, flux_msg_watcher_t *w, const flux_msg_t *msg, void *arg) { const char *json_str; flux_rpc_t *r; errno = 0; ok (!(r = flux_rpc (h, NULL, NULL, FLUX_NODEID_ANY, 0)) && errno == EINVAL, "flux_rpc with NULL topic fails with EINVAL"); /* working no-payload RPC */ ok ((r = flux_rpc (h, "rpctest.hello", NULL, FLUX_NODEID_ANY, 0)) != NULL, "flux_rpc with no payload when none is expected works"); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); ok (flux_rpc_get (r, NULL, NULL) == 0, "flux_rpc_get works"); flux_rpc_destroy (r); /* cause remote EPROTO (unexpected payload) - will be picked up in _get() */ ok ((r = flux_rpc (h, "rpctest.hello", "foo", FLUX_NODEID_ANY, 0)) != NULL, "flux_rpc with payload when none is expected works, at first"); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); errno = 0; ok (flux_rpc_get (r, NULL, NULL) < 0 && errno == EPROTO, "flux_rpc_get fails with EPROTO"); flux_rpc_destroy (r); /* cause remote EPROTO (missing payload) - will be picked up in _get() */ errno = 0; ok ((r = flux_rpc (h, "rpctest.echo", NULL, FLUX_NODEID_ANY, 0)) != NULL, "flux_rpc with no payload when payload is expected works, at first"); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); errno = 0; ok (flux_rpc_get (r, NULL, NULL) < 0 && errno == EPROTO, "flux_rpc_get fails with EPROTO"); flux_rpc_destroy (r); /* working with-payload RPC */ ok ((r = flux_rpc (h, "rpctest.echo", "foo", FLUX_NODEID_ANY, 0)) != NULL, "flux_rpc with payload when payload is expected works"); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); json_str = NULL; ok (flux_rpc_get (r, NULL, &json_str) == 0 && json_str && !strcmp (json_str, "foo"), "flux_rpc_get works and returned expected payload"); flux_rpc_destroy (r); flux_reactor_stop (h); }
static void then_cb (flux_rpc_t *r, void *arg) { flux_t h = arg; uint32_t nodeid; if (flux_rpc_get (r, &nodeid, NULL) < 0 || !nodeset_add_rank (then_ns, nodeid) || ++then_count == 128) { flux_reactor_stop (flux_get_reactor (h)); } }
static void then_cb (flux_rpc_t *r, void *arg) { flux_t h = arg; const char *json_str; ok (flux_rpc_check (r) == true, "flux_rpc_check says get won't block in then callback"); json_str = NULL; ok (flux_rpc_get (r, NULL, &json_str) == 0 && json_str && !strcmp (json_str, "xxx"), "flux_rpc_get works and returned expected payload in then callback"); flux_reactor_stop (h); }
static void watch_timeout_cb (flux_reactor_t *r, flux_watcher_t *w, int revents, void *arg) { watch_count_t *wc = arg; /* timeout */ if (wc->lastcount == changecount) flux_reactor_stop (r); else wc->lastcount = changecount; }
void watch_prepare_cb (flux_reactor_t *r, flux_watcher_t *w, int revents, void *arg) { /* Tell main it can now launch commit threads */ if (!watch_init) { pthread_mutex_lock (&watch_init_lock); watch_init++; pthread_cond_signal (&watch_init_cond); pthread_mutex_unlock (&watch_init_lock); } if (changecount >= threadcount) flux_reactor_stop (r); }
static void store_completion (flux_rpc_t *rpc, void *arg) { flux_reactor_t *r = arg; const char *blobref; int blobref_size; if (flux_rpc_get_raw (rpc, &blobref, &blobref_size) < 0) log_err_exit ("store"); if (!blobref || blobref[blobref_size - 1] != '\0') log_msg_exit ("store: protocol error"); //printf ("%s\n", blobref); flux_rpc_destroy (rpc); if (--spam_cur_inflight < spam_max_inflight/2) flux_reactor_stop (r); }
static int unwatch_timer_cb (flux_t h, void *arg) { static int count = 0; const char *key = arg; if (kvs_put_int (h, key, count++) < 0) err_exit ("%s: kvs_put_int", __FUNCTION__); if (kvs_commit (h) < 0) err_exit ("%s: kvs_commit", __FUNCTION__); if (count == 10) { if (kvs_unwatch (h, key) < 0) err_exit ("%s: kvs_unwatch", __FUNCTION__); } else if (count == 20) flux_reactor_stop (flux_get_reactor (h)); return 0; }
static void unwatch_timer_cb (flux_reactor_t *r, flux_watcher_t *w, int revents, void *arg) { struct timer_ctx *ctx = arg; static int count = 0; log_msg ("%s", __FUNCTION__); if (kvs_put_int (ctx->h, ctx->key, count++) < 0) log_err_exit ("%s: kvs_put_int", __FUNCTION__); if (kvs_commit (ctx->h) < 0) log_err_exit ("%s: kvs_commit", __FUNCTION__); if (count == 10) { if (kvs_unwatch (ctx->h, ctx->key) < 0) log_err_exit ("%s: kvs_unwatch", __FUNCTION__); } else if (count == 20) flux_reactor_stop (r); }
/* expect val: {-1,0,1,...,(changes - 1)} * count will therefore run 0...changes. */ static int mt_watch_cb (const char *k, int val, void *arg, int errnum) { thd_t *t = arg; if (errnum != 0) { log_errn (errnum, "%d: %s", t->n, __FUNCTION__); return -1; } if (val == t->last_val) { log_msg ("%d: %s: called with same value as last time: %d", t->n, __FUNCTION__, val); return -1; } t->last_val = val; /* normal stop */ if (val + 1 == changes) flux_reactor_stop (flux_get_reactor (t->h)); t->change_count++; return 0; }
static void attach_stderr_ready_cb (kz_t *kz, void *arg) { t_kzutil_ctx_t *ctx = arg; int len; char *data; do { if ((len = kz_get (kz, &data)) < 0) { if (errno != EAGAIN) log_err_exit ("kz_get stderr"); } else if (len > 0) { if (write_all (STDERR_FILENO, data, len) < 0) log_err_exit ("write_all stderr"); free (data); } } while (len > 0); if (len == 0) { /* EOF */ if (--ctx->readers == 0) flux_reactor_stop (flux_get_reactor (ctx->h)); } }
void rpctest_thenbug_cb (flux_t h, flux_msg_watcher_t *w, const flux_msg_t *msg, void *arg) { (void)flux_rpc_check (thenbug_r); flux_reactor_stop (h); }
static int job_request_cb (flux_t h, int typemask, zmsg_t **zmsg, void *arg) { const char *json_str; json_object *o = NULL; const char *topic; if (flux_msg_get_topic (*zmsg, &topic) < 0) goto out; if (flux_msg_get_payload_json (*zmsg, &json_str) < 0) goto out; if (json_str && !(o = json_tokener_parse (json_str))) goto out; if (strcmp (topic, "job.shutdown") == 0) { flux_reactor_stop (h); } if (strcmp (topic, "job.next-id") == 0) { if (flux_rank (h) == 0) { unsigned long id = lwj_next_id (h); json_object *ox = json_id (id); flux_json_respond (h, ox, zmsg); json_object_put (o); } else { fprintf (stderr, "%s: forwarding request\n", topic); flux_json_request (h, FLUX_NODEID_ANY, FLUX_MATCHTAG_NONE, topic, o); } } if (strcmp (topic, "job.create") == 0) { json_object *jobinfo = NULL; unsigned long id = lwj_next_id (h); bool should_workaround = false; //"Fix" for Race Condition if (util_json_object_get_boolean (o, "race_workaround", &should_workaround) < 0) { should_workaround = false; } else if (should_workaround) { if (wait_for_lwj_watch_init (h, id) < 0) { flux_err_respond (h, errno, zmsg); goto out; } } int rc = kvs_job_new (h, id); if (rc < 0) { flux_err_respond (h, errno, zmsg); goto out; } add_jobinfo (h, id, o); kvs_commit (h); /* Generate reply with new jobid */ jobinfo = util_json_object_new_object (); util_json_object_add_int64 (jobinfo, "jobid", id); flux_json_respond (h, jobinfo, zmsg); json_object_put (jobinfo); } out: if (o) json_object_put (o); zmsg_destroy (zmsg); return 0; }
/* Manage shutdown of this module. * Tell content cache to disable backing store, * then write everything back to it before exiting. */ void shutdown_cb (flux_t *h, flux_msg_handler_t *mh, const flux_msg_t *msg, void *arg) { sqlite_ctx_t *ctx = arg; flux_future_t *f; int count = 0; int old_state; flux_log (h, LOG_DEBUG, "shutdown: begin"); if (register_backing_store (h, false, "content-sqlite") < 0) { flux_log_error (h, "shutdown: unregistering backing store"); goto done; } if (ctx->broker_shutdown) { flux_log (h, LOG_DEBUG, "shutdown: instance is terminating, don't reload to cache"); goto done; } //delay cancellation to ensure lock-correctness in sqlite pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old_state); while (sqlite3_step (ctx->dump_stmt) == SQLITE_ROW) { const char *blobref; int blobref_size; const void *data = NULL; int uncompressed_size; int size = sqlite3_column_bytes (ctx->dump_stmt, 0); if (sqlite3_column_type (ctx->dump_stmt, 0) != SQLITE_BLOB && size > 0) { flux_log (h, LOG_ERR, "shutdown: encountered non-blob value"); continue; } data = sqlite3_column_blob (ctx->dump_stmt, 0); if (sqlite3_column_type (ctx->dump_stmt, 1) != SQLITE_INTEGER) { flux_log (h, LOG_ERR, "shutdown: selected value is not an integer"); errno = EINVAL; goto done; } uncompressed_size = sqlite3_column_int (ctx->dump_stmt, 1); if (uncompressed_size != -1) { if (ctx->lzo_bufsize < uncompressed_size && grow_lzo_buf (ctx, uncompressed_size) < 0) goto done; int r = LZ4_decompress_safe (data, ctx->lzo_buf, size, uncompressed_size); if (r < 0) { errno = EINVAL; goto done; } if (r != uncompressed_size) { flux_log (h, LOG_ERR, "shutdown: blob size mismatch"); errno = EINVAL; goto done; } data = ctx->lzo_buf; size = uncompressed_size; } if (!(f = flux_rpc_raw (h, "content.store", data, size, FLUX_NODEID_ANY, 0))) { flux_log_error (h, "shutdown: store"); continue; } if (flux_rpc_get_raw (f, (const void **)&blobref, &blobref_size) < 0) { flux_log_error (h, "shutdown: store"); flux_future_destroy (f); continue; } if (!blobref || blobref[blobref_size - 1] != '\0') { flux_log (h, LOG_ERR, "shutdown: store returned malformed blobref"); flux_future_destroy (f); continue; } flux_future_destroy (f); count++; } (void )sqlite3_reset (ctx->dump_stmt); flux_log (h, LOG_DEBUG, "shutdown: %d entries returned to cache", count); done: pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &old_state); flux_reactor_stop (flux_get_reactor (h)); }
void rpctest_begin_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg) { const char *json_str; flux_rpc_t *r; errno = 0; ok (!(r = flux_rpc (h, NULL, NULL, FLUX_NODEID_ANY, 0)) && errno == EINVAL, "flux_rpc with NULL topic fails with EINVAL"); /* working no-payload RPC */ ok ((r = flux_rpc (h, "rpctest.hello", NULL, FLUX_NODEID_ANY, 0)) != NULL, "flux_rpc with no payload when none is expected works"); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); ok (flux_rpc_get (r, NULL) == 0, "flux_rpc_get works"); flux_rpc_destroy (r); /* cause remote EPROTO (unexpected payload) - will be picked up in _get() */ ok ((r = flux_rpc (h, "rpctest.hello", "{}", FLUX_NODEID_ANY, 0)) != NULL, "flux_rpc with payload when none is expected works, at first"); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); errno = 0; ok (flux_rpc_get (r, NULL) < 0 && errno == EPROTO, "flux_rpc_get fails with EPROTO"); flux_rpc_destroy (r); /* cause remote EPROTO (missing payload) - will be picked up in _get() */ errno = 0; ok ((r = flux_rpc (h, "rpctest.echo", NULL, FLUX_NODEID_ANY, 0)) != NULL, "flux_rpc with no payload when payload is expected works, at first"); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); errno = 0; ok (flux_rpc_get (r, NULL) < 0 && errno == EPROTO, "flux_rpc_get fails with EPROTO"); flux_rpc_destroy (r); /* working with-payload RPC */ ok ((r = flux_rpc (h, "rpctest.echo", "{}", FLUX_NODEID_ANY, 0)) != NULL, "flux_rpc with payload when payload is expected works"); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); json_str = NULL; ok (flux_rpc_get (r, &json_str) == 0 && json_str && !strcmp (json_str, "{}"), "flux_rpc_get works and returned expected payload"); flux_rpc_destroy (r); /* working with-payload RPC (raw) */ char *d, data[] = "aaaaaaaaaaaaaaaaaaaa"; int l, len = strlen (data); ok ((r = flux_rpc_raw (h, "rpctest.rawecho", data, len, FLUX_NODEID_ANY, 0)) != NULL, "flux_rpc_raw with payload when payload is expected works"); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); json_str = NULL; ok (flux_rpc_get_raw (r, &d, &l) == 0 && d != NULL && l == len && memcmp (data, d, len) == 0, "flux_rpc_get_raw works and returned expected payload"); flux_rpc_destroy (r); /* use newish pack/unpack payload interfaces */ int i = 0; ok ((r = flux_rpcf (h, "rpctest.incr", FLUX_NODEID_ANY, 0, "{s:i}", "n", 107)) != NULL, "flux_rpcf works"); ok (flux_rpc_getf (r, "{s:i}", "n", &i) == 0, "flux_rpc_getf works"); ok (i == 108, "and service returned incremented value"); flux_rpc_destroy (r); flux_reactor_stop (flux_get_reactor (h)); }
void rpctest_thenbug_cb (flux_t *h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg) { (void)flux_rpc_check (thenbug_r); flux_reactor_stop (flux_get_reactor (h)); }
static void shutdown_cb (flux_t h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg) { flux_reactor_stop (flux_get_reactor (h)); }