void CacheQuorum::handle_put() { #ifdef DEBUG printf("CACHE_NODE handle_put\n"); print_msg_info(&(node->msg_info)); #endif fprintf(stderr, "CacheQuorum cache_handle_put not implemented!\n"); MPI_ASSERT(FAILURE); /* int result; result = recv_msg(buf, msg_info->count, MPI_UINT8_T, msg_info->src, PUT, msg_info->comm, status); MPI_ASSERT(result == MPI_SUCCESS); // Parse the Put message within buf, and add it to the cache. PutTemplate *format = (PutTemplate *)buf; std::string key(format->key, format->key + format->key_size); Parcel parcel; parcel.timestamp = format->timestamp; parcel.value = std::string(format->value, format->value + format->value_size); cache[key] = parcel; // Send msg to parent swing node. result = send_msg(buf, msg_info->count, MPI_UINT8_T, node->coord_rank, PUT, node->parent_comm, &request); MPI_ASSERT(result == MPI_SUCCESS); */ }
void LeaderNode::handle_exit_ack() { #ifdef DEBUG printf("===== EXIT_ACK =====\n"); printf("LeaderNode %d\n", local_rank); print_msg_info(&msg_info); #endif int result; // Recv the message result = recv_msg(buf, msg_info.count, MPI_UINT8_T, msg_info.src, EXIT_ACK, msg_info.comm, &status); ASSERT(result == MPI_SUCCESS, MPI_Abort(MPI_COMM_WORLD, 1)); // TODO: Remove the swing node from the list of swing nodes and incorporate // this into logic maybe?? // decrement num_swing_nodes --num_swing_nodes; // reply with an exit_ack so it can close result = send_msg(buf, msg_info.count, MPI_UINT8_T, msg_info.src, EXIT_ACK, msg_info.comm, &request); if (num_swing_nodes == 0 && shutdown == true) { MPI_Finalize(); } }
void CacheQuorum::handle_put_ack() { #ifdef DEBUG printf("CACHE_NODE handle_put_ack\n"); print_msg_info(&(node->msg_info)); #endif fprintf(stderr, "CacheQuorum cache_handle_put_ack not implemented!\n"); MPI_ASSERT(FAILURE); /* int result; result = recv_msg(buf, msg_info->count, MPI_UINT8_T, msg_info->src, PUT_ACK, msg_info->comm, status); MPI_ASSERT(result == MPI_SUCCESS); // Parse the Put message within buf, and add it to the cache. PutAckTemplate *format = (PutAckTemplate *)buf; uint32_t job_num = format->job_num; uint32_t job_node = format->job_node; MPI_Comm job_comm = node->job_to_comms[job_num].job; // Send msg to job node informing it that the put is complete. result = send_msg(buf, sizeof(PutAckTemplate), MPI_UINT8_T, job_node, PUT_ACK, job_comm, &request); MPI_ASSERT(result == MPI_SUCCESS); */ }
void CacheQuorum::handle_put_local_ack() { #ifdef DEBUG printf("CACHE_NODE handle_put_local_ack\n"); print_msg_info(&(node->msg_info)); #endif int result; // Receive ack from swing node telling you it now knows you have a new key result = recv_msg(buf, msg_info->count, MPI_UINT8_T, msg_info->src, PUT_LOCAL_ACK, msg_info->comm, status); MPI_ASSERT(result == MPI_SUCCESS); // Parse the PutAck message within buf and determine which node it is for. PutAckTemplate *format = (PutAckTemplate *)buf; uint32_t job_num = format->job_num; uint32_t job_node = format->job_node; // Grab the communicator associated with the target job node. MPI_Comm job_comm = node->job_to_comms[job_num].job; // Send msg to job node informing it that the put_local is complete. Note // that we didn't set the result field of the message because the swing node // we passed this to would have done that. result = send_msg(buf, sizeof(PutAckTemplate), MPI_UINT8_T, job_node, PUT_LOCAL_ACK, job_comm, &request); MPI_ASSERT(result == MPI_SUCCESS); }
// TODO: REWORK?? void CacheQuorum::handle_push() { #ifdef DEBUG printf("CACHE_NODE handle_push\n"); print_msg_info(&(node->msg_info)); #endif fprintf(stderr, "CacheQuorum handle_push not implemented!\n"); MPI_ASSERT(FAILURE); }
void LeaderNode::handle_spawn_cache() { #ifdef DEBUG printf("===== SPAWN CACHE =====\n"); printf("LeaderNode %d\n", local_rank); print_msg_info(&msg_info); #endif fprintf(stderr, "handle_spawn_cache not implemented on leader_node!\n"); MPI_ASSERT(FAILURE); }
void CacheQuorum::handle_put_local() { #ifdef DEBUG printf("CACHE_NODE handle_put_local\n"); print_msg_info(&(node->msg_info)); #endif int result; result = recv_msg(buf, msg_info->count, MPI_UINT8_T, msg_info->src, PUT_LOCAL, msg_info->comm, status); MPI_ASSERT(result == MPI_SUCCESS); // Parse the Put message within buf PutTemp put; PutTemplate *format = (PutTemplate *)buf; put.unpack(format); // Create a parcel to store in the cache Parcel parcel; parcel.timestamp = put.timestamp; parcel.value.assign(put.value); // If this is a new entry in the cache, notify the swing nodes so they know // about its existance for future requests. if (cache.count(put.key) == 0) { // Send msg to parent swing node. result = send_msg(buf, msg_info->count, MPI_UINT8_T, node->coord_rank, PUT_LOCAL, node->parent_comm, &request); MPI_ASSERT(result == MPI_SUCCESS); } // Otherwise, let the job node know the put_local is complete. else { // Grab the communicator associated with the target job node. MPI_Comm job_comm = node->job_to_comms[put.job_num].job; // Pack the Put Ack template PutAckTemp put_ack; PutAckTemplate *temp = (PutAckTemplate *)buf; put_ack.pack(temp, put.job_num, put.job_node, put.cache_node, put.key, result); // Send msg to job node informing it that the put_local is complete. result = send_msg(buf, sizeof(PutAckTemplate), MPI_UINT8_T, put.job_node, PUT_LOCAL_ACK, job_comm, &request); MPI_ASSERT(result == MPI_SUCCESS); } // Update the key locally. cache[put.key] = parcel; }
/* code not used !*/ int buffered_printer(int infd) { int i,k=0,retval; char *missatge=0,*myerror=""; struct sip_msg msg; static char mybuffer[1400]; static int end=0,last=0; while((i=read(infd,&mybuffer[last],1400-last))==1400-last){ if((end=memstr(mybuffer,last+i,"\n\n\n",3))<0){ last+=i; return 0; }else{ end+=3; while(end<1400 && (mybuffer[end]=='\n' || mybuffer[end]=='.' || mybuffer[end]=='\r')) end++; if((missatge=pkg_malloc(end))==0){ myerror="Out of memory !!\n"; goto error; } memset(missatge,0,end); memcpy(missatge,mybuffer,end); memset(&msg,0,sizeof(struct sip_msg)); msg.buf=missatge; msg.len=end; if(!parse_msg(msg.buf,msg.len,&msg)) print_msg_info(1,&msg); printf("PARSED:%d,last=%d,end=%d\n",k++,last,end); free_sip_msg(&msg); pkg_free(missatge); memmove(mybuffer,&mybuffer[end],1400-end); last=1400-end; } } retval=0; goto exit; error: printf("Error on %s",myerror); retval=1; exit: if(missatge) pkg_free(missatge); return retval; }
void LeaderNode::handle_requests() { #ifdef DEBUG printf("LeaderNode entering handle_requests!\n"); #endif while (true) { while (msg_ready() == false) { message_select(); } while (msg_ready() == true) { msg_info = msg_queue.front(); msg_queue.pop_front(); #ifdef DEBUG printf("msg_queue.size: %u\n", msg_queue.size()); #endif switch (msg_info.tag) { case SPAWN_JOB: handle_spawn_job(); break; case SPAWN_CACHE: handle_spawn_cache(); break; case EXIT: handle_exit(); break; case EXIT_ACK: handle_exit_ack(); break; default: printf("===== DEFAULT =====\n"); printf("LeaderNode %d\n", local_rank); print_msg_info(&msg_info); MPI_ASSERT(FAILURE); break; } } } }
void CacheQuorum::handle_get() { #ifdef DEBUG printf("CACHE_NODE handle_get\n"); print_msg_info(&(node->msg_info)); #endif fprintf(stderr, "CacheQuorum handle_get not implemented!\n"); MPI_ASSERT(FAILURE); /* int result; result = recv_msg(buf, msg_info->count, MPI_UINT8_T, msg_info->src, GET, msg_info->comm, status); MPI_ASSERT(result == MPI_SUCCESS); GetTemplate *format = (GetTemplate *)buf; // Build a GetReq for this key/value lookup so the cache nodes can vote as a // whole and achieve consistency. GetReq get_req; get_req.job_num = format->job_num; get_req.job_node = format->job_node; get_req.key = std::string(format->key, format->key + format->key_size); // Set max voter size and upate later when the cache_node hears back from // its coord_swing node. get_req.votes_req = node->local_size; get_req.census = std::vector<Parcel>(); // If this cache node has the key, put it inside the GetReq's census vector. if (cache.count(get_req.key) != 0) { get_req.census.push_back(cache[get_req.key]); } // Add the GetReq to the vector of pending requests for this cache node. pending_get_requests.push_back(get_req); // Pass on the GET message to this cache node's coordinator swing node. result = send_msg(buf, msg_info->count, MPI_UINT8_T, node->coord_rank, GET, node->parent_comm, &request); MPI_ASSERT(result == MPI_SUCCESS); */ }
void CacheQuorum::handle_get_local() { #ifdef DEBUG printf("CACHE_NODE handle_get_local\n"); print_msg_info(&(node->msg_info)); #endif int result; uint8_t key_found = FAILURE; std::string value = ""; uint64_t timestamp = 0; // Recv get_local request from the job node result = recv_msg(buf, msg_info->count, MPI_UINT8_T, msg_info->src, GET_LOCAL, msg_info->comm, status); MPI_ASSERT(result == MPI_SUCCESS); // Parse the GetTemplate GetTemp get; GetTemplate *get_format = (GetTemplate *)buf; get.unpack(get_format); // Build the GetAckTemplate GetAckTemp get_ack; GetAckTemplate *get_ack_format = (GetAckTemplate *)node->buf; // Lookup the key locally if (cache.count(get.key) != 0) { Parcel parcel = cache[get.key]; value.assign(parcel.value); timestamp = parcel.timestamp; key_found = SUCCESS; } // Pack the value string into message get_ack.pack(get_ack_format, get.job_num, get.job_node, get.key, value, timestamp, key_found); // Reply to the requesting job node. result = send_msg(node->buf, sizeof(GetAckTemplate), MPI_UINT8_T, get_ack.job_node, GET_LOCAL_ACK, msg_info->comm, &request); MPI_ASSERT(result == MPI_SUCCESS); }
void CacheQuorum::handle_push_local() { #ifdef DEBUG printf("CACHE_NODE handle_push_local\n"); print_msg_info(&(node->msg_info)); #endif int result; // Recv push_local message from job node. result = recv_msg(buf, msg_info->count, MPI_UINT8_T, msg_info->src, PUSH_LOCAL, msg_info->comm, status); MPI_ASSERT(result == MPI_SUCCESS); // If this came from a cache node if (msg_info->comm == MPI_COMM_WORLD) { parse_and_save_push_local(buf, msg_info); } // If this came from a job node else { push_to_target_node(buf, msg_info); } }
void CacheQuorum::handle_push_local_ack() { #ifdef DEBUG printf("CACHE_NODE handle_push_local_ack\n"); print_msg_info(&(node->msg_info)); #endif int result; result = recv_msg(buf, msg_info->count, MPI_UINT8_T, msg_info->src, PUSH_LOCAL_ACK, msg_info->comm, status); MPI_ASSERT(result == MPI_SUCCESS); PutAckTemplate *put_ack = (PutAckTemplate *)buf; put_ack->result = SUCCESS; uint32_t job_num = put_ack->job_num; uint32_t job_node = put_ack->job_node; MPI_Comm job_comm = node->job_to_comms[job_num].job; // Reply back to original job node with outcome. result = send_msg(buf, sizeof(PushAckTemplate), MPI_UINT8_T, job_node, PUSH_LOCAL_ACK, job_comm, &request); MPI_ASSERT(result == MPI_SUCCESS); }
void CacheQuorum::handle_get_ack() { #ifdef DEBUG printf("CACHE_NODE handle_get_ack\n"); print_msg_info(&(node->msg_info)); #endif fprintf(stderr, "CacheQuorum handle_get not implemented!\n"); MPI_ASSERT(FAILURE); /* int result; result = recv_msg(buf, msg_info->count, MPI_UINT8_T, msg_info->src, GET_ACK, msg_info->comm, status); MPI_ASSERT(result == MPI_SUCCESS); // Iterator to find the GetReq that matches this get_ack. std::vector<GetReq>::iterator it; // If this is a message from this cache_node's coordinator swing_node if (msg_info->comm == node->parent_comm && msg_info->src == node->coord_rank) { #ifdef DEBUG printf("CacheNode %d got CensusTemplate from Swing Node!\n",\ node->local_rank); #endif // Build out the match for the GetReq entry from the message. CensusTemplate *format = (CensusTemplate *)buf; GetReq updated_vote; updated_vote.job_num = format->job_num; updated_vote.job_node = format->job_node; updated_vote.key = std::string(format->key, format->key + format->key_size); // Match the GetReq object to an entry in pending_get_requests. it = std::find(pending_get_requests.begin(), pending_get_requests.end(), updated_vote); if (it == pending_get_requests.end()) { // This should never happen so abort. MPI_ASSERT(FAILURE); } else { // Update the votes_required it->votes_req = format->votes_req; } } else { #ifdef DEBUG printf("CacheNode %d got vote from CacheNode %d!\n", node->local_rank, msg_info->src); #endif GetReq new_vote; GetAckTemplate *format = (GetAckTemplate *)buf; new_vote.job_num = format->job_num; new_vote.job_node = format->job_node; new_vote.key = std::string(format->key, format->key + format->key_size); // Match the GetReq object to an entry in pending_get_requests. it = std::find(pending_get_requests.begin(), pending_get_requests.end(), new_vote); if (it == pending_get_requests.end()) { // This should never happen so abort. MPI_ASSERT(FAILURE); } else { // Add the new value to the vector of votes. Parcel vote; vote.value = std::string (format->value, format->value + format->value_size); vote.timestamp = format->timestamp; it->census.push_back(vote); } } if (it->votes_req == it->census.size()) { #ifdef DEBUG printf("CacheNode %d - key %s - received all %d votes!\n", node->local_rank, it->key.c_str(), it->census.size()); #endif send_job_node_get_ack(it); pending_get_requests.erase(it); } #ifdef DEBUG else { printf("CacheNode %d - key %s - votes %d/%u\n", node->local_rank, it->key.c_str(), it->census.size(), it->votes_req); } #endif */ }