示例#1
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
}
示例#2
0
func TxnFromCap(exe *dispatcher.Executor, vd *VarDispatcher, stateChange TxnLocalStateChange, ourRMId common.RMId, txnCap *msgs.Txn) *Txn {
	txnId := common.MakeTxnId(txnCap.Id())
	actions := txnCap.Actions()
	txn := &Txn{
		Id:          txnId,
		Retry:       txnCap.Retry(),
		writes:      make([]*common.VarUUId, 0, actions.Len()),
		TxnCap:      txnCap,
		exe:         exe,
		vd:          vd,
		stateChange: stateChange,
	}

	allocations := txnCap.Allocations()
	for idx, l := 0, allocations.Len(); idx < l; idx++ {
		alloc := allocations.At(idx)
		rmId := common.RMId(alloc.RmId())
		if ourRMId == rmId {
			txn.populate(alloc.ActionIndices(), actions)
			break
		}
	}

	return txn
}
示例#3
0
func NewBallotAccumulator(txnId *common.TxnId, txn *msgs.Txn) *BallotAccumulator {
	actions := txn.Actions()
	ba := &BallotAccumulator{
		Txn:            txn,
		txnId:          txnId,
		vUUIdToBallots: make(map[common.VarUUId]*varBallot),
		outcome:        nil,
		incompleteVars: actions.Len(),
		dirty:          false,
	}

	vBallots := make([]varBallot, ba.incompleteVars)
	for idx := 0; idx < ba.incompleteVars; idx++ {
		action := actions.At(idx)
		vUUId := common.MakeVarUUId(action.VarId())
		vBallot := &vBallots[idx]
		vBallot.vUUId = vUUId
		ba.vUUIdToBallots[*vUUId] = vBallot
	}

	allocs := txn.Allocations()
	for idx, l := 0, allocs.Len(); idx < l; idx++ {
		alloc := allocs.At(idx)
		if alloc.Active() == 0 {
			break
		}
		indices := alloc.ActionIndices()
		for idy, m := 0, indices.Len(); idy < m; idy++ {
			vBallots[int(indices.At(idy))].voters++
		}
	}

	return ba
}
示例#4
0
func MakeAbortBallots(txn *msgs.Txn, alloc *msgs.Allocation) []*eng.Ballot {
	actions := txn.Actions()
	actionIndices := alloc.ActionIndices()
	ballots := make([]*eng.Ballot, actionIndices.Len())
	for idx, l := 0, actionIndices.Len(); idx < l; idx++ {
		action := actions.At(int(actionIndices.At(idx)))
		vUUId := common.MakeVarUUId(action.VarId())
		ballots[idx] = eng.NewBallot(vUUId, eng.AbortDeadlock, nil)
	}
	return ballots
}
示例#5
0
func TxnToRootBytes(txn *msgs.Txn) []byte {
	seg := capn.NewBuffer(nil)
	txnCap := msgs.NewRootTxn(seg)
	txnCap.SetId(txn.Id())
	txnCap.SetRetry(txn.Retry())
	txnCap.SetSubmitter(txn.Submitter())
	txnCap.SetSubmitterBootCount(txn.SubmitterBootCount())
	txnCap.SetActions(txn.Actions())
	txnCap.SetAllocations(txn.Allocations())
	txnCap.SetFInc(txn.FInc())
	txnCap.SetTopologyVersion(txn.TopologyVersion())

	return server.SegToBytes(seg)
}
示例#6
0
func ImmigrationTxnFromCap(exe *dispatcher.Executor, vd *VarDispatcher, stateChange TxnLocalStateChange, ourRMId common.RMId, txnCap *msgs.Txn, varCaps *msgs.Var_List) {
	txn := TxnFromCap(exe, vd, stateChange, ourRMId, txnCap)
	txnActions := txnCap.Actions()
	txn.localActions = make([]localAction, varCaps.Len())
	actionsMap := make(map[common.VarUUId]*localAction)
	for idx, l := 0, varCaps.Len(); idx < l; idx++ {
		varCap := varCaps.At(idx)
		action := &txn.localActions[idx]
		action.Txn = txn
		action.vUUId = common.MakeVarUUId(varCap.Id())
		action.writeTxnActions = &txnActions
		positions := varCap.Positions()
		action.createPositions = (*common.Positions)(&positions)
		action.outcomeClock = VectorClockFromCap(varCap.WriteTxnClock())
		action.writesClock = VectorClockFromCap(varCap.WritesClock())
		actionsMap[*action.vUUId] = action
	}

	for idx, l := 0, txnActions.Len(); idx < l; idx++ {
		actionCap := txnActions.At(idx)
		vUUId := common.MakeVarUUId(actionCap.VarId())
		if action, found := actionsMap[*vUUId]; found {
			action.writeAction = &actionCap
		}
	}

	txn.Start(false)
	txn.nextState()
	for idx := range txn.localActions {
		action := &txn.localActions[idx]
		f := func(v *Var) {
			if v == nil {
				panic(fmt.Sprintf("%v immigration error: %v unable to create var!", txn.Id, action.vUUId))
			} else {
				v.ReceiveTxnOutcome(action)
			}
		}
		vd.ApplyToVar(f, true, action.vUUId)
	}
}
示例#7
0
func isDeflated(txn *msgs.Txn) bool {
	actions := txn.Actions()
	return actions.Len() != 0 && actions.At(0).Which() == msgs.ACTION_MISSING
}