github.com/pachyderm/pachyderm@v1.13.4/src/server/pkg/pfsdb/pfsdb.go (about)

     1  // Package pfsdb contains the database schema that PFS uses.
     2  package pfsdb
     3  
     4  import (
     5  	"path"
     6  
     7  	etcd "github.com/coreos/etcd/clientv3"
     8  	"github.com/pachyderm/pachyderm/src/client/pfs"
     9  	"github.com/pachyderm/pachyderm/src/client/pkg/errors"
    10  	col "github.com/pachyderm/pachyderm/src/server/pkg/collection"
    11  	"github.com/pachyderm/pachyderm/src/server/pkg/uuid"
    12  )
    13  
    14  const (
    15  	reposPrefix          = "/repos"
    16  	putFileRecordsPrefix = "/putFileRecords"
    17  	commitsPrefix        = "/commits"
    18  	branchesPrefix       = "/branches"
    19  	openCommitsPrefix    = "/openCommits"
    20  	mergesPrefix         = "/merges"
    21  	shardsPrefix         = "/shards"
    22  )
    23  
    24  var (
    25  	// ProvenanceIndex is a secondary index on provenance
    26  	ProvenanceIndex = &col.Index{Field: "Provenance", Multi: true}
    27  )
    28  
    29  // Repos returns a collection of repos
    30  func Repos(etcdClient *etcd.Client, etcdPrefix string) col.Collection {
    31  	return col.NewCollection(
    32  		etcdClient,
    33  		path.Join(etcdPrefix, reposPrefix),
    34  		nil,
    35  		&pfs.RepoInfo{},
    36  		nil,
    37  		nil,
    38  	)
    39  }
    40  
    41  // PutFileRecords returns a collection of putFileRecords
    42  func PutFileRecords(etcdClient *etcd.Client, etcdPrefix string) col.Collection {
    43  	return col.NewCollection(
    44  		etcdClient,
    45  		path.Join(etcdPrefix, putFileRecordsPrefix),
    46  		nil,
    47  		&pfs.PutFileRecords{},
    48  		nil,
    49  		nil,
    50  	)
    51  }
    52  
    53  // Commits returns a collection of commits
    54  func Commits(etcdClient *etcd.Client, etcdPrefix string, repo string) col.Collection {
    55  	return col.NewCollection(
    56  		etcdClient,
    57  		path.Join(etcdPrefix, commitsPrefix, repo),
    58  		[]*col.Index{ProvenanceIndex},
    59  		&pfs.CommitInfo{},
    60  		nil,
    61  		nil,
    62  	)
    63  }
    64  
    65  // Branches returns a collection of branches
    66  func Branches(etcdClient *etcd.Client, etcdPrefix string, repo string) col.Collection {
    67  	return col.NewCollection(
    68  		etcdClient,
    69  		path.Join(etcdPrefix, branchesPrefix, repo),
    70  		nil,
    71  		&pfs.BranchInfo{},
    72  		func(key string) error {
    73  			if uuid.IsUUIDWithoutDashes(key) {
    74  				return errors.Errorf("branch name cannot be a UUID V4")
    75  			}
    76  			return nil
    77  		},
    78  		nil,
    79  	)
    80  }
    81  
    82  // OpenCommits returns a collection of open commits
    83  func OpenCommits(etcdClient *etcd.Client, etcdPrefix string) col.Collection {
    84  	return col.NewCollection(
    85  		etcdClient,
    86  		path.Join(etcdPrefix, openCommitsPrefix),
    87  		nil,
    88  		&pfs.Commit{},
    89  		nil,
    90  		nil,
    91  	)
    92  }