static void check_unit_destroy(check_unit *cunit) { if (cunit->cdata != NULL) { cunit->cdata->finished_keys_count ++; if (cunit->cdata->finished_keys_count >= cunit->cdata->keys_count) { aeStop(cunit->cdata->loop); } } if (cunit->key != NULL) { sdsfree(cunit->key); cunit->key = NULL; } if (cunit->result1 != NULL) { msg_put(cunit->result1); msg_free(cunit->result1); cunit->result1 = NULL; } if (cunit->result2 != NULL) { msg_put(cunit->result2); msg_free(cunit->result2); cunit->result2 = NULL; } rmt_free(cunit); }
struct msg * msg_get(mbuf_base *mb, int request, int kind) { struct msg *msg; if (mb == NULL) { return NULL; } msg = _msg_get(); if (msg == NULL) { return NULL; } msg->mb = mb; msg->request = request ? 1 : 0; if (request) { if (kind == REDIS_DATA_TYPE_RDB) { msg->parser = redis_parse_req_rdb; } else if(kind == REDIS_DATA_TYPE_CMD) { msg->parser = redis_parse_req; } else { msg_put(msg); msg_free(msg); return NULL; } msg->kind = kind; } else { msg->parser = redis_parse_rsp; } msg->data = listCreate(); if (msg->data == NULL) { msg_put(msg); msg_free(msg); return NULL; } if (request) { msg->request = 1; } else { msg->request = 0; } msg->fragment = redis_fragment; msg->reply = redis_reply; msg->pre_coalesce = redis_pre_coalesce; msg->post_coalesce = redis_post_coalesce; msg->resp_check = redis_response_check; log_debug(LOG_VVERB, "get msg %p id %"PRIu64" request %d", msg, msg->id, msg->request); return msg; }
void task1(void *arg) { os_printf("task1 start....\n"); for (;;) { #if msg_queue_test msg_put(&my_queue, &msg1, FIFO); msg_put(&my_queue, &msg2, FIFO); msg_put(&my_queue, &msg3, FIFO); msg_put(&my_queue1, &msg4, FIFO); msg_put(&my_queue1, &msg5, FIFO); msg_put(&my_queue1, &msg6, FIFO); msg_put(&my_queue2, &msg7, FIFO); msg_put(&my_queue2, &msg8, FIFO); msg_put(&my_queue2, &msg9, FIFO); #endif #if sem_test sem_put(&sem); os_printf("task1 sem.count = %d\n", sem.count ); #endif #if mutex_test mutex_get(&mutex); os_printf("task1 priority: %d\n", new_task->prio ); schedule(); os_printf("task1 running\n"); mutex_put(&mutex); #endif os_delay(300); } }
/* IE_COMPLETE */ void enc_ie_complete(unsigned char **ntmode, msg_t *msg, int complete, int nt, struct misdn_bchannel *bc) { unsigned char *p; Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN); if (complete<0 || complete>1) { printf("%s: ERROR: complete(%d) is out of range.\n", __FUNCTION__, complete); return; } if (complete) if (MISDN_IE_DEBG) printf(" complete=%d\n", complete); if (complete) { p = msg_put(msg, 1); if (nt) { *ntmode = p; } else qi->sending_complete = p - (unsigned char *)qi - sizeof(Q931_info_t); p[0] = IE_COMPLETE; } }
void dnode_rsp_put(struct msg *msg) { ASSERT(!msg->request); ASSERT(msg->peer == NULL); msg_put(msg); }
static void req_forward_remote_dc(struct context *ctx, struct conn *c_conn, struct msg *msg, struct mbuf *orig_mbuf, uint8_t *key, uint32_t keylen, struct datacenter *dc) { uint32_t rack_cnt = array_n(&dc->racks); if (rack_cnt == 0) return; struct rack *rack = dc->preselected_rack_for_replication; if (rack == NULL) rack = array_get(&dc->racks, 0); struct msg *rack_msg = msg_get(c_conn, msg->request, __FUNCTION__); if (rack_msg == NULL) { log_debug(LOG_VERB, "whelp, looks like yer screwed now, buddy. no inter-rack messages for you!"); msg_put(rack_msg); return; } msg_clone(msg, orig_mbuf, rack_msg); log_info("msg (%d:%d) clone to remote rack msg (%d:%d)", msg->id, msg->parent_id, rack_msg->id, rack_msg->parent_id); rack_msg->swallow = true; if (log_loggable(LOG_DEBUG)) { log_debug(LOG_DEBUG, "forwarding request to conn '%s' on rack '%.*s'", dn_unresolve_peer_desc(c_conn->sd), rack->name->len, rack->name->data); } remote_req_forward(ctx, c_conn, rack_msg, rack, key, keylen); }
void kernel_footprint(void) { init(); // generate code for process struct Process *p = proc_new(proc1_main, 0, sizeof(proc1_stack), proc1_stack); proc_setPri(p, 5); proc_yield(); // generate code for msg Msg msg; msg_initPort(&in_port, event_createSignal(p, SIG_USER1)); msg_put(&in_port, &msg); msg_peek(&in_port); Msg *msg_re = msg_get(&in_port); msg_reply(msg_re); // generate code for signals sig_send(p, SIG_USER0); // generate code for msg Semaphore sem; sem_init(&sem); sem_obtain(&sem); sem_release(&sem); sig_wait(SIG_USER0); }
/* IE_CALLED_PN */ void enc_ie_called_pn(unsigned char **ntmode, msg_t *msg, int type, int plan, unsigned char *number, int nt, struct misdn_bchannel *bc) { unsigned char *p; Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN); int l; if (type<0 || type>7) { printf("%s: ERROR: type(%d) is out of range.\n", __FUNCTION__, type); return; } if (plan<0 || plan>15) { printf("%s: ERROR: plan(%d) is out of range.\n", __FUNCTION__, plan); return; } if (!number[0]) { printf("%s: ERROR: number is not given.\n", __FUNCTION__); return; } if (MISDN_IE_DEBG) printf(" type=%d plan=%d number='%s'\n", type, plan, number); l = 1+strlen((char *)number); p = msg_put(msg, l+2); if (nt) *ntmode = p+1; else qi->called_nr = p - (unsigned char *)qi - sizeof(Q931_info_t); p[0] = IE_CALLED_PN; p[1] = l; p[2] = 0x80 + (type<<4) + plan; strncpy((char *)p+3, (char *)number, strlen((char *)number)); }
/* IE_BEARER */ void enc_ie_bearer(unsigned char **ntmode, msg_t *msg, int coding, int capability, int mode, int rate, int multi, int user, int nt, struct misdn_bchannel *bc) { unsigned char *p; Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN); int l; if (coding<0 || coding>3) { printf("%s: ERROR: coding(%d) is out of range.\n", __FUNCTION__, coding); return; } if (capability<0 || capability>31) { printf("%s: ERROR: capability(%d) is out of range.\n", __FUNCTION__, capability); return; } if (mode<0 || mode>3) { printf("%s: ERROR: mode(%d) is out of range.\n", __FUNCTION__, mode); return; } if (rate<0 || rate>31) { printf("%s: ERROR: rate(%d) is out of range.\n", __FUNCTION__, rate); return; } if (multi>127) { printf("%s: ERROR: multi(%d) is out of range.\n", __FUNCTION__, multi); return; } if (user>31) { printf("%s: ERROR: user L1(%d) is out of range.\n", __FUNCTION__, rate); return; } if (rate!=24 && multi>=0) { printf("%s: WARNING: multi(%d) is only possible if rate(%d) would be 24.\n", __FUNCTION__, multi, rate); multi = -1; } if (MISDN_IE_DEBG) printf(" coding=%d capability=%d mode=%d rate=%d multi=%d user=%d\n", coding, capability, mode, rate, multi, user); l = 2 + (multi>=0) + (user>=0); p = msg_put(msg, l+2); if (nt) *ntmode = p+1; else qi->bearer_capability = p - (unsigned char *)qi - sizeof(Q931_info_t); p[0] = IE_BEARER; p[1] = l; p[2] = 0x80 + (coding<<5) + capability; p[3] = 0x80 + (mode<<5) + rate; if (multi >= 0) p[4] = 0x80 + multi; if (user >= 0) p[4+(multi>=0)] = 0xa0 + user; }
void rsp_put(struct msg *msg) { if (!msg) return; ASSERT(!msg->request); //ASSERT(msg->peer == NULL); msg_put(msg); }
/* IE_CALLING_PN */ void enc_ie_calling_pn(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, int screen, unsigned char *number, int nt, struct misdn_bchannel *bc) { unsigned char *p; Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN); int l; if (type<0 || type>7) { printf("%s: ERROR: type(%d) is out of range.\n", __FUNCTION__, type); return; } if (plan<0 || plan>15) { printf("%s: ERROR: plan(%d) is out of range.\n", __FUNCTION__, plan); return; } if (present>3) { printf("%s: ERROR: present(%d) is out of range.\n", __FUNCTION__, present); return; } if (present >= 0) if (screen<0 || screen>3) { printf("%s: ERROR: screen(%d) is out of range.\n", __FUNCTION__, screen); return; } if (MISDN_IE_DEBG) printf(" type=%d plan=%d present=%d screen=%d number='%s'\n", type, plan, present, screen, number); l = 1; if (number) if (number[0]) l += strlen((char *)number); if (present >= 0) l += 1; p = msg_put(msg, l+2); if (nt) *ntmode = p+1; else qi->calling_nr = p - (unsigned char *)qi - sizeof(Q931_info_t); p[0] = IE_CALLING_PN; p[1] = l; if (present >= 0) { p[2] = 0x00 + (type<<4) + plan; p[3] = 0x80 + (present<<5) + screen; if (number) if (number[0]) strncpy((char *)p+4, (char *)number, strlen((char *)number)); } else { p[2] = 0x80 + (type<<4) + plan; if (number) if (number[0]) strncpy((char *)p+3, (char *)number, strlen((char *)number)); } }
static void l2_mdl_assign(struct FsmInst *fi, int event, void *arg) { layer2_t *l2 = fi->userdata; msg_t *msg = arg; mISDNuser_head_t *hh; FsmChangeState(fi, ST_L2_3); msg_trim(msg, 0); hh = (mISDNuser_head_t *)msg_put(msg, mISDNUSER_HEAD_SIZE); hh->prim = MDL_ASSIGN | INDICATION; hh->dinfo = 0; if (l2_tei(l2->tm, msg)) free_msg(msg); }
void main() { queue_create(&my_queue, 1000, "first", 0); MSG msg1; MSG msg2; MSG msg3; msg1.buff = "abcd"; msg2.buff = "abce"; msg3.buff = "abcf"; printf("test read = %s\n", msg1.buff); U8 *buffer = (U8 *)malloc(10); memset(buffer, 0, 10); msg_put(&my_queue, &msg1, 0); msg_put(&my_queue, &msg2, 0); msg_put(&my_queue, &msg3, 0); msg_get(&my_queue, buffer); printf("first read = %s\n", buffer); msg_get(&my_queue, buffer); printf("second read = %s\n", buffer); msg_get(&my_queue, buffer); printf("three read = %s\n", buffer); }
void req_put(struct msg *msg) { struct msg *pmsg; /* peer message (response) */ ASSERT(msg->request); pmsg = msg->peer; if (pmsg != NULL) { ASSERT(!pmsg->request && pmsg->peer == msg); msg->peer = NULL; pmsg->peer = NULL; rsp_put(pmsg); } msg_put(msg); }
static void send_uframe(layer2_t *l2, msg_t *msg, u_char cmd, u_char cr) { u_char tmp[MAX_HEADER_LEN]; int i; i = sethdraddr(l2, tmp, cr); tmp[i++] = cmd; if (msg) msg_trim(msg, 0); else if ((msg = alloc_msg(i + mISDNUSER_HEAD_SIZE))) msg_reserve(msg, mISDNUSER_HEAD_SIZE); else { dprint(DBGM_L2, l2->nst->cardnr,"%s: can't alloc msguff\n", __FUNCTION__); return; } memcpy(msg_put(msg, i), tmp, i); msg_push(msg, mISDNUSER_HEAD_SIZE); enqueue_super(l2, msg); }
void enquiry_cr(layer2_t *l2, u_char typ, u_char cr, u_char pf) { msg_t *msg; u_char tmp[MAX_HEADER_LEN]; int i; i = sethdraddr(l2, tmp, cr); if (test_bit(FLG_MOD128, &l2->flag)) { tmp[i++] = typ; tmp[i++] = (l2->vr << 1) | (pf ? 1 : 0); } else tmp[i++] = (l2->vr << 5) | typ | (pf ? 0x10 : 0); if (!(msg = alloc_msg(i + mISDNUSER_HEAD_SIZE))) { dprint(DBGM_L2, l2->nst->cardnr, "isdnl2 can't alloc sbbuff for enquiry_cr\n"); return; } else msg_reserve(msg, mISDNUSER_HEAD_SIZE); memcpy(msg_put(msg, i), tmp, i); msg_push(msg, mISDNUSER_HEAD_SIZE); enqueue_super(l2, msg); }
static void direct_reply(struct context *ctx, struct conn *conn, struct msg *smsg, char *_msg) { struct mbuf *mbuf; int n; struct msg *msg = msg_get(conn, true, conn->redis); if (msg == NULL) { conn->err = errno; conn->done = 1; return; } mbuf = STAILQ_LAST(&msg->mhdr, mbuf, next); if (mbuf == NULL || mbuf_full(mbuf)) { mbuf = mbuf_get(); if (mbuf != NULL) { mbuf_insert(&msg->mhdr, mbuf); msg->pos = mbuf->pos; } } if (mbuf == NULL) { conn->err = errno; conn->done = 1; msg_put(msg); return; } smsg->peer = msg; msg->peer = smsg; msg->request = 0; n = (int)strlen(_msg); memcpy(mbuf->last, _msg, (size_t)n); mbuf->last += n; msg->mlen += (uint32_t)n; smsg->done = 1; event_add_out(ctx->evb, conn); conn->enqueue_outq(ctx, conn, smsg); }
/* IE_CALL_ID */ void enc_ie_call_id(unsigned char **ntmode, msg_t *msg, unsigned char *callid, int callid_len, int nt, struct misdn_bchannel *bc) { unsigned char *p; Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN); int l; char debug[25]; int i; if (!callid || callid_len<=0) { return; } if (callid_len>8) { printf("%s: ERROR: callid_len(%d) is out of range.\n", __FUNCTION__, callid_len); return; } i = 0; while(i < callid_len) { if (MISDN_IE_DEBG) printf(debug+(i*3), " %02x", callid[i]); i++; } if (MISDN_IE_DEBG) printf(" callid%s\n", debug); l = callid_len; p = msg_put(msg, l+2); if (nt) *ntmode = p+1; else qi->call_id = p - (unsigned char *)qi - sizeof(Q931_info_t); p[0] = IE_CALL_ID; p[1] = l; memcpy(p+2, callid, callid_len); }
/* IE_FACILITY */ void enc_ie_facility(unsigned char **ntmode, msg_t *msg, unsigned char *facility, int facility_len, int nt, struct misdn_bchannel *bc) { unsigned char *p; Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN); int l; if (!facility || facility_len<=0) { return; } l = facility_len; p = msg_put(msg, l+2); if (nt) *ntmode = p+1; else qi->QI_ELEMENT(facility) = p - (unsigned char *)qi - sizeof(Q931_info_t); p[0] = IE_FACILITY; p[1] = l; memcpy(p+2, facility, facility_len); }
static int send_msg_to_all(check_unit *cunit, struct msg *msg) { int ret; thread_data *cdata = cunit->cdata; redis_group *trgroup = cdata->trgroup; redis_node *trnode; struct msg *msg_same; listNode *lnode; struct mbuf *mbuf; if (cunit == NULL || msg == NULL) { return RMT_ERROR; } msg_same = msg_get(msg->mb, msg->request, msg->kind); if (msg_same == NULL) { log_error("ERROR: msg clone failed."); msg_put(msg); msg_free(msg); msg = NULL; return RMT_ERROR; } lnode = listFirst(msg->data); while (lnode) { mbuf = listNodeValue(lnode); lnode = lnode->next; ret = msg_append_full(msg_same, mbuf->pos, mbuf_length(mbuf)); if (ret != RMT_OK) { log_error("ERROR: out of memory."); msg_put(msg_same); msg_free(msg_same); msg = NULL; return RMT_ERROR; } } msg_same->ptr = msg->ptr; msg_same->resp_check = msg->resp_check; ret = prepare_send_msg(cunit->srnode, msg, cunit->srnode); if (ret != RMT_OK) { msg_put(msg); msg_free(msg); msg = NULL; msg_put(msg_same); msg_free(msg_same); return RMT_ERROR; } msg = NULL; trnode = trgroup->get_backend_node(trgroup, (uint8_t *)cunit->key, (uint32_t)sdslen(cunit->key)); if(prepare_send_msg(trnode, msg_same, trnode) != RMT_OK){ msg_put(msg_same); msg_free(msg_same); return RMT_ERROR; } return RMT_OK; }
void remote_req_forward(struct context *ctx, struct conn *c_conn, struct msg *msg, struct rack *rack, uint8_t *key, uint32_t keylen) { ASSERT((c_conn->type == CONN_CLIENT) || (c_conn->type == CONN_DNODE_PEER_CLIENT)); struct node * peer = dnode_peer_pool_server(ctx, c_conn->owner, rack, key, keylen, msg->msg_routing); if (peer->is_local) { log_debug(LOG_VERB, "c_conn: %p forwarding %d:%d is local", c_conn, msg->id, msg->parent_id); local_req_forward(ctx, c_conn, msg, key, keylen); return; } /* enqueue message (request) into client outq, if response is expected */ if (msg->expect_datastore_reply && !msg->swallow) { conn_enqueue_outq(ctx, c_conn, msg); } // now get a peer connection struct conn *p_conn = dnode_peer_pool_server_conn(ctx, peer); if ((p_conn == NULL) || (p_conn->connecting)) { if (p_conn) { usec_t now = dn_usec_now(); static usec_t next_log = 0; // Log every 1 sec if (now > next_log) { log_warn("still connecting to peer '%.*s'......", peer->endpoint.pname.len, peer->endpoint.pname.data); next_log = now + 1000 * 1000; } } // No response for DC_ONE & swallow if ((msg->consistency == DC_ONE) && (msg->swallow)) { msg_put(msg); return; } // No response for remote dc struct server_pool *pool = c_conn->owner; bool same_dc = is_same_dc(pool, peer)? 1 : 0; if (!same_dc) { msg_put(msg); return; } // All other cases return a response struct msg *rsp = msg_get(c_conn, false, __FUNCTION__); msg->done = 1; rsp->error = msg->error = 1; rsp->err = msg->err = (p_conn ? PEER_HOST_NOT_CONNECTED : PEER_HOST_DOWN); rsp->dyn_error = msg->dyn_error = (p_conn ? PEER_HOST_NOT_CONNECTED: PEER_HOST_DOWN); rsp->dmsg = dmsg_get(); rsp->peer = msg; rsp->dmsg->id = msg->id; log_info("%lu:%lu <-> %lu:%lu Short circuit....", msg->id, msg->parent_id, rsp->id, rsp->parent_id); conn_handle_response(c_conn, msg->parent_id ? msg->parent_id : msg->id, rsp); if (msg->swallow) msg_put(msg); return; } log_debug(LOG_VERB, "c_conn: %p forwarding %d:%d to p_conn %p", c_conn, msg->id, msg->parent_id, p_conn); dnode_peer_req_forward(ctx, c_conn, p_conn, msg, rack, key, keylen); }
int main(int argc, char *argv[]) { const char *iface_name = NULL; char *config = NULL, *progname; int c, cnt, index, length, tmo = -1, batch_mode = 0, zero_datalen = 0; int ret = 0; char line[1024], *command = NULL, uds_local[MAX_IFNAME_SIZE + 1]; enum transport_type transport_type = TRANS_UDP_IPV4; UInteger8 boundary_hops = 1, domain_number = 0, transport_specific = 0; struct ptp_message *msg; struct option *opts; struct config *cfg; #define N_FD 2 struct pollfd pollfd[N_FD]; handle_term_signals(); cfg = config_create(); if (!cfg) { return -1; } opts = config_long_options(cfg); /* Process the command line arguments. */ progname = strrchr(argv[0], '/'); progname = progname ? 1+progname : argv[0]; while (EOF != (c = getopt_long(argc, argv, "246u""b:d:f:hi:s:t:vz", opts, &index))) { switch (c) { case 0: if (config_parse_option(cfg, opts[index].name, optarg)) { ret = -1; goto out; } break; case '2': if (config_set_int(cfg, "network_transport", TRANS_IEEE_802_3)) { ret = -1; goto out; } break; case '4': if (config_set_int(cfg, "network_transport", TRANS_UDP_IPV4)) { ret = -1; goto out; } break; case '6': if (config_set_int(cfg, "network_transport", TRANS_UDP_IPV6)) { ret = -1; goto out; } break; case 'u': if (config_set_int(cfg, "network_transport", TRANS_UDS)) { ret = -1; goto out; } break; case 'b': boundary_hops = atoi(optarg); break; case 'd': if (config_set_int(cfg, "domainNumber", atoi(optarg))) { ret = -1; goto out; } break; case 'f': config = optarg; break; case 'i': iface_name = optarg; break; case 's': if (strlen(optarg) > MAX_IFNAME_SIZE) { fprintf(stderr, "path %s too long, max is %d\n", optarg, MAX_IFNAME_SIZE); config_destroy(cfg); return -1; } if (config_set_string(cfg, "uds_address", optarg)) { config_destroy(cfg); return -1; } break; case 't': if (1 == sscanf(optarg, "%x", &c)) { if (config_set_int(cfg, "transportSpecific", c)) { ret = -1; goto out; } } break; case 'v': version_show(stdout); config_destroy(cfg); return 0; case 'z': zero_datalen = 1; break; case 'h': usage(progname); config_destroy(cfg); return 0; case '?': default: usage(progname); config_destroy(cfg); return -1; } } if (config && (c = config_read(config, cfg))) { config_destroy(cfg); return -1; } transport_type = config_get_int(cfg, NULL, "network_transport"); transport_specific = config_get_int(cfg, NULL, "transportSpecific") << 4; domain_number = config_get_int(cfg, NULL, "domainNumber"); if (!iface_name) { if (transport_type == TRANS_UDS) { snprintf(uds_local, sizeof(uds_local), "/var/run/pmc.%d", getpid()); iface_name = uds_local; } else { iface_name = "eth0"; } } if (optind < argc) { batch_mode = 1; } print_set_progname(progname); print_set_syslog(1); print_set_verbose(1); pmc = pmc_create(cfg, transport_type, iface_name, boundary_hops, domain_number, transport_specific, zero_datalen); if (!pmc) { fprintf(stderr, "failed to create pmc\n"); config_destroy(cfg); return -1; } pollfd[0].fd = batch_mode ? -1 : STDIN_FILENO; pollfd[1].fd = pmc_get_transport_fd(pmc); while (is_running()) { if (batch_mode && !command) { if (optind < argc) { command = argv[optind++]; } else { /* No more commands, wait a bit for any outstanding replies and exit. */ tmo = 100; } } pollfd[0].events = 0; pollfd[1].events = POLLIN | POLLPRI; if (!batch_mode && !command) pollfd[0].events |= POLLIN | POLLPRI; if (command) pollfd[1].events |= POLLOUT; cnt = poll(pollfd, N_FD, tmo); if (cnt < 0) { if (EINTR == errno) { continue; } else { pr_emerg("poll failed"); ret = -1; break; } } else if (!cnt) { break; } if (pollfd[0].revents & POLLHUP) { if (tmo == -1) { /* Wait a bit longer for outstanding replies. */ tmo = 100; pollfd[0].fd = -1; pollfd[0].events = 0; } else { break; } } if (pollfd[0].revents & (POLLIN|POLLPRI)) { if (!fgets(line, sizeof(line), stdin)) { break; } length = strlen(line); if (length < 2) { continue; } line[length - 1] = 0; command = line; } if (pollfd[1].revents & POLLOUT) { if (pmc_do_command(pmc, command)) { fprintf(stderr, "bad command: %s\n", command); } command = NULL; } if (pollfd[1].revents & (POLLIN|POLLPRI)) { msg = pmc_recv(pmc); if (msg) { pmc_show(msg, stdout); msg_put(msg); } } } pmc_destroy(pmc); msg_cleanup(); out: config_destroy(cfg); return ret; }
/* * Sending a mbuf of gossip data over the wire to a peer */ void dnode_peer_gossip_forward(struct context *ctx, struct conn *conn, bool redis, struct mbuf *data_buf) { rstatus_t status; struct msg *msg = msg_get(conn, 1, redis); if (msg == NULL) { log_debug(LOG_DEBUG, "Unable to obtain a msg"); return; } struct mbuf *header_buf = mbuf_get(); if (header_buf == NULL) { log_debug(LOG_DEBUG, "Unable to obtain a data_buf"); msg_put(msg); return; } uint64_t msg_id = peer_msg_id++; if (conn->dnode_secured) { log_debug(LOG_VERB, "Assemble a secured msg to send"); log_debug(LOG_VERB, "AES encryption key: %s\n", base64_encode(conn->aes_key, AES_KEYLEN)); struct mbuf *encrypted_buf = mbuf_get(); if (encrypted_buf == NULL) { loga("Unable to obtain an data_buf for encryption!"); return; //TODOs: need to clean up } status = dyn_aes_encrypt(data_buf->pos, mbuf_length(data_buf), encrypted_buf, conn->aes_key); log_debug(LOG_VERB, "#encrypted bytes : %d", status); //write dnode header dmsg_write(header_buf, msg_id, GOSSIP_SYN, conn, mbuf_length(encrypted_buf)); mbuf_insert_head(&msg->mhdr, header_buf); if (TRACING_LEVEL == LOG_VVERB) { log_hexdump(LOG_VVERB, data_buf->pos, mbuf_length(data_buf), "dyn message original payload: "); log_hexdump(LOG_VVERB, encrypted_buf->pos, mbuf_length(encrypted_buf), "dyn message encrypted payload: "); } mbuf_insert(&msg->mhdr, encrypted_buf); //free data_buf as no one will need it again mbuf_put(data_buf); } else { log_debug(LOG_VERB, "Assemble a non-secured msg to send"); dmsg_write_mbuf(header_buf, msg_id, GOSSIP_SYN, conn, mbuf_length(data_buf)); mbuf_insert_head(&msg->mhdr, header_buf); mbuf_insert(&msg->mhdr, data_buf); } if (TRACING_LEVEL == LOG_VVERB) { log_hexdump(LOG_VVERB, header_buf->pos, mbuf_length(header_buf), "dyn gossip message header: "); msg_dump(msg); } /* enqueue the message (request) into peer inq */ if (TAILQ_EMPTY(&conn->imsg_q)) { status = event_add_out(ctx->evb, conn); if (status != DN_OK) { dnode_req_forward_error(ctx, conn, msg); conn->err = errno; return; } } //need to handle a reply //conn->enqueue_outq(ctx, conn, msg); msg->noreply = 1; conn->enqueue_inq(ctx, conn, msg); }
enum fsm_event e2e_event(struct port *p, int fd_index) { int cnt, fd = p->fda.fd[fd_index]; enum fsm_event event = EV_NONE; struct ptp_message *msg, *dup; switch (fd_index) { case FD_ANNOUNCE_TIMER: case FD_SYNC_RX_TIMER: pr_debug("port %hu: %s timeout", portnum(p), fd_index == FD_SYNC_RX_TIMER ? "rx sync" : "announce"); if (p->best) { fc_clear(p->best); } port_set_announce_tmo(p); return EV_ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES; case FD_DELAY_TIMER: pr_debug("port %hu: delay timeout", portnum(p)); port_set_delay_tmo(p); delay_req_prune(p); tc_prune(p); if (!clock_free_running(p->clock)) { switch (p->state) { case PS_UNCALIBRATED: case PS_SLAVE: if (port_delay_request(p)) { event = EV_FAULT_DETECTED; } break; default: break; }; } return event; case FD_QUALIFICATION_TIMER: pr_debug("port %hu: qualification timeout", portnum(p)); return EV_QUALIFICATION_TIMEOUT_EXPIRES; case FD_MANNO_TIMER: case FD_SYNC_TX_TIMER: case FD_UNICAST_REQ_TIMER: case FD_UNICAST_SRV_TIMER: pr_err("unexpected timer expiration"); return EV_NONE; case FD_RTNL: pr_debug("port %hu: received link status notification", portnum(p)); rtnl_link_status(fd, p->name, port_link_status, p); if (p->link_status == (LINK_UP|LINK_STATE_CHANGED)) { return EV_FAULT_CLEARED; } else if ((p->link_status == (LINK_DOWN|LINK_STATE_CHANGED)) || (p->link_status & TS_LABEL_CHANGED)) { return EV_FAULT_DETECTED; } else { return EV_NONE; } } msg = msg_allocate(); if (!msg) { return EV_FAULT_DETECTED; } msg->hwts.type = p->timestamping; cnt = transport_recv(p->trp, fd, msg); if (cnt <= 0) { pr_err("port %hu: recv message failed", portnum(p)); msg_put(msg); return EV_FAULT_DETECTED; } if (msg_sots_valid(msg)) { ts_add(&msg->hwts.ts, -p->rx_timestamp_offset); } if (msg_unicast(msg)) { pl_warning(600, "cannot handle unicast messages!"); msg_put(msg); return EV_NONE; } dup = msg_duplicate(msg, cnt); if (!dup) { msg_put(msg); return EV_NONE; } if (tc_ignore(p, dup)) { msg_put(dup); dup = NULL; } switch (msg_type(msg)) { case SYNC: if (tc_fwd_sync(p, msg)) { event = EV_FAULT_DETECTED; break; } if (dup) { process_sync(p, dup); } break; case DELAY_REQ: if (tc_fwd_request(p, msg)) { event = EV_FAULT_DETECTED; } break; case PDELAY_REQ: break; case PDELAY_RESP: break; case FOLLOW_UP: if (tc_fwd_folup(p, msg)) { event = EV_FAULT_DETECTED; break; } if (dup) { process_follow_up(p, dup); } break; case DELAY_RESP: if (tc_fwd_response(p, msg)) { event = EV_FAULT_DETECTED; } if (dup) { process_delay_resp(p, dup); } break; case PDELAY_RESP_FOLLOW_UP: break; case ANNOUNCE: if (tc_forward(p, msg)) { event = EV_FAULT_DETECTED; break; } if (dup && process_announce(p, dup)) { event = EV_STATE_DECISION_EVENT; } break; case SIGNALING: case MANAGEMENT: if (tc_forward(p, msg)) { event = EV_FAULT_DETECTED; } break; } msg_put(msg); if (dup) { msg_put(dup); } return event; }
static void dnode_req_forward(struct context *ctx, struct conn *conn, struct msg *msg) { struct server_pool *pool; uint8_t *key; uint32_t keylen; if (log_loggable(LOG_DEBUG)) { log_debug(LOG_DEBUG, "dnode_req_forward entering "); } log_debug(LOG_DEBUG, "DNODE REQ RECEIVED %s %d dmsg->id %u", conn_get_type_string(conn), conn->sd, msg->dmsg->id); ASSERT(conn->type == CONN_DNODE_PEER_CLIENT); pool = conn->owner; key = NULL; keylen = 0; log_debug(LOG_DEBUG, "conn %p adding message %d:%d", conn, msg->id, msg->parent_id); dictAdd(conn->outstanding_msgs_dict, &msg->id, msg); if (!string_empty(&pool->hash_tag)) { struct string *tag = &pool->hash_tag; uint8_t *tag_start, *tag_end; tag_start = dn_strchr(msg->key_start, msg->key_end, tag->data[0]); if (tag_start != NULL) { tag_end = dn_strchr(tag_start + 1, msg->key_end, tag->data[1]); if (tag_end != NULL) { key = tag_start + 1; keylen = (uint32_t)(tag_end - key); } } } if (keylen == 0) { key = msg->key_start; keylen = (uint32_t)(msg->key_end - msg->key_start); } ASSERT(msg->dmsg != NULL); if (msg->dmsg->type == DMSG_REQ) { local_req_forward(ctx, conn, msg, key, keylen); } else if (msg->dmsg->type == DMSG_REQ_FORWARD) { struct mbuf *orig_mbuf = STAILQ_FIRST(&msg->mhdr); struct datacenter *dc = server_get_dc(pool, &pool->dc); uint32_t rack_cnt = array_n(&dc->racks); uint32_t rack_index; for(rack_index = 0; rack_index < rack_cnt; rack_index++) { struct rack *rack = array_get(&dc->racks, rack_index); //log_debug(LOG_DEBUG, "forwarding to rack '%.*s'", // rack->name->len, rack->name->data); struct msg *rack_msg; if (string_compare(rack->name, &pool->rack) == 0 ) { rack_msg = msg; } else { rack_msg = msg_get(conn, msg->request, __FUNCTION__); if (rack_msg == NULL) { log_debug(LOG_VERB, "whelp, looks like yer screwed now, buddy. no inter-rack messages for you!"); continue; } if (msg_clone(msg, orig_mbuf, rack_msg) != DN_OK) { msg_put(rack_msg); continue; } rack_msg->swallow = true; } if (log_loggable(LOG_DEBUG)) { log_debug(LOG_DEBUG, "forwarding request from conn '%s' to rack '%.*s' dc '%.*s' ", dn_unresolve_peer_desc(conn->sd), rack->name->len, rack->name->data, rack->dc->len, rack->dc->data); } remote_req_forward(ctx, conn, rack_msg, rack, key, keylen); } } }
static int check_response(redis_node *rnode, struct msg *r) { int ret; rmtContext *ctx = rnode->ctx; struct msg *resp, *msg = NULL; check_data *chdata; check_unit *cunit; char extra_err[50]; struct array args; sds *arg; struct array *bulks1 = NULL, *bulks2 = NULL; sds *bulk1, *bulk2; if (r == NULL) { return RMT_ERROR; } extra_err[0] = '\0'; resp = r->peer; r->peer = NULL; array_init(&args, 3, sizeof(sds)); ASSERT(r->request && r->sent); ASSERT(resp != NULL && resp->request == 0); cunit = (check_unit *)r->ptr; chdata = cunit->cdata->data; if(resp->type == MSG_RSP_REDIS_ERROR){ log_warn("Response from node[%s] for %s is error", rnode->addr, msg_type_string(r->type)); goto error; } if (cunit->state == CHECK_UNIT_STATE_GET_KEY) { ASSERT(cunit->key == NULL); ASSERT(cunit->key_type == -1); ASSERT(cunit->result1 == NULL && cunit->result2 == NULL); ASSERT(cunit->srnode == rnode); if (resp->type != MSG_RSP_REDIS_BULK) { log_error("ERROR: the response type for command 'randomkey' from node[%s] is error: %s", rnode->addr, msg_type_string(resp->type)); goto error; } if (msg_cmp_str(resp, (const uint8_t*)REDIS_REPLY_BULK_NULL, rmt_strlen(REDIS_REPLY_BULK_NULL)) == 0) { /* source group may have no keys, stop it */ cunit->cdata->keys_count --; goto done; } cunit->key = redis_msg_response_get_bulk_string(resp); if (cunit->key == NULL) { log_error("ERROR: get bulk string from response of node[%s] failed, " "bulk_len: %"PRIu32", bulk_start: %p", rnode->addr, resp->bulk_len, resp->bulk_start); goto error; } if (ctx->filter != NULL && !stringmatchlen(ctx->filter, sdslen(ctx->filter), cunit->key, sdslen(cunit->key), 0)) { goto done; } ASSERT(sdslen(cunit->key) == resp->bulk_len); msg = msg_get(r->mb, 1, REDIS_DATA_TYPE_CMD); if (msg == NULL) { log_error("ERROR: out of memory."); goto error; } arg = array_push(&args); *arg = sdsnew("type"); arg = array_push(&args); *arg = sdsdup(cunit->key); ret = redis_msg_append_command_full_safe(msg, &args); if (ret != RMT_OK) { log_error("ERROR: msg append multi bulk len failed."); goto error; } while (array_n(&args) > 0) { arg = array_pop(&args); sdsfree(*arg); } msg->ptr = cunit; msg->resp_check = check_response; ret = prepare_send_msg(rnode, msg, rnode); if (ret != RMT_OK) { log_error("ERROR: prepare send msg node[%s] failed.", rnode->addr); goto error; } cunit->state = CHECK_UNIT_STATE_GET_TYPE; goto next_step; } if (cunit->state == CHECK_UNIT_STATE_GET_TYPE) { ASSERT(cunit->key != NULL); ASSERT(cunit->key_type == -1); ASSERT(cunit->result1 == NULL && cunit->result2 == NULL); ASSERT(cunit->srnode == rnode); if (resp->type != MSG_RSP_REDIS_STATUS) { log_error("ERROR: the response type for command 'type' from node[%s] is error: %s", rnode->addr, msg_type_string(resp->type)); goto error; } if (msg_cmp_str(resp, (const uint8_t*)REDIS_REPLY_STATUS_NONE, rmt_strlen(REDIS_REPLY_STATUS_NONE)) == 0) { /* This key doesn't exit, may be expired or evicted */ goto done; } msg = msg_get(r->mb, 1, REDIS_DATA_TYPE_CMD); if (msg == NULL) { log_error("ERROR: out of memory."); goto error; } if (msg_cmp_str(resp, (const uint8_t*)REDIS_REPLY_STATUS_STRING, rmt_strlen(REDIS_REPLY_STATUS_STRING)) == 0) { cunit->key_type = REDIS_STRING; arg = array_push(&args); *arg = sdsnew("get"); arg = array_push(&args); *arg = sdsdup(cunit->key); ret = redis_msg_append_command_full_safe(msg, &args); if (ret != RMT_OK) { log_error("ERROR: msg append multi bulk len failed."); goto error; } while (array_n(&args) > 0) { arg = array_pop(&args); sdsfree(*arg); } } else if (msg_cmp_str(resp, (const uint8_t*)REDIS_REPLY_STATUS_LIST, rmt_strlen(REDIS_REPLY_STATUS_LIST)) == 0) { cunit->key_type = REDIS_LIST; arg = array_push(&args); *arg = sdsnew("lrange"); arg = array_push(&args); *arg = sdsdup(cunit->key); arg = array_push(&args); *arg = sdsnew("0"); arg = array_push(&args); *arg = sdsnew("-1"); ret = redis_msg_append_command_full_safe(msg, &args); if (ret != RMT_OK) { log_error("ERROR: msg append multi bulk len failed."); goto error; } while (array_n(&args) > 0) { arg = array_pop(&args); sdsfree(*arg); } } else if (msg_cmp_str(resp, (const uint8_t*)REDIS_REPLY_STATUS_SET, rmt_strlen(REDIS_REPLY_STATUS_SET)) == 0) { cunit->key_type = REDIS_SET; arg = array_push(&args); *arg = sdsnew("smembers"); arg = array_push(&args); *arg = sdsdup(cunit->key); ret = redis_msg_append_command_full_safe(msg, &args); if (ret != RMT_OK) { log_error("ERROR: msg append multi bulk len failed."); goto error; } while (array_n(&args) > 0) { arg = array_pop(&args); sdsfree(*arg); } } else if (msg_cmp_str(resp, (const uint8_t*)REDIS_REPLY_STATUS_ZSET, rmt_strlen(REDIS_REPLY_STATUS_ZSET)) == 0) { cunit->key_type = REDIS_ZSET; arg = array_push(&args); *arg = sdsnew("zrange"); arg = array_push(&args); *arg = sdsdup(cunit->key); arg = array_push(&args); *arg = sdsnew("0"); arg = array_push(&args); *arg = sdsnew("-1"); ret = redis_msg_append_command_full_safe(msg, &args); if (ret != RMT_OK) { log_error("ERROR: msg append multi bulk len failed."); goto error; } while (array_n(&args) > 0) { arg = array_pop(&args); sdsfree(*arg); } } else if (msg_cmp_str(resp, (const uint8_t*)REDIS_REPLY_STATUS_HASH, rmt_strlen(REDIS_REPLY_STATUS_HASH)) == 0) { cunit->key_type = REDIS_HASH; arg = array_push(&args); *arg = sdsnew("hgetall"); arg = array_push(&args); *arg = sdsdup(cunit->key); ret = redis_msg_append_command_full_safe(msg, &args); if (ret != RMT_OK) { log_error("ERROR: msg append multi bulk len failed."); goto error; } while (array_n(&args) > 0) { arg = array_pop(&args); sdsfree(*arg); } } else { log_error("ERROR: response key type from node[%s] is error: ", rnode->addr); goto error; } msg->ptr = cunit; msg->resp_check = check_response; ret = send_msg_to_all(cunit, msg); if (ret != RMT_OK) { log_error("ERROR: send msg to source and target group failed."); goto error; } cunit->state = CHECK_UNIT_STATE_GET_VALUE; goto next_step; } if (cunit->state == CHECK_UNIT_STATE_GET_VALUE) { ASSERT(cunit->key != NULL); ASSERT(cunit->key_type >= 0); ASSERT(cunit->result1 == NULL || cunit->result2 == NULL); if (cunit->key_type == REDIS_STRING) { if (resp->type != MSG_RSP_REDIS_BULK) { log_error("ERROR: the response type for %s from node[%s] is error: %s", rnode->addr, msg_type_string(r->type), msg_type_string(resp->type)); goto error; } } else if (cunit->key_type == REDIS_LIST) { } else if (cunit->key_type == REDIS_SET) { } else if (cunit->key_type == REDIS_ZSET) { } else if (cunit->key_type == REDIS_HASH) { } else { NOT_REACHED(); } if (cunit->result1 == NULL) { cunit->result1 = resp; resp = NULL; } else if (cunit->result2 == NULL) { cunit->result2 = resp; resp = NULL; } else { NOT_REACHED(); } if (cunit->result1 != NULL && cunit->result2 != NULL) { if (cunit->key_type == REDIS_SET) { uint32_t j; bulks1 = get_multi_bulk_array_from_mbuf_list(cunit->result1->data); bulks2 = get_multi_bulk_array_from_mbuf_list(cunit->result2->data); if (bulks1 == NULL || bulks2 == NULL) { log_error("ERROR: get multi bulk array from mbufs failed"); goto error; } if (array_n(bulks1) != array_n(bulks2)) { chdata->err_inconsistent_value_keys_count ++; rmt_safe_snprintf(extra_err, 50, ", value is inconsistent\0"); goto error; } array_sort(bulks1, string_binary_cmp); array_sort(bulks2, string_binary_cmp); for (j = 0; j < array_n(bulks1); j ++) { bulk1 = array_get(bulks1, j); bulk2 = array_get(bulks2, j); if (string_binary_cmp(bulk1, bulk2) != 0) { chdata->err_inconsistent_value_keys_count ++; rmt_safe_snprintf(extra_err, 50, ", value is inconsistent\0"); goto error; } } } else if (cunit->key_type == REDIS_HASH) { struct array *hash_datas1, *hash_datas2; uint32_t hash_len; uint32_t j; struct hash_data *hd1, *hd2; hash_datas1 = hash_datas2 = NULL; bulks1 = get_multi_bulk_array_from_mbuf_list(cunit->result1->data); bulks2 = get_multi_bulk_array_from_mbuf_list(cunit->result2->data); if (bulks1 == NULL || bulks2 == NULL) { log_error("ERROR: get multi bulk array from mbufs failed"); goto error; } if (array_n(bulks1)%2 != 0 || array_n(bulks2)%2 != 0) { log_error("ERROR: bad hash value"); goto error; } if (array_n(bulks1) != array_n(bulks2)) { chdata->err_inconsistent_value_keys_count ++; rmt_safe_snprintf(extra_err, 50, ", value is inconsistent\0"); goto error; } hash_len = array_n(bulks1)/2; hash_datas1 = array_create(hash_len, sizeof(struct hash_data)); hash_datas2 = array_create(hash_len, sizeof(struct hash_data)); for (j = 0; j < hash_len; j ++) { hd1 = array_push(hash_datas1); hd2 = array_push(hash_datas2); bulk1 = array_pop(bulks1); bulk2 = array_pop(bulks1); hd1->field = *bulk1; hd1->value = *bulk2; bulk1 = array_pop(bulks2); bulk2 = array_pop(bulks2); hd2->field = *bulk1; hd2->value = *bulk2; } array_sort(hash_datas1, hash_data_field_cmp); array_sort(hash_datas2, hash_data_field_cmp); for (j = 0; j < array_n(bulks1); j ++) { hd1 = array_get(hash_datas1, j); hd2 = array_get(hash_datas2, j); if (string_binary_cmp(hd1->field, hd2->field) != 0) { chdata->err_inconsistent_value_keys_count ++; rmt_safe_snprintf(extra_err, 50, ", value is inconsistent\0"); if (hash_datas1 != NULL) { while (array_n(hash_datas1) > 0) { hd1 = array_pop(hash_datas1); sdsfree(hd1->field); sdsfree(hd1->value); } array_destroy(hash_datas1); hash_datas1 = NULL; } if (hash_datas2 != NULL) { while (array_n(hash_datas2) > 0) { hd2 = array_pop(hash_datas2); sdsfree(hd2->field); sdsfree(hd2->value); } array_destroy(hash_datas2); hash_datas2 = NULL; } goto error; } if (string_binary_cmp(hd1->value, hd2->value) != 0) { chdata->err_inconsistent_value_keys_count ++; rmt_safe_snprintf(extra_err, 50, ", value is inconsistent\0"); if (hash_datas1 != NULL) { while (array_n(hash_datas1) > 0) { hd1 = array_pop(hash_datas1); sdsfree(hd1->field); sdsfree(hd1->value); } array_destroy(hash_datas1); hash_datas1 = NULL; } if (hash_datas2 != NULL) { while (array_n(hash_datas2) > 0) { hd2 = array_pop(hash_datas2); sdsfree(hd2->field); sdsfree(hd2->value); } array_destroy(hash_datas2); hash_datas2 = NULL; } goto error; } } if (hash_datas1 != NULL) { while (array_n(hash_datas1) > 0) { hd1 = array_pop(hash_datas1); sdsfree(hd1->field); sdsfree(hd1->value); } array_destroy(hash_datas1); hash_datas1 = NULL; } if (hash_datas2 != NULL) { while (array_n(hash_datas2) > 0) { hd2 = array_pop(hash_datas2); sdsfree(hd2->field); sdsfree(hd2->value); } array_destroy(hash_datas2); hash_datas2 = NULL; } } else if (msg_data_compare(cunit->result1, cunit->result2) != 0) { chdata->err_inconsistent_value_keys_count ++; rmt_safe_snprintf(extra_err, 50, ", value is inconsistent\0"); goto error; } msg_put(cunit->result1); msg_free(cunit->result1); cunit->result1 = NULL; msg_put(cunit->result2); msg_free(cunit->result2); cunit->result2 = NULL; if (bulks1 != NULL) { while (array_n(bulks1) > 0) { bulk1 = array_pop(bulks1); sdsfree(*bulk1); } array_destroy(bulks1); bulks1 = NULL; } if (bulks2 != NULL) { while (array_n(bulks2) > 0) { bulk2 = array_pop(bulks2); sdsfree(*bulk2); } array_destroy(bulks2); bulks2 = NULL; } msg = msg_get(r->mb, 1, REDIS_DATA_TYPE_CMD); if (msg == NULL) { log_error("ERROR: out of memory."); goto error; } arg = array_push(&args); *arg = sdsnew("ttl"); arg = array_push(&args); *arg = sdsdup(cunit->key); ret = redis_msg_append_command_full_safe(msg, &args); if (ret != RMT_OK) { log_error("ERROR: msg append multi bulk len failed."); goto error; } while (array_n(&args) > 0) { arg = array_pop(&args); sdsfree(*arg); } msg->ptr = cunit; msg->resp_check = check_response; ret = send_msg_to_all(cunit, msg); if (ret != RMT_OK) { log_error("ERROR: send msg to source and target group failed."); goto error; } cunit->state = CHECK_UNIT_STATE_GET_EXPIRE; } goto next_step; } if (cunit->state == CHECK_UNIT_STATE_GET_EXPIRE) { ASSERT(cunit->key != NULL); ASSERT(cunit->key_type >= 0); ASSERT(cunit->result1 == NULL || cunit->result2 == NULL); if (resp->type != MSG_RSP_REDIS_INTEGER) { log_error("ERROR: the response type for command 'ttl' from node[%s] is error: %s", rnode->addr, msg_type_string(resp->type)); goto error; } if (cunit->result1 == NULL) { cunit->result1 = resp; resp = NULL; } else if (cunit->result2 == NULL) { cunit->result2 = resp; resp = NULL; } else { NOT_REACHED(); } if (cunit->result1 != NULL && cunit->result2 != NULL) { if (msg_data_compare(cunit->result1, cunit->result2) != 0) { int mistake = (int)cunit->result1->integer - (int)cunit->result2->integer; ASSERT(mistake != 0); if (abs(mistake) > TTL_MISTAKE_CAN_BE_ACCEPT) { chdata->err_inconsistent_expire_keys_count ++; rmt_safe_snprintf(extra_err, 50, ", remaining time are %"PRIu32" and %"PRIu32"\0", cunit->result1->integer, cunit->result2->integer); goto error; } } /* OK, this key is consistent between source group and target group */ goto done; } goto next_step; } done: check_unit_destroy(cunit); next_step: msg_put(r); msg_free(r); if (resp != NULL) { msg_put(resp); msg_free(resp); } array_deinit(&args); return RMT_OK; error: chdata->err_check_keys_count ++; if (cunit->key != NULL) { log_error("ERROR: key checked failed: %s%s. key(len:%zu, type:%s): %.*s", get_check_error(cunit), extra_err, sdslen(cunit->key), get_redis_type_string(cunit->key_type), sdslen(cunit->key), cunit->key); } else { log_error("ERROR: key checked failed: %s%s.", get_check_error(cunit), extra_err); } MSG_DUMP(r, LOG_ERR, 1); msg_put(r); msg_free(r); if (resp != NULL) { MSG_DUMP(resp, LOG_ERR, 1); msg_put(resp); msg_free(resp); } if (msg != NULL) { msg_put(msg); msg_free(msg); } check_unit_destroy(cunit); while (array_n(&args) > 0) { arg = array_pop(&args); sdsfree(*arg); } array_deinit(&args); if (bulks1 != NULL) { while (array_n(bulks1) > 0) { bulk1 = array_pop(bulks1); sdsfree(*bulk1); } array_destroy(bulks1); bulks1 = NULL; } if (bulks2 != NULL) { while (array_n(bulks2) > 0) { bulk2 = array_pop(bulks2); sdsfree(*bulk2); } array_destroy(bulks2); bulks2 = NULL; } return RMT_OK; }