-
Notifications
You must be signed in to change notification settings - Fork 390
/
database.go
64 lines (52 loc) · 1.34 KB
/
database.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package bootstrapdb
import (
"github.com/zeebo/errs"
"storj.io/storj/bootstrap"
"storj.io/storj/pkg/kademlia"
"storj.io/storj/storage"
"storj.io/storj/storage/boltdb"
"storj.io/storj/storage/teststore"
)
var _ bootstrap.DB = (*DB)(nil)
// Config configures storage node database
type Config struct {
Kademlia string
}
// DB contains access to different database tables
type DB struct {
kdb, ndb storage.KeyValueStore
}
// New creates a new master database for storage node
func New(config Config) (*DB, error) {
dbs, err := boltdb.NewShared(config.Kademlia, kademlia.KademliaBucket, kademlia.NodeBucket)
if err != nil {
return nil, err
}
return &DB{
kdb: dbs[0],
ndb: dbs[1],
}, nil
}
// NewInMemory creates new inmemory master database for storage node
// TODO: still stores data on disk
func NewInMemory(storageDir string) (*DB, error) {
return &DB{
kdb: teststore.New(),
ndb: teststore.New(),
}, nil
}
// CreateTables initializes the database
func (db *DB) CreateTables() error { return nil }
// Close closes any resources.
func (db *DB) Close() error {
return errs.Combine(
db.kdb.Close(),
db.ndb.Close(),
)
}
// RoutingTable returns kademlia routing table
func (db *DB) RoutingTable() (kdb, ndb storage.KeyValueStore) {
return db.kdb, db.ndb
}