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 }
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 }
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 }
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 }