From 10ecf80ca1204b0efa7a19e6f3463c3a767a4bdf Mon Sep 17 00:00:00 2001 From: chrislu Date: Tue, 11 Jan 2022 23:25:04 -0800 Subject: [PATCH] add a debug capability to list all metadata keys --- weed/filer/filerstore.go | 5 +++++ weed/filer/filerstore_wrapper.go | 8 ++++++++ weed/filer/leveldb/leveldb_store.go | 15 +++++++++++++++ weed/filesys/meta_cache/meta_cache.go | 7 +++++++ 4 files changed, 35 insertions(+) diff --git a/weed/filer/filerstore.go b/weed/filer/filerstore.go index 38927d6fb..a092ee456 100644 --- a/weed/filer/filerstore.go +++ b/weed/filer/filerstore.go @@ -4,6 +4,7 @@ import ( "context" "errors" "github.com/chrislusf/seaweedfs/weed/util" + "io" ) var ( @@ -45,3 +46,7 @@ type BucketAware interface { OnBucketDeletion(bucket string) CanDropWholeBucket() bool } + +type Debuggable interface { + Debug(writer io.Writer) +} diff --git a/weed/filer/filerstore_wrapper.go b/weed/filer/filerstore_wrapper.go index 47b5036f7..ca531dc3a 100644 --- a/weed/filer/filerstore_wrapper.go +++ b/weed/filer/filerstore_wrapper.go @@ -4,6 +4,7 @@ import ( "context" "github.com/chrislusf/seaweedfs/weed/glog" "github.com/viant/ptrie" + "io" "math" "strings" "time" @@ -15,6 +16,7 @@ import ( var ( _ = VirtualFilerStore(&FilerStoreWrapper{}) + _ = Debuggable(&FilerStoreWrapper{}) ) type VirtualFilerStore interface { @@ -333,3 +335,9 @@ func (fsw *FilerStoreWrapper) KvGet(ctx context.Context, key []byte) (value []by func (fsw *FilerStoreWrapper) KvDelete(ctx context.Context, key []byte) (err error) { return fsw.getDefaultStore().KvDelete(ctx, key) } + +func (fsw *FilerStoreWrapper) Debug(writer io.Writer) { + if debuggable, ok := fsw.getDefaultStore().(Debuggable); ok { + debuggable.Debug(writer) + } +} diff --git a/weed/filer/leveldb/leveldb_store.go b/weed/filer/leveldb/leveldb_store.go index 9a7670d42..73d757e62 100644 --- a/weed/filer/leveldb/leveldb_store.go +++ b/weed/filer/leveldb/leveldb_store.go @@ -9,6 +9,7 @@ import ( "github.com/syndtr/goleveldb/leveldb/filter" "github.com/syndtr/goleveldb/leveldb/opt" leveldb_util "github.com/syndtr/goleveldb/leveldb/util" + "io" "os" "github.com/chrislusf/seaweedfs/weed/filer" @@ -21,6 +22,10 @@ const ( DIR_FILE_SEPARATOR = byte(0x00) ) +var ( + _ = filer.Debuggable(&LevelDBStore{}) +) + func init() { filer.Stores = append(filer.Stores, &LevelDBStore{}) } @@ -242,3 +247,13 @@ func getNameFromKey(key []byte) string { func (store *LevelDBStore) Shutdown() { store.db.Close() } + +func (store *LevelDBStore) Debug(writer io.Writer) { + iter := store.db.NewIterator(&leveldb_util.Range{}, nil) + for iter.Next() { + key := iter.Key() + fullName := bytes.Replace(key, []byte{DIR_FILE_SEPARATOR}, []byte{' '}, 1) + fmt.Fprintf(writer, "%v\n", string(fullName)) + } + iter.Release() +} diff --git a/weed/filesys/meta_cache/meta_cache.go b/weed/filesys/meta_cache/meta_cache.go index 23384f592..6d5eeca03 100644 --- a/weed/filesys/meta_cache/meta_cache.go +++ b/weed/filesys/meta_cache/meta_cache.go @@ -144,3 +144,10 @@ func (mc *MetaCache) Shutdown() { func (mc *MetaCache) mapIdFromFilerToLocal(entry *filer.Entry) { entry.Attr.Uid, entry.Attr.Gid = mc.uidGidMapper.FilerToLocal(entry.Attr.Uid, entry.Attr.Gid) } + +func (mc *MetaCache) Debug() { + if debuggable, ok := mc.localStore.(filer.Debuggable); ok { + println("start debugging") + debuggable.Debug(os.Stderr) + } +}