本文整理汇总了Golang中github.com/cockroachdb/cockroach/proto.RequestHeader.Timestamp方法的典型用法代码示例。如果您正苦于以下问题:Golang RequestHeader.Timestamp方法的具体用法?Golang RequestHeader.Timestamp怎么用?Golang RequestHeader.Timestamp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/proto.RequestHeader
的用法示例。
在下文中一共展示了RequestHeader.Timestamp方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: beginCmd
// beginCmd waits for any overlapping, already-executing commands via
// the command queue and adds itself to the queue to gate follow-on
// commands which overlap its key range. This method will block if
// there are any overlapping commands already in the queue. Returns
// the command queue insertion key, to be supplied to subsequent
// invocation of endCmd().
func (r *Range) beginCmd(header *proto.RequestHeader, readOnly bool) interface{} {
r.Lock()
var wg sync.WaitGroup
r.cmdQ.GetWait(header.Key, header.EndKey, readOnly, &wg)
cmdKey := r.cmdQ.Add(header.Key, header.EndKey, readOnly)
r.Unlock()
wg.Wait()
// Update the incoming timestamp if unset. Wait until after any
// preceding command(s) for key range are complete so that the node
// clock has been updated to the high water mark of any commands
// which might overlap this one in effect.
if header.Timestamp.Equal(proto.ZeroTimestamp) {
header.Timestamp = r.rm.Clock().Now()
}
return cmdKey
}
示例2: TestTxnPutOutOfOrder
//.........这里部分代码省略.........
epoch := -1
// Start a txn that does read-after-write.
// The txn will be restarted twice, and the out-of-order put
// will happen in the second epoch.
if err := store.DB().Txn(func(txn *client.Txn) error {
epoch++
if epoch == 1 {
// Wait until the second get operation is issued.
close(waitTxnRestart)
<-waitSecondGet
}
updatedVal := []byte("updatedVal")
if err := txn.Put(key, updatedVal); err != nil {
return err
}
// Make sure a get will return the value that was just written.
actual, err := txn.Get(key)
if err != nil {
return err
}
if !bytes.Equal(actual.ValueBytes(), updatedVal) {
t.Fatalf("unexpected get result: %s", actual)
}
if epoch == 0 {
// Wait until the first get operation will push the txn timestamp.
close(waitPut)
<-waitFirstGet
}
b := &client.Batch{}
err = txn.Commit(b)
return err
}); err != nil {
t.Fatal(err)
}
if epoch != 2 {
t.Fatalf("unexpected number of txn retries: %d", epoch)
}
close(waitTxnComplete)
}()
<-waitPut
// Start the Reader.
// Advance the clock and send a get operation with higher
// priority to trigger the txn restart.
manualClock.Increment(100)
priority := int32(math.MaxInt32)
requestHeader := proto.RequestHeader{
Key: proto.Key(key),
RaftID: 1,
Replica: proto.Replica{StoreID: store.StoreID()},
UserPriority: &priority,
Timestamp: clock.Now(),
}
getCall := proto.Call{
Args: &proto.GetRequest{
RequestHeader: requestHeader,
},
Reply: &proto.GetResponse{},
}
err = store.ExecuteCmd(context.Background(), getCall)
if err != nil {
t.Fatalf("failed to get: %s", err)
}
// Wait until the writer restarts the txn.
close(waitFirstGet)
<-waitTxnRestart
// Advance the clock and send a get operation again. This time
// we use TestingCommandFilter so that a get operation is not
// processed after the write intent is resolved (to prevent the
// timestamp cache from being updated).
manualClock.Increment(100)
requestHeader.Timestamp = clock.Now()
getCall = proto.Call{
Args: &proto.GetRequest{
RequestHeader: requestHeader,
},
Reply: &proto.GetResponse{},
}
err = store.ExecuteCmd(context.Background(), getCall)
if err == nil {
t.Fatal("unexpected success of get")
}
close(waitSecondGet)
<-waitTxnComplete
}