From c7e7431fd367117590930cc1948aa9a25da60d7a Mon Sep 17 00:00:00 2001 From: qieqieplus Date: Thu, 7 Jan 2021 17:07:56 +0800 Subject: [PATCH 1/2] fix seek lastkey may reach EOF --- weed/filer/rocksdb/rocksdb_store.go | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/weed/filer/rocksdb/rocksdb_store.go b/weed/filer/rocksdb/rocksdb_store.go index 9e058a96d..2d5501637 100644 --- a/weed/filer/rocksdb/rocksdb_store.go +++ b/weed/filer/rocksdb/rocksdb_store.go @@ -182,17 +182,9 @@ func enumerate(iter *gorocksdb.Iterator, prefix, lastKey []byte, includeLastKey } else { iter.Seek(lastKey) - if !includeLastKey { - key := iter.Key().Data() - - if !bytes.HasPrefix(key, prefix) { - return nil - } - - if bytes.Equal(key, lastKey) { - iter.Next() - } - + if iter.Valid() && !includeLastKey && + bytes.Equal(iter.Key().Data(), lastKey) { + iter.Next() } } @@ -250,10 +242,6 @@ func (store *RocksDBStore) ListDirectoryPrefixedEntries(ctx context.Context, ful if fileName == "" { return true } - limit-- - if limit < 0 { - return false - } entry := &filer.Entry{ FullPath: weed_util.NewFullPath(string(fullpath), fileName), } From 0f18592315e8a184f1733d9eb9ddc77e682e0c23 Mon Sep 17 00:00:00 2001 From: qieqieplus Date: Thu, 7 Jan 2021 18:21:48 +0800 Subject: [PATCH 2/2] alter style --- weed/filer/rocksdb/rocksdb_store.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/weed/filer/rocksdb/rocksdb_store.go b/weed/filer/rocksdb/rocksdb_store.go index 2d5501637..0793f547c 100644 --- a/weed/filer/rocksdb/rocksdb_store.go +++ b/weed/filer/rocksdb/rocksdb_store.go @@ -181,10 +181,12 @@ func enumerate(iter *gorocksdb.Iterator, prefix, lastKey []byte, includeLastKey iter.Seek(prefix) } else { iter.Seek(lastKey) - - if iter.Valid() && !includeLastKey && - bytes.Equal(iter.Key().Data(), lastKey) { - iter.Next() + if !includeLastKey { + if iter.Valid() { + if bytes.Equal(iter.Key().Data(), lastKey) { + iter.Next() + } + } } }