示例#1
0
func (dt *DTable) zmq_promoteKey_handler(request *dendrite.ChordMsg, w chan *dendrite.ChordMsg) {
	pbMsg := request.TransportMsg.(PBDTablePromoteKey)
	reqItem := new(kvItem)
	reqItem.lock = new(sync.Mutex)
	reqItem.from_protobuf(pbMsg.GetItem())

	// send out the event to delegator
	ev := &dtableEvent{
		evType: evPromoteKey,
		vnode:  dendrite.VnodeFromProtobuf(pbMsg.GetDest()),
		item:   reqItem,
	}
	dt.dtable_c <- ev

	zmq_transport := dt.transport.(*dendrite.ZMQTransport)

	setResp := &PBDTableResponse{
		Ok: proto.Bool(true),
	}

	// encode and send the response
	pbdata, err := proto.Marshal(setResp)
	if err != nil {
		errorMsg := zmq_transport.NewErrorMsg("ZMQ::DTable::SetReplicaHandler - failed to marshal response - " + err.Error())
		w <- errorMsg
		return
	}
	w <- &dendrite.ChordMsg{
		Type: PbDtableResponse,
		Data: pbdata,
	}
	return
}
示例#2
0
func (dt *DTable) zmq_status_handler(request *dendrite.ChordMsg, w chan *dendrite.ChordMsg) {
	pbMsg := request.TransportMsg.(PBDTableStatus)

	dest := dendrite.VnodeFromProtobuf(pbMsg.GetDest())
	dest_key_str := fmt.Sprintf("%x", dest.Id)
	zmq_transport := dt.transport.(*dendrite.ZMQTransport)

	// make sure destination vnode exists locally
	_, ok := dt.table[dest_key_str]
	setResp := &PBDTableResponse{}
	if !ok {
		setResp.Ok = proto.Bool(false)
		setResp.Error = proto.String("local dtable vnode not found")
	} else {
		setResp.Ok = proto.Bool(true)
	}

	// encode and send the response
	pbdata, err := proto.Marshal(setResp)
	if err != nil {
		errorMsg := zmq_transport.NewErrorMsg("ZMQ::DTable::StatusHandler - failed to marshal response - " + err.Error())
		w <- errorMsg
		return
	}
	w <- &dendrite.ChordMsg{
		Type: PbDtableResponse,
		Data: pbdata,
	}
	return
}
示例#3
0
func (dt *DTable) zmq_setReplica_handler(request *dendrite.ChordMsg, w chan *dendrite.ChordMsg) {
	pbMsg := request.TransportMsg.(PBDTableSetItem)
	reqItem := new(kvItem)
	reqItem.lock = new(sync.Mutex)
	reqItem.from_protobuf(pbMsg.GetItem())
	dest := dendrite.VnodeFromProtobuf(pbMsg.GetDest())
	dest_key_str := fmt.Sprintf("%x", dest.Id)
	zmq_transport := dt.transport.(*dendrite.ZMQTransport)

	// make sure destination vnode exists locally
	_, ok := dt.table[dest_key_str]
	if !ok {
		errorMsg := zmq_transport.NewErrorMsg("ZMQ::DTable::SetReplicaHandler - local vnode table not found")
		w <- errorMsg
		return
	}
	setResp := &PBDTableResponse{
		Ok: proto.Bool(true),
	}
	dt.setReplica(dest, reqItem)

	// encode and send the response
	pbdata, err := proto.Marshal(setResp)
	if err != nil {
		errorMsg := zmq_transport.NewErrorMsg("ZMQ::DTable::SetReplicaHandler - failed to marshal response - " + err.Error())
		w <- errorMsg
		return
	}
	w <- &dendrite.ChordMsg{
		Type: PbDtableResponse,
		Data: pbdata,
	}

	return
}
示例#4
0
func replicaInfo_from_protobuf(pb *PBDTableReplicaInfo) *kvReplicaInfo {
	if pb == nil {
		return nil
	}
	rInfo := new(kvReplicaInfo)
	rInfo.master = dendrite.VnodeFromProtobuf(pb.GetMaster())
	rInfo.vnodes = make([]*dendrite.Vnode, 0)
	for _, pb_vnode := range pb.GetVnodes() {
		rInfo.vnodes = append(rInfo.vnodes, dendrite.VnodeFromProtobuf(pb_vnode))
	}
	rInfo.orphan_vnodes = make([]*dendrite.Vnode, 0)
	for _, pb_orphanVnode := range pb.GetOrphanVnodes() {
		rInfo.orphan_vnodes = append(rInfo.orphan_vnodes, dendrite.VnodeFromProtobuf(pb_orphanVnode))
	}
	rInfo.state = replicaState(int(pb.GetState()))
	rInfo.depth = int(pb.GetDepth())
	return rInfo
}
示例#5
0
func (dt *DTable) zmq_clearreplica_handler(request *dendrite.ChordMsg, w chan *dendrite.ChordMsg) {
	pbMsg := request.TransportMsg.(PBDTableClearReplica)
	keyHash := pbMsg.GetKeyHash()
	demoted := pbMsg.GetDemoted()
	dest := dendrite.VnodeFromProtobuf(pbMsg.GetDest())
	dest_key_str := fmt.Sprintf("%x", dest.Id)
	zmq_transport := dt.transport.(*dendrite.ZMQTransport)

	// make sure destination vnode exists locally
	r_table, ok := dt.rtable[dest_key_str]
	if !ok {
		errorMsg := zmq_transport.NewErrorMsg("ZMQ::DTable::ClearReplicaHandler - local vnode table not found")
		w <- errorMsg
		return
	}

	key_str := fmt.Sprintf("%x", keyHash)
	if demoted {
		d_table, _ := dt.demoted_table[dest_key_str]
		if _, ok := d_table[key_str]; ok {
			delete(d_table, key_str)
		} else {
			errorMsg := zmq_transport.NewErrorMsg("ZMQ::DTable::ClearReplicaHandler - key " + key_str + " not found in demoted table")
			w <- errorMsg
			return
		}
	} else {
		if _, ok := r_table[key_str]; ok {
			delete(r_table, key_str)
		} else {
			errorMsg := zmq_transport.NewErrorMsg("ZMQ::DTable::ClearReplicaHandler - key " + key_str + " not found in replica table on vnode " + dest.String())
			w <- errorMsg
			return
		}
	}

	// encode and send the response
	setResp := &PBDTableResponse{
		Ok: proto.Bool(true),
	}
	pbdata, err := proto.Marshal(setResp)
	if err != nil {
		errorMsg := zmq_transport.NewErrorMsg("ZMQ::DTable::ClearReplicaHandler - failed to marshal response - " + err.Error())
		w <- errorMsg
		return
	}
	w <- &dendrite.ChordMsg{
		Type: PbDtableResponse,
		Data: pbdata,
	}
	return
}
示例#6
0
func (dt *DTable) zmq_get_handler(request *dendrite.ChordMsg, w chan *dendrite.ChordMsg) {
	pbMsg := request.TransportMsg.(PBDTableGetItem)
	keyHash := pbMsg.GetKeyHash()
	dest := dendrite.VnodeFromProtobuf(pbMsg.GetDest())
	dest_key_str := fmt.Sprintf("%x", dest.Id)
	zmq_transport := dt.transport.(*dendrite.ZMQTransport)

	// make sure destination vnode exists locally
	vn_table, ok := dt.table[dest_key_str]
	if !ok {
		errorMsg := zmq_transport.NewErrorMsg("ZMQ::DTable::GetHandler - local vnode table not found")
		w <- errorMsg
		return
	}
	key_str := fmt.Sprintf("%x", keyHash)

	var itemResp *PBDTableItem

	if localItem, ok := vn_table[key_str]; ok {
		itemResp = localItem.to_protobuf()
		itemResp.Found = proto.Bool(true)
	} else {
		itemResp = &PBDTableItem{
			Found: proto.Bool(false),
		}
	}

	// encode and send the response
	pbdata, err := proto.Marshal(itemResp)
	if err != nil {
		errorMsg := zmq_transport.NewErrorMsg("ZMQ::DTable::GetHandler - failed to marshal response - " + err.Error())
		w <- errorMsg
		return
	}
	w <- &dendrite.ChordMsg{
		Type: PbDtableItem,
		Data: pbdata,
	}
	return
}
示例#7
0
func (dt *DTable) zmq_setReplicaInfo_handler(request *dendrite.ChordMsg, w chan *dendrite.ChordMsg) {
	pbMsg := request.TransportMsg.(PBDTableSetReplicaInfo)
	rInfo := replicaInfo_from_protobuf(pbMsg.GetReplicaInfo())
	keyHash := pbMsg.GetKeyHash()
	dest := dendrite.VnodeFromProtobuf(pbMsg.GetDest())
	dest_key_str := fmt.Sprintf("%x", dest.Id)
	zmq_transport := dt.transport.(*dendrite.ZMQTransport)

	// make sure destination vnode exists locally
	vn_table, ok := dt.rtable[dest_key_str]
	if !ok {
		errorMsg := zmq_transport.NewErrorMsg("ZMQ::DTable::SetMetaHandler - local vnode table not found")
		w <- errorMsg
		return
	}
	key_str := fmt.Sprintf("%x", keyHash)
	item, ok := vn_table[key_str]
	if !ok {
		errorMsg := zmq_transport.NewErrorMsg("ZMQ::DTable::SetMetaHandler - key not found")
		w <- errorMsg
		return
	}
	item.replicaInfo = rInfo

	// encode and send the response
	setResp := &PBDTableResponse{
		Ok: proto.Bool(true),
	}
	pbdata, err := proto.Marshal(setResp)
	if err != nil {
		errorMsg := zmq_transport.NewErrorMsg("ZMQ::DTable::SetMetaHandler - failed to marshal response - " + err.Error())
		w <- errorMsg
		return
	}
	w <- &dendrite.ChordMsg{
		Type: PbDtableResponse,
		Data: pbdata,
	}
	return
}
示例#8
0
func (dt *DTable) zmq_set_handler(request *dendrite.ChordMsg, w chan *dendrite.ChordMsg) {
	pbMsg := request.TransportMsg.(PBDTableSetItem)
	reqItem := new(kvItem)
	reqItem.lock = new(sync.Mutex)
	reqItem.from_protobuf(pbMsg.GetItem())
	demoting := pbMsg.GetDemoting()
	minAcks := int(pbMsg.GetMinAcks())
	dest := dendrite.VnodeFromProtobuf(pbMsg.GetDest())
	origin := dendrite.VnodeFromProtobuf(pbMsg.GetOrigin())
	dest_key_str := fmt.Sprintf("%x", dest.Id)
	zmq_transport := dt.transport.(*dendrite.ZMQTransport)

	// make sure destination vnode exists locally
	_, ok := dt.table[dest_key_str]
	if !ok {
		errorMsg := zmq_transport.NewErrorMsg("ZMQ::DTable::SetHandler - local vnode table not found")
		w <- errorMsg
		return
	}
	setResp := &PBDTableResponse{
		Ok: proto.Bool(false),
	}

	if demoting {
		old_master := reqItem.replicaInfo.master
		reqItem.replicaInfo.master = dest
		reqItem.lock.Lock()
		err := dt.table[dest_key_str].put(reqItem)
		if err != nil {
			errorMsg := zmq_transport.NewErrorMsg("ZMQ::DTable::SetHandler - demote received error on - " + err.Error())
			w <- errorMsg
			reqItem.lock.Unlock()
			return
		}
		go dt.processDemoteKey(dest, origin, old_master, reqItem)
		setResp.Ok = proto.Bool(true)
		reqItem.lock.Unlock()
	} else {
		wait := make(chan error)
		go dt.set(dest, reqItem, minAcks, wait)
		err := <-wait
		if err != nil {
			setResp.Error = proto.String("ZMQ::DTable::SetHandler - error executing transaction - " + err.Error())
		} else {
			setResp.Ok = proto.Bool(true)
		}
	}

	// encode and send the response
	pbdata, err := proto.Marshal(setResp)
	if err != nil {
		errorMsg := zmq_transport.NewErrorMsg("ZMQ::DTable::SetHandler - failed to marshal response - " + err.Error())
		w <- errorMsg
		return
	}
	w <- &dendrite.ChordMsg{
		Type: PbDtableResponse,
		Data: pbdata,
	}

	return
}