Skip to content

Commit

Permalink
Update keeper registry methods, add/update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
yunginnanet committed Jun 15, 2024
1 parent 4691789 commit 82d3f4f
Show file tree
Hide file tree
Showing 7 changed files with 269 additions and 5 deletions.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@

## Documentation

#### func AllKeepers

```go
func AllKeepers() map[string]KeeperCreator
```

#### func RegisterKeeper

```go
func RegisterKeeper(name string, keeper KeeperCreator)
```

#### type Filer

```go
Expand Down Expand Up @@ -53,17 +65,43 @@ type Keeper interface {
// With provides access to the given dataStore by providing a pointer to the related Filer.
With(name string) Store

// WithNew should initialize a new Filer at the given path.
WithNew(name string, options ...any) Filer

Discover() ([]string, error)

AllStores() map[string]Filer

Meta() models.Metadata

Close(name string) error

CloseAll() error
SyncAll() error
SyncAndCloseAll() error
}
```

Keeper will be in charge of the more meta operations involving Filers. This
includes operations like initialization, syncing to disk if applicable, and
backing up.

- When opening a folder of Filers, it should be able to discover and initialize all of them.
- Additionally, it should be able to confirm the type of the underlying key/value store.

#### type KeeperCreator

```go
type KeeperCreator func(path string) (Keeper, error)
```


#### func GetKeeper

```go
func GetKeeper(name string) KeeperCreator
```

#### type Searcher

```go
Expand All @@ -89,3 +127,5 @@ type Store interface {
```

Store is an implementation of a Filer and a Searcher.

---
88 changes: 88 additions & 0 deletions backup/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# backup



#### type BackupMetadata

```go
type BackupMetadata struct {
Date time.Time `json:"timestamp"`
FileFormat string `json:"format"`
FilePath string `json:"path"`
Stores []string `json:"stores,omitempty"`
Checksum Checksum `json:"checksum,omitempty"`
Size int64 `json:"size,omitempty"`
}
```


#### func (BackupMetadata) Format

```go
func (bm BackupMetadata) Format() string
```

#### func (BackupMetadata) Path

```go
func (bm BackupMetadata) Path() string
```

#### func (BackupMetadata) Timestamp

```go
func (bm BackupMetadata) Timestamp() time.Time
```

#### type Checksum

```go
type Checksum struct {
Type string `json:"type"`
Value string `json:"value"`
}
```


#### type Format

```go
type Format string
```


```go
const (
FormatTarGz Format = "tar.gz"
FormatTar Format = "tar"
FormatZip Format = "zip"
)
```

#### type TarGzBackup

```go
type TarGzBackup struct {
}
```


#### func NewTarGzBackup

```go
func NewTarGzBackup(inPath string, outPath string, stores []string, extraData ...[]byte) (*TarGzBackup, error)
```

#### func (*TarGzBackup) Format

```go
func (tgz *TarGzBackup) Format() string
```

#### func (*TarGzBackup) Metadata

```go
func (tgz *TarGzBackup) Metadata() BackupMetadata
```

---
2 changes: 1 addition & 1 deletion bitcask/reg.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package bitcask
import "git.tcp.direct/tcp.direct/database"

func init() {
database.Register("bitcask", func(path string) (database.Keeper, error) {
database.RegisterKeeper("bitcask", func(path string) (database.Keeper, error) {
db := OpenDB(path)
err := db.init()
return db, err
Expand Down
111 changes: 111 additions & 0 deletions metadata/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# metadata



#### type Metadata

```go
type Metadata struct {
KeeperType string `json:"type"`
Created time.Time `json:"created,omitempty"`
LastOpened time.Time `json:"last_opened,omitempty"`
KnownStores []string `json:"stores,omitempty"`
Backups map[string]models.Backup `json:"backups,omitempty"`
}
```

Metadata is a struct that holds the metadata for a [Keeper]'s DB. This is
critical for migrating data between [Keeper]s. The only absolute requirement is
that the [Type] field is set.

#### func NewMeta

```go
func NewMeta(keeperType string) *Metadata
```

#### func NewMetaFile

```go
func NewMetaFile(keeperType, path string) (*Metadata, error)
```

#### func OpenMetaFile

```go
func OpenMetaFile(path string) (*Metadata, error)
```

#### func (*Metadata) AddStore

```go
func (m *Metadata) AddStore(name string)
```

#### func (*Metadata) Close

```go
func (m *Metadata) Close() error
```

#### func (*Metadata) Ping

```go
func (m *Metadata) Ping()
```

#### func (*Metadata) RemoveStore

```go
func (m *Metadata) RemoveStore(name string)
```

#### func (*Metadata) Sync

```go
func (m *Metadata) Sync() error
```

#### func (*Metadata) Timestamp

```go
func (m *Metadata) Timestamp() time.Time
```

#### func (*Metadata) Type

```go
func (m *Metadata) Type() string
```

#### func (*Metadata) WithBackups

```go
func (m *Metadata) WithBackups(backups ...models.Backup) *Metadata
```

#### func (*Metadata) WithCreated

```go
func (m *Metadata) WithCreated(created time.Time) *Metadata
```

#### func (*Metadata) WithLastOpened

```go
func (m *Metadata) WithLastOpened(lastOpened time.Time) *Metadata
```

#### func (*Metadata) WithStores

```go
func (m *Metadata) WithStores(stores ...string) *Metadata
```

#### func (*Metadata) WithWriter

```go
func (m *Metadata) WithWriter(w io.WriteCloser) *Metadata
```

---
25 changes: 25 additions & 0 deletions models/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# models



#### type Backup

```go
type Backup interface {
Metadata() Metadata
Format() string
Path() string
}
```


#### type Metadata

```go
type Metadata interface {
Type() string
Timestamp() time.Time
}
```

---
2 changes: 1 addition & 1 deletion pogreb/reg.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package pogreb
import "git.tcp.direct/tcp.direct/database"

func init() {
database.Register("pogreb", func(path string) (database.Keeper, error) {
database.RegisterKeeper("pogreb", func(path string) (database.Keeper, error) {
db := OpenDB(path)
err := db.init()
return db, err
Expand Down
6 changes: 3 additions & 3 deletions reg.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ var (
regMu = &sync.RWMutex{}
)

func Register(name string, keeper KeeperCreator) {
func RegisterKeeper(name string, keeper KeeperCreator) {
regMu.Lock()
keepers[name] = keeper
regMu.Unlock()
}

func Get(name string) KeeperCreator {
func GetKeeper(name string) KeeperCreator {
regMu.RLock()
k := keepers[name]
regMu.RUnlock()
return k
}

func All() map[string]KeeperCreator {
func AllKeepers() map[string]KeeperCreator {
regMu.RLock()
ks := keepers
regMu.RUnlock()
Expand Down

0 comments on commit 82d3f4f

Please sign in to comment.