Documentation ¶
Overview ¶
Package praefect is a Gitaly reverse proxy for transparently routing gRPC calls to a set of Gitaly services.
Index ¶
- Variables
- func GetBuildTime() string
- func GetVersion() string
- func GetVersionString() string
- func NewBackchannelServerFactory(logger *logrus.Entry, refSvc gitalypb.RefTransactionServer, ...) backchannel.ServerFactory
- func NewClockSyncCheck(...) func(_ config.Config, _ io.Writer, _ bool) *Check
- func NewGRPCServer(conf config.Config, logger *logrus.Entry, registry *protoregistry.Registry, ...) *grpc.Server
- func RemoveRepositoryHandler(rs datastore.RepositoryStore, conns Connections) grpc.StreamHandler
- func RepositoryExistsHandler(rs datastore.RepositoryStore) grpc.StreamHandler
- func WithDelayMetric(h prommetrics.HistogramVec) func(*ReplMgr)
- func WithDequeueBatchSize(size uint) func(*ReplMgr)
- func WithLatencyMetric(h prommetrics.HistogramVec) func(*ReplMgr)
- func WithParallelStorageProcessingWorkers(n uint) func(*ReplMgr)
- type AssignmentGetter
- type AssignmentStore
- type Backoff
- type BackoffFactory
- type BackoffReset
- type Check
- func NewGitalyNodeConnectivityCheck(conf config.Config, w io.Writer, quiet bool) *Check
- func NewPostgresReadWriteCheck(conf config.Config, w io.Writer, quiet bool) *Check
- func NewPraefectMigrationCheck(conf config.Config, w io.Writer, quiet bool) *Check
- func NewUnavailableReposCheck(conf config.Config, w io.Writer, quiet bool) *Check
- type CheckFunc
- type Connections
- type Coordinator
- type ExpBackoffFactory
- type HealthChecker
- type Node
- type NodeSet
- type PerRepositoryRouter
- func (r *PerRepositoryRouter) RouteRepositoryAccessor(ctx context.Context, virtualStorage, relativePath string, forcePrimary bool) (RepositoryAccessorRoute, error)
- func (r *PerRepositoryRouter) RouteRepositoryCreation(ctx context.Context, ...) (RepositoryMutatorRoute, error)
- func (r *PerRepositoryRouter) RouteRepositoryMutator(ctx context.Context, ...) (RepositoryMutatorRoute, error)
- func (r *PerRepositoryRouter) RouteStorageAccessor(ctx context.Context, virtualStorage string) (RouterNode, error)
- func (r *PerRepositoryRouter) RouteStorageMutator(ctx context.Context, virtualStorage string) (StorageMutatorRoute, error)
- type PrimaryGetter
- type Random
- type ReplMgr
- func (r ReplMgr) Collect(ch chan<- prometheus.Metric)
- func (r ReplMgr) Describe(ch chan<- *prometheus.Desc)
- func (r ReplMgr) ProcessBacklog(ctx context.Context, b BackoffFactory)
- func (r ReplMgr) ProcessReplicationEvent(ctx context.Context, event datastore.ReplicationEvent, ...) error
- func (r ReplMgr) ProcessStale(ctx context.Context, ticker helper.Ticker, staleAfter time.Duration) chan struct{}
- type ReplMgrOpt
- type Replicator
- type RepositoryAccessorRoute
- type RepositoryMutatorRoute
- type Router
- type RouterNode
- type ServerFactory
- type Severity
- type StaticHealthChecker
- type StorageMutatorRoute
Constants ¶
This section is empty.
Variables ¶
var ErrNoHealthyNodes = errors.New("no healthy nodes")
ErrNoHealthyNodes is returned when there are no healthy nodes to serve a request.
var ErrNoSuitableNode = errors.New("no suitable node to serve the request")
ErrNoSuitableNode is returned when there is not suitable node to serve a request.
var ErrRepositoryReadOnly = helper.ErrFailedPreconditionf("repository is in read-only mode")
ErrRepositoryReadOnly is returned when the repository is in read-only mode. This happens if the primary does not have the latest changes.
Functions ¶
func GetBuildTime ¶
func GetBuildTime() string
GetBuildTime returns the time at which the build took place
func GetVersionString ¶
func GetVersionString() string
GetVersionString returns a standard version header
func NewBackchannelServerFactory ¶
func NewBackchannelServerFactory(logger *logrus.Entry, refSvc gitalypb.RefTransactionServer, registry *sidechannel.Registry) backchannel.ServerFactory
NewBackchannelServerFactory returns a ServerFactory that serves the RefTransactionServer on the backchannel connection.
func NewClockSyncCheck ¶ added in v14.8.0
func NewClockSyncCheck(clockDriftCheck func(ntpHost string, driftThreshold time.Duration) (bool, error)) func(_ config.Config, _ io.Writer, _ bool) *Check
NewClockSyncCheck returns a function that returns a check that verifies if system clock is in sync.
func NewGRPCServer ¶
func NewGRPCServer( conf config.Config, logger *logrus.Entry, registry *protoregistry.Registry, director proxy.StreamDirector, txMgr *transactions.Manager, rs datastore.RepositoryStore, assignmentStore AssignmentStore, conns Connections, primaryGetter PrimaryGetter, creds credentials.TransportCredentials, grpcOpts ...grpc.ServerOption, ) *grpc.Server
NewGRPCServer returns gRPC server with registered proxy-handler and actual services praefect serves on its own. It includes a set of unary and stream interceptors required to add logging, authentication, etc.
func RemoveRepositoryHandler ¶ added in v14.5.0
func RemoveRepositoryHandler(rs datastore.RepositoryStore, conns Connections) grpc.StreamHandler
RemoveRepositoryHandler intercepts RemoveRepository calls, deletes the database records and deletes the repository from every backing Gitaly node.
func RepositoryExistsHandler ¶ added in v14.4.0
func RepositoryExistsHandler(rs datastore.RepositoryStore) grpc.StreamHandler
RepositoryExistsHandler handles /gitaly.RepositoryService/RepositoryExists calls by checking whether there is a record of the repository in the database.
func WithDelayMetric ¶
func WithDelayMetric(h prommetrics.HistogramVec) func(*ReplMgr)
WithDelayMetric is an option to set the delay prometheus metric
func WithDequeueBatchSize ¶
WithDequeueBatchSize configures the number of events to dequeue in a single batch.
func WithLatencyMetric ¶
func WithLatencyMetric(h prommetrics.HistogramVec) func(*ReplMgr)
WithLatencyMetric is an option to set the latency prometheus metric
func WithParallelStorageProcessingWorkers ¶ added in v14.4.0
WithParallelStorageProcessingWorkers configures the number of workers used to process replication events per virtual storage.
Types ¶
type AssignmentGetter ¶
type AssignmentGetter interface { // GetHostAssignments returns the names of the storages assigned to host the repository. // The primary node must always be assigned. GetHostAssignments(ctx context.Context, virtualStorage string, repositoryID int64) ([]string, error) }
AssignmentGetter is an interface for getting repository host node assignments.
type AssignmentStore ¶
type AssignmentStore interface { AssignmentGetter // SetReplicationFactor sets a repository's replication factor to the desired value and returns the // resulting assignments. SetReplicationFactor(ctx context.Context, virtualStorage, relativePath string, replicationFactor int) ([]string, error) }
AssignmentStore is the interface which Praefect uses to operate on repository assignments.
func NewDisabledAssignmentStore ¶
func NewDisabledAssignmentStore(storages map[string][]string) AssignmentStore
NewDisabledAssignmentStore returns an assignments store that can be used if no database is configured. It returns every configured storage as assigned and errors when trying to set assignments.
type BackoffFactory ¶ added in v14.4.0
type BackoffFactory interface { // Create return new backoff provider and a reset function for it. Create() (Backoff, BackoffReset) }
BackoffFactory creates backoff function and a reset pair for it.
type Check ¶ added in v14.5.0
type Check struct { Run func(ctx context.Context) error Name string Description string Severity Severity }
Check is a struct representing a check on the health of a Gitaly cluster's setup. These are separate from the "healthcheck" concept which is more concerned with the health of the praefect service. These checks are meant to diagnose any issues with the praefect cluster setup itself and will be run on startup/restarts.
func NewGitalyNodeConnectivityCheck ¶ added in v14.5.0
NewGitalyNodeConnectivityCheck returns a check that ensures Praefect can talk to all nodes of all virtual storages
func NewPostgresReadWriteCheck ¶ added in v14.6.0
NewPostgresReadWriteCheck returns a check that ensures Praefect can read and write to the database
func NewPraefectMigrationCheck ¶ added in v14.5.0
NewPraefectMigrationCheck returns a Check that checks if all praefect migrations have run
type CheckFunc ¶ added in v14.5.0
CheckFunc is a function type that takes a praefect config and returns a Check
type Connections ¶
type Connections map[string]map[string]*grpc.ClientConn
Connections is a set of connections to configured storage nodes by their virtual storages.
type Coordinator ¶
type Coordinator struct {
// contains filtered or unexported fields
}
Coordinator takes care of directing client requests to the appropriate downstream server. The coordinator is thread safe; concurrent calls to register nodes are safe.
func NewCoordinator ¶
func NewCoordinator( queue datastore.ReplicationEventQueue, rs datastore.RepositoryStore, router Router, txMgr *transactions.Manager, conf config.Config, r *protoregistry.Registry, ) *Coordinator
NewCoordinator returns a new Coordinator that utilizes the provided logger
func (*Coordinator) Collect ¶
func (c *Coordinator) Collect(metrics chan<- prometheus.Metric)
nolint: revive,stylecheck // This is unintentionally missing documentation.
func (*Coordinator) Describe ¶
func (c *Coordinator) Describe(descs chan<- *prometheus.Desc)
nolint: revive,stylecheck // This is unintentionally missing documentation.
func (*Coordinator) StreamDirector ¶
func (c *Coordinator) StreamDirector(ctx context.Context, fullMethodName string, peeker proxy.StreamPeeker) (*proxy.StreamParameters, error)
StreamDirector determines which downstream servers receive requests
type ExpBackoffFactory ¶ added in v14.4.0
ExpBackoffFactory creates exponentially growing durations.
func (ExpBackoffFactory) Create ¶ added in v14.4.0
func (b ExpBackoffFactory) Create() (Backoff, BackoffReset)
Create returns a backoff function based on Start and Max time durations.
type HealthChecker ¶
type HealthChecker interface { // HealthyNodes gets a list of healthy storages by their virtual storage. HealthyNodes() map[string][]string }
HealthChecker manages information of locally healthy nodes.
type Node ¶
type Node struct { // Storage is the name of the storage node. Storage string // Address is the address of the node. Address string // Token is the authentication token of the node. Token string // Connection is a gRPC connection to the storage node. Connection *grpc.ClientConn }
Node is a storage node in a virtual storage.
type NodeSet ¶
NodeSet contains nodes by their virtual storage and storage names.
func DialNodes ¶
func DialNodes( ctx context.Context, virtualStorages []*config.VirtualStorage, registry *protoregistry.Registry, errorTracker tracker.ErrorTracker, handshaker client.Handshaker, sidechannelRegistry *sidechannel.Registry, ) (NodeSet, error)
DialNodes dials the configured storage nodes.
func NodeSetFromNodeManager ¶
NodeSetFromNodeManager converts connections set up by the node manager in to a NodeSet. This is a temporary adapter required due to cyclic imports between the praefect and nodes packages.
func (NodeSet) Close ¶
func (set NodeSet) Close()
Close closes the connections in the NodeSet. Errors on closing are ignored.
func (NodeSet) Connections ¶
func (set NodeSet) Connections() Connections
Connections is a convenience method to return the connections from the NodeSet.
func (NodeSet) HealthClients ¶
func (set NodeSet) HealthClients() nodes.HealthClients
HealthClients is a convenience method to return the HealthClients from the NodeSet.
type PerRepositoryRouter ¶
type PerRepositoryRouter struct {
// contains filtered or unexported fields
}
PerRepositoryRouter implements a router that routes requests respecting per repository primary nodes.
func NewPerRepositoryRouter ¶
func NewPerRepositoryRouter( conns Connections, pg PrimaryGetter, hc HealthChecker, rand Random, csg datastore.ConsistentStoragesGetter, ag AssignmentGetter, rs datastore.RepositoryStore, defaultReplicationFactors map[string]int) *PerRepositoryRouter
NewPerRepositoryRouter returns a new PerRepositoryRouter using the passed configuration.
func (*PerRepositoryRouter) RouteRepositoryAccessor ¶
func (r *PerRepositoryRouter) RouteRepositoryAccessor(ctx context.Context, virtualStorage, relativePath string, forcePrimary bool) (RepositoryAccessorRoute, error)
nolint: revive,stylecheck // This is unintentionally missing documentation.
func (*PerRepositoryRouter) RouteRepositoryCreation ¶
func (r *PerRepositoryRouter) RouteRepositoryCreation(ctx context.Context, virtualStorage, relativePath, additionalRelativePath string) (RepositoryMutatorRoute, error)
RouteRepositoryCreation picks a random healthy node to act as the primary node and selects the secondary nodes if assignments are enabled. Healthy secondaries take part in the transaction, unhealthy secondaries are set as replication targets.
func (*PerRepositoryRouter) RouteRepositoryMutator ¶
func (r *PerRepositoryRouter) RouteRepositoryMutator(ctx context.Context, virtualStorage, relativePath, additionalRelativePath string) (RepositoryMutatorRoute, error)
nolint: revive,stylecheck // This is unintentionally missing documentation.
func (*PerRepositoryRouter) RouteStorageAccessor ¶
func (r *PerRepositoryRouter) RouteStorageAccessor(ctx context.Context, virtualStorage string) (RouterNode, error)
RouteStorageAccessor routes requests for storage-scoped accessor RPCs. The only storage scoped accessor RPC is RemoteService/FindRemoteRepository, which in turn executes a command without a repository. This can be done by any Gitaly server as it doesn't depend on the state on the server.
func (*PerRepositoryRouter) RouteStorageMutator ¶
func (r *PerRepositoryRouter) RouteStorageMutator(ctx context.Context, virtualStorage string) (StorageMutatorRoute, error)
RouteStorageMutator is not implemented here. The only storage scoped mutator RPC is related to namespace operations. These are not relevant anymore, given hashed storage is default everywhere, and should be eventually removed.
type PrimaryGetter ¶
type PrimaryGetter interface { // GetPrimary returns the primary storage for a given repository. GetPrimary(ctx context.Context, virtualStorage string, repositoryID int64) (string, error) }
PrimaryGetter is an interface for getting a primary of a repository.
type Random ¶
type Random interface { // Intn returns a random integer in the range [0,n). Intn(n int) int // Shuffle pseudo-randomizes the order of elements. n is the number of elements. // Shuffle panics if n < 0. swap swaps the elements with indexes i and j. Shuffle(n int, swap func(i, j int)) }
Random is the interface of the Go random number generator.
func NewLockedRandom ¶
NewLockedRandom wraps the passed in Random to make it safe for concurrent use.
type ReplMgr ¶
type ReplMgr struct {
// contains filtered or unexported fields
}
ReplMgr is a replication manager for handling replication jobs
func NewReplMgr ¶
func NewReplMgr(log logrus.FieldLogger, storageNames map[string][]string, queue datastore.ReplicationEventQueue, rs datastore.RepositoryStore, hc HealthChecker, nodes NodeSet, opts ...ReplMgrOpt) ReplMgr
NewReplMgr initializes a replication manager with the provided dependencies and options
func (ReplMgr) Collect ¶
func (r ReplMgr) Collect(ch chan<- prometheus.Metric)
nolint: revive,stylecheck // This is unintentionally missing documentation.
func (ReplMgr) Describe ¶
func (r ReplMgr) Describe(ch chan<- *prometheus.Desc)
nolint: revive,stylecheck // This is unintentionally missing documentation.
func (ReplMgr) ProcessBacklog ¶
func (r ReplMgr) ProcessBacklog(ctx context.Context, b BackoffFactory)
ProcessBacklog starts processing of queued jobs. It will be processing jobs until ctx is Done. ProcessBacklog blocks until all backlog processing goroutines have returned
func (ReplMgr) ProcessReplicationEvent ¶ added in v14.6.0
func (r ReplMgr) ProcessReplicationEvent(ctx context.Context, event datastore.ReplicationEvent, targetCC *grpc.ClientConn) error
ProcessReplicationEvent processes a single replication event given the target client connection
type ReplMgrOpt ¶
type ReplMgrOpt func(*ReplMgr)
ReplMgrOpt allows a replicator to be configured with additional options
type Replicator ¶
type Replicator interface { // Replicate propagates changes from the source to the target Replicate(ctx context.Context, event datastore.ReplicationEvent, source, target *grpc.ClientConn) error // Destroy will remove the target repo on the specified target connection Destroy(ctx context.Context, event datastore.ReplicationEvent, target *grpc.ClientConn) error // Rename will rename(move) the target repo on the specified target connection Rename(ctx context.Context, event datastore.ReplicationEvent, target *grpc.ClientConn) error // GarbageCollect will run gc on the target repository GarbageCollect(ctx context.Context, event datastore.ReplicationEvent, target *grpc.ClientConn) error // RepackFull will do a full repack on the target repository RepackFull(ctx context.Context, event datastore.ReplicationEvent, target *grpc.ClientConn) error // RepackIncremental will do an incremental repack on the target repository RepackIncremental(ctx context.Context, event datastore.ReplicationEvent, target *grpc.ClientConn) error // Cleanup will do a cleanup on the target repository Cleanup(ctx context.Context, event datastore.ReplicationEvent, target *grpc.ClientConn) error // PackRefs will optimize references on the target repository PackRefs(ctx context.Context, event datastore.ReplicationEvent, target *grpc.ClientConn) error // WriteCommitGraph will optimize references on the target repository WriteCommitGraph(ctx context.Context, event datastore.ReplicationEvent, target *grpc.ClientConn) error // MidxRepack will optimize references on the target repository MidxRepack(ctx context.Context, event datastore.ReplicationEvent, target *grpc.ClientConn) error // OptimizeRepository will optimize the target repository OptimizeRepository(ctx context.Context, event datastore.ReplicationEvent, target *grpc.ClientConn) error // PruneUnreachableObjects prunes unreachable objects from the target repository PruneUnreachableObjects(ctx context.Context, event datastore.ReplicationEvent, target *grpc.ClientConn) error }
Replicator performs the actual replication logic between two nodes
type RepositoryAccessorRoute ¶ added in v14.5.0
type RepositoryAccessorRoute struct { // ReplicaPath is the disk path where the replicas are stored. ReplicaPath string // Node contains the details of the node that should handle the request. Node RouterNode }
RepositoryAccessorRoute describes how to route a repository scoped accessor call.
type RepositoryMutatorRoute ¶
type RepositoryMutatorRoute struct { // RepositoryID is the repository's ID as Praefect identifies it. RepositoryID int64 // ReplicaPath is the disk path where the replicas are stored. ReplicaPath string // AdditionalReplicaPath is the disk path where the possible additional repository in the request // is stored. This is only used for object pools. AdditionalReplicaPath string // Primary is the primary node of the transaction. Primary RouterNode // Secondaries are the secondary participating in a transaction. Secondaries []RouterNode // ReplicationTargets are additional nodes that do not participate in a transaction // but need the changes replicated. ReplicationTargets []string }
RepositoryMutatorRoute describes how to route a repository scoped mutator call.
type Router ¶
type Router interface { // RouteStorageAccessor returns the node which should serve the storage accessor request. RouteStorageAccessor(ctx context.Context, virtualStorage string) (RouterNode, error) // RouteStorageAccessor returns the primary and secondaries that should handle the storage // mutator request. RouteStorageMutator(ctx context.Context, virtualStorage string) (StorageMutatorRoute, error) // RouteRepositoryAccessor returns the node that should serve the repository accessor // request. If forcePrimary is set to `true`, it returns the primary node. RouteRepositoryAccessor(ctx context.Context, virtualStorage, relativePath string, forcePrimary bool) (RepositoryAccessorRoute, error) // RouteRepositoryMutatorTransaction returns the primary and secondaries that should handle the repository mutator request. // Additionally, it returns nodes which should have the change replicated to. RouteRepositoryMutator should only be used // with existing repositories. RouteRepositoryMutator(ctx context.Context, virtualStorage, relativePath, additionalRepoRelativePath string) (RepositoryMutatorRoute, error) // RouteRepositoryCreation decides returns the primary and secondaries that should handle the repository creation // request. It is up to the caller to store the assignments and primary information after finishing the RPC. RouteRepositoryCreation(ctx context.Context, virtualStorage, relativePath, additionalRepoRelativePath string) (RepositoryMutatorRoute, error) }
Router decides which nodes to direct accessor and mutator RPCs to.
func NewNodeManagerRouter ¶
func NewNodeManagerRouter(mgr nodes.Manager, rs datastore.RepositoryStore) Router
NewNodeManagerRouter returns a router that uses the NodeManager to make routing decisions.
type RouterNode ¶
type RouterNode struct { // Storage is storage of the node. Storage string // Connection is the connection to the node. Connection *grpc.ClientConn }
RouterNode is a subset of a node's configuration needed to perform request routing.
type ServerFactory ¶
type ServerFactory struct {
// contains filtered or unexported fields
}
ServerFactory is a factory of praefect grpc servers
func NewServerFactory ¶
func NewServerFactory( conf config.Config, logger *logrus.Entry, director proxy.StreamDirector, nodeMgr nodes.Manager, txMgr *transactions.Manager, queue datastore.ReplicationEventQueue, rs datastore.RepositoryStore, assignmentStore AssignmentStore, registry *protoregistry.Registry, conns Connections, primaryGetter PrimaryGetter, ) *ServerFactory
NewServerFactory returns factory object for initialization of praefect gRPC servers.
func (*ServerFactory) Create ¶
func (s *ServerFactory) Create(secure bool) (*grpc.Server, error)
Create returns newly instantiated and initialized with interceptors instance of the gRPC server.
func (*ServerFactory) GracefulStop ¶
func (s *ServerFactory) GracefulStop()
GracefulStop stops both the secure and insecure servers gracefully.
func (*ServerFactory) Serve ¶
func (s *ServerFactory) Serve(l net.Listener, secure bool) error
Serve starts serving on the provided listener with newly created grpc.Server
func (*ServerFactory) Stop ¶
func (s *ServerFactory) Stop()
Stop stops all servers created by the factory.
type Severity ¶ added in v14.5.0
type Severity string
Severity is a type that indicates the severity of a check
const ( // Warning indicates a severity level of warning Warning Severity = "warning" // Fatal indicates a severity level of fatal // any checks that are Fatal will prevent Praefect from starting up Fatal = "fatal" )
type StaticHealthChecker ¶
StaticHealthChecker returns the nodes as always healthy.
func (StaticHealthChecker) HealthyNodes ¶
func (healthyNodes StaticHealthChecker) HealthyNodes() map[string][]string
nolint: revive,stylecheck // This is unintentionally missing documentation.
type StorageMutatorRoute ¶
type StorageMutatorRoute struct { // Primary is the primary node of the routing decision. Primary RouterNode // Secondaries are the secondary nodes of the routing decision. Secondaries []RouterNode }
StorageMutatorRoute describes how to route a storage scoped mutator call.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package commonerr contains common errors between different Praefect components.
|
Package commonerr contains common errors between different Praefect components. |
Package datastore provides data models and datastore persistence abstractions for tracking the state of repository replicas.
|
Package datastore provides data models and datastore persistence abstractions for tracking the state of repository replicas. |
advisorylock
Package advisorylock contains the lock IDs of all advisory locks used in Praefect.
|
Package advisorylock contains the lock IDs of all advisory locks used in Praefect. |
glsql
Package glsql (Gitaly SQL) is a helper package to work with plain SQL queries.
|
Package glsql (Gitaly SQL) is a helper package to work with plain SQL queries. |
grpc-proxy
|
|
proxy
Package proxy provides a reverse proxy handler for gRPC.
|
Package proxy provides a reverse proxy handler for gRPC. |