static void send_some_more_messages_later (void) { cpg_dispatch (cpg_handle, CS_DISPATCH_ALL); poll_timer_add ( ta_poll_handle_get(), 300, NULL, send_some_more_messages, &more_messages_timer_handle); }
static void send_some_more_messages_later (void) { cpg_dispatch (cpg_handle, CS_DISPATCH_ALL); qb_loop_timer_add ( ta_poll_handle_get(), QB_LOOP_MED, 300*QB_TIME_NS_IN_MSEC, NULL, send_some_more_messages, &more_messages_timer_handle); }
static int pcmk_cpg_dispatch(gpointer user_data) { cpg_handle_t *handle = (cpg_handle_t *) user_data; cs_error_t rc = cpg_dispatch(*handle, CS_DISPATCH_ALL); if (rc != CS_OK) { return -1; } return 0; }
static gboolean pcmk_cpg_dispatch(int sender, gpointer user_data) { cpg_handle_t *handle = (cpg_handle_t *) user_data; cs_error_t rc = cpg_dispatch(*handle, CS_DISPATCH_ALL); if (rc != CS_OK) { return FALSE; } return TRUE; }
int main (void) { cpg_handle_t handle; cs_error_t result; unsigned int i = 0; struct iovec iov; int res; unsigned int msg_size; result = cpg_initialize (&handle, &callbacks); if (result != CS_OK) { printf ("Couldn't initialize CPG service %d\n", result); exit (0); } res = cpg_join (handle, &group_name); if (res != CS_OK) { printf ("cpg_join failed with result %d\n", res); exit (1); } iov.iov_base = (void *)buffer; /* * Demonstrate cpg_mcast_joined */ msg_size = 1025000; for (i = 0; i < 1000000000; i++) { iov.iov_len = msg_size; try_again_one: result = cpg_mcast_joined (handle, CPG_TYPE_AGREED, &iov, 1); if (result == CS_ERR_TRY_AGAIN) { goto try_again_one; } if (result == CS_ERR_INVALID_PARAM) { printf ("found boundary at %d\n", msg_size); exit (1); } msg_size += 1; printf ("msg size %d\n", msg_size); result = cpg_dispatch (handle, CS_DISPATCH_ALL); } cpg_finalize (handle); return (0); }
static PyObject * py_cpg_dispatch(PyObject *self, PyObject *args) { int ret; cpg_handle_t handle; cs_dispatch_flags_t dispatch; if (!PyArg_ParseTuple(args, "li", &handle, &dispatch)) return NULL; ret = cpg_dispatch(handle, dispatch); RETURN_ON_ERROR(ret, "cpg_dispach"); Py_INCREF(Py_None); return Py_None; }
static void cpg_benchmark ( cpg_handle_t handle, int write_size) { struct timeval tv1, tv2, tv_elapsed; struct iovec iov; unsigned int res; cpg_flow_control_state_t flow_control_state; alarm_notice = 0; iov.iov_base = data; iov.iov_len = write_size; write_count = 0; alarm (10); gettimeofday (&tv1, NULL); do { /* * Test checkpoint write */ cpg_flow_control_state_get (handle, &flow_control_state); if (flow_control_state == CPG_FLOW_CONTROL_DISABLED) { retry: res = cpg_mcast_joined (handle, CPG_TYPE_AGREED, &iov, 1); if (res == CS_ERR_TRY_AGAIN) { goto retry; } } res = cpg_dispatch (handle, CS_DISPATCH_ALL); if (res != CS_OK) { printf ("cpg dispatch returned error %d\n", res); exit (1); } } while (alarm_notice == 0); gettimeofday (&tv2, NULL); timersub (&tv2, &tv1, &tv_elapsed); printf ("%5d messages received ", write_count); printf ("%5d bytes per write ", write_size); printf ("%7.3f Seconds runtime ", (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0))); printf ("%9.3f TP/s ", ((float)write_count) / (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0))); printf ("%7.3f MB/s.\n", ((float)write_count) * ((float)write_size) / ((tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)) * 1000000.0)); }
static int pcmk_cpg_dispatch(gpointer user_data) { int rc = 0; crm_cluster_t *cluster = (crm_cluster_t*) user_data; rc = cpg_dispatch(cluster->cpg_handle, CS_DISPATCH_ONE); if (rc != CS_OK) { crm_err("Connection to the CPG API failed: %s (%d)", ais_error2text(rc), rc); cluster->cpg_handle = 0; return -1; } else if(cpg_evicted) { crm_err("Evicted from CPG membership"); return -1; } return 0; }
gboolean send_cpg_message(struct iovec * iov) { int rc = CS_OK; int retries = 0; errno = 0; do { rc = cpg_mcast_joined(cpg_handle, CPG_TYPE_AGREED, iov, 1); if (rc == CS_ERR_TRY_AGAIN || rc == CS_ERR_QUEUE_FULL) { cpg_flow_control_state_t fc_state = CPG_FLOW_CONTROL_DISABLED; int rc2 = cpg_flow_control_state_get(cpg_handle, &fc_state); if (rc2 == CS_OK && fc_state == CPG_FLOW_CONTROL_ENABLED) { crm_debug("Attempting to clear cpg dispatch queue"); rc2 = cpg_dispatch(cpg_handle, CS_DISPATCH_ALL); } if (rc2 != CS_OK) { crm_warn("Could not check/clear the cpg connection"); goto bail; } else { retries++; crm_debug("Retrying operation after %ds", retries); sleep(retries); } } else { break; } /* 5 retires is plenty, we'll resend once the membership reforms anyway */ } while (retries < 5); bail: if (rc != CS_OK) { crm_err("Sending message via cpg FAILED: (rc=%d) %s", rc, ais_error2text(rc)); } return (rc == CS_OK); }
static int cpg_dispatch_wrapper_fn ( int fd, int revents, void *data) { cs_error_t error; if (revents & POLLHUP || revents & POLLERR) { qb_log (LOG_ERR, "got POLLHUP disconnecting from CPG"); cpg_finalize(cpg_handle); cpg_handle = 0; return -1; } error = cpg_dispatch (cpg_handle, CS_DISPATCH_ALL); if (error == CS_ERR_LIBRARY) { qb_log (LOG_ERR, "got LIB error disconnecting from CPG"); cpg_finalize(cpg_handle); cpg_handle = 0; return -1; } return 0; }
static int cpg_dispatch_wrapper_fn (hdb_handle_t handle, int fd, int revents, void *data) { cs_error_t error; if (revents & POLLHUP || revents & POLLERR) { syslog (LOG_ERR, "%s() got POLLHUP disconnecting from CPG", __func__); poll_dispatch_delete (ta_poll_handle_get(), cpg_fd); close (cpg_fd); cpg_fd = -1; return -1; } error = cpg_dispatch (cpg_handle, CS_DISPATCH_ALL); if (error == CS_ERR_LIBRARY) { syslog (LOG_ERR, "%s() got LIB error disconnecting from CPG", __func__); poll_dispatch_delete (ta_poll_handle_get(), cpg_fd); close (cpg_fd); cpg_fd = -1; return -1; } return 0; }
static void* dispatch_thread (void *arg) { cpg_dispatch (handle, CS_DISPATCH_BLOCKING); return NULL; }
static void test_cpg(void) { cpg_handle_t cpg_handle; struct cpg_name group_name; cs_error_t cs_res; unsigned int local_nodeid; int cpg_fd; struct pollfd pfd; int poll_res; int state; int cont; ENTER(); state = 0; strcpy(group_name.value, TEST_GROUP_NAME); group_name.length = strlen(TEST_GROUP_NAME); cs_repeat(cs_res = cpg_model_initialize(&cpg_handle, CPG_MODEL_V1, (cpg_model_data_t *)&model_data, NULL)); assert(cs_res == CS_OK); cs_repeat(cs_res = cpg_join(cpg_handle, &group_name)); assert(cs_res == CS_OK); cs_repeat(cs_res = cpg_local_get(cpg_handle, &local_nodeid)); assert(cs_res == CS_OK); assert(local_nodeid == TEST_NODEID); cs_repeat(cs_res = cpg_fd_get(cpg_handle, &cpg_fd)); assert(cs_res == CS_OK); cont = 1; do { pfd.fd = cpg_fd; pfd.events = POLLIN; pfd.revents = 0; poll_res = poll(&pfd, 1, INFTIM); if (poll_res == -1) { perror("poll_res == -1"); } assert(poll_res != 0); assert(pfd.revents & POLLIN); cs_repeat(cs_res = cpg_dispatch(cpg_handle, CS_DISPATCH_ALL)); assert(cs_res == CS_OK); switch (state) { case 0: /* * Waiting for cpg_confchg_received and cpg_totem_confchg_received */ if (cpg_confchg_received && cpg_totem_confchg_received) { /* * Send first message and wait for it in next state */ send_msg(cpg_handle); state = 1; } break; case 1: if (received_msg_seq_no >= MESSAGES_TO_SENT) { cont = 0; } else if (received_msg_seq_no == sent_msg_seq_no) { /* * Message delivered so sent new one and wait for it */ send_msg(cpg_handle); } break; } } while (cont); cs_repeat(cs_res = cpg_leave(cpg_handle, &group_name)); assert(cs_res == CS_OK); cs_repeat(cs_res = cpg_finalize(cpg_handle)); assert(cs_res == CS_OK); LEAVE(); }
int main (int argc, char *argv[]) { cpg_handle_t handle; cs_error_t result; int i = 0; int j; struct my_msg msg; struct iovec iov[2]; const char *options = "i:"; int iter = 1000; int opt; int run_forever = 1; unsigned int sha1_len; while ((opt = getopt(argc, argv, options)) != -1) { switch (opt) { case 'i': run_forever = 0; iter = atoi(optarg); break; } } result = cpg_initialize (&handle, &callbacks); if (result != CS_OK) { printf ("Couldn't initialize CPG service %d\n", result); exit (0); } if (NSS_NoDB_Init(".") != SECSuccess) { printf ("Couldn't initialize nss\n"); exit (0); } if ((sha1_context = PK11_CreateDigestContext(SEC_OID_SHA1)) == NULL) { printf ("Couldn't initialize nss\n"); exit (0); } result = cpg_join (handle, &group_name); if (result != CS_OK) { printf ("cpg_join failed with result %d\n", result); exit (1); } iov[0].iov_base = (void *)&msg; iov[0].iov_len = sizeof (struct my_msg); iov[1].iov_base = (void *)buffer; /* * Demonstrate cpg_mcast_joined */ i = 0; do { msg.msg_size = 100 + rand() % 100000; iov[1].iov_len = msg.msg_size; for (j = 0; j < msg.msg_size; j++) { buffer[j] = j; } sprintf ((char *)buffer, "cpg_mcast_joined: This is message %12d", i); PK11_DigestBegin(sha1_context); PK11_DigestOp(sha1_context, buffer, msg.msg_size); PK11_DigestFinal(sha1_context, msg.sha1, &sha1_len, sizeof(msg.sha1)); try_again_one: result = cpg_mcast_joined (handle, CPG_TYPE_AGREED, iov, 2); if (result == CS_ERR_TRY_AGAIN) { goto try_again_one; } result = cpg_dispatch (handle, CS_DISPATCH_ALL); i++; } while (run_forever || i < iter); PK11_DestroyContext(sha1_context, PR_TRUE); cpg_finalize (handle); return (0); }
cs_error_t CorosyncCpg::dispatchOne() { return cpg_dispatch(handle, CS_DISPATCH_ONE); }
int main (int argc, char *argv[]) { cpg_handle_t handle; fd_set read_fds; int select_fd; int result; const char *options = "i"; int opt; unsigned int nodeid; char *fgets_res; while ( (opt = getopt(argc, argv, options)) != -1 ) { switch (opt) { case 'i': show_ip = 1; break; } } if (argc > optind) { strcpy(group_name.value, argv[optind]); group_name.length = strlen(argv[optind]); } else { strcpy(group_name.value, "GROUP"); group_name.length = 6; } result = cpg_initialize (&handle, &callbacks); if (result != CS_OK) { printf ("Could not initialize Cluster Process Group API instance error %d\n", result); exit (1); } result = cpg_local_get (handle, &nodeid); if (result != CS_OK) { printf ("Could not get local node id\n"); exit (1); } printf ("Local node id is %x\n", nodeid); result = cpg_join(handle, &group_name); if (result != CS_OK) { printf ("Could not join process group, error %d\n", result); exit (1); } FD_ZERO (&read_fds); cpg_fd_get(handle, &select_fd); printf ("Type EXIT to finish\n"); do { FD_SET (select_fd, &read_fds); FD_SET (STDIN_FILENO, &read_fds); result = select (select_fd + 1, &read_fds, 0, 0, 0); if (result == -1) { perror ("select\n"); } if (FD_ISSET (STDIN_FILENO, &read_fds)) { char inbuf[132]; struct iovec iov; fgets_res = fgets(inbuf, sizeof(inbuf), stdin); if (fgets_res == NULL) { cpg_leave(handle, &group_name); } if (strncmp(inbuf, "EXIT", 4) == 0) { cpg_leave(handle, &group_name); } else { iov.iov_base = inbuf; iov.iov_len = strlen(inbuf)+1; cpg_mcast_joined(handle, CPG_TYPE_AGREED, &iov, 1); } } if (FD_ISSET (select_fd, &read_fds)) { if (cpg_dispatch (handle, CS_DISPATCH_ALL) != CS_OK) exit(1); } } while (result && !quit); result = cpg_finalize (handle); printf ("Finalize result is %d (should be 1)\n", result); return (0); }
cs_error_t CorosyncCpg::dispatchAll() { return cpg_dispatch(handle, CS_DISPATCH_ALL); }
cs_error_t CorosyncCpg::dispatchBlocking() { return cpg_dispatch(handle, CS_DISPATCH_BLOCKING); }
int main (int argc, char *argv[]) { cpg_handle_t handle; fd_set read_fds; int select_fd; int result; int retries; const char *options = "i"; int opt; unsigned int nodeid; char *fgets_res; struct cpg_address member_list[64]; int member_list_entries; int i; int recnt; int doexit; const char *exitStr = "EXIT"; doexit = 0; #ifdef QBLOG qb_log_init("testcpg", LOG_USER, LOG_ERR); qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE); qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD, QB_LOG_FILTER_FILE, "*", LOG_TRACE); qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE); qb_log_format_set(QB_LOG_STDERR, "[%p] %f %b"); #endif while ( (opt = getopt(argc, argv, options)) != -1 ) { switch (opt) { case 'i': show_ip = 1; break; } } if (argc > optind) { strcpy(group_name.value, argv[optind]); group_name.length = strlen(argv[optind]); } else { strcpy(group_name.value, "GROUP"); group_name.length = 6; } recnt = 0; printf ("Type %s to finish\n", exitStr); restart = 1; do { if(restart) { restart = 0; retries = 0; cs_repeat_init(retries, 30, result = cpg_model_initialize (&handle, CPG_MODEL_V1, (cpg_model_data_t *)&model_data, NULL)); if (result != CS_OK) { printf ("Could not initialize Cluster Process Group API instance error %d\n", result); retrybackoff(recnt); } retries = 0; cs_repeat(retries, 30, result = cpg_local_get(handle, &nodeid)); if (result != CS_OK) { printf ("Could not get local node id\n"); retrybackoff(recnt); } printf ("Local node id is %x\n", nodeid); nodeidStart = nodeid; retries = 0; cs_repeat(retries, 30, result = cpg_join(handle, &group_name)); if (result != CS_OK) { printf ("Could not join process group, error %d\n", result); retrybackoff(recnt); } retries = 0; cs_repeat(retries, 30, result = cpg_membership_get (handle, &group_name, (struct cpg_address *)&member_list, &member_list_entries)); if (result != CS_OK) { printf ("Could not get current membership list %d\n", result); retrybackoff(recnt); } recnt = 0; printf ("membership list\n"); for (i = 0; i < member_list_entries; i++) { printf ("node id %d pid %d\n", member_list[i].nodeid, member_list[i].pid); } FD_ZERO (&read_fds); cpg_fd_get(handle, &select_fd); } FD_SET (select_fd, &read_fds); FD_SET (STDIN_FILENO, &read_fds); result = select (select_fd + 1, &read_fds, 0, 0, 0); if (result == -1) { perror ("select\n"); } if (FD_ISSET (STDIN_FILENO, &read_fds)) { char inbuf[132]; struct iovec iov; fgets_res = fgets(inbuf, (int)sizeof(inbuf), stdin); if (fgets_res == NULL) { doexit = 1; cpg_leave(handle, &group_name); } if (strncmp(inbuf, exitStr, strlen(exitStr)) == 0) { doexit = 1; cpg_leave(handle, &group_name); } else { iov.iov_base = inbuf; iov.iov_len = strlen(inbuf)+1; cpg_mcast_joined(handle, CPG_TYPE_AGREED, &iov, 1); } } if (FD_ISSET (select_fd, &read_fds)) { if (cpg_dispatch (handle, CS_DISPATCH_ALL) != CS_OK) { if(doexit) { exit(1); } restart = 1; } } if(restart) { if(!doexit) { result = cpg_finalize (handle); printf ("Finalize+restart result is %d (should be 1)\n", result); continue; } } } while (result && !quit && !doexit); result = cpg_finalize (handle); printf ("Finalize result is %d (should be 1)\n", result); return (0); }
cs_error_t CorosyncCpg::dispatchOneNonBlocking() { return cpg_dispatch(handle, CS_DISPATCH_ONE_NONBLOCKING); }