Skip to content

Commit

Permalink
asdf
Browse files Browse the repository at this point in the history
  • Loading branch information
firelizzard18 committed Apr 11, 2024
1 parent a55ccb6 commit 6dd25de
Show file tree
Hide file tree
Showing 15 changed files with 331 additions and 57 deletions.
23 changes: 23 additions & 0 deletions cmd/accumulated/run/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,29 @@ MemoryStorage:
fields: ~

BadgerStorage:
union: { type: storage }
non-binary: true
fields:
- name: Path
type: string
- name: Version
type: int

BoltStorage:
union: { type: storage }
non-binary: true
fields:
- name: Path
type: string

LevelDBStorage:
union: { type: storage }
non-binary: true
fields:
- name: Path
type: string

ExpBlockDBStorage:
union: { type: storage }
non-binary: true
fields:
Expand Down
7 changes: 7 additions & 0 deletions cmd/accumulated/run/enums.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ StorageType:
value: 1
Badger:
value: 2
Bolt:
value: 3
LevelDB:
value: 4

ExpBlockDB:
value: 1001

ConfigurationType:
CoreValidator:
Expand Down
23 changes: 22 additions & 1 deletion cmd/accumulated/run/enums_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ const StorageTypeMemory StorageType = 1
// StorageTypeBadger .
const StorageTypeBadger StorageType = 2

// StorageTypeBolt .
const StorageTypeBolt StorageType = 3

// StorageTypeLevelDB .
const StorageTypeLevelDB StorageType = 4

// StorageTypeExpBlockDB .
const StorageTypeExpBlockDB StorageType = 1001

// GetEnumValue returns the value of the Configuration Type
func (v ConfigurationType) GetEnumValue() uint64 { return uint64(v) }

Expand Down Expand Up @@ -363,7 +372,7 @@ func (v StorageType) GetEnumValue() uint64 { return uint64(v) }
func (v *StorageType) SetEnumValue(id uint64) bool {
u := StorageType(id)
switch u {
case StorageTypeMemory, StorageTypeBadger:
case StorageTypeMemory, StorageTypeBadger, StorageTypeBolt, StorageTypeLevelDB, StorageTypeExpBlockDB:
*v = u
return true
}
Expand All @@ -377,6 +386,12 @@ func (v StorageType) String() string {
return "memory"
case StorageTypeBadger:
return "badger"
case StorageTypeBolt:
return "bolt"
case StorageTypeLevelDB:
return "levelDB"
case StorageTypeExpBlockDB:
return "expBlockDB"
}
return fmt.Sprintf("StorageType:%d", v)
}
Expand All @@ -388,6 +403,12 @@ func StorageTypeByName(name string) (StorageType, bool) {
return StorageTypeMemory, true
case "badger":
return StorageTypeBadger, true
case "bolt":
return StorageTypeBolt, true
case "leveldb":
return StorageTypeLevelDB, true
case "expblockdb":
return StorageTypeExpBlockDB, true
}
return 0, false
}
Expand Down
64 changes: 58 additions & 6 deletions cmd/accumulated/run/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
package run

import (
"io"

"gitlab.com/accumulatenetwork/accumulate/exp/ioc"
"gitlab.com/accumulatenetwork/accumulate/pkg/database/keyvalue"
"gitlab.com/accumulatenetwork/accumulate/pkg/database/keyvalue/badger"
"gitlab.com/accumulatenetwork/accumulate/pkg/database/keyvalue/block"
"gitlab.com/accumulatenetwork/accumulate/pkg/database/keyvalue/bolt"
"gitlab.com/accumulatenetwork/accumulate/pkg/database/keyvalue/leveldb"
"gitlab.com/accumulatenetwork/accumulate/pkg/database/keyvalue/memory"
"golang.org/x/exp/slog"
)
Expand Down Expand Up @@ -84,17 +89,64 @@ func (s *MemoryStorage) open(inst *Instance) (keyvalue.Beginner, error) {
}

func (s *BadgerStorage) open(inst *Instance) (keyvalue.Beginner, error) {
db, err := badger.New(inst.path(s.Path))
var db interface {
keyvalue.Beginner
io.Closer
}
var err error
switch s.Version {
case 0, 1:
db, err = badger.OpenV1(inst.path(s.Path))
case 2:
db, err = badger.OpenV2(inst.path(s.Path))
case 3:
db, err = badger.OpenV3(inst.path(s.Path))
case 4:
db, err = badger.OpenV4(inst.path(s.Path))
}
if err != nil {
return nil, err
}

inst.cleanup(func() {
err := db.Close()
inst.cleanupCloser(db, "Error while closing database")
return db, nil
}

func (s *BoltStorage) open(inst *Instance) (keyvalue.Beginner, error) {
db, err := bolt.Open(inst.path(s.Path))
if err != nil {
return nil, err
}

inst.cleanupCloser(db, "Error while closing database")
return db, nil
}

func (s *LevelDBStorage) open(inst *Instance) (keyvalue.Beginner, error) {
db, err := leveldb.Open(inst.path(s.Path))
if err != nil {
return nil, err
}

inst.cleanupCloser(db, "Error while closing database")
return db, nil
}

func (s *ExpBlockDBStorage) open(inst *Instance) (keyvalue.Beginner, error) {
db, err := block.Open(inst.path(s.Path))
if err != nil {
return nil, err
}

inst.cleanupCloser(db, "Error while closing database")
return db, nil
}

func (i *Instance) cleanupCloser(c io.Closer, msg string) {
i.cleanup(func() {
err := c.Close()
if err != nil {
slog.ErrorCtx(inst.context, "Error while closing Badger", "error", err)
slog.ErrorCtx(i.context, msg, "error", err)
}
})

return db, nil
}
Loading

0 comments on commit 6dd25de

Please sign in to comment.