github.com/petermattis/pebble@v0.0.0-20190905164901-ab51a2166067/tool/tool.go (about) 1 // Copyright 2019 The LevelDB-Go and Pebble Authors. All rights reserved. Use 2 // of this source code is governed by a BSD-style license that can be found in 3 // the LICENSE file. 4 5 package tool 6 7 import ( 8 "github.com/petermattis/pebble/bloom" 9 "github.com/petermattis/pebble/cache" 10 "github.com/petermattis/pebble/internal/base" 11 "github.com/petermattis/pebble/sstable" 12 "github.com/spf13/cobra" 13 ) 14 15 // Comparer exports the base.Comparer type. 16 type Comparer = base.Comparer 17 18 // FilterPolicy exports the base.FilterPolicy type. 19 type FilterPolicy = base.FilterPolicy 20 21 // Merger exports the base.Merger type. 22 type Merger = base.Merger 23 24 // T is the container for all of the introspection tools. 25 type T struct { 26 Commands []*cobra.Command 27 db *dbT 28 manifest *manifestT 29 sstable *sstableT 30 wal *walT 31 opts base.Options 32 comparers sstable.Comparers 33 mergers sstable.Mergers 34 } 35 36 // New creates a new introspection tool. 37 func New() *T { 38 t := &T{ 39 opts: base.Options{ 40 Cache: cache.New(128 << 20 /* 128 MB */), 41 Filters: make(map[string]FilterPolicy), 42 ReadOnly: true, 43 }, 44 comparers: make(sstable.Comparers), 45 mergers: make(sstable.Mergers), 46 } 47 48 t.RegisterComparer(base.DefaultComparer) 49 t.RegisterFilter(bloom.FilterPolicy(10)) 50 t.RegisterMerger(base.DefaultMerger) 51 52 t.db = newDB(&t.opts, t.comparers, t.mergers) 53 t.manifest = newManifest(&t.opts, t.comparers) 54 t.sstable = newSSTable(&t.opts, t.comparers, t.mergers) 55 t.wal = newWAL(&t.opts) 56 t.Commands = []*cobra.Command{ 57 t.db.Root, 58 t.manifest.Root, 59 t.sstable.Root, 60 t.wal.Root, 61 } 62 return t 63 } 64 65 // RegisterComparer registers a comparer for use by the introspection tools. 66 func (t *T) RegisterComparer(c *Comparer) { 67 t.comparers[c.Name] = c 68 } 69 70 // RegisterFilter registers a filter policy for use by the introspection tools. 71 func (t *T) RegisterFilter(f FilterPolicy) { 72 t.opts.Filters[f.Name()] = f 73 } 74 75 // RegisterMerger registers a merger for use by the introspection tools. 76 func (t *T) RegisterMerger(m *Merger) { 77 t.mergers[m.Name] = m 78 }