Ejemplo n.º 1
0
/**
 * paxos_ack_retrieve - Acknowledge a retrieve.
 *
 * This basically just unpacks and wraps a resend.
 */
int paxos_ack_retrieve(struct paxos_header *hdr, msgpack_object *o)
{
  paxid_t paxid;
  msgpack_object *p;
  struct paxos_value val;
  struct paxos_request *req;
  struct paxos_acceptor *acc;

  // Make sure the payload is well-formed.
  assert(o->type == MSGPACK_OBJECT_ARRAY);
  assert(o->via.array.size == 2);
  p = o->via.array.ptr;

  // Unpack the retriever's ID and the value being retrieved.
  paxos_paxid_unpack(&paxid, p++);
  paxos_value_unpack(&val, p++);

  // Retrieve the request.
  assert(request_needs_cached(val.pv_dkind));
  req = request_find(&pax->rcache, val.pv_reqid);
  if (req != NULL) {
    // If we have the request, look up the recipient and resend.
    acc = acceptor_find(&pax->alist, paxid);
    return paxos_resend(acc, hdr, req);
  } else {
    // If we don't have the request either, just return.
    return 0;
  }
}
Ejemplo n.º 2
0
int
acceptor_ack_truncate(struct paxos_header *hdr, msgpack_object *o)
{
  // Unpack the new ibase.
  paxos_paxid_unpack(&pax->ibase, o);

  // Do the truncate (< pax->ibase).
  ilist_truncate_prefix(&pax->ilist, pax->ibase);

  return 0;
}
Ejemplo n.º 3
0
/**
 * proposer_ack_last - Update sync state based on acceptor's reply.
 */
int
proposer_ack_last(struct paxos_header *hdr, msgpack_object *o)
{
  paxid_t last;

  // Ignore replies to older sync commands.
  if (hdr->ph_inum != pax->sync_id) {
    return 0;
  }

  // Update our knowledge of the system's last contiguous learn.
  paxos_paxid_unpack(&last, o);
  if (last < pax->sync->ps_last || pax->sync->ps_last == 0) {
    pax->sync->ps_last = last;
  }

  // Increment acks and command a truncate if the sync is over.
  pax->sync->ps_acks++;
  if (pax->sync->ps_acks == pax->sync->ps_total) {
    return proposer_truncate(hdr);
  }

  return 0;
}