-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding getDbSize functionality #135
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -260,6 +260,12 @@ public Iterator<DKVEntry> iterate(byte[] startKey, byte[] keyPref) { | |
return dkvClient.iterate(startKey, keyPref); | ||
} | ||
|
||
@Override | ||
public long getDbSize() { | ||
//TODO: implement this behaviour | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably this shouldn't even be exposed to java client unless its an exact value. |
||
return 0; | ||
} | ||
|
||
@Override | ||
public void close() { | ||
pool.close(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -285,6 +285,10 @@ func (bdb *badgerDB) CompareAndSet(key, expect, update []byte) (bool, error) { | |
return err == nil, err | ||
} | ||
|
||
func (bdb *badgerDB) GetKeySpaceSize() (int64, error) { | ||
return 0, nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
const ( | ||
badgerSSTPrefix = "badger-snapshot-" | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |
"os" | ||
"path" | ||
"path/filepath" | ||
"strconv" | ||
"strings" | ||
"sync/atomic" | ||
"time" | ||
|
@@ -380,6 +381,17 @@ func (rdb *rocksDB) CompareAndSet(key, expect, update []byte) (bool, error) { | |
return err == nil, err | ||
} | ||
|
||
func (rdb *rocksDB) GetKeySpaceSize() (int64, error) { | ||
defer rdb.opts.statsCli.Timing("rocksdb.property.latency.dbSize", time.Now()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The metric name doesn't match function name. Let's be consistent. |
||
keySize := rdb.db.GetProperty("rocksdb.estimate-num-keys") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be incorrect, Need to sum up sizes for multiple column families. Add test case to verify all scenarios |
||
dbKeySize, err := strconv.ParseInt(keySize, 10, 64) | ||
if err != nil { | ||
rdb.opts.statsCli.Incr("rocksdb.property.latency.dbSize", 1) | ||
return 0, err | ||
} | ||
return dbKeySize, nil | ||
} | ||
|
||
const ( | ||
sstPrefix = "rocksdb-sstfile-" | ||
sstDefaultCF = "/default.cf" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,8 @@ type KVStore interface { | |
// If the expected value is `nil`, then the key is created and | ||
// initialized with the given value, atomically. | ||
CompareAndSet(key, expect, update []byte) (bool, error) | ||
//GetKeySpaceSize returns the estimated number of keys the db | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this estimated? |
||
GetKeySpaceSize() (int64, error) | ||
} | ||
|
||
// A Backupable represents the capability of the underlying store | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,6 +205,10 @@ func (ms *memStore) CompareAndSet(key, expect, update []byte) (bool, error) { | |
return true, nil | ||
} | ||
|
||
func (ms *memStore) GetKeySpaceSize() (int64, error) { | ||
return 0, nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be the count of keys in the db. |
||
} | ||
|
||
func (ms *memStore) Close() error { | ||
ms.store = nil | ||
return nil | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |
"errors" | ||
"github.com/flipkart-incubator/dkv/internal/hlc" | ||
"github.com/flipkart-incubator/nexus/models" | ||
"google.golang.org/protobuf/types/known/emptypb" | ||
"io" | ||
"time" | ||
|
||
|
@@ -262,6 +263,13 @@ func (dkvClnt *DKVClient) Iterate(keyPrefix, startKey []byte) (<-chan *KVPair, e | |
return ch, nil | ||
} | ||
|
||
// GetDbSize returns the approximate count of the number of the keys in the db | ||
func (dkvClnt *DKVClient) GetDbSize() (*serverpb.KeySpaceSizeResponse, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be better named as |
||
ctx, cancel := context.WithTimeout(context.Background(), Timeout) | ||
defer cancel() | ||
return dkvClnt.dkvCli.GetKeySpaceSize(ctx, &emptypb.Empty{}) | ||
} | ||
|
||
// Close closes the underlying GRPC client connection to DKV service | ||
func (dkvClnt *DKVClient) Close() error { | ||
if dkvClnt.cliConn != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to add
get
as a prefix as its implicit thatdBSize
is a read-only operation