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 }
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 }