Skip to content

Commit

Permalink
Added Pebble DB CLI util tool (#371)
Browse files Browse the repository at this point in the history
The tools allows for debug / inspect / repair a Pebble DB.
  • Loading branch information
merlimat authored Jul 23, 2023
1 parent def56b9 commit dbc52a9
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 13 deletions.
2 changes: 2 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
37 changes: 37 additions & 0 deletions cmd/pebble/cmd.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
30 changes: 17 additions & 13 deletions server/kv/kv_pebble.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{
{
Expand Down

0 comments on commit dbc52a9

Please sign in to comment.