Skip to content

Commit

Permalink
store: Introduce Info() for datastore information
Browse files Browse the repository at this point in the history
Signed-off-by: Simarpreet Singh <[email protected]>
  • Loading branch information
simar7 committed Dec 12, 2019
1 parent 17fa71e commit a837bd5
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 6 deletions.
13 changes: 13 additions & 0 deletions bbolt/bbolt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bbolt

import (
"errors"
"os"

"github.com/simar7/gokv/types"

Expand Down Expand Up @@ -247,3 +248,15 @@ func (s Store) Scan(input types.ScanInput) (types.ScanOutput, error) {
func (s Store) Close() error {
return s.db.Close()
}

func (s Store) Info() (types.StoreInfo, error) {
f, err := os.Stat(s.dbPath)
if err != nil {
return types.StoreInfo{}, err
}

return types.StoreInfo{
Name: s.rbc.Name,
Size: f.Size(),
}, nil
}
23 changes: 18 additions & 5 deletions bbolt/bbolt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import (
"sync"
"testing"

"github.com/simar7/gokv/encoding"

"github.com/simar7/gokv/util"
bolt "go.etcd.io/bbolt"
h "github.com/dustin/go-humanize"

"github.com/simar7/gokv/encoding"
"github.com/simar7/gokv/types"

"github.com/simar7/gokv/util"
"github.com/stretchr/testify/assert"
bolt "go.etcd.io/bbolt"
)

func setupStoreWithCodec(codec encoding.Codec) (*Store, *os.File, error) {
Expand Down Expand Up @@ -369,3 +368,17 @@ func TestStore_Scan(t *testing.T) {
assert.Empty(t, scanOut)
})
}

func TestStore_Info(t *testing.T) {
s, f, err := setupStore()
defer func() {
_ = f.Close()
_ = os.RemoveAll(f.Name())
}()
assert.NoError(t, err)

actualInfo, err := s.Info()
assert.NoError(t, err)
assert.Equal(t, "gokvbbolt", actualInfo.Name)
assert.Equal(t, "32 KiB", h.IBytes(uint64(actualInfo.Size)))
}
6 changes: 5 additions & 1 deletion dynamodb/dynamodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var (

var (
ErrMissingTableName = errors.New("table name is required")
//ErrNotImplemented = errors.New("function not implemented")
ErrNotImplemented = errors.New("function not implemented")
)

type Options struct {
Expand Down Expand Up @@ -245,3 +245,7 @@ func (s Store) Scan(input types.ScanInput) (types.ScanOutput, error) {

return scanOuput, nil
}

func (s Store) Info() (types.StoreInfo, error) {
return types.StoreInfo{}, ErrNotImplemented
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/alicebob/miniredis/v2 v2.11.0
github.com/aws/aws-sdk-go v1.25.31
github.com/davecgh/go-spew v1.1.0
github.com/dustin/go-humanize v1.0.0
github.com/gomodule/redigo v2.0.0+incompatible
github.com/stretchr/testify v1.4.0
go.etcd.io/bbolt v1.3.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5P
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/gomodule/redigo v1.7.1-0.20190322064113-39e2c31b7ca3/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0=
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
Expand Down
5 changes: 5 additions & 0 deletions redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var (
ErrInvalidAddress = errors.New("invalid redis address specified")
ErrRedisInitFailed = errors.New("redis initialization failed")
ErrKeyNotFound = errors.New("key not found")
ErrNotImplemented = errors.New("function not implemented")
)

type Options struct {
Expand Down Expand Up @@ -243,3 +244,7 @@ func (s Store) getAllKeys() ([]string, error) {
}
return keys, nil
}

func (s Store) Info() (types.StoreInfo, error) {
return types.StoreInfo{}, ErrNotImplemented
}
1 change: 1 addition & 0 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ type Store interface {
Delete(input types.DeleteItemInput) error
Close() error
Scan(input types.ScanInput) (types.ScanOutput, error)
Info() (types.StoreInfo, error)
}
5 changes: 5 additions & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ type ScanOutput struct {
Keys []string `dynamodbav:"k"`
Values [][]byte `dynamodbav:"v"`
}

type StoreInfo struct {
Name string
Size int64
}

0 comments on commit a837bd5

Please sign in to comment.