/
pfsdb.go
90 lines (81 loc) · 2.06 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
86
87
88
89
90
// 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"
col "github.com/pachyderm/pachyderm/src/server/pkg/collection"
"github.com/pachyderm/pachyderm/src/server/pkg/uuid"
)
const (
reposPrefix = "/repos"
putFileRecordsPrefix = "/putFileRecords"
commitsPrefix = "/commits"
branchesPrefix = "/branches"
openCommitsPrefix = "/openCommits"
)
var (
// ProvenanceIndex is a secondary index on provenance
ProvenanceIndex = &col.Index{Field: "Provenance", Multi: true}
)
// Repos returns a collection of repos
func Repos(etcdClient *etcd.Client, etcdPrefix string) col.Collection {
return col.NewCollection(
etcdClient,
path.Join(etcdPrefix, reposPrefix),
nil,
&pfs.RepoInfo{},
nil,
nil,
)
}
// PutFileRecords returns a collection of putFileRecords
func PutFileRecords(etcdClient *etcd.Client, etcdPrefix string) col.Collection {
return col.NewCollection(
etcdClient,
path.Join(etcdPrefix, putFileRecordsPrefix),
nil,
&pfs.PutFileRecords{},
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,
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.BranchInfo{},
func(key string) error {
if uuid.IsUUIDWithoutDashes(key) {
return fmt.Errorf("branch name cannot be a UUID V4")
}
return nil
},
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,
nil,
)
}