本文整理匯總了Golang中github.com/cockroachdb/cockroach/proto.Timestamp.Add方法的典型用法代碼示例。如果您正苦於以下問題:Golang Timestamp.Add方法的具體用法?Golang Timestamp.Add怎麽用?Golang Timestamp.Add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cockroachdb/cockroach/proto.Timestamp
的用法示例。
在下文中一共展示了Timestamp.Add方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: requestLeaderLease
// requestLeaderLease sends a request to obtain or extend a leader lease for
// this replica. Unless an error is returned, the obtained lease will be valid
// for a time interval containing the requested timestamp.
func (r *Range) requestLeaderLease(timestamp proto.Timestamp) error {
// TODO(Tobias): get duration from configuration, either as a config flag
// or, later, dynamically adjusted.
duration := int64(DefaultLeaderLeaseDuration)
// Prepare a Raft command to get a leader lease for this replica.
expiration := timestamp.Add(duration, 0)
args := &proto.InternalLeaderLeaseRequest{
RequestHeader: proto.RequestHeader{
Key: r.Desc().StartKey,
Timestamp: timestamp,
CmdID: proto.ClientCmdID{
WallTime: r.rm.Clock().Now().WallTime,
Random: rand.Int63(),
},
},
Lease: proto.Lease{
Start: timestamp,
Expiration: expiration,
RaftNodeID: r.rm.RaftNodeID(),
},
}
// Send lease request directly to raft in order to skip unnecessary
// checks from normal request machinery, (e.g. the command queue).
errChan, pendingCmd := r.proposeRaftCommand(r.context(), args, &proto.InternalLeaderLeaseResponse{})
var err error
if err = <-errChan; err == nil {
// Next if the command was committed, wait for the range to apply it.
err = <-pendingCmd.done
}
return err
}
示例2: requestLeaderLease
// requestLeaderLease sends a request to obtain or extend a leader lease for
// this replica. Unless an error is returned, the obtained lease will be valid
// for a time interval containing the requested timestamp.
func (r *Replica) requestLeaderLease(timestamp proto.Timestamp) error {
// TODO(Tobias): get duration from configuration, either as a config flag
// or, later, dynamically adjusted.
duration := int64(DefaultLeaderLeaseDuration)
// Prepare a Raft command to get a leader lease for this replica.
expiration := timestamp.Add(duration, 0)
desc := r.Desc()
args := &proto.LeaderLeaseRequest{
RequestHeader: proto.RequestHeader{
Key: desc.StartKey,
Timestamp: timestamp,
CmdID: proto.ClientCmdID{
WallTime: r.rm.Clock().Now().WallTime,
Random: rand.Int63(),
},
RangeID: desc.RangeID,
},
Lease: proto.Lease{
Start: timestamp,
Expiration: expiration,
RaftNodeID: r.rm.RaftNodeID(),
},
}
// Send lease request directly to raft in order to skip unnecessary
// checks from normal request machinery, (e.g. the command queue).
// Note that the command itself isn't traced, but usually the caller
// waiting for the result has an active Trace.
errChan, pendingCmd := r.proposeRaftCommand(r.context(), args)
if err := <-errChan; err != nil {
return err
}
// Next if the command was committed, wait for the range to apply it.
return (<-pendingCmd.done).Err
}