func (c *cache) updateFromTxnCommit(txn *msgs.ClientTxn, txnId *common.TxnId) { actions := txn.Actions() c.Lock() defer c.Unlock() for idx, l := 0, actions.Len(); idx < l; idx++ { action := actions.At(idx) vUUId := common.MakeVarUUId(action.VarId()) switch action.Which() { case msgs.CLIENTACTION_WRITE: write := action.Write() refs := write.References() c.updateFromWrite(txnId, vUUId, write.Value(), &refs) case msgs.CLIENTACTION_READWRITE: rw := action.Readwrite() refs := rw.References() c.updateFromWrite(txnId, vUUId, rw.Value(), &refs) case msgs.CLIENTACTION_CREATE: create := action.Create() refs := create.References() c.updateFromWrite(txnId, vUUId, create.Value(), &refs) case msgs.CLIENTACTION_READ: // do nothing } } }
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 }