Skip to content
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

User persister factory in storage unit #32

Merged
merged 4 commits into from
Dec 7, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fixes after review
  • Loading branch information
ssd04 committed Dec 5, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 873df9f557adae81613dce130ab6a801af6091e9
11 changes: 10 additions & 1 deletion storageUnit/storageunit.go
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ package storageUnit
import (
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"sync"
"time"
@@ -73,6 +74,9 @@ const MaxRetriesToCreateDB = 10
// SleepTimeBetweenCreateDBRetries represents the number of seconds to sleep between DB creates
const SleepTimeBetweenCreateDBRetries = 5 * time.Second

// ErrNilPersisterFactory signals that a nil persister factory handler has been provided
var ErrNilPersisterFactory = errors.New("nil persister factory")

// UnitConfig holds the configurable elements of the storage unit
type UnitConfig struct {
CacheConf CacheConfig
@@ -290,6 +294,7 @@ func NewStorageUnit(c types.Cacher, p types.Persister) (*Unit, error) {
// PersisterFactoryHandler defines the behaviour of a component which is able to create persisters
type PersisterFactoryHandler interface {
Create(path string) (types.Persister, error)
IsInterfaceNil() bool
}

// NewStorageUnitFromConf creates a new storage unit from a storage unit config
@@ -375,8 +380,12 @@ type ArgDB struct {

// NewDB creates a new database from database config
// TODO: refactor to integrate retries loop into persister factory; maybe implement persister
// factory separatelly in storage repo
// factory separatelly in storage repo
func NewDB(persisterFactory PersisterFactoryHandler, path string) (types.Persister, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for extra protection (even if this is temporary) I would add a nil check for the provided persisterFactory. Maybe make the interface implement NilInterfaceChecker interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added nil check

if check.IfNil(persisterFactory) {
return nil, ErrNilPersisterFactory
}

var db types.Persister
var err error