Exemplo n.º 1
0
func (sts *SimpleTxnSubmitter) clientToServerTxn(clientTxnCap *cmsgs.ClientTxn, topologyVersion uint32) (*msgs.Txn, []common.RMId, []common.RMId, error) {
	outgoingSeg := capn.NewBuffer(nil)
	txnCap := msgs.NewTxn(outgoingSeg)

	txnCap.SetId(clientTxnCap.Id())
	txnCap.SetRetry(clientTxnCap.Retry())
	txnCap.SetSubmitter(uint32(sts.rmId))
	txnCap.SetSubmitterBootCount(sts.bootCount)
	txnCap.SetFInc(sts.topology.FInc)
	txnCap.SetTopologyVersion(topologyVersion)

	clientActions := clientTxnCap.Actions()
	actions := msgs.NewActionList(outgoingSeg, clientActions.Len())
	txnCap.SetActions(actions)
	picker := ch.NewCombinationPicker(int(sts.topology.FInc), sts.disabledHashCodes)

	rmIdToActionIndices, err := sts.translateActions(outgoingSeg, picker, &actions, &clientActions)
	if err != nil {
		return nil, nil, nil, err
	}

	// NB: we're guaranteed that activeRMs and passiveRMs are
	// disjoint. Thus there is no RM that has some active and some
	// passive actions.
	activeRMs, passiveRMs, err := picker.Choose()
	if err != nil {
		return nil, nil, nil, err
	}
	allocations := msgs.NewAllocationList(outgoingSeg, len(activeRMs)+len(passiveRMs))
	txnCap.SetAllocations(allocations)
	sts.setAllocations(0, rmIdToActionIndices, &allocations, outgoingSeg, true, activeRMs)
	sts.setAllocations(len(activeRMs), rmIdToActionIndices, &allocations, outgoingSeg, false, passiveRMs)
	return &txnCap, activeRMs, passiveRMs, nil
}
Exemplo n.º 2
0
func deflateTxn(txn *msgs.Txn, seg *capn.Segment) *msgs.Txn {
	if isDeflated(txn) {
		return txn
	}
	deflatedTxn := msgs.NewTxn(seg)
	deflatedTxn.SetId(txn.Id())
	deflatedTxn.SetRetry(txn.Retry())
	deflatedTxn.SetSubmitter(txn.Submitter())
	deflatedTxn.SetSubmitterBootCount(txn.SubmitterBootCount())
	deflatedTxn.SetFInc(txn.FInc())
	deflatedTxn.SetTopologyVersion(txn.TopologyVersion())

	deflatedTxn.SetAllocations(txn.Allocations())

	actionsList := txn.Actions()
	deflatedActionsList := msgs.NewActionList(seg, actionsList.Len())
	deflatedTxn.SetActions(deflatedActionsList)
	for idx, l := 0, actionsList.Len(); idx < l; idx++ {
		deflatedAction := deflatedActionsList.At(idx)
		deflatedAction.SetVarId(actionsList.At(idx).VarId())
		deflatedAction.SetMissing()
	}

	return &deflatedTxn
}
Exemplo n.º 3
0
func (br badReads) AddToSeg(seg *capn.Segment) msgs.Update_List {
	txnIdToBadReadActions := make(map[common.TxnId]*[]*badReadAction, len(br))
	for _, bra := range br {
		if bras, found := txnIdToBadReadActions[*bra.txnId]; found {
			*bras = append(*bras, bra)
		} else {
			list := []*badReadAction{bra}
			txnIdToBadReadActions[*bra.txnId] = &list
		}
	}

	updates := msgs.NewUpdateList(seg, len(txnIdToBadReadActions))
	idx := 0
	for txnId, badReadActions := range txnIdToBadReadActions {
		update := updates.At(idx)
		idx++
		update.SetTxnId(txnId[:])
		actionList := msgs.NewActionList(seg, len(*badReadActions))
		update.SetActions(actionList)
		clock := eng.NewVectorClock()
		for idy, bra := range *badReadActions {
			action := bra.action
			switch action.Which() {
			case msgs.ACTION_READ:
				newAction := actionList.At(idy)
				newAction.SetVarId(action.VarId())
				newAction.SetMissing()
			case msgs.ACTION_WRITE:
				actionList.Set(idy, *action)
			case msgs.ACTION_READWRITE:
				readWrite := action.Readwrite()
				newAction := actionList.At(idy)
				newAction.SetVarId(action.VarId())
				newAction.SetWrite()
				newWrite := newAction.Write()
				newWrite.SetValue(readWrite.Value())
				newWrite.SetReferences(readWrite.References())
			case msgs.ACTION_CREATE:
				create := action.Create()
				newAction := actionList.At(idy)
				newAction.SetVarId(action.VarId())
				newAction.SetWrite()
				newWrite := newAction.Write()
				newWrite.SetValue(create.Value())
				newWrite.SetReferences(create.References())
			case msgs.ACTION_ROLL:
				roll := action.Roll()
				newAction := actionList.At(idy)
				newAction.SetVarId(action.VarId())
				newAction.SetWrite()
				newWrite := newAction.Write()
				newWrite.SetValue(roll.Value())
				newWrite.SetReferences(roll.References())
			default:
				panic(fmt.Sprintf("Unexpected action type (%v) for badread of %v at %v",
					action.Which(), action.VarId(), txnId))
			}
			clock.SetVarIdMax(*bra.vUUId, bra.clockElem)
		}
		update.SetClock(clock.AddToSeg(seg))
	}

	return updates
}