forked from pachyderm/pachyderm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pfsdb.go
85 lines (76 loc) · 2.04 KB
/
pfsdb.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
75
76
77
78
79
80
81
82
83
84
85
// Package pfsdb contains the database schema that PFS uses.
package pfsdb
import (
"fmt"
"path"
etcd "github.com/coreos/etcd/clientv3"
"github.com/pachyderm/pachyderm/src/client/pfs"
"github.com/pachyderm/pachyderm/src/client/pkg/uuid"
col "github.com/pachyderm/pachyderm/src/server/pkg/collection"
)
const (
reposPrefix = "/repos"
repoRefCountsPrefix = "/repoRefCounts"
commitsPrefix = "/commits"
branchesPrefix = "/branches"
openCommitsPrefix = "/openCommits"
)
var (
// ProvenanceIndex is a secondary index on provenance
ProvenanceIndex = col.Index{"Provenance", true}
)
// Repos returns a collection of repos
func Repos(etcdClient *etcd.Client, etcdPrefix string) col.Collection {
return col.NewCollection(
etcdClient,
path.Join(etcdPrefix, reposPrefix),
[]col.Index{ProvenanceIndex},
&pfs.RepoInfo{},
nil,
)
}
// RepoRefCounts returns a collection of repo ref counts
func RepoRefCounts(etcdClient *etcd.Client, etcdPrefix string) col.Collection {
return col.NewCollection(
etcdClient,
path.Join(etcdPrefix, repoRefCountsPrefix),
nil,
nil,
nil,
)
}
// Commits returns a collection of commits
func Commits(etcdClient *etcd.Client, etcdPrefix string, repo string) col.Collection {
return col.NewCollection(
etcdClient,
path.Join(etcdPrefix, commitsPrefix, repo),
[]col.Index{ProvenanceIndex},
&pfs.CommitInfo{},
nil,
)
}
// Branches returns a collection of branches
func Branches(etcdClient *etcd.Client, etcdPrefix string, repo string) col.Collection {
return col.NewCollection(
etcdClient,
path.Join(etcdPrefix, branchesPrefix, repo),
nil,
&pfs.Commit{},
func(key string) error {
if len(key) == uuid.UUIDWithoutDashesLength {
return fmt.Errorf("branch name cannot be of the same length as commit IDs")
}
return nil
},
)
}
// OpenCommits returns a collection of open commits
func OpenCommits(etcdClient *etcd.Client, etcdPrefix string) col.Collection {
return col.NewCollection(
etcdClient,
path.Join(etcdPrefix, openCommitsPrefix),
nil,
&pfs.Commit{},
nil,
)
}