From dbc52a9c18320f18828b011d138d8fa4889fe749 Mon Sep 17 00:00:00 2001 From: Matteo Merli Date: Sun, 23 Jul 2023 17:21:37 +0200 Subject: [PATCH] Added Pebble DB CLI util tool (#371) The tools allows for debug / inspect / repair a Pebble DB. --- cmd/main.go | 2 ++ cmd/pebble/cmd.go | 37 +++++++++++++++++++++++++++++++++++++ server/kv/kv_pebble.go | 30 +++++++++++++++++------------- 3 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 cmd/pebble/cmd.go diff --git a/cmd/main.go b/cmd/main.go index 2a569a80..e5c80a0c 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -23,6 +23,7 @@ import ( "oxia/cmd/client" "oxia/cmd/coordinator" "oxia/cmd/health" + "oxia/cmd/pebble" "oxia/cmd/perf" "oxia/cmd/server" "oxia/cmd/standalone" @@ -57,6 +58,7 @@ func init() { rootCmd.AddCommand(perf.Cmd) rootCmd.AddCommand(server.Cmd) rootCmd.AddCommand(standalone.Cmd) + rootCmd.AddCommand(pebble.Cmd) } func configureLogLevel(cmd *cobra.Command, args []string) error { diff --git a/cmd/pebble/cmd.go b/cmd/pebble/cmd.go new file mode 100644 index 00000000..a7e40cb8 --- /dev/null +++ b/cmd/pebble/cmd.go @@ -0,0 +1,37 @@ +// Copyright 2023 StreamNative, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package pebble + +import ( + "github.com/cockroachdb/pebble/tool" + "github.com/spf13/cobra" + "oxia/server/kv" +) + +var ( + Cmd = &cobra.Command{ + Use: "pebble", + Short: "Pebble DB utils", + Long: `Tools for the Pebble DB`, + } +) + +func init() { + t := tool.New(tool.DefaultComparer(kv.OxiaSlashSpanComparer)) + + for _, cmd := range t.Commands { + Cmd.AddCommand(cmd) + } +} diff --git a/server/kv/kv_pebble.go b/server/kv/kv_pebble.go index 542d33da..f5cea57e 100644 --- a/server/kv/kv_pebble.go +++ b/server/kv/kv_pebble.go @@ -32,6 +32,21 @@ import ( "time" ) +var ( + OxiaSlashSpanComparer = &pebble.Comparer{ + Compare: CompareWithSlash, + Equal: pebble.DefaultComparer.Equal, + AbbreviatedKey: pebble.DefaultComparer.AbbreviatedKey, + FormatKey: pebble.DefaultComparer.FormatKey, + FormatValue: pebble.DefaultComparer.FormatValue, + Separator: pebble.DefaultComparer.Separator, + Split: pebble.DefaultComparer.Split, + Successor: pebble.DefaultComparer.Successor, + ImmediateSuccessor: pebble.DefaultComparer.ImmediateSuccessor, + Name: "oxia-slash-spans", + } +) + type PebbleFactory struct { dataDir string cache *pebble.Cache @@ -171,19 +186,8 @@ func newKVPebble(factory *PebbleFactory, namespace string, shardId int64) (KV, e } pbOptions := &pebble.Options{ - Cache: factory.cache, - Comparer: &pebble.Comparer{ - Compare: CompareWithSlash, - Equal: pebble.DefaultComparer.Equal, - AbbreviatedKey: pebble.DefaultComparer.AbbreviatedKey, - FormatKey: pebble.DefaultComparer.FormatKey, - FormatValue: pebble.DefaultComparer.FormatValue, - Separator: pebble.DefaultComparer.Separator, - Split: pebble.DefaultComparer.Split, - Successor: pebble.DefaultComparer.Successor, - ImmediateSuccessor: pebble.DefaultComparer.ImmediateSuccessor, - Name: "oxia-slash-spans", - }, + Cache: factory.cache, + Comparer: OxiaSlashSpanComparer, MemTableSize: 32 * 1024 * 1024, Levels: []pebble.LevelOptions{ {