Ejemplo n.º 1
0
Archivo: server.C Proyecto: Amit-DU/dht
void
vnode_impl::find_successor_cb (chordID x, cbroute_t cb, vec<chord_node> s, 
			       route search_path, chordstat status)
{
  if (status != CHORD_OK) {
    warnx << "find_successor_cb: find successor of " 
	  << x << " failed: " << status << "\n";
  } else {
    nhops += search_path.size ();
    if (search_path.size () > nmaxhops)
      nmaxhops = search_path.size ();
  }
  cb (s, search_path, status);
}
Ejemplo n.º 2
0
void
pmaint::pmaint_lookup (bigint key, dhash_stat err, vec<chord_node> sl, route r)
{
  if (err) {
    warning << host_node->my_ID () << " lookup failed. key " << key << ", err " << err << "\n";
    pmaint_next (); //XXX delay?
    return;
  }

  assert (r.size () >= 2);
  assert (sl.size () >= 1);

  chordID succ = r.pop_back ()->id ();
  chordID pred = r.pop_back ()->id ();
  assert (succ == sl[0].x);

  if (dhblock_chash::num_efrags () > sl.size ()) {
    warning << "not enough successors: " << sl.size () 
	 << " vs " << dhblock_chash::num_efrags () << "\n";
    //try again later
    active_cb = delaycb (PRTTMLONG, wrap (this, &pmaint::pmaint_next));
    return;
  }

  if ((sl.size () > dhblock_chash::num_efrags() &&
      dhblock_chash::num_efrags () > 1 &&
      betweenbothincl (sl[0].x, sl[sl.size () - 1].x, 
		       host_node->my_ID ()))
      ||
      (dhblock_chash::num_efrags () == 1 && sl[0].x == host_node->my_ID ()) 
      //above is a special case since between always returns true
      // when the first two arguments are equal
      ) { 

    trace << host_node->my_ID () << " PMAINT: we are a replica for " 
	 << key << " " << sl[0].x << " -- " << sl[dhblock_chash::num_efrags () - 1] 
	 << "\n";
    //case I: we are a replica of the key. 
    //i.e. in the successor list. Do nothing.
    //next time we'll do a lookup with the next key
    active_cb = delaycb (PRTTMTINY, wrap (this, &pmaint::pmaint_next));
  } else {
    //case II: this key doesn't belong to us. Offer it to another node
    
    pmaint_searching = false;
    
    trace << host_node->my_ID () << ": offering " << key << "\n";

    pmaint_offer (key, sl[0]);
  }
}