本文整理汇总了Golang中github.com/cockroachdb/cockroach/util/uuid.FromBytes函数的典型用法代码示例。如果您正苦于以下问题:Golang FromBytes函数的具体用法?Golang FromBytes怎么用?Golang FromBytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FromBytes函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestTransactionString
func TestTransactionString(t *testing.T) {
txnID, err := uuid.FromBytes([]byte("ת\x0f^\xe4-Fؽ\xf7\x16\xe4\xf9\xbe^\xbe"))
if err != nil {
t.Fatal(err)
}
ts1 := makeTS(10, 11)
txn := Transaction{
TxnMeta: TxnMeta{
Isolation: SERIALIZABLE,
Key: Key("foo"),
ID: txnID,
Epoch: 2,
Timestamp: makeTS(20, 21),
},
Name: "name",
Priority: 957356782,
Status: COMMITTED,
LastHeartbeat: &ts1,
OrigTimestamp: makeTS(30, 31),
MaxTimestamp: makeTS(40, 41),
}
expStr := `"name" id=d7aa0f5e key="foo" rw=false pri=44.58039917 iso=SERIALIZABLE stat=COMMITTED ` +
`epo=2 ts=0.000000020,21 orig=0.000000030,31 max=0.000000040,41`
if str := txn.String(); str != expStr {
t.Errorf("expected txn %s; got %s", expStr, str)
}
var txnEmpty Transaction
_ = txnEmpty.String() // prevent regression of NPE
}
开发者ID:cuongdo,项目名称:cockroach,代码行数:31,代码来源:data_test.go
示例2: localRangeKeyPrint
func localRangeKeyPrint(key roachpb.Key) string {
var buf bytes.Buffer
for _, s := range rangeSuffixDict {
if s.atEnd {
if bytes.HasSuffix(key, s.suffix) {
key = key[:len(key)-len(s.suffix)]
fmt.Fprintf(&buf, "%s/%s", decodeKeyPrint(key), s.name)
return buf.String()
}
} else {
begin := bytes.Index(key, s.suffix)
if begin > 0 {
addrKey := key[:begin]
txnID, err := uuid.FromBytes(key[(begin + len(s.suffix)):])
if err != nil {
return fmt.Sprintf("/%q/err:%v", key, err)
}
fmt.Fprintf(&buf, "%s/%s/addrKey:/id:%q", decodeKeyPrint(addrKey), s.name, txnID)
return buf.String()
}
}
}
fmt.Fprintf(&buf, "%s", decodeKeyPrint(key))
return buf.String()
}
开发者ID:CubeLite,项目名称:cockroach,代码行数:27,代码来源:printer.go
示例3: sequenceCacheKeyPrint
func sequenceCacheKeyPrint(key roachpb.Key) string {
b, id, err := encoding.DecodeBytesAscending([]byte(key), nil)
if err != nil {
return fmt.Sprintf("/%q/err:%v", key, err)
}
txnID, err := uuid.FromBytes(id)
if err != nil {
return fmt.Sprintf("/%q/err:%v", key, err)
}
if len(b) == 0 {
return fmt.Sprintf("/%q", txnID)
}
b, epoch, err := encoding.DecodeUint32Descending(b)
if err != nil {
return fmt.Sprintf("/%q/err:%v", txnID, err)
}
_, seq, err := encoding.DecodeUint32Descending(b)
if err != nil {
return fmt.Sprintf("/%q/epoch:%d/err:%v", txnID, epoch, err)
}
return fmt.Sprintf("/%q/epoch:%d/seq:%d", txnID, epoch, seq)
}
开发者ID:bogdanbatog,项目名称:cockroach,代码行数:27,代码来源:printer.go
示例4: DecodeAbortCacheKey
// DecodeAbortCacheKey decodes the provided abort cache entry,
// returning the transaction ID.
func DecodeAbortCacheKey(key roachpb.Key, dest []byte) (*uuid.UUID, error) {
// TODO(tschottdorf): redundant check.
if !bytes.HasPrefix(key, LocalRangeIDPrefix) {
return nil, util.Errorf("key %s does not have %s prefix", key, LocalRangeIDPrefix)
}
// Cut the prefix, the Range ID, and the infix specifier.
b := key[len(LocalRangeIDPrefix):]
b, _, err := encoding.DecodeUvarintAscending(b)
if err != nil {
return nil, err
}
b = b[1:]
if !bytes.HasPrefix(b, LocalAbortCacheSuffix) {
return nil, util.Errorf("key %s does not contain the abort cache suffix %s",
key, LocalAbortCacheSuffix)
}
// Cut the abort cache suffix.
b = b[len(LocalAbortCacheSuffix):]
// Decode the id.
b, idBytes, err := encoding.DecodeBytesAscending(b, dest)
if err != nil {
return nil, err
}
if len(b) > 0 {
return nil, util.Errorf("key %q has leftover bytes after decode: %s; indicates corrupt key", key, b)
}
txnID, err := uuid.FromBytes(idBytes)
return txnID, err
}
开发者ID:petermattis,项目名称:cockroach,代码行数:31,代码来源:keys.go
示例5: abortCacheKeyPrint
func abortCacheKeyPrint(key roachpb.Key) string {
_, id, err := encoding.DecodeBytesAscending([]byte(key), nil)
if err != nil {
return fmt.Sprintf("/%q/err:%v", key, err)
}
txnID, err := uuid.FromBytes(id)
if err != nil {
return fmt.Sprintf("/%q/err:%v", key, err)
}
return fmt.Sprintf("/%q", txnID)
}
开发者ID:CubeLite,项目名称:cockroach,代码行数:13,代码来源:printer.go
示例6: DecodeAbortCacheKey
// DecodeAbortCacheKey decodes the provided abort cache entry,
// returning the transaction ID.
func DecodeAbortCacheKey(key roachpb.Key, dest []byte) (*uuid.UUID, error) {
_, _, suffix, detail, err := DecodeRangeIDKey(key)
if err != nil {
return nil, err
}
if !bytes.Equal(suffix, LocalAbortCacheSuffix) {
return nil, errors.Errorf("key %s does not contain the abort cache suffix %s",
key, LocalAbortCacheSuffix)
}
// Decode the id.
detail, idBytes, err := encoding.DecodeBytesAscending(detail, dest)
if err != nil {
return nil, err
}
if len(detail) > 0 {
return nil, errors.Errorf("key %q has leftover bytes after decode: %s; indicates corrupt key", key, detail)
}
txnID, err := uuid.FromBytes(idBytes)
return txnID, err
}
开发者ID:CubeLite,项目名称:cockroach,代码行数:22,代码来源:keys.go
示例7: decodeSequenceCacheKey
func decodeSequenceCacheKey(key roachpb.Key, dest []byte) (*uuid.UUID, uint32, uint32, error) {
// TODO(tschottdorf): redundant check.
if !bytes.HasPrefix(key, keys.LocalRangeIDPrefix) {
return nil, 0, 0, util.Errorf("key %s does not have %s prefix", key, keys.LocalRangeIDPrefix)
}
// Cut the prefix and the Range ID.
b := key[len(keys.LocalRangeIDPrefix):]
b, _, err := encoding.DecodeUvarintAscending(b)
if err != nil {
return nil, 0, 0, err
}
if !bytes.HasPrefix(b, keys.LocalSequenceCacheSuffix) {
return nil, 0, 0, util.Errorf("key %s does not contain the sequence cache suffix %s",
key, keys.LocalSequenceCacheSuffix)
}
// Cut the sequence cache suffix.
b = b[len(keys.LocalSequenceCacheSuffix):]
// Decode the id.
b, idBytes, err := encoding.DecodeBytesAscending(b, dest)
if err != nil {
return nil, 0, 0, err
}
// Decode the epoch.
b, epoch, err := encoding.DecodeUint32Descending(b)
if err != nil {
return nil, 0, 0, err
}
// Decode the sequence number.
b, seq, err := encoding.DecodeUint32Descending(b)
if err != nil {
return nil, 0, 0, err
}
if len(b) > 0 {
return nil, 0, 0, util.Errorf("key %q has leftover bytes after decode: %s; indicates corrupt key",
key, b)
}
txnID, err := uuid.FromBytes(idBytes)
return txnID, epoch, seq, err
}
开发者ID:binlijin,项目名称:cockroach,代码行数:39,代码来源:sequence_cache.go
示例8: TestTransactionString
func TestTransactionString(t *testing.T) {
txnID, err := uuid.FromBytes([]byte("ת\x0f^\xe4-Fؽ\xf7\x16\xe4\xf9\xbe^\xbe"))
if err != nil {
t.Fatal(err)
}
ts1 := makeTS(10, 11)
txn := Transaction{
TxnMeta: enginepb.TxnMeta{
Isolation: enginepb.SERIALIZABLE,
Key: Key("foo"),
ID: txnID,
Epoch: 2,
Timestamp: makeTS(20, 21),
Priority: 957356782,
},
Name: "name",
Status: COMMITTED,
LastHeartbeat: &ts1,
OrigTimestamp: makeTS(30, 31),
MaxTimestamp: makeTS(40, 41),
}
expStr := `"name" id=d7aa0f5e key="foo" rw=false pri=44.58039917 iso=SERIALIZABLE stat=COMMITTED ` +
`epo=2 ts=0.000000020,21 orig=0.000000030,31 max=0.000000040,41 wto=false rop=false`
if str := txn.String(); str != expStr {
t.Errorf("expected txn %s; got %s", expStr, str)
}
var txnEmpty Transaction
_ = txnEmpty.String() // prevent regression of NPE
var cmd RaftCommand
cmd.Cmd.Txn = &txn
if actStr, idStr := fmt.Sprintf("%s", &cmd), txn.ID.String(); !strings.Contains(actStr, idStr) {
t.Fatalf("expected to find '%s' in '%s'", idStr, actStr)
}
}
开发者ID:csdigi,项目名称:cockroach,代码行数:37,代码来源:data_test.go
示例9: connectGossip
// connectGossip connects to gossip network and reads cluster ID. If
// this node is already part of a cluster, the cluster ID is verified
// for a match. If not part of a cluster, the cluster ID is set. The
// node's address is gossiped with node ID as the gossip key.
func (n *Node) connectGossip() {
log.Infof("connecting to gossip network to verify cluster ID...")
// No timeout or stop condition is needed here. Log statements should be
// sufficient for diagnosing this type of condition.
<-n.ctx.Gossip.Connected
uuidBytes, err := n.ctx.Gossip.GetInfo(gossip.KeyClusterID)
if err != nil {
log.Fatalf("unable to ascertain cluster ID from gossip network: %s", err)
}
gossipClusterIDPtr, err := uuid.FromBytes(uuidBytes)
if err != nil {
log.Fatalf("unable to ascertain cluster ID from gossip network: %s", err)
}
gossipClusterID := *gossipClusterIDPtr
if n.ClusterID == *uuid.EmptyUUID {
n.ClusterID = gossipClusterID
} else if n.ClusterID != gossipClusterID {
log.Fatalf("node %d belongs to cluster %q but is attempting to connect to a gossip network for cluster %q",
n.Descriptor.NodeID, n.ClusterID, gossipClusterID)
}
log.Infof("node connected via gossip and verified as part of cluster %q", gossipClusterID)
}
开发者ID:guanqun,项目名称:cockroach,代码行数:28,代码来源:node.go
注:本文中的github.com/cockroachdb/cockroach/util/uuid.FromBytes函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论