Skip to content

Commit

Permalink
*: misc additions to frostdb (#585)
Browse files Browse the repository at this point in the history
- Adds a method that returns all columnstore database names
- Adds an option to limit recovery concurrency
  • Loading branch information
asubiotto authored Nov 6, 2023
1 parent 0a6fc10 commit 9b8bc02
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion db.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type ColumnStore struct {
manualBlockRotation bool
snapshotTriggerSize int64
metrics metrics
recoveryConcurrency int

// indexDegree is the degree of the btree index (default = 2)
indexDegree int
Expand Down Expand Up @@ -262,6 +263,16 @@ func WithSnapshotTriggerSize(size int64) Option {
}
}

// WithRecoveryConcurrency limits the number of databases that are recovered
// simultaneously when calling frostdb.New. This helps limit memory usage on
// recovery.
func WithRecoveryConcurrency(concurrency int) Option {
return func(s *ColumnStore) error {
s.recoveryConcurrency = concurrency
return nil
}
}

// Close persists all data from the columnstore to storage.
// It is no longer valid to use the coumnstore for reads or writes, and the object should not longer be reused.
func (s *ColumnStore) Close() error {
Expand Down Expand Up @@ -315,7 +326,10 @@ func (s *ColumnStore) recoverDBsFromStorage(ctx context.Context) error {

g, ctx := errgroup.WithContext(ctx)
// Limit this operation since WAL recovery could be very memory intensive.
g.SetLimit(runtime.GOMAXPROCS(0))
if s.recoveryConcurrency == 0 {
s.recoveryConcurrency = runtime.GOMAXPROCS(0)
}
g.SetLimit(s.recoveryConcurrency)
for _, f := range files {
databaseName := f.Name()
g.Go(func() error {
Expand Down Expand Up @@ -599,6 +613,13 @@ func (s *ColumnStore) DB(ctx context.Context, name string, opts ...DBOption) (*D
return db, nil
}

// DBs returns all the DB names of this column store.
func (s *ColumnStore) DBs() []string {
s.mtx.RLock()
defer s.mtx.RUnlock()
return maps.Keys(s.dbs)
}

func (s *ColumnStore) GetDB(name string) (*DB, error) {
s.mtx.RLock()
defer s.mtx.RUnlock()
Expand Down

0 comments on commit 9b8bc02

Please sign in to comment.