forked from coreos/torus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
local_server.go
74 lines (65 loc) · 1.35 KB
/
local_server.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
65
66
67
68
69
70
71
72
73
74
package torus
import (
"os"
"path/filepath"
"github.com/coreos/torus/models"
)
func MkdirsFor(dir string) error {
if dir == "" {
return nil
}
err := os.MkdirAll(dir, 0700)
if err != nil {
return err
}
err = os.MkdirAll(filepath.Join(dir, "metadata"), 0700)
if err != nil {
return err
}
err = os.MkdirAll(filepath.Join(dir, "block"), 0700)
if err != nil {
return err
}
return nil
}
func NewServer(cfg Config, metadataServiceKind, blockStoreKind string) (*Server, error) {
err := MkdirsFor(cfg.DataDir)
if err != nil {
return nil, err
}
mds, err := CreateMetadataService(metadataServiceKind, cfg)
if err != nil {
return nil, err
}
global, err := mds.GlobalMetadata()
if err != nil {
return nil, err
}
blocks, err := CreateBlockStore(blockStoreKind, "current", cfg, global)
if err != nil {
return nil, err
}
return NewServerByImpl(cfg, mds, blocks)
}
func NewMemoryServer() *Server {
cfg := Config{
StorageSize: 100 * 1024 * 1024,
}
x, err := NewServer(cfg, "temp", "temp")
if err != nil {
panic(err)
}
return x
}
func NewServerByImpl(cfg Config, mds MetadataService, blocks BlockStore) (*Server, error) {
return &Server{
Blocks: blocks,
MDS: mds,
INodes: NewINodeStore(blocks),
peersMap: make(map[string]*models.PeerInfo),
Cfg: cfg,
peerInfo: &models.PeerInfo{
UUID: mds.UUID(),
},
}, nil
}