-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbfactory.go
58 lines (46 loc) · 1.67 KB
/
dbfactory.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
package doltswarm
import (
"context"
"fmt"
"net/url"
"github.com/dolthub/dolt/go/store/chunks"
"github.com/dolthub/dolt/go/store/datas"
"github.com/dolthub/dolt/go/store/prolly/tree"
"github.com/dolthub/dolt/go/store/types"
"github.com/sirupsen/logrus"
)
type ClientRetriever interface {
GetClient(peerID string) (*DBClient, error)
}
func NewDoltSwarmFactory(dbName string, clientRetriever ClientRetriever, logger *logrus.Entry) DoltSwarmFactory {
return DoltSwarmFactory{dbName, clientRetriever, logger}
}
type DoltSwarmFactory struct {
dbName string
clientRetriever ClientRetriever
logger *logrus.Entry
}
func (fact DoltSwarmFactory) PrepareDB(ctx context.Context, nbf *types.NomsBinFormat, urlObj *url.URL, params map[string]interface{}) error {
return nil
}
func (fact DoltSwarmFactory) CreateDB(ctx context.Context, nbf *types.NomsBinFormat, urlObj *url.URL, params map[string]interface{}) (datas.Database, types.ValueReadWriter, tree.NodeStore, error) {
cs, err := fact.newChunkStore(urlObj.Host, nbf.VersionString())
if err != nil {
return nil, nil, nil, err
}
vrw := types.NewValueStore(cs)
ns := tree.NewNodeStore(cs)
typesDB := datas.NewTypesDatabase(vrw, ns)
return typesDB, vrw, ns, nil
}
func (fact DoltSwarmFactory) newChunkStore(peerID string, nbfVersion string) (chunks.ChunkStore, error) {
client, err := fact.clientRetriever.GetClient(peerID)
if err != nil {
return nil, fmt.Errorf("could not get client for '%s': %w", peerID, err)
}
cs, err := NewRemoteChunkStore(client, peerID, fact.dbName, nbfVersion, fact.logger)
if err != nil {
return nil, fmt.Errorf("could not create remote cs for '%s': %w", peerID, err)
}
return cs, err
}