本文整理汇总了Golang中github.com/cockroachdb/cockroach/keys.DecodeRangeKey函数的典型用法代码示例。如果您正苦于以下问题:Golang DecodeRangeKey函数的具体用法?Golang DecodeRangeKey怎么用?Golang DecodeRangeKey使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DecodeRangeKey函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: checkRangeDescriptorKey
func checkRangeDescriptorKey(key engine.MVCCKey) error {
_, suffix, _, err := keys.DecodeRangeKey(key.Key)
if err != nil {
return err
}
if !bytes.Equal(suffix, keys.LocalRangeDescriptorSuffix) {
return fmt.Errorf("wrong suffix: %s", suffix)
}
return nil
}
示例2: tryRangeDescriptor
func tryRangeDescriptor(kv engine.MVCCKeyValue) (string, error) {
_, suffix, _, err := keys.DecodeRangeKey(kv.Key.Key)
if err != nil {
return "", err
}
if !bytes.Equal(suffix, keys.LocalRangeDescriptorSuffix) {
return "", fmt.Errorf("wrong suffix: %s", suffix)
}
value := roachpb.Value{
RawBytes: kv.Value,
}
var desc roachpb.RangeDescriptor
if err := value.GetProto(&desc); err != nil {
return "", err
}
return descStr(desc), nil
}
示例3: printRangeDescriptor
func printRangeDescriptor(kv engine.MVCCKeyValue) (bool, error) {
startKey, suffix, _, err := keys.DecodeRangeKey(kv.Key.Key)
if err != nil {
return false, err
}
if !bytes.Equal(suffix, keys.LocalRangeDescriptorSuffix) {
return false, nil
}
value := roachpb.Value{
RawBytes: kv.Value,
}
var desc roachpb.RangeDescriptor
if err := value.GetProto(&desc); err != nil {
return false, err
}
fmt.Printf("Range descriptor with start key %s at time %s\n%s\n", startKey, kv.Key.Timestamp.GoTime(), &desc)
return false, nil
}
示例4: runDebugGCCmd
func runDebugGCCmd(cmd *cobra.Command, args []string) error {
stopper := stop.NewStopper()
defer stopper.Stop()
if len(args) != 1 {
return errors.New("required arguments: dir")
}
var rangeID roachpb.RangeID
if len(args) == 2 {
var err error
if rangeID, err = parseRangeID(args[1]); err != nil {
return err
}
}
db, err := openStore(cmd, args[0], stopper)
if err != nil {
return err
}
start := keys.RangeDescriptorKey(roachpb.RKeyMin)
end := keys.RangeDescriptorKey(roachpb.RKeyMax)
var descs []roachpb.RangeDescriptor
if _, err := engine.MVCCIterate(context.Background(), db, start, end, hlc.MaxTimestamp,
false /* !consistent */, nil, /* txn */
false /* !reverse */, func(kv roachpb.KeyValue) (bool, error) {
var desc roachpb.RangeDescriptor
_, suffix, _, err := keys.DecodeRangeKey(kv.Key)
if err != nil {
return false, err
}
if !bytes.Equal(suffix, keys.LocalRangeDescriptorSuffix) {
return false, nil
}
if err := kv.Value.GetProto(&desc); err != nil {
return false, err
}
if desc.RangeID == rangeID || rangeID == 0 {
descs = append(descs, desc)
}
return desc.RangeID == rangeID, nil
}); err != nil {
return err
}
if len(descs) == 0 {
return fmt.Errorf("no range matching the criteria found")
}
for _, desc := range descs {
snap := db.NewSnapshot()
defer snap.Close()
_, info, err := storage.RunGC(context.Background(), &desc, snap, hlc.Timestamp{WallTime: timeutil.Now().UnixNano()},
config.GCPolicy{TTLSeconds: 24 * 60 * 60 /* 1 day */}, func(_ hlc.Timestamp, _ *roachpb.Transaction, _ roachpb.PushTxnType) {
}, func(_ []roachpb.Intent, _, _ bool) error { return nil })
if err != nil {
return err
}
fmt.Printf("RangeID: %d [%s, %s):\n", desc.RangeID, desc.StartKey, desc.EndKey)
_, _ = pretty.Println(info)
}
return nil
}