예제 #1
0
RC TPCCTxnManager::run_tpcc_phase2() {
  TPCCQuery* tpcc_query = (TPCCQuery*) query;
  RC rc = RCOK;
  assert(CC_ALG == CALVIN);

	uint64_t w_id = tpcc_query->w_id;
  uint64_t d_id = tpcc_query->d_id;
  uint64_t c_id = tpcc_query->c_id;
  //uint64_t d_w_id = tpcc_query->d_w_id;
  //uint64_t c_w_id = tpcc_query->c_w_id;
  //uint64_t c_d_id = tpcc_query->c_d_id;
	//char * c_last = tpcc_query->c_last;
  //double h_amount = tpcc_query->h_amount;
	//bool by_last_name = tpcc_query->by_last_name;
	bool remote = tpcc_query->remote;
	uint64_t ol_cnt = tpcc_query->ol_cnt;
	uint64_t o_entry_d = tpcc_query->o_entry_d;
  //uint64_t o_id = tpcc_query->o_id;

	uint64_t part_id_w = wh_to_part(w_id);
	//uint64_t part_id_c_w = wh_to_part(c_w_id);
  bool w_loc = GET_NODE_ID(part_id_w) == g_node_id;
  //bool c_w_loc = GET_NODE_ID(part_id_c_w) == g_node_id;


	switch (tpcc_query->txn_type) {
		case TPCC_PAYMENT :
      break;
		case TPCC_NEW_ORDER :
      if(w_loc) {
			  rc = new_order_0( w_id, d_id, c_id, remote, ol_cnt, o_entry_d, &tpcc_query->o_id, row); 
        rc = new_order_1( w_id, d_id, c_id, remote, ol_cnt, o_entry_d, &tpcc_query->o_id, row); 
        rc = new_order_2( w_id, d_id, c_id, remote, ol_cnt, o_entry_d, &tpcc_query->o_id, row); 
        rc = new_order_3( w_id, d_id, c_id, remote, ol_cnt, o_entry_d, &tpcc_query->o_id, row); 
        rc = new_order_4( w_id, d_id, c_id, remote, ol_cnt, o_entry_d, &tpcc_query->o_id, row); 
        tpcc_query->o_id = *(int64_t *) row->get_value(D_NEXT_O_ID);
        //rc = new_order_5( w_id, d_id, c_id, remote, ol_cnt, o_entry_d, &tpcc_query->o_id, row); 
      }
        for(uint64_t i = 0; i < tpcc_query->ol_cnt; i++) {

          uint64_t ol_number = i;
          uint64_t ol_i_id = tpcc_query->items[ol_number]->ol_i_id;
          uint64_t ol_supply_w_id = tpcc_query->items[ol_number]->ol_supply_w_id;
          //uint64_t ol_quantity = tpcc_query->items[ol_number].ol_quantity;
          //uint64_t ol_amount = tpcc_query->ol_amount;
          uint64_t part_id_ol_supply_w = wh_to_part(ol_supply_w_id);
          bool ol_supply_w_loc = GET_NODE_ID(part_id_ol_supply_w) == g_node_id;
          if(ol_supply_w_loc) {
            rc = new_order_6(ol_i_id, row);
            rc = new_order_7(ol_i_id, row);
          }
        }
        break;
    default: assert(false);
  }
  return rc;
}
예제 #2
0
파일: txn.cpp 프로젝트: rharding6373/ddbms
void TxnManager::send_prepare_messages() {
  rsp_cnt = query->partitions_touched.size() - 1;
  DEBUG("%ld Send PREPARE messages to %d\n",get_txn_id(),rsp_cnt);
  for(uint64_t i = 0; i < query->partitions_touched.size(); i++) {
    if(GET_NODE_ID(query->partitions_touched[i]) == g_node_id) {
      continue;
    }
    msg_queue.enqueue(get_thd_id(),Message::create_message(this,RPREPARE),GET_NODE_ID(query->partitions_touched[i]));
  }
}
예제 #3
0
static void print_tree_node(tree_node_t main_node, int id) {
  int i;
  printf("%d> %d num_children: %d\n", id, (int)GET_NODE_ID(main_node), GET_NUM_CHILDREN(main_node));
  for(i=0; i<GET_NUM_CHILDREN(main_node); i++) {
    printf("%d> %d child: %d %d\n", id, (int)GET_NODE_ID(main_node), i, (int)GET_NODE_ID(GET_CHILD_IDX(main_node,i)));
  }
  for(i=0; i<GET_NUM_CHILDREN(main_node); i++) {
    print_tree_node(GET_CHILD_IDX(main_node, i), id);
  }
  return;
}
예제 #4
0
파일: txn.cpp 프로젝트: rharding6373/ddbms
void TxnManager::send_finish_messages() {
  rsp_cnt = query->partitions_touched.size() - 1;
  assert(IS_LOCAL(get_txn_id()));
  DEBUG("%ld Send FINISH messages to %d\n",get_txn_id(),rsp_cnt);
  for(uint64_t i = 0; i < query->partitions_touched.size(); i++) {
    if(GET_NODE_ID(query->partitions_touched[i]) == g_node_id) {
      continue;
    }
    msg_queue.enqueue(get_thd_id(),Message::create_message(this,RFIN),GET_NODE_ID(query->partitions_touched[i]));
  }
}
예제 #5
0
void TPCCTxnManager::copy_remote_items(TPCCQueryMessage * msg) {
  TPCCQuery* tpcc_query = (TPCCQuery*) query;
  msg->items.init(tpcc_query->items.size());
  if(tpcc_query->txn_type == TPCC_PAYMENT)
    return;
  uint64_t dest_node_id = GET_NODE_ID(wh_to_part(tpcc_query->items[next_item_id]->ol_supply_w_id));
  while(next_item_id < tpcc_query->items.size() && !is_local_item(next_item_id) && GET_NODE_ID(wh_to_part(tpcc_query->items[next_item_id]->ol_supply_w_id)) == dest_node_id) {
    Item_no * req = (Item_no*) mem_allocator.alloc(sizeof(Item_no));
    req->copy(tpcc_query->items[next_item_id++]);
    msg->items.add(req);
  }
}
예제 #6
0
uint64_t TPCCQuery::participants(bool *& pps,Workload * wl) {
  int n = 0;
  for(uint64_t i = 0; i < g_node_cnt; i++)
    pps[i] = false;
  uint64_t id;

  switch(txn_type) {
    case TPCC_PAYMENT:
      id = GET_NODE_ID(wh_to_part(w_id));
      if(!pps[id]) {
        pps[id] = true;
        n++;
      }
      id = GET_NODE_ID(wh_to_part(c_w_id));
      if(!pps[id]) {
        pps[id] = true;
        n++;
      }
      break;
    case TPCC_NEW_ORDER: 
      id = GET_NODE_ID(wh_to_part(w_id));
      if(!pps[id]) {
        pps[id] = true;
        n++;
      }
      /*
      id = GET_NODE_ID(wh_to_part(c_w_id));
      if(!pps[id]) {
        pps[id] = true;
        n++;
      }
      id = GET_NODE_ID(wh_to_part(d_w_id));
      if(!pps[id]) {
        pps[id] = true;
        n++;
      }
      */
      for(uint64_t i = 0; i < ol_cnt; i++) {
        uint64_t req_nid = GET_NODE_ID(wh_to_part(items[i]->ol_supply_w_id));
        if(!pps[req_nid]) {
          pps[req_nid] = true;
          n++;
        }
      }
      break;
    default: assert(false);
  }

  return n;
}
예제 #7
0
RC YCSBTxnManager::run_ycsb() {
  RC rc = RCOK;
  assert(CC_ALG == CALVIN);
  YCSBQuery* ycsb_query = (YCSBQuery*) query;
  
  for (uint64_t i = 0; i < ycsb_query->requests.size(); i++) {
	  ycsb_request * req = ycsb_query->requests[i];
    if(this->phase == CALVIN_LOC_RD && req->acctype == WR)
      continue;
    if(this->phase == CALVIN_EXEC_WR && req->acctype == RD)
      continue;

		uint64_t part_id = _wl->key_to_part( req->key );
    bool loc = GET_NODE_ID(part_id) == g_node_id;

    if(!loc)
      continue;

    rc = run_ycsb_0(req,row);
    assert(rc == RCOK);

    rc = run_ycsb_1(req->acctype,row);
    assert(rc == RCOK);
  }
  return rc;

}
예제 #8
0
RC YCSBTxnManager::run_txn_state() {
  YCSBQuery* ycsb_query = (YCSBQuery*) query;
	ycsb_request * req = ycsb_query->requests[next_record_id];
	uint64_t part_id = _wl->key_to_part( req->key );
  bool loc = GET_NODE_ID(part_id) == g_node_id;

	RC rc = RCOK;

	switch (state) {
		case YCSB_0 :
      if(loc) {
        rc = run_ycsb_0(req,row);
      } else {
        rc = send_remote_request();
        
      }

      break;
		case YCSB_1 :
      rc = run_ycsb_1(req->acctype,row);
      break;
    case YCSB_FIN :
      state = YCSB_FIN;
      break;
    default:
			assert(false);
  }

  if(rc == RCOK)
    next_ycsb_state();

  return rc;
}
예제 #9
0
RC YCSBTxnManager::send_remote_request() {
  YCSBQuery* ycsb_query = (YCSBQuery*) query;
  uint64_t dest_node_id = GET_NODE_ID(ycsb_query->requests[next_record_id]->key);
  ycsb_query->partitions_touched.add_unique(GET_PART_ID(0,dest_node_id));
  msg_queue.enqueue(get_thd_id(),Message::create_message(this,RQRY),dest_node_id);
  return WAIT_REM;
}
예제 #10
0
void PPSWorkload::init_tab_suppliers() {
  char * padding = new char[100];
  for (int i = 0; i < 100; i++) {
    padding[i] = 'z';
  }
  for (UInt32 id = 1; id <= g_max_supplier_key; id++) {
    if (GET_NODE_ID(suppliers_to_partition(id)) != g_node_id) 
      continue;
		row_t * row;
		uint64_t row_id;
    t_suppliers->get_new_row(row, 0, row_id);
    row->set_primary_key(id);
    row->set_value(0,id);
    row->set_value(FIELD1,padding);
    row->set_value(FIELD2,padding);
    row->set_value(FIELD3,padding);
    row->set_value(FIELD4,padding);
    row->set_value(FIELD5,padding);
    row->set_value(FIELD6,padding);
    row->set_value(FIELD7,padding);
    row->set_value(FIELD8,padding);
    row->set_value(FIELD9,padding);
    row->set_value(FIELD10,padding);
    
		index_insert(i_suppliers, id, row, suppliers_to_partition(id));

  }
}
예제 #11
0
void PPSWorkload::init_tab_products() {
  char * padding = new char[100];
  for (int i = 0; i < 100; i++) {
    padding[i] = 'z';
  }
  for (UInt32 id = 1; id <= g_max_product_key; id++) {
    if (GET_NODE_ID(products_to_partition(id)) != g_node_id) 
      continue;
		row_t * row;
		uint64_t row_id;
    t_products->get_new_row(row, 0, row_id);
    row->set_primary_key(id);
    row->set_value(0,id);
    row->set_value(FIELD1,padding);
    row->set_value(FIELD2,padding);
    row->set_value(FIELD3,padding);
    row->set_value(FIELD4,padding);
    row->set_value(FIELD5,padding);
    row->set_value(FIELD6,padding);
    row->set_value(FIELD7,padding);
    row->set_value(FIELD8,padding);
    row->set_value(FIELD9,padding);
    row->set_value(FIELD10,padding);
    
		index_insert(i_products, id, row, products_to_partition(id));
    DEBUG("PRODUCTS added (%d, ...)\n",id);

  }
}
예제 #12
0
void YCSBTxnManager::copy_remote_requests(YCSBQueryMessage * msg) {
  YCSBQuery* ycsb_query = (YCSBQuery*) query;
  //msg->requests.init(ycsb_query->requests.size());
  uint64_t dest_node_id = GET_NODE_ID(ycsb_query->requests[next_record_id]->key);
  while(next_record_id < ycsb_query->requests.size() && !is_local_request(next_record_id) && GET_NODE_ID(ycsb_query->requests[next_record_id]->key) == dest_node_id) {
    YCSBQuery::copy_request_to_msg(ycsb_query,msg,next_record_id++);
  }
}
예제 #13
0
std::set<uint64_t> YCSBQuery::participants(Message * msg, Workload * wl) {
  std::set<uint64_t> participant_set;
  YCSBClientQueryMessage* ycsb_msg = ((YCSBClientQueryMessage*)msg);
  for(uint64_t i = 0; i < ycsb_msg->requests.size(); i++) {
    uint64_t req_nid = GET_NODE_ID(((YCSBWorkload*)wl)->key_to_part(ycsb_msg->requests[i]->key));
    participant_set.insert(req_nid);
  }
  return participant_set;
}
예제 #14
0
uint64_t TPCCQuery::get_participants(Workload * wl) {
   uint64_t participant_cnt = 0;
   uint64_t active_cnt = 0;
  assert(participant_nodes.size()==0);
  assert(active_nodes.size()==0);
  for(uint64_t i = 0; i < g_node_cnt; i++) {
      participant_nodes.add(0);
      active_nodes.add(0);
  }
  assert(participant_nodes.size()==g_node_cnt);
  assert(active_nodes.size()==g_node_cnt);

  uint64_t home_wh_node;
  home_wh_node = GET_NODE_ID(wh_to_part(w_id));
  participant_nodes.set(home_wh_node,1);
  active_nodes.set(home_wh_node,1);
  participant_cnt++;
  active_cnt++;
  if(txn_type == TPCC_PAYMENT) {
      uint64_t req_nid = GET_NODE_ID(wh_to_part(c_w_id));
      if(participant_nodes[req_nid] == 0) {
        participant_cnt++;
        participant_nodes.set(req_nid,1);
        active_cnt++;
        active_nodes.set(req_nid,1);
      }

  } else if (txn_type == TPCC_NEW_ORDER) {
    for(uint64_t i = 0; i < ol_cnt; i++) {
      uint64_t req_nid = GET_NODE_ID(wh_to_part(items[i]->ol_supply_w_id));
      if(participant_nodes[req_nid] == 0) {
        participant_cnt++;
        participant_nodes.set(req_nid,1);
        active_cnt++;
        active_nodes.set(req_nid,1);
      }
    }
  }
  return participant_cnt;
}
예제 #15
0
uint64_t YCSBQuery::participants(bool *& pps,Workload * wl) {
  int n = 0;
  for(uint64_t i = 0; i < g_node_cnt; i++)
    pps[i] = false;

  for(uint64_t i = 0; i < requests.size(); i++) {
    uint64_t req_nid = GET_NODE_ID(((YCSBWorkload*)wl)->key_to_part(requests[i]->key));
    if(!pps[req_nid])
      n++;
    pps[req_nid] = true;
  }
  return n;
}
예제 #16
0
static tree_node_t find_node(tree_node_t tree, gasnet_node_t id) {
  gasnet_node_t i;
  if(GET_NODE_ID(tree)==id) return tree;
  for(i=0; i<GET_NUM_CHILDREN(tree); i++) {
    tree_node_t temp = find_node(GET_CHILD_IDX(tree,i), id);
    /*found a match in the subtree return it*/
    if(temp!=NULL) {
      return temp;
    }
  }
  /*no match found */
  return NULL;
}
예제 #17
0
RC TPCCTxnManager::send_remote_request() {
  assert(IS_LOCAL(get_txn_id()));
  TPCCQuery* tpcc_query = (TPCCQuery*) query;
  TPCCRemTxnType next_state = TPCC_FIN;
	uint64_t w_id = tpcc_query->w_id;
  uint64_t c_w_id = tpcc_query->c_w_id;
  uint64_t dest_node_id = UINT64_MAX;
  if(state == TPCC_PAYMENT0) {
    dest_node_id = GET_NODE_ID(wh_to_part(w_id));
    next_state = TPCC_PAYMENT2;
  } else if(state == TPCC_PAYMENT4) {
    dest_node_id = GET_NODE_ID(wh_to_part(c_w_id));
    next_state = TPCC_FIN;
  } else if(state == TPCC_NEWORDER0) {
    dest_node_id = GET_NODE_ID(wh_to_part(w_id));
    next_state = TPCC_NEWORDER6;
  } else if(state == TPCC_NEWORDER8) {
    dest_node_id = GET_NODE_ID(wh_to_part(tpcc_query->items[next_item_id]->ol_supply_w_id));
    /*
    while(GET_NODE_ID(wh_to_part(tpcc_query->items[next_item_id]->ol_supply_w_id)) != dest_node_id) {
      msg->items.add(tpcc_query->items[next_item_id++]);
    }
    */
    if(is_done())
      next_state = TPCC_FIN;
    else 
      next_state = TPCC_NEWORDER6;
  } else {
    assert(false);
  }
  TPCCQueryMessage * msg = (TPCCQueryMessage*)Message::create_message(this,RQRY);
  msg->state = state;
  query->partitions_touched.add_unique(GET_PART_ID(0,dest_node_id));
  msg_queue.enqueue(get_thd_id(),msg,dest_node_id);
  state = next_state;
  return WAIT_REM;
}
예제 #18
0
std::set<uint64_t> TPCCQuery::participants(Message * msg, Workload * wl) {
  std::set<uint64_t> participant_set;
  TPCCClientQueryMessage* tpcc_msg = ((TPCCClientQueryMessage*)msg);
  uint64_t id;

  id = GET_NODE_ID(wh_to_part(tpcc_msg->w_id));
  participant_set.insert(id);

  switch(tpcc_msg->txn_type) {
    case TPCC_PAYMENT:
      id = GET_NODE_ID(wh_to_part(tpcc_msg->c_w_id));
      participant_set.insert(id);
      break;
    case TPCC_NEW_ORDER: 
      for(uint64_t i = 0; i < tpcc_msg->ol_cnt; i++) {
        uint64_t req_nid = GET_NODE_ID(wh_to_part(tpcc_msg->items[i]->ol_supply_w_id));
        participant_set.insert(req_nid);
      }
      break;
    default: assert(false);
  }

  return participant_set;
}
예제 #19
0
파일: mdkernel.c 프로젝트: jurabr/microdef
/* returnes position of node numbered "id" */
int md_node_find_by_number(int id)
{
  static int pos ;
  int i ;

  for (i=0; i<n_len; i++)
  {
    if (GET_NODE_ID(i) == id)
    {
      pos = i ;
      return(pos);
    }
  }

  return(-1);
}
예제 #20
0
RC YCSBTxnManager::acquire_locks() {
  uint64_t starttime = get_sys_clock();
  assert(CC_ALG == CALVIN);
  YCSBQuery* ycsb_query = (YCSBQuery*) query;
  locking_done = false;
  RC rc = RCOK;
  incr_lr();
  assert(ycsb_query->requests.size() == g_req_per_query);
  assert(phase == CALVIN_RW_ANALYSIS);
	for (uint32_t rid = 0; rid < ycsb_query->requests.size(); rid ++) {
		ycsb_request * req = ycsb_query->requests[rid];
		uint64_t part_id = _wl->key_to_part( req->key );
    DEBUG("LK Acquire (%ld,%ld) %d,%ld -> %ld\n",get_txn_id(),get_batch_id(),req->acctype,req->key,GET_NODE_ID(part_id));
    if(GET_NODE_ID(part_id) != g_node_id)
      continue;
		INDEX * index = _wl->the_index;
		itemid_t * item;
		item = index_read(index, req->key, part_id);
		row_t * row = ((row_t *)item->location);
		RC rc2 = get_lock(row,req->acctype);
    if(rc2 != RCOK) {
      rc = rc2;
    }
	}
  if(decr_lr() == 0) {
    if(ATOM_CAS(lock_ready,false,true))
      rc = RCOK;
  }
  txn_stats.wait_starttime = get_sys_clock();
  /*
  if(rc == WAIT && lock_ready_cnt == 0) {
    if(ATOM_CAS(lock_ready,false,true))
    //lock_ready = true;
      rc = RCOK;
  }
  */
  INC_STATS(get_thd_id(),calvin_sched_time,get_sys_clock() - starttime);
  locking_done = true;
  return rc;
}
예제 #21
0
uint64_t YCSBQuery::get_participants(Workload * wl) {

  uint64_t participant_cnt = 0;
  assert(participant_nodes.size()==0);
  assert(active_nodes.size()==0);
  for(uint64_t i = 0; i < g_node_cnt; i++) {
      participant_nodes.add(0);
      active_nodes.add(0);
  }
  assert(participant_nodes.size()==g_node_cnt);
  assert(active_nodes.size()==g_node_cnt);
  for(uint64_t i = 0; i < requests.size(); i++) {
    uint64_t req_nid = GET_NODE_ID(((YCSBWorkload*)wl)->key_to_part(requests[i]->key));
    if(requests[i]->acctype == RD) {
      if(participant_nodes[req_nid] == 0)
        ++participant_cnt;
      participant_nodes.set(req_nid,1);
    }
    if(requests[i]->acctype == WR)
      active_nodes.set(req_nid,1);
  }
  return participant_cnt;
}
예제 #22
0
파일: lifegrd.c 프로젝트: alex262/MB96F330
/* Retourne le node-id */
UNS8 proceedNMTerror(UNS8 bus_id, Message* m )
{
//	UNS16 time, should_time;
//	UNS8 *   pbConsumerHeartbeatCount;
	// Pointer to HBConsumerTimeArray (Array of expected heartbeat cycle time for each node.
	// HBConsumerTimeArray is defined in objdict.c *  \param CheckAccess if other than 0, do not read if the data is Write Only
//	UNS32 *  pbConsumerHeartbeatEntry;// Index 1016 on 32 bits
	UNS8 *   pdwSize;
	UNS8     dwSize;//, count, ConsummerHeartBeat_nodeId ;
//	UNS8 index; // Index to scan the table of heartbeat consumers
	UNS8 nodeId = (UNS8) GET_NODE_ID((*m));

	pdwSize = &dwSize;
	if((m->rtr == 1) ) /* Notice that only the master can have sent this node guarding request */
	{ // Receiving a NMT NodeGuarding (request of the state by the master)
		//  only answer to the NMT NodeGuarding request, the master is not checked (not implemented)
		if (nodeId == bDeviceNodeId )
		{
			Message msg;
			msg.cob_id = bDeviceNodeId + 0x700;
			msg.len = (UNS8)0x01;
			msg.rtr = 0;
			msg.data[0] = getState(); 
			if (toggle)
			{
				msg.data[0] |= 0x80 ;
				toggle = 0 ;
			}
			else
				toggle = 1 ; 
				// send the nodeguard response.
			MSG_WAR(0x3130, "Sending NMT Nodeguard to master, state: ", nodeState);
			f_can_send( bus_id, &msg );
		}  
		return 1 ;
	}
	if (m->rtr == 0) // Not a request CAN
	{
		MSG_WAR(0x3110, "Received NMT nodeId : ", nodeId);
		/* the slave's state receievd is stored in the NMTable */
		// The state is stored on 7 bit
	//	NMTable[bus_id][nodeId] = (e_nodeState) ((*m).data[0] & 0x7F) ;
    
		/* Boot-Up frame reception */
//		if ( NMTable[bus_id][nodeId] == Initialisation)
//		{
			// The device send the boot-up message (Initialisation)
			// to indicate the master that it is entered in pre_operational mode
			// Because the  device enter automaticaly in pre_operational mode,
			// the pre_operational mode is stored 
			//  NMTable[bus_id][nodeId] = Pre_operational;
	//		MSG_WAR(0x3100, "The NMT is a bootup from node : ", nodeId);
	//		return 1;
	//	}
      
/*		if( NMTable[bus_id][nodeId] != Unknown_state ) 
		{
			if( getODentry( (UNS16)0x1016, (UNS8)0x0, 
							(void * *) &pbConsumerHeartbeatCount, 
							pdwSize, 0 ) == OD_SUCCESSFUL )
			{
				if (*pbConsumerHeartbeatCount > (UNS8)NB_OF_HEARTBEAT_PRODUCERS)
					count = (UNS8)NB_OF_HEARTBEAT_PRODUCERS ;
				else
					count = *pbConsumerHeartbeatCount ;

				for( index = (UNS8)0x00; index < count; index++ )
				{
					if( getODentry( (UNS16)0x1016, (UNS8)index + 1,
									(void * *)&pbConsumerHeartbeatEntry, 
									pdwSize, 0 ) == OD_SUCCESSFUL )
					{
						should_time = (UNS16) ( (*pbConsumerHeartbeatEntry) & (UNS32)0x0000FFFF ) ;
						ConsummerHeartBeat_nodeId = (UNS8)( ((*pbConsumerHeartbeatEntry) & (UNS32)0x00FF0000) >> (UNS8)16 );
						if (( should_time )&&( nodeId == ConsummerHeartBeat_nodeId ))
						{
							time = getTime16( &(heartBeatTable[index].time) );
							MSG_WAR(0x3105, "HeartBeat received from node : ", nodeId );
							MSG_WAR(0x3106, "                     at time : ", time);
							setTime16( &heartBeatTable[index].time, (UNS8)0x0000 );
							if( bErrorOccured == TRUE )
							{
								lifeguardCallback( (UNS8)CONNECTION_OK ); // a little strange
								return 0 ;
							}
						}
					}
				} // end for
			}  
		} //End if( NMTable[bus_id][nodeId] != Unknown_state) 
	*/
	} // End if (m->rtr == 0)
	
	return 1;
}
예제 #23
0
RC TPCCTxnManager::run_txn_state() {
    TPCCQuery* tpcc_query = (TPCCQuery*) query;
    uint64_t w_id = tpcc_query->w_id;
    uint64_t d_id = tpcc_query->d_id;
    uint64_t c_id = tpcc_query->c_id;
    uint64_t d_w_id = tpcc_query->d_w_id;
    uint64_t c_w_id = tpcc_query->c_w_id;
    uint64_t c_d_id = tpcc_query->c_d_id;
    char * c_last = tpcc_query->c_last;
    double h_amount = tpcc_query->h_amount;
    bool by_last_name = tpcc_query->by_last_name;
    bool remote = tpcc_query->remote;
    uint64_t ol_cnt = tpcc_query->ol_cnt;
    uint64_t o_entry_d = tpcc_query->o_entry_d;
    uint64_t ol_i_id = 0;
    uint64_t ol_supply_w_id = 0;
    uint64_t ol_quantity = 0;
    if(tpcc_query->txn_type == TPCC_NEW_ORDER) {
        ol_i_id = tpcc_query->items[next_item_id]->ol_i_id;
        ol_supply_w_id = tpcc_query->items[next_item_id]->ol_supply_w_id;
        ol_quantity = tpcc_query->items[next_item_id]->ol_quantity;
    }
    uint64_t ol_number = next_item_id;
    uint64_t ol_amount = tpcc_query->ol_amount;
    uint64_t o_id = tpcc_query->o_id;

    uint64_t part_id_w = wh_to_part(w_id);
    uint64_t part_id_c_w = wh_to_part(c_w_id);
    uint64_t part_id_ol_supply_w = wh_to_part(ol_supply_w_id);
    bool w_loc = GET_NODE_ID(part_id_w) == g_node_id;
    bool c_w_loc = GET_NODE_ID(part_id_c_w) == g_node_id;
    bool ol_supply_w_loc = GET_NODE_ID(part_id_ol_supply_w) == g_node_id;

	RC rc = RCOK;

	switch (state) {
		case TPCC_PAYMENT0 :
            if(w_loc)
                    rc = run_payment_0(w_id, d_id, d_w_id, h_amount, row);
            else {
              rc = send_remote_request();
            }
            break;
		case TPCC_PAYMENT1 :
            rc = run_payment_1(w_id, d_id, d_w_id, h_amount, row);
            break;
		case TPCC_PAYMENT2 :
            rc = run_payment_2(w_id, d_id, d_w_id, h_amount, row);
            break;
		case TPCC_PAYMENT3 :
            rc = run_payment_3(w_id, d_id, d_w_id, h_amount, row);
            break;
		case TPCC_PAYMENT4 :
            if(c_w_loc)
                rc = run_payment_4( w_id,  d_id, c_id, c_w_id,  c_d_id, c_last, h_amount, by_last_name, row);
            else {
                rc = send_remote_request();
            }
            break;
		case TPCC_PAYMENT5 :
            rc = run_payment_5( w_id,  d_id, c_id, c_w_id,  c_d_id, c_last, h_amount, by_last_name, row);
            break;
		case TPCC_NEWORDER0 :
            if(w_loc)
                rc = new_order_0( w_id, d_id, c_id, remote, ol_cnt, o_entry_d, &tpcc_query->o_id, row);
            else {
                rc = send_remote_request();
            }
			break;
		case TPCC_NEWORDER1 :
            rc = new_order_1( w_id, d_id, c_id, remote, ol_cnt, o_entry_d, &tpcc_query->o_id, row);
            break;
		case TPCC_NEWORDER2 :
            rc = new_order_2( w_id, d_id, c_id, remote, ol_cnt, o_entry_d, &tpcc_query->o_id, row);
            break;
		case TPCC_NEWORDER3 :
            rc = new_order_3( w_id, d_id, c_id, remote, ol_cnt, o_entry_d, &tpcc_query->o_id, row);
            break;
		case TPCC_NEWORDER4 :
            rc = new_order_4( w_id, d_id, c_id, remote, ol_cnt, o_entry_d, &tpcc_query->o_id, row);
            break;
		case TPCC_NEWORDER5 :
            rc = new_order_5( w_id, d_id, c_id, remote, ol_cnt, o_entry_d, &tpcc_query->o_id, row);
            break;
		case TPCC_NEWORDER6 :
			rc = new_order_6(ol_i_id, row);
			break;
		case TPCC_NEWORDER7 :
			rc = new_order_7(ol_i_id, row);
			break;
		case TPCC_NEWORDER8 :
		      if(ol_supply_w_loc) {
                  rc = new_order_8( w_id, d_id, remote, ol_i_id, ol_supply_w_id, ol_quantity,  ol_number, o_id, row);
		      }
		      else {
                  rc = send_remote_request();
		      }
              break;
		case TPCC_NEWORDER9 :
            rc = new_order_9( w_id, d_id, remote, ol_i_id, ol_supply_w_id, ol_quantity,  ol_number, ol_amount, o_id, row);
            break;
    case TPCC_FIN :
        state = TPCC_FIN;
        if(tpcc_query->rbk)
            return Abort;
            //return finish(tpcc_query,false);
        break;
    default:
        assert(false);
	}

  if(rc == RCOK)
    next_tpcc_state();
  return rc;
}
예제 #24
0
bool YCSBTxnManager::is_local_request(uint64_t idx) {
  return GET_NODE_ID(_wl->key_to_part(((YCSBQuery*)query)->requests[idx]->key)) == g_node_id;
}
예제 #25
0
bool TPCCTxnManager::is_local_item(uint64_t idx) {
  TPCCQuery* tpcc_query = (TPCCQuery*) query;
	uint64_t ol_supply_w_id = tpcc_query->items[idx]->ol_supply_w_id;
  uint64_t part_id_ol_supply_w = wh_to_part(ol_supply_w_id);
  return GET_NODE_ID(part_id_ol_supply_w) == g_node_id;
}
예제 #26
0
RC TPCCTxnManager::acquire_locks() {
  uint64_t starttime = get_sys_clock();
  assert(CC_ALG == CALVIN);
  locking_done = false;
  RC rc = RCOK;
  RC rc2;
  INDEX * index;
  itemid_t * item;
  row_t* row;
  uint64_t key;
  incr_lr();
  TPCCQuery* tpcc_query = (TPCCQuery*) query;

	uint64_t w_id = tpcc_query->w_id;
  uint64_t d_id = tpcc_query->d_id;
  uint64_t c_id = tpcc_query->c_id;
  uint64_t d_w_id = tpcc_query->d_w_id;
  uint64_t c_w_id = tpcc_query->c_w_id;
  uint64_t c_d_id = tpcc_query->c_d_id;
	char * c_last = tpcc_query->c_last;
  uint64_t part_id_w = wh_to_part(w_id);
  uint64_t part_id_c_w = wh_to_part(c_w_id);
  switch(tpcc_query->txn_type) {
    case TPCC_PAYMENT:
      if(GET_NODE_ID(part_id_w) == g_node_id) {
      // WH
        index = _wl->i_warehouse;
        item = index_read(index, w_id, part_id_w);
        row_t * row = ((row_t *)item->location);
        rc2 = get_lock(row,g_wh_update? WR:RD);
        if(rc2 != RCOK)
          rc = rc2;

      // Dist
        key = distKey(d_id, d_w_id);
        item = index_read(_wl->i_district, key, part_id_w);
        row = ((row_t *)item->location);
        rc2 = get_lock(row, WR);
        if(rc2 != RCOK)
          rc = rc2;
      }
      if(GET_NODE_ID(part_id_c_w) == g_node_id) {
      // Cust
        if (tpcc_query->by_last_name) { 

          key = custNPKey(c_last, c_d_id, c_w_id);
          index = _wl->i_customer_last;
          item = index_read(index, key, part_id_c_w);
          int cnt = 0;
          itemid_t * it = item;
          itemid_t * mid = item;
          while (it != NULL) {
            cnt ++;
            it = it->next;
            if (cnt % 2 == 0)
              mid = mid->next;
          }
          row = ((row_t *)mid->location);
          
        }
        else { 
          key = custKey(c_id, c_d_id, c_w_id);
          index = _wl->i_customer_id;
          item = index_read(index, key, part_id_c_w);
          row = (row_t *) item->location;
        }
        rc2  = get_lock(row, WR);
        if(rc2 != RCOK)
          rc = rc2;
 
      }
      break;
    case TPCC_NEW_ORDER:
      if(GET_NODE_ID(part_id_w) == g_node_id) {
      // WH
        index = _wl->i_warehouse;
        item = index_read(index, w_id, part_id_w);
        row_t * row = ((row_t *)item->location);
        rc2 = get_lock(row,RD);
        if(rc2 != RCOK)
          rc = rc2;
      // Cust
        index = _wl->i_customer_id;
        key = custKey(c_id, d_id, w_id);
        item = index_read(index, key, wh_to_part(w_id));
        row = (row_t *) item->location;
        rc2 = get_lock(row, RD);
        if(rc2 != RCOK)
          rc = rc2;
      // Dist
        key = distKey(d_id, w_id);
        item = index_read(_wl->i_district, key, wh_to_part(w_id));
        row = ((row_t *)item->location);
        rc2 = get_lock(row, WR);
        if(rc2 != RCOK)
          rc = rc2;
      }
      // Items
        for(uint64_t i = 0; i < tpcc_query->ol_cnt; i++) {
          if(GET_NODE_ID(wh_to_part(tpcc_query->items[i]->ol_supply_w_id)) != g_node_id) 
            continue;

          key = tpcc_query->items[i]->ol_i_id;
          item = index_read(_wl->i_item, key, 0);
          row = ((row_t *)item->location);
          rc2 = get_lock(row, RD);
          if(rc2 != RCOK)
            rc = rc2;
          key = stockKey(tpcc_query->items[i]->ol_i_id, tpcc_query->items[i]->ol_supply_w_id);
          index = _wl->i_stock;
          item = index_read(index, key, wh_to_part(tpcc_query->items[i]->ol_supply_w_id));
          row = ((row_t *)item->location);
          rc2 = get_lock(row, WR);
          if(rc2 != RCOK)
            rc = rc2;
        }
      break;
    default: assert(false);
  }
  if(decr_lr() == 0) {
    if(ATOM_CAS(lock_ready,false,true))
      rc = RCOK;
  }
  txn_stats.wait_starttime = get_sys_clock();
  locking_done = true;
  INC_STATS(get_thd_id(),calvin_sched_time,get_sys_clock() - starttime);
  return rc;
}
예제 #27
0
///
/// \brief CiA301CommPort::WaitForAnswer Read the port until expected canopen answer shows
/// up in the port reads.
/// \param output Expected canopen answer.
/// \param canIndex: Index of the caller.
/// \return
///
int CiA301CommPort::ReadCobId(uint16_t expected_cobid, co_msg & output )
{

//    cout<<" --> ReadCobId. Expecting: "  << std::hex << expected_cobid << std::dec  << endl;


    vector<can_msg> otherMsgs(0);



    //cout << " Canid Received: " << std::hex << input.id << std::dec << endl;

    for(long reps=0 ; reps<FIND_RETRY ;reps++)
    {
        GetMsg(input);
        //cout << " Received: " << std::hex << input.id << std::dec << endl;
        //First check for the input.
        //If the response is the answer expected, continue
        if (input.id == expected_cobid)
        {
            //cout << " comp: " << (input.id == expected_cobid) << endl;
            break;
        }
        //if not cobid but node id:
        if (GET_NODE_ID(input.id) == GET_NODE_ID(expected_cobid) )
        {
            //cout << " Cobid still not received. Received: " << std::hex << input.id << std::dec << endl;
            //if id, check if error
            //return -1;
        }
        else
        {
            //cout << " Cobid still not received. Received: " << std::hex << input.id << std::dec << endl;
            otherMsgs.push_back(input);
        }
        if (reps==FIND_RETRY-1)
        {
            cout<<"  Max retry reached " << endl;
            return -1;
        }


    }
    //GetMsg(input);

//    for (int i=0; i<otherMsgs.size(); i++)
//    {
//        cout << "resend number : " << i << " with bytes: " << otherMsgs[i].dlc;  ;
//        cout<<" message with cob id: " << std::hex << otherMsgs[i].id << std::dec <<" rtr: " << otherMsgs[i].rtr << endl;
//        for (int j = 0; j < otherMsgs[i].dlc; j++)
//        {

//            printf("%02x ",otherMsgs[i].data[j]);
//        }
        //TODO: find another way for this without sending again
        //SendCanMessage(otherMsgs[i]);
//    }

    //convert received data to canopen
    if(CanBusToCanOpen(input, output)!=0)
    {
       err(1,"error al convertir el mensaje");
       return -1;
    }
    else
    {

//        cout<<"  <-- ReadCobId. Received: " << std::hex << output.id_co << std::dec << endl;
//        cout << "ID: " << std::hex<< GET_NODE_ID(output.id_co) << std::dec<< endl;
        //cout << " rtr: " << output.rtr << endl;
//        cout<<"received canopen data: ";
//        for (int i = 0; i < output.dlc_co; i++)
//        {

//            printf("%02x ",output.data_co[i]);
//        }
//        cout<<endl;
        //TODO: use dlc here!!!
        return data4x8to32(&output.data_co[4],output.dlc_co);
    }

    return 0;
}
예제 #28
0
/*this fucntion is already serialized in the function that calls this 
  so from here on out there is no worry about locking*/
gasnete_coll_local_tree_geom_t *gasnete_coll_tree_geom_create_local(gasnete_coll_tree_type_t in_type, int rootrank, gasnete_coll_team_t team, gasnete_coll_tree_geom_t *base_geom)  {
  gasnete_coll_local_tree_geom_t *geom;
  int i;
  gasnete_coll_tree_type_t intype_copy;
  tree_node_t *allnodes = (tree_node_t*) team->tree_construction_scratch;
  tree_node_t rootnode,mynode;
  gasneti_assert(rootrank<team->total_ranks && rootrank >=0);
  gasneti_assert_always(in_type);
  intype_copy = in_type;
  geom = (gasnete_coll_local_tree_geom_t*)gasneti_malloc(sizeof(gasnete_coll_local_tree_geom_t));
  gasneti_assert_always(in_type==intype_copy);
  
  switch (in_type->tree_class) {
#if 1
  case GASNETE_COLL_NARY_TREE:
      gasneti_assert(in_type->num_params ==1);
      allnodes =  allocate_nodes((tree_node_t**) &team->tree_construction_scratch, team, rootrank);
      rootnode = make_nary_tree(allnodes, team->total_ranks, in_type->params[0]);
       geom->rotation_points = (int*) gasneti_malloc(sizeof(int)*1);
       geom->num_rotations = 1;
       geom->rotation_points[0] = rootrank;
      break;
    case GASNETE_COLL_KNOMIAL_TREE:
      gasneti_assert(in_type->num_params ==1);
       allnodes = allocate_nodes((tree_node_t**) &team->tree_construction_scratch, team, rootrank);
      rootnode = make_knomial_tree(allnodes, team->total_ranks, in_type->params[0]);
       geom->rotation_points = (int*) gasneti_malloc(sizeof(int)*1);
       geom->num_rotations = 1;
       geom->rotation_points[0] = rootrank;
      break;
    case GASNETE_COLL_FLAT_TREE:
      allocate_nodes((tree_node_t**) &team->tree_construction_scratch , team, rootrank);
      rootnode = make_flat_tree(team->tree_construction_scratch, team->total_ranks);
      geom->rotation_points = (int*) gasneti_malloc(sizeof(int)*1);
      geom->num_rotations = 1;
      geom->rotation_points[0] = rootrank;
      break;
    case GASNETE_COLL_RECURSIVE_TREE:
      gasneti_assert(in_type->num_params ==1);
      allnodes = allocate_nodes((tree_node_t**) &team->tree_construction_scratch, team, rootrank);
      rootnode = make_recursive_tree(allnodes, team->total_ranks, in_type->params[0]);
      geom->rotation_points = (int*) gasneti_malloc(sizeof(int)*1);
      geom->num_rotations = 1;
      geom->rotation_points[0] = rootrank;
      break;
    case GASNETE_COLL_FORK_TREE:
      allnodes = allocate_nodes((tree_node_t**) &team->tree_construction_scratch, team, rootrank);
      rootnode = make_fork_tree(allnodes, team->total_ranks, in_type->params, in_type->num_params);
       geom->rotation_points = (int*) gasneti_malloc(sizeof(int)*1);
       geom->num_rotations = 1;
       geom->rotation_points[0] = rootrank;
      break;
    case GASNETE_COLL_HIERARCHICAL_TREE:
#if 0
      allnodes = team->tree_construction_scratch = allocate_nodes(allnodes, team, 0);
      rootnode = make_hiearchical_tree(in_type, allnodes, team->total_ranks);
       /* XXX ADD CODE TO GET ROTATION POINTS*/
      break;
#else
       gasneti_fatalerror("HIERARCHICAL_TREE not yet fully supported");
#endif
#endif
    default:
       gasneti_fatalerror("unknown tree type");
      break;
  }
  
  rootnode = setparents(rootnode);
  mynode = find_node(rootnode, team->myrank);

  geom->root = rootrank;
  geom->tree_type = in_type;
  geom->total_size = team->total_ranks;
  geom->parent = GET_PARENT_ID(mynode);
  geom->child_count = GET_NUM_CHILDREN(mynode);
  geom->mysubtree_size = treesize(mynode);
  geom->parent_subtree_size = treesize(mynode->parent);
  geom->children_reversed = mynode->children_reversed;
  if(rootrank != team->myrank) {
    geom->num_siblings = GET_NUM_CHILDREN(mynode->parent);
    geom->sibling_id = -1;
    geom->sibling_offset = 0;
    for(i=0; i<geom->num_siblings; i++) {
      int tmp_id;
      if(mynode->parent->children_reversed==1) {
        tmp_id = geom->num_siblings-1-i;
      } else {
        tmp_id =i;
      }
      if(GET_NODE_ID(GET_CHILD_IDX(mynode->parent, tmp_id))==team->myrank) {
        geom->sibling_id = tmp_id;
        break;
      } else {
        geom->sibling_offset += treesize(GET_CHILD_IDX(mynode->parent, tmp_id));
      }
    }
  } else {
    geom->num_siblings = 0;
    geom->sibling_id = 0;
    geom->sibling_offset = 0;
    /***** THIS NEEDS TO BE TAKEN OUT
      The DFS ordering that we impose on the trees will mean that this no longer needs to be kept around
      but it's in here for now for backward compatability sake until we make the neccessary changes to all the other collective algorithms
      ****/
    geom->dfs_order = (gasnet_node_t*) gasneti_malloc(sizeof(gasnet_node_t)*team->total_ranks);
    for(i=0; i<team->total_ranks; i++) {
      geom->dfs_order[i] = (i+rootrank)%team->total_ranks;
    }
  }
  geom->seq_dfs_order = 1;
  geom->child_list = (gasnet_node_t*) gasneti_malloc(sizeof(gasnet_node_t)*geom->child_count);
  geom->subtree_sizes = (gasnet_node_t*) gasneti_malloc(sizeof(gasnet_node_t)*geom->child_count);
  geom->child_offset = (gasnet_node_t*) gasneti_malloc(sizeof(gasnet_node_t)*geom->child_count);
  geom->grand_children = (gasnet_node_t*)gasneti_malloc(sizeof(gasnet_node_t)*geom->child_count); 
  geom->num_non_leaf_children=0;
  geom->num_leaf_children=0;
  geom->child_contains_wrap = 0;
  for(i=0; i<geom->child_count; i++) {
    geom->child_list[i] = GET_NODE_ID(GET_CHILD_IDX(mynode,i));
    geom->subtree_sizes[i] = treesize(GET_CHILD_IDX(mynode,i));
    geom->grand_children[i] = GET_NUM_CHILDREN(GET_CHILD_IDX(mynode, i));
    if(geom->subtree_sizes[i] > 1) {
      geom->num_non_leaf_children++;
    } else {
      geom->num_leaf_children++;
    }
    if(geom->child_list[i]+geom->subtree_sizes[i] > geom->total_size) {
      geom->child_contains_wrap = 1;
    }
    
  }
  gasneti_assert((geom->num_leaf_children+geom->num_non_leaf_children) == geom->child_count);
  
  if(mynode->children_reversed==1) {
    size_t temp_offset = 0;
    for(i=geom->child_count-1; i>=0; i--) {
      geom->child_offset[i] = temp_offset; 
      temp_offset+=geom->subtree_sizes[i];
    }
  } else {
    size_t temp_offset = 0;
    for(i=0; i<geom->child_count; i++) {
      geom->child_offset[i] = temp_offset; 
      temp_offset+=geom->subtree_sizes[i];
    }
  }

#if 0
  /* Not using the reference counts for now */
  gasneti_weakatomic_set(&(geom->ref_count), 0, 0);
  geom->base_geom = base_geom;
#endif

#if 0  
  gasnete_coll_print_tree(geom, gasneti_mynode);
#endif
  return geom;
}