Skip to content

Commit

Permalink
Add constant value to make the code more readable (#568)
Browse files Browse the repository at this point in the history
* add memery size constant values to make the code more readable

* change the unit to kib, mib etc.

* change the unit from Tib to TiB

---------

Co-authored-by: Matthias Loibl <[email protected]>
  • Loading branch information
elliotchenzichang and metalmatze authored Oct 24, 2023
1 parent d1b841f commit c5dd467
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
12 changes: 10 additions & 2 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ import (
"github.com/polarsignals/frostdb/wal"
)

const (
B = 1
KiB = 1024 * B
MiB = 1024 * KiB
GiB = 1024 * MiB
TiB = 1024 * GiB
)

type ColumnStore struct {
mtx *sync.RWMutex
dbs map[string]*DB
Expand Down Expand Up @@ -89,8 +97,8 @@ func New(
indexConfig: DefaultIndexConfig(),
indexDegree: 2,
splitSize: 2,
granuleSizeBytes: 1 * 1024 * 1024, // 1MB granule size before splitting
activeMemorySize: 512 * 1024 * 1024, // 512MB
granuleSizeBytes: 1 * MiB,
activeMemorySize: 512 * MiB,
}

for _, option := range options {
Expand Down
16 changes: 8 additions & 8 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestDBWithWALAndBucket(t *testing.T) {
WithWAL(),
WithStoragePath(dir),
WithReadWriteStorage(sinksource),
WithActiveMemorySize(100*1024),
WithActiveMemorySize(100*KiB),
)
require.NoError(t, err)
db, err := c.DB(context.Background(), "test")
Expand All @@ -71,7 +71,7 @@ func TestDBWithWALAndBucket(t *testing.T) {
WithWAL(),
WithStoragePath(dir),
WithReadWriteStorage(sinksource),
WithActiveMemorySize(100*1024),
WithActiveMemorySize(100*KiB),
)
require.NoError(t, err)
defer c.Close()
Expand Down Expand Up @@ -1358,7 +1358,7 @@ func Test_DB_ReadOnlyQuery(t *testing.T) {
WithWAL(),
WithStoragePath(dir),
WithReadWriteStorage(sinksource),
WithActiveMemorySize(100*1024),
WithActiveMemorySize(100*KiB),
)
require.NoError(t, err)
db, err := c.DB(context.Background(), "test")
Expand All @@ -1383,7 +1383,7 @@ func Test_DB_ReadOnlyQuery(t *testing.T) {
WithWAL(),
WithStoragePath(dir),
WithReadWriteStorage(sinksource),
WithActiveMemorySize(100*1024),
WithActiveMemorySize(100*KiB),
)
require.NoError(t, err)
defer c.Close()
Expand Down Expand Up @@ -1867,7 +1867,7 @@ func Test_DB_DropStorage(t *testing.T) {
WithLogger(logger),
WithWAL(),
WithStoragePath(dir),
WithActiveMemorySize(1024*1024),
WithActiveMemorySize(1*MiB),
)
defer func() {
_ = c.Close()
Expand Down Expand Up @@ -1909,7 +1909,7 @@ func Test_DB_DropStorage(t *testing.T) {
WithLogger(logger),
WithWAL(),
WithStoragePath(dir),
WithActiveMemorySize(1024*1024),
WithActiveMemorySize(1*MiB),
)
defer func() {
_ = c.Close()
Expand Down Expand Up @@ -2009,8 +2009,8 @@ func Test_DB_SnapshotOnClose(t *testing.T) {
WithLogger(logger),
WithStoragePath(dir),
WithWAL(),
WithActiveMemorySize(1024*1024*1024),
WithSnapshotTriggerSize(1024*1024*1024),
WithActiveMemorySize(1*GiB),
WithSnapshotTriggerSize(1*GiB),
WithManualBlockRotation(),
)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion store.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (b *DefaultObjstoreBucket) openBlockFile(ctx context.Context, blockName str
file, err := parquet.OpenFile(
r,
size,
parquet.ReadBufferSize(5*1024*1024), // 5MB read buffers
parquet.ReadBufferSize(5*MiB), // 5MB read buffers
parquet.SkipBloomFilters(true),
parquet.FileReadMode(parquet.ReadModeAsync),
)
Expand Down
2 changes: 1 addition & 1 deletion table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ func Test_Table_DynamicColumnNotDefined(t *testing.T) {
func TestTableUniquePrimaryIndex(t *testing.T) {
c, err := New(WithGranuleSizeBytes(1), WithIndexConfig([]*index.LevelConfig{
{Level: index.L0, MaxSize: 180},
{Level: index.L1, MaxSize: 1024 * 1024 * 1024 * 1024},
{Level: index.L1, MaxSize: 1 * TiB},
}))
require.NoError(t, err)
defer c.Close()
Expand Down

0 comments on commit c5dd467

Please sign in to comment.