func (vc *VectorClock) AddToSeg(seg *capn.Segment) msgs.VectorClock { if vc == nil { vcCap := msgs.NewVectorClock(seg) vcCap.SetVarUuids(seg.NewDataList(0)) vcCap.SetValues(seg.NewUInt64List(0)) return vcCap } else if vc.cap == nil { vcCap := msgs.NewVectorClock(seg) vc.cap = &vcCap vUUIds := seg.NewDataList(len(vc.Clock)) values := seg.NewUInt64List(len(vc.Clock)) vcCap.SetVarUuids(vUUIds) vcCap.SetValues(values) idx := 0 for vUUId, ver := range vc.Clock { vUUIds.Set(idx, vUUId[:]) values.Set(idx, ver) idx++ } return vcCap } else { return *vc.cap } }
func (cts *ClientTxnSubmitter) translateUpdates(seg *capn.Segment, updates map[*msgs.Update][]*msgs.Action) cmsgs.ClientUpdate_List { clientUpdates := cmsgs.NewClientUpdateList(seg, len(updates)) idx := 0 for update, actions := range updates { clientUpdate := clientUpdates.At(idx) idx++ clientUpdate.SetVersion(update.TxnId()) clientActions := cmsgs.NewClientActionList(seg, len(actions)) clientUpdate.SetActions(clientActions) for idy, action := range actions { clientAction := clientActions.At(idy) clientAction.SetVarId(action.VarId()) switch action.Which() { case msgs.ACTION_MISSING: clientAction.SetDelete() case msgs.ACTION_WRITE: clientAction.SetWrite() write := action.Write() clientWrite := clientAction.Write() clientWrite.SetValue(write.Value()) references := write.References() clientReferences := seg.NewDataList(references.Len()) clientWrite.SetReferences(clientReferences) for idz, n := 0, references.Len(); idz < n; idz++ { ref := references.At(idz) clientReferences.Set(idz, ref.Id()) positions := common.Positions(ref.Positions()) cts.hashCache.AddPosition(common.MakeVarUUId(ref.Id()), &positions) } default: panic(fmt.Sprintf("Unexpected action type: %v", action.Which())) } } } return clientUpdates }
func (config *Configuration) AddToSegAutoRoot(seg *capn.Segment) msgs.Configuration { cap := msgs.AutoNewConfiguration(seg) cap.SetClusterId(config.ClusterId) cap.SetVersion(config.Version) hosts := seg.NewTextList(len(config.Hosts)) cap.SetHosts(hosts) for idx, host := range config.Hosts { hosts.Set(idx, host) } cap.SetF(config.F) cap.SetMaxRMCount(config.MaxRMCount) cap.SetNoSync(config.NoSync) rms := seg.NewUInt32List(len(config.rms)) cap.SetRms(rms) for idx, rmId := range config.rms { rms.Set(idx, uint32(rmId)) } rmsRemoved := seg.NewUInt32List(len(config.rmsRemoved)) cap.SetRmsRemoved(rmsRemoved) idx := 0 for rmId := range config.rmsRemoved { rmsRemoved.Set(idx, uint32(rmId)) idx++ } fingerprintsMap := config.fingerprints fingerprints := seg.NewDataList(len(fingerprintsMap)) cap.SetFingerprints(fingerprints) idx = 0 for fingerprint := range fingerprintsMap { fingerprints.Set(idx, fingerprint[:]) idx++ } if config.nextConfiguration == nil { cap.SetStable() } else { nextConfig := config.nextConfiguration cap.SetTransitioningTo() next := cap.TransitioningTo() next.SetConfiguration(nextConfig.Configuration.AddToSegAutoRoot(seg)) allHostsCap := seg.NewTextList(len(nextConfig.AllHosts)) for idx, host := range nextConfig.AllHosts { allHostsCap.Set(idx, host) } next.SetAllHosts(allHostsCap) newRMIdsCap := seg.NewUInt32List(len(nextConfig.NewRMIds)) for idx, rmId := range nextConfig.NewRMIds { newRMIdsCap.Set(idx, uint32(rmId)) } next.SetNewRMIds(newRMIdsCap) survivingRMIdsCap := seg.NewUInt32List(len(nextConfig.SurvivingRMIds)) for idx, rmId := range nextConfig.SurvivingRMIds { survivingRMIdsCap.Set(idx, uint32(rmId)) } next.SetSurvivingRMIds(survivingRMIdsCap) lostRMIdsCap := seg.NewUInt32List(len(nextConfig.LostRMIds)) for idx, rmId := range nextConfig.LostRMIds { lostRMIdsCap.Set(idx, uint32(rmId)) } next.SetLostRMIds(lostRMIdsCap) barrierReached1Cap := seg.NewUInt32List(len(nextConfig.BarrierReached1)) for idx, rmId := range nextConfig.BarrierReached1 { barrierReached1Cap.Set(idx, uint32(rmId)) } next.SetBarrierReached1(barrierReached1Cap) barrierReached2Cap := seg.NewUInt32List(len(nextConfig.BarrierReached2)) for idx, rmId := range nextConfig.BarrierReached2 { barrierReached2Cap.Set(idx, uint32(rmId)) } next.SetBarrierReached2(barrierReached2Cap) next.SetInstalledOnNew(nextConfig.InstalledOnNew) next.SetPending(nextConfig.Pending.AddToSeg(seg)) } return cap }