本文整理汇总了Golang中github.com/cockroachdb/cockroach/util/hlc.Timestamp.Equal方法的典型用法代码示例。如果您正苦于以下问题:Golang Timestamp.Equal方法的具体用法?Golang Timestamp.Equal怎么用?Golang Timestamp.Equal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/util/hlc.Timestamp
的用法示例。
在下文中一共展示了Timestamp.Equal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: putInternal
func (mvcc *MVCC) putInternal(key Key, timestamp hlc.Timestamp, value []byte, txnID string) error {
keyMeta := &keyMetadata{}
ok, err := GetI(mvcc.engine, key, keyMeta)
if err != nil {
return err
}
// In case the key metadata exists.
if ok {
// There is an uncommitted write intent and the current Put
// operation does not come from the same transaction.
// This should not happen since range should check the existing
// write intent before executing any Put action at MVCC level.
if len(keyMeta.TxnID) > 0 && (len(txnID) == 0 || keyMeta.TxnID != txnID) {
return &writeIntentError{TxnID: keyMeta.TxnID}
}
if keyMeta.Timestamp.Less(timestamp) ||
(timestamp.Equal(keyMeta.Timestamp) && txnID == keyMeta.TxnID) {
// Update key metadata.
PutI(mvcc.engine, key, &keyMetadata{TxnID: txnID, Timestamp: timestamp})
} else {
// In case we receive a Put request to update an old version,
// it must be an error since raft should handle any client
// retry from timeout.
return &writeTimestampTooOldError{Timestamp: keyMeta.Timestamp}
}
} else { // In case the key metadata does not exist yet.
// Create key metadata.
PutI(mvcc.engine, key, &keyMetadata{TxnID: txnID, Timestamp: timestamp})
}
// Save the value with the given version (Key + Timestamp).
return mvcc.engine.Put(mvccEncodeKey(key, timestamp), value)
}