本文整理汇总了Golang中goshawkdb/io/common.MakeTxnId函数的典型用法代码示例。如果您正苦于以下问题:Golang MakeTxnId函数的具体用法?Golang MakeTxnId怎么用?Golang MakeTxnId使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MakeTxnId函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handleTxnOutcome
func (cr *connectionRun) handleTxnOutcome(outcome *msgs.ClientTxnOutcome) error {
txnId := common.MakeTxnId(outcome.Id())
if cr.liveTxn == nil {
return fmt.Errorf("Received txn outcome for unknown txn: %v", txnId)
}
finalTxnId := common.MakeTxnId(outcome.FinalId())
if !bytes.Equal(cr.liveTxn.txn.Id(), outcome.Id()) {
return fmt.Errorf("Received txn outcome for wrong txn: %v (expecting %v) (final %v) (which %v)", txnId, common.MakeTxnId(cr.liveTxn.txn.Id()), finalTxnId, outcome.Which())
}
var err error
final := binary.BigEndian.Uint64(finalTxnId[:8])
if final < cr.nextTxnId {
return fmt.Errorf("Final (%v) < next (%v)\n", final, cr.nextTxnId)
}
cr.nextTxnId = final + 1 + uint64(cr.rng.Intn(8))
var modifiedVars []*common.VarUUId
switch outcome.Which() {
case msgs.CLIENTTXNOUTCOME_COMMIT:
cr.cache.updateFromTxnCommit(cr.liveTxn.txn, finalTxnId)
case msgs.CLIENTTXNOUTCOME_ABORT:
updates := outcome.Abort()
modifiedVars = cr.cache.updateFromTxnAbort(&updates)
case msgs.CLIENTTXNOUTCOME_ERROR:
err = fmt.Errorf(outcome.Error())
}
if !cr.liveTxn.setOutcomeError(outcome, modifiedVars, err) {
return fmt.Errorf("Live txn already closed")
}
cr.liveTxn = nil
return nil
}
示例2: verifyTopology
func (cash *connectionAwaitServerHandshake) verifyTopology(topology *server.Topology, remote *msgs.HelloFromServer) (bool, *server.Topology) {
remoteTopologyDBVersion := common.MakeTxnId(remote.TopologyDBVersion())
remoteTopologyCap := remote.Topology()
remoteRoot := remote.Root()
remoteTopology := server.TopologyFromCap(remoteTopologyDBVersion, &remoteRoot, &remoteTopologyCap)
return topology.Configuration.Equal(remoteTopology.Configuration), remoteTopology
}
示例3: VarFromData
func VarFromData(data []byte, exe *dispatcher.Executor, disk *mdbs.MDBServer, vm *VarManager) (*Var, error) {
seg, _, err := capn.ReadFromMemoryZeroCopy(data)
if err != nil {
return nil, err
}
varCap := msgs.ReadRootVar(seg)
v := newVar(common.MakeVarUUId(varCap.Id()), exe, disk, vm)
positions := varCap.Positions()
if positions.Len() != 0 {
v.positions = (*common.Positions)(&positions)
}
writeTxnId := common.MakeTxnId(varCap.WriteTxnId())
writeTxnClock := VectorClockFromCap(varCap.WriteTxnClock())
writesClock := VectorClockFromCap(varCap.WritesClock())
server.Log(v.UUId, "Restored", writeTxnId)
if result, err := disk.ReadonlyTransaction(func(rtxn *mdbs.RTxn) (interface{}, error) {
return db.ReadTxnFromDisk(rtxn, writeTxnId)
}).ResultError(); err == nil {
if result == nil || result.(*msgs.Txn) == nil {
panic(fmt.Sprintf("%v Unable to find txn %v on disk (%v)", v.UUId, writeTxnId, result))
}
actions := result.(*msgs.Txn).Actions()
v.curFrame = NewFrame(nil, v, writeTxnId, &actions, writeTxnClock, writesClock)
v.curFrameOnDisk = v.curFrame
} else {
return nil, err
}
v.varCap = &varCap
return v, nil
}
示例4: updateFromTxnAbort
func (c *cache) updateFromTxnAbort(updates *msgs.ClientUpdate_List) []*common.VarUUId {
modifiedVars := make([]*common.VarUUId, 0, updates.Len())
c.Lock()
defer c.Unlock()
for idx, l := 0, updates.Len(); idx < l; idx++ {
update := updates.At(idx)
txnId := common.MakeTxnId(update.Version())
actions := update.Actions()
for idy, m := 0, actions.Len(); idy < m; idy++ {
action := actions.At(idy)
vUUId := common.MakeVarUUId(action.VarId())
//fmt.Printf("%[email protected]%v ", vUUId, txnId)
switch action.Which() {
case msgs.CLIENTACTION_DELETE:
c.updateFromDelete(vUUId, txnId)
modifiedVars = append(modifiedVars, vUUId)
case msgs.CLIENTACTION_WRITE:
// We're missing TxnId and TxnId made a write of vUUId (to
// version TxnId).
write := action.Write()
refs := write.References()
if c.updateFromWrite(txnId, vUUId, write.Value(), &refs) {
modifiedVars = append(modifiedVars, vUUId)
}
default:
log.Fatal("Received update that was neither a read or write action:", action.Which())
}
}
}
//fmt.Println(".")
return modifiedVars
}
示例5: submitRetryTransaction
func (txn *Txn) submitRetryTransaction() error {
reads := make(map[common.VarUUId]*objectState)
for ancestor := txn; ancestor != nil; ancestor = ancestor.parent {
for _, obj := range ancestor.objs {
if _, found := reads[*obj.Id]; !found && obj.state.txn == ancestor && obj.state.read {
reads[*obj.Id] = obj.state
}
}
}
seg := capn.NewBuffer(nil)
cTxn := msgs.NewClientTxn(seg)
cTxn.SetRetry(true)
actions := msgs.NewClientActionList(seg, len(reads))
cTxn.SetActions(actions)
idx := 0
for _, state := range reads {
action := actions.At(idx)
action.SetVarId(state.Id[:])
action.SetRead()
action.Read().SetVersion(state.curVersion[:])
idx++
}
outcome, _, err := txn.conn.submitTransaction(&cTxn)
if err != nil {
return err
}
txn.stats.TxnId = common.MakeTxnId(outcome.FinalId())
for ancestor := txn; ancestor != nil; ancestor = ancestor.parent {
ancestor.resetInProgress = true
}
return nil
}
示例6: handleMsgFromPeer
func (cr *connectionRun) handleMsgFromPeer(msg *msgs.Message) error {
if cr.currentState != cr {
// probably just draining the queue from the reader after a restart
return nil
}
cr.missingBeats = 0
switch which := msg.Which(); which {
case msgs.MESSAGE_HEARTBEAT:
// do nothing
case msgs.MESSAGE_CLIENTTXNSUBMISSION:
ctxn := msg.ClientTxnSubmission()
origTxnId := common.MakeTxnId(ctxn.Id())
cr.submitter.SubmitClientTransaction(&ctxn, func(clientOutcome *msgs.ClientTxnOutcome, err error) {
switch {
case err != nil:
cr.clientTxnError(&ctxn, err, origTxnId)
case clientOutcome == nil: // shutdown
return
default:
seg := capn.NewBuffer(nil)
msg := msgs.NewRootMessage(seg)
msg.SetClientTxnOutcome(*clientOutcome)
cr.sendMessage(server.SegToBytes(msg.Segment))
}
})
default:
cr.connectionManager.Dispatchers.DispatchMessage(cr.remoteRMId, which, msg)
}
return nil
}
示例7: loadFromDisk
func (ad *AcceptorDispatcher) loadFromDisk(server *mdbs.MDBServer) {
res, err := server.ReadonlyTransaction(func(rtxn *mdbs.RTxn) (interface{}, error) {
return rtxn.WithCursor(db.DB.BallotOutcomes, func(cursor *mdb.Cursor) (interface{}, error) {
// cursor.Get returns a copy of the data. So it's fine for us
// to store and process this later - it's not about to be
// overwritten on disk.
count := 0
txnIdData, acceptorState, err := cursor.Get(nil, nil, mdb.FIRST)
for ; err == nil; txnIdData, acceptorState, err = cursor.Get(nil, nil, mdb.NEXT) {
count++
txnId := common.MakeTxnId(txnIdData)
acceptorStateCopy := acceptorState
ad.withAcceptorManager(txnId, func(am *AcceptorManager) {
am.loadFromData(txnId, acceptorStateCopy)
})
}
if err == mdb.NotFound {
// fine, we just fell off the end as expected.
return count, nil
} else {
return count, err
}
})
}).ResultError()
if err == nil {
log.Printf("Loaded %v acceptors from disk\n", res.(int))
} else {
log.Println("AcceptorDispatcher error loading from disk:", err)
}
}
示例8: loadVars
func loadVars(disk *mdbs.MDBServer, vars map[common.VarUUId]*varstate) {
_, err := disk.ReadonlyTransaction(func(rtxn *mdbs.RTxn) (interface{}, error) {
return rtxn.WithCursor(db.DB.Vars, func(cursor *mdb.Cursor) (interface{}, error) {
key, data, err := cursor.Get(nil, nil, mdb.FIRST)
for ; err == nil; key, data, err = cursor.Get(nil, nil, mdb.NEXT) {
vUUId := common.MakeVarUUId(key)
seg, _, err := capn.ReadFromMemoryZeroCopy(data)
if err != nil {
log.Println(err)
continue
}
varCap := msgs.ReadRootVar(seg)
pos := varCap.Positions()
positions := (*common.Positions)(&pos)
writeTxnId := common.MakeTxnId(varCap.WriteTxnId())
writeTxnClock := eng.VectorClockFromCap(varCap.WriteTxnClock())
writesClock := eng.VectorClockFromCap(varCap.WritesClock())
if state, found := vars[*vUUId]; found {
if err := state.matches(disk, writeTxnId, writeTxnClock, writesClock, positions); err != nil {
log.Println(err)
}
} else {
state = &varstate{
vUUId: vUUId,
disks: []*mdbs.MDBServer{disk},
writeTxnId: writeTxnId,
writeTxnClock: writeTxnClock,
writeWritesClock: writesClock,
positions: positions,
}
vars[*vUUId] = state
}
}
if err == mdb.NotFound {
return nil, nil
} else {
return nil, err
}
})
}).ResultError()
if err != nil {
log.Println(err)
}
}
示例9: SubmitTransaction
func (sts *SimpleTxnSubmitter) SubmitTransaction(txnCap *msgs.Txn, activeRMs []common.RMId, continuation TxnCompletionConsumer, delay time.Duration) {
seg := capn.NewBuffer(nil)
msg := msgs.NewRootMessage(seg)
msg.SetTxnSubmission(*txnCap)
txnId := common.MakeTxnId(txnCap.Id())
server.Log(txnId, "Submitting txn")
txnSender := paxos.NewRepeatingSender(server.SegToBytes(seg), activeRMs...)
if delay == 0 {
sts.connectionManager.AddSender(txnSender)
} else {
go func() {
// fmt.Printf("%v ", delay)
time.Sleep(delay)
sts.connectionManager.AddSender(txnSender)
}()
}
acceptors := paxos.GetAcceptorsFromTxn(txnCap)
shutdownFun := func(shutdown bool) {
delete(sts.outcomeConsumers, *txnId)
// fmt.Printf("sts%v ", len(sts.outcomeConsumers))
sts.connectionManager.RemoveSenderAsync(txnSender)
paxos.NewOneShotSender(paxos.MakeTxnSubmissionCompleteMsg(txnId), sts.connectionManager, acceptors...)
if shutdown {
if txnCap.Retry() {
paxos.NewOneShotSender(paxos.MakeTxnSubmissionAbortMsg(txnId), sts.connectionManager, activeRMs...)
}
continuation(txnId, nil)
}
}
shutdownFunPtr := &shutdownFun
sts.onShutdown[shutdownFunPtr] = server.EmptyStructVal
outcomeAccumulator := paxos.NewOutcomeAccumulator(int(txnCap.FInc()), acceptors)
consumer := func(sender common.RMId, txnId *common.TxnId, outcome *msgs.Outcome) {
if outcome, _ = outcomeAccumulator.BallotOutcomeReceived(sender, outcome); outcome != nil {
delete(sts.onShutdown, shutdownFunPtr)
shutdownFun(false)
continuation(txnId, outcome)
}
}
sts.outcomeConsumers[*txnId] = consumer
// fmt.Printf("sts%v ", len(sts.outcomeConsumers))
}
示例10: DispatchMessage
func (d *Dispatchers) DispatchMessage(sender common.RMId, msgType msgs.Message_Which, msg *msgs.Message) {
switch msgType {
case msgs.MESSAGE_TXNSUBMISSION:
txn := msg.TxnSubmission()
d.ProposerDispatcher.TxnReceived(sender, &txn)
case msgs.MESSAGE_SUBMISSIONOUTCOME:
outcome := msg.SubmissionOutcome()
txnId := common.MakeTxnId(outcome.Txn().Id())
connNumber := binary.BigEndian.Uint32(txnId[8:12])
bootNumber := binary.BigEndian.Uint32(txnId[12:16])
if conn := d.connectionManager.GetClient(bootNumber, connNumber); conn == nil {
NewOneShotSender(MakeTxnSubmissionCompleteMsg(txnId), d.connectionManager, sender)
} else {
conn.SubmissionOutcomeReceived(sender, txnId, &outcome)
return
}
case msgs.MESSAGE_SUBMISSIONCOMPLETE:
tsc := msg.SubmissionComplete()
d.AcceptorDispatcher.TxnSubmissionCompleteReceived(sender, &tsc)
case msgs.MESSAGE_SUBMISSIONABORT:
tsa := msg.SubmissionAbort()
d.ProposerDispatcher.TxnSubmissionAbortReceived(sender, &tsa)
case msgs.MESSAGE_ONEATXNVOTES:
oneATxnVotes := msg.OneATxnVotes()
d.AcceptorDispatcher.OneATxnVotesReceived(sender, &oneATxnVotes)
case msgs.MESSAGE_ONEBTXNVOTES:
oneBTxnVotes := msg.OneBTxnVotes()
d.ProposerDispatcher.OneBTxnVotesReceived(sender, &oneBTxnVotes)
case msgs.MESSAGE_TWOATXNVOTES:
twoATxnVotes := msg.TwoATxnVotes()
d.AcceptorDispatcher.TwoATxnVotesReceived(sender, &twoATxnVotes)
case msgs.MESSAGE_TWOBTXNVOTES:
twoBTxnVotes := msg.TwoBTxnVotes()
d.ProposerDispatcher.TwoBTxnVotesReceived(sender, &twoBTxnVotes)
case msgs.MESSAGE_TXNLOCALLYCOMPLETE:
tlc := msg.TxnLocallyComplete()
d.AcceptorDispatcher.TxnLocallyCompleteReceived(sender, &tlc)
case msgs.MESSAGE_TXNGLOBALLYCOMPLETE:
tgc := msg.TxnGloballyComplete()
d.ProposerDispatcher.TxnGloballyCompleteReceived(sender, &tgc)
default:
panic(fmt.Sprintf("Unexpected message received from %v", sender))
}
}
示例11:
package server
import (
"fmt"
capn "github.com/glycerine/go-capnproto"
"goshawkdb.io/common"
msgs "goshawkdb.io/common/capnp"
"goshawkdb.io/server/configuration"
)
var (
TopologyVarUUId = common.MakeVarUUId([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})
VersionOne = common.MakeTxnId([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1})
)
var BlankTopology = &Topology{
Configuration: &configuration.Configuration{
F: 0,
MaxRMCount: 1,
},
AllRMs: []common.RMId{},
FInc: 1,
TwoFInc: 1,
DBVersion: VersionOne,
}
type Topology struct {
*configuration.Configuration
AllRMs common.RMIds
FInc uint8
TwoFInc uint16
示例12: String
func (instId instanceId) String() string {
txnId := common.MakeTxnId(instId[0:common.KeyLen])
rmId := common.RMId(binary.BigEndian.Uint32(instId[common.KeyLen:]))
vUUId := common.MakeVarUUId(instId[common.KeyLen+4:])
return fmt.Sprintf("PaxosInstanceId:%v:%v:%v", txnId, rmId, vUUId)
}