void SortSlaveMP::MultiBinChopStart(size32_t keybuffsize,const byte *keybuff, byte cmpfn) /* async */ { CMessageBuffer mb; mb.append((byte)FN_MultiBinChopStart); serializeblk(mb,keybuffsize,keybuff).append(cmpfn); sendRecv(mb); }
void SortSlaveMP::GetMultiMidPointStop(size32_t &mkeybuffsize, void * &mkeybuf) { CMessageBuffer mb; mb.append((byte)FN_GetMultiMidPointStop); sendRecv(mb); deserializeblk(mb,mkeybuffsize,mkeybuf); }
void SortSlaveMP::StartMiniSort(rowcount_t _totalrows) /* async */ { CMessageBuffer mb; mb.append((byte)FN_StartMiniSort); mb.append(_totalrows); sendRecv(mb); }
void SortSlaveMP::MultiBinChop(size32_t keybuffsize,const byte *keybuff, unsigned num,rowcount_t *pos,byte cmpfn) { CMessageBuffer mb; mb.append((byte)FN_MultiBinChop); serializeblk(mb,keybuffsize,keybuff).append(num).append(cmpfn); sendRecv(mb); mb.read(num*sizeof(rowcount_t),pos); }
void SortSlaveMP::GetMultiMidPointStart(size32_t lkeybuffsize, const void * lkeybuff, size32_t hkeybuffsize, const void * hkeybuff) /* async */ { CMessageBuffer mb; mb.append((byte)FN_GetMultiMidPointStart); serializeblk(mb,lkeybuffsize,lkeybuff); serializeblk(mb,hkeybuffsize,hkeybuff); sendRecv(mb); }
void SortSlaveMP::GetGatherInfo(rowcount_t &numlocal, offset_t &totalsize, unsigned &overflowscale, bool hasserializer) { CMessageBuffer mb; mb.append((byte)FN_GetGatherInfo); mb.append(hasserializer); sendRecv(mb); mb.read(numlocal).read(totalsize).read(overflowscale); }
void SortSlaveMP::MultiBinChopStop(unsigned num,rowcount_t *pos) { CMessageBuffer mb; mb.append((byte)FN_MultiBinChopStop); mb.append(num); sendRecv(mb); mb.read(num*sizeof(rowcount_t),pos); }
void SortSlaveMP::GetMultiNthRow(unsigned numsplits,size32_t &mkeybuffsize, void * &mkeybuf) { CMessageBuffer mb; mb.append((byte)FN_GetMultiNthRow); mb.append(numsplits); sendRecv(mb); deserializeblk(mb,mkeybuffsize,mkeybuf); }
void SortSlaveMP::OverflowAdjustMapStart(unsigned mapsize,rowcount_t *map,size32_t keybuffsize,const byte *keybuff, byte cmpfn,bool useaux) /* async */ { CMessageBuffer mb; mb.append((byte)FN_OverflowAdjustMapStart); mb.append(mapsize).append(mapsize*sizeof(rowcount_t),map); serializeblk(mb,keybuffsize,keybuff).append(cmpfn).append(useaux); sendRecv(mb); }
int sem_imanager_req(){ int i, j; void *buf; unsigned int offset; unsigned int queue_count; unsigned int src_node; unsigned int seq_number; struct sem *find; struct req_node_info node; char *sem_name; if(g_group.coordinator.sem_id == g_group.node_id) return 1; //max 33 sem buf = mem_malloc(SEM_ISEM_SIZE); ((struct request_header*)buf)->msg_type = MSG_ISEM_MANAGER; sendRecv(g_group.coordinator.sem_id, buf, sizeof(struct request_header), buf, SEM_ISEM_SIZE); if(g_group.sem_table == NULL){ g_group.sem_table = hashTableCreate(SEM_HASH_SIZE); } src_node = ((struct isem_reply*)buf)->req.src_node; seq_number = ((struct isem_reply*)buf)->req.src_seq_number; offset = sizeof(struct isem_reply); for(i=0; i<((struct isem_reply*)buf)->sem_num; i++){ //sem name sem_name = malloc(((struct sem_info*)(buf+offset))->name_len); memcpy(sem_name, buf+offset+sizeof(struct sem_info), ((struct sem_info*)(buf+offset))->name_len); sem_name[((struct sem_info*)(buf+offset))->name_len] = 0; //search sem find = hashTableSearch(g_group.sem_table, ((struct sem_info*)(buf+offset))->hash_id, sem_name); if(find == NULL){ //create new find = createNewSem(((struct sem_info*)(buf+offset))->hash_id, sem_name, ((struct sem_info*)(buf+offset))->value); hashTableInsert(g_group.sem_table, (struct hashheader*)find); }else{ if(find->queue->use!=0){ while(queuePop(find->queue)!=NULL); } } //copy queue info queue_count = ((struct sem_info*)(buf+offset))->queue_count; offset += sizeof(struct sem_info)+strlen(sem_name); for(j=0; j< queue_count;j++){ node.id = ((struct req_node_info*)(buf+offset))->id; node.seq_number = ((struct req_node_info*)(buf+offset))->seq_number; queuePush(find->queue, (void*)&node); offset += sizeof(struct req_node_info); } } g_group.coordinator.sem_id = g_group.node_id; ((struct request_header*)buf)->msg_type = MSG_ISEM_READY; ((struct request_header*)buf)->seq_number = seq_number; sendTo(src_node ,buf, sizeof(struct request_header)); mem_free(buf); return 1; }
rowcount_t SortSlaveMP::OverflowAdjustMapStop( unsigned mapsize, rowcount_t *map) { CMessageBuffer mb; mb.append((byte)FN_OverflowAdjustMapStop); mb.append(mapsize); sendRecv(mb); rowcount_t ret; mb.read(ret).read(mapsize*sizeof(rowcount_t),map); return ret; }
bool SortSlaveMP::Connect(unsigned _part, unsigned _numnodes) { CMessageBuffer mb; mb.append((byte)FN_Connect); mb.append(_part).append(_numnodes); sendRecv(mb); bool ret; mb.read(ret); return ret; }
rowcount_t SortSlaveMP::GetMinMax(size32_t &keybuffsize,void *&keybuff, size32_t &avrecsizesize) { CMessageBuffer mb; mb.append((byte)FN_GetMinMax); sendRecv(mb); deserializeblk(mb,keybuffsize,keybuff); mb.read(avrecsizesize); rowcount_t ret; mb.read(ret); return ret; }
int sem_imanager_reply(void *request){ int i, j; void *buf; int index; unsigned int sem_num = 0; unsigned int offset; unsigned int *send_node; struct req_node_info *node; struct sem *now; buf = mem_malloc(sizeof(struct isem_reply) + g_group.sem_table->item_num*310); ((struct isem_reply*)buf)->req.msg_type = MSG_ISEM_REPLY; ((struct isem_reply*)buf)->req.seq_number = ((struct request_header*)request)->src_seq_number; offset = sizeof(struct isem_reply); for(i=0; i<g_group.sem_table->table_size; i++){ now = (struct sem*)g_group.sem_table->row[i]; while(now!=NULL){ sem_num++; //max 305 byte of one sem 16+32+1+8*32 = 305 ((struct sem_info*)(buf+offset))->hash_id = now->hash.id; ((struct sem_info*)(buf+offset))->name_len = strlen(now->hash.name); ((struct sem_info*)(buf+offset))->value = now->value; ((struct sem_info*)(buf+offset))->queue_count = now->queue->use; offset += sizeof(struct sem_info); memcpy(buf+offset, now->hash.name, strlen(now->hash.name)); offset += strlen(now->hash.name); //node info in the queue for(j=0;j<now->queue->use;j++){ index = now->queue->front + j; if(index >= now->queue->queue_size) index -= now->queue->queue_size; node = now->queue->row[index]; ((struct req_node_info*)(buf+offset))->id = node->id; ((struct req_node_info*)(buf+offset))->seq_number = node->seq_number; offset += sizeof(struct req_node_info); } now = (struct sem*)now->hash.next; } } ((struct isem_reply*)buf)->sem_num = sem_num; //send sem info & wait new sem ready sendRecv(((struct request_header*)request)->src_node, buf, offset, buf, sizeof(struct request_header)); g_group.coordinator.sem_id = ((struct request_header*)request)->src_node; //send to other node the ((struct new_manager_req*)buf)->req.msg_type = MSG_NEWSEM_MANAGER; ((struct new_manager_req*)buf)->new_manager = ((struct request_header*)request)->src_node; for(i=0;i<g_group.node_table->table_size;i++){ send_node = tableGetRow(g_group.node_table, i); if(*send_node != -1 && *send_node != g_group.node_id && *send_node != ((struct request_header*)request)->src_node) sendTo(*send_node, buf, sizeof(struct new_manager_req)); } mem_free(buf); return 1; }
bool SortSlaveMP::FirstRowOfFile(const char *filename,size32_t &rowbuffsize, byte * &rowbuf) { CMessageBuffer mb; mb.append((byte)FN_FirstRowOfFile); mb.append(filename); sendRecv(mb); deserializeblk(mb,rowbuffsize,rowbuf); bool ret; mb.read(ret); return ret; }
void SortSlaveMP::MultiMerge(unsigned mapsize,rowcount_t *map,unsigned num,SocketEndpoint* endpoints) /* async */ { CMessageBuffer mb; mb.append((byte)FN_MultiMerge); mb.append(mapsize).append(mapsize*sizeof(rowcount_t),map); mb.append(num); while (num--) { endpoints->serialize(mb); endpoints++; } sendRecv(mb); }
int exit_manager_req(){ int i; char move = NO; void *buf; unsigned int sendnode; struct node *node; buf = mem_malloc(sizeof(struct umanager_req)); bzero(buf, sizeof(struct umanager_req)); //send to the chose node , that will do the original node's manager if(g_group.coordinator.main_id == g_group.node_id){ ((struct umanager_req*)buf)->manager.main = YES; move = YES; } if(g_group.coordinator.mutex_id == g_group.node_id){ ((struct umanager_req*)buf)->manager.mutex = YES; move = YES; } if(g_group.coordinator.sem_id == g_group.node_id){ ((struct umanager_req*)buf)->manager.sem = YES; move = YES; } if(g_group.coordinator.barrier_id == g_group.node_id){ ((struct umanager_req*)buf)->manager.barrier = YES; move = YES; } if(move == YES){ sendnode = chose_one(g_group.node_id); ((struct umanager_req*)buf)->req.msg_type = MSG_YOU_MANAGER; sendRecv(sendnode, buf, sizeof(struct umanager_req), buf, sizeof(struct request_header)); } //send to other node to notice this node will exit ((struct request_header*)buf)->msg_type = MSG_NODE_EXIT; for( i=0; i<g_group.node_table->table_size; i++){ node =(struct node*)tableGetRow(g_group.node_table, i); if(node->id != -1 && node->id != g_group.node_id){ sendTo(node->id , buf, sizeof(struct request_header)); } } mem_free(buf); return 1; }
void SortSlaveMP::StartGather() { CMessageBuffer mb; mb.append((byte)FN_StartGather); sendRecv(mb); }
void SortSlaveMP::Disconnect() /* async */ { CMessageBuffer mb; mb.append((byte)FN_Disconnect); sendRecv(mb); }
void SortSlaveMP::CloseWait() { CMessageBuffer mb; mb.append((byte)FN_CloseWait); sendRecv(mb); }
void SortSlaveMP::Close() /* async */ { CMessageBuffer mb; mb.append((byte)FN_Close); sendRecv(mb); }
void SortSlaveMP::SingleMerge() /* async */ { CMessageBuffer mb; mb.append((byte)FN_SingleMerge); sendRecv(mb); }
int main_imanager_req(){ int i, j; int index; void *buf; unsigned int offset; unsigned int users_count; unsigned int src_node; unsigned int seq_number; unsigned int node_id; struct sm_header *find; char *sm_name; if(g_group.coordinator.main_id == g_group.node_id) return 1; //max 33 mutex buf = mem_malloc(MAIN_IMAIN_SIZE); ((struct request_header*)buf)->msg_type = MSG_IMAIN_MANAGER; sendRecv(g_group.coordinator.main_id, buf, sizeof(struct request_header), buf, MSG_IMAIN_MANAGER); if(g_group.sm_table == NULL){ g_group.sm_table = hashTableCreate(SM_HASH_SIZE); } src_node = ((struct imain_reply*)buf)->req.src_node; seq_number = ((struct imain_reply*)buf)->req.src_seq_number; offset = sizeof(struct imain_reply); //copy share memory data for(i=0; i<((struct imain_reply*)buf)->sm_num; i++){ //mutex name sm_name = malloc(((struct main_sm_info*)(buf+offset))->name_len); memcpy(sm_name, buf+offset+sizeof(struct main_sm_info), ((struct main_sm_info*)(buf+offset))->name_len); sm_name[((struct main_sm_info*)(buf+offset))->name_len] = 0; printf("%s", sm_name); //search mutex find = hashTableSearch(g_group.sm_table, ((struct main_sm_info*)(buf+offset))->hash_id, sm_name); if(find == NULL){ //create new find = createSM(((struct main_sm_info*)(buf+offset))->hash_id, sm_name, ((struct main_sm_info*)(buf+offset))->home_node, ((struct main_sm_info*)(buf+offset))->size); hashTableInsert(g_group.sm_table, (struct hashheader*)find); } //copy find->count = ((struct main_sm_info*)(buf+offset))->count; //copy queue info users_count = ((struct main_sm_info*)(buf+offset))->users_count; offset += sizeof(struct main_sm_info)+strlen(sm_name); if(find->users == NULL) find->users = tableCreate(MAX_NODE_NUM, sizeof(unsigned int)); for(j=0; j< users_count; j++){ node_id = *((unsigned int*)(buf+offset)); if(searchNode(find->users, src_node)==-1){ index = tableGetEmpty(find->users); if(index == -1) return -1; tableAdd(find->users, (void*)&src_node, index); } offset += sizeof(unsigned int); } } g_group.coordinator.main_id = g_group.node_id; ((struct request_header*)buf)->msg_type = MSG_IMAIN_READY; ((struct request_header*)buf)->seq_number = seq_number; sendTo(src_node ,buf, sizeof(struct request_header)); mem_free(buf); return 1; }
int main_imanager_reply(void *request){ int i, j; void *buf; // int index; int sockfd; int *node; unsigned int src_node; unsigned int sm_num = 0; unsigned int offset; unsigned int *send_node; struct sm_header *now; struct sockaddr_in server_addr; src_node = ((struct request_header*)request)->src_node; buf = mem_malloc(sizeof(struct imain_reply) + g_group.sm_table->item_num*200); ((struct imain_reply*)buf)->req.msg_type = MSG_IMAIN_REPLY; ((struct imain_reply*)buf)->req.seq_number = ((struct request_header*)request)->src_seq_number; offset = sizeof(struct imain_reply); for(i=0; i<g_group.sm_table->table_size; i++){ now = (struct sm_header*)g_group.sm_table->row[i]; while(now!=NULL){ sm_num++; //max 200 byte of one mutex 24+32+4*32 = 184 ((struct main_sm_info*)(buf+offset))->hash_id = now->hash.id; ((struct main_sm_info*)(buf+offset))->name_len = strlen(now->hash.name); ((struct main_sm_info*)(buf+offset))->home_node = now->home_node; ((struct main_sm_info*)(buf+offset))->size = now->size; ((struct main_sm_info*)(buf+offset))->count = now->count; ((struct main_sm_info*)(buf+offset))->users_count = now->users->use; offset += sizeof(struct main_sm_info); memcpy(buf+offset, now->hash.name, strlen(now->hash.name)); offset += strlen(now->hash.name); //node id in the table for(j=0;j<now->users->table_size;j++){ node = now->users->row[j]; if(*node != -1){ *((unsigned int*)(buf+offset)) = *node; offset += sizeof(unsigned int); } } now = (struct sm_header*)now->hash.next; } } ((struct imain_reply*)buf)->sm_num = sm_num; //send mutex info & wait new mutex ready sendRecv(src_node, buf, offset, buf, sizeof(struct request_header)); g_group.coordinator.main_id = ((struct request_header*)request)->src_node; //send to other node the ((struct new_manager_req*)buf)->req.msg_type = MSG_NEWMAIN_MANAGER; ((struct new_manager_req*)buf)->new_manager = src_node; for(i=0;i<g_group.node_table->table_size;i++){ send_node = tableGetRow(g_group.node_table, i); if(*send_node != -1 && *send_node != g_group.node_id && *send_node != src_node) sendTo(*send_node, buf, sizeof(struct new_manager_req)); } //send to demon ((struct main_s2d_req*)buf)->msg_type = MSG_NEWMAIN_MANAGER; ((struct main_s2d_req*)buf)->app_len = strlen(g_group.app_name); ((struct main_s2d_req*)buf)->group_len = strlen(g_group.group_name); ((struct main_s2d_req*)buf)->ip = ((struct node*)g_group.node_table->row[src_node])->ip; ((struct main_s2d_req*)buf)->port = ((struct node*)g_group.node_table->row[src_node])->port; ((struct main_s2d_req*)buf)->id = src_node; memcpy( buf+sizeof(struct main_s2d_req), g_group.app_name, ((struct main_s2d_req*)buf)->app_len); memcpy( buf+sizeof(struct main_s2d_req)+strlen(g_group.app_name), g_group.group_name, ((struct main_s2d_req*)buf)->group_len); bzero(&server_addr, sizeof(server_addr)); sockfd = UDP_init(g_system_conf.broadcast_ip, g_system_conf.demon_port, &server_addr); UDP_setBroadcast(sockfd); UDP_setTTL(sockfd, 1); sendto(sockfd, buf, sizeof(struct main_s2d_req)+((struct main_s2d_req*)buf)->app_len+((struct main_s2d_req*)buf)->group_len, 0, (struct sockaddr*)&server_addr, sizeof(server_addr)); mem_free(buf); return 1; }
int client_run() { function_footprint(); try { ResultCode resultCode; auto client = getTcpClientPool().getTcpClient(resultCode); if (resultCode != RC_SUCCESS) { cerr << "Get Client error: " << getErrorDescription(resultCode) << endl; return RC_ERROR; } // step 1, 2 idgs::client::ClientActorMessagePtr clientActorMsg = make_shared<idgs::client::ClientActorMessage>(); clientActorMsg->setDestActorId(test_server_id); clientActorMsg->setDestMemberId(ANY_MEMBER); clientActorMsg->setSourceActorId("client_actor_id"); clientActorMsg->setSourceMemberId(CLIENT_MEMBER); clientActorMsg->setOperationName(start_work_operation); clientActorMsg->getRpcMessage()->set_payload("payload"); ResultCode errorCode; idgs::client::ClientActorMessagePtr response; errorCode = client->sendRecv(clientActorMsg, response); if (errorCode != RC_SUCCESS) { cerr << "execute the command error: " << getErrorDescription(errorCode) << endl; client->close(); return RC_ERROR; } DLOG(INFO) << "write message to server" << clientActorMsg->toString(); // step 3, 4 errorCode = client->receive(response); if (errorCode != RC_SUCCESS) { DLOG(INFO) << "get response error " << errorCode; return errorCode; } if (response->getOperationName() == sending_reponse_succ) { response->setOperationName(new_client_message_comes); response->setDestActorId(test_server_id); response->setSourceActorId("client_actor_id"); response->setDestMemberId(response->getSourceMemberId()); response->setChannel(TC_TCP); response->setSourceMemberId(CLIENT_MEMBER); ResultCode errorCode; idgs::client::ClientActorMessagePtr tcpResponse; errorCode = client->sendRecv(response, tcpResponse); DVLOG(2) << "after sendRecv"; if (errorCode != RC_SUCCESS) { cerr << "execute the command error: " << getErrorDescription(errorCode) << endl; client->close(); return RC_ERROR; } if (tcpResponse->getOperationName() == sending_total) { idgs::pb::Long l; tcpResponse->parsePayload(&l); test_server_count = l.value(); } ++count; } else { std::cerr <<"Test client error, receive error server response" ; return RC_ERROR; } //while (1) {} //socket.close(); } catch (std::exception& e) { std::cerr <<"Test client error" << e.what() << std::endl; return RC_ERROR; } return RC_SUCCESS; }