housekeeping

package
v15.9.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2023 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanupWorktrees

func CleanupWorktrees(ctx context.Context, repo *localrepo.Repo) error

CleanupWorktrees cleans up stale and disconnected worktrees for the given repository.

func FixDirectoryPermissions

func FixDirectoryPermissions(ctx context.Context, path string) error

FixDirectoryPermissions does a recursive directory walk to look for directories that cannot be accessed by the current user, and tries to fix those with chmod. The motivating problem is that directories with mode 0 break os.RemoveAll.

func GetRepackGitConfig

func GetRepackGitConfig(ctx context.Context, repo repository.GitRepo, bitmap bool) []git.ConfigPair

GetRepackGitConfig returns configuration suitable for Git commands which write new packfiles.

func RepackObjects

func RepackObjects(ctx context.Context, repo *localrepo.Repo, cfg RepackObjectsConfig) error

RepackObjects repacks objects in the given repository and updates the commit-graph. The way objects are repacked is determined via the RepackObjectsConfig.

func WriteCommitGraph

func WriteCommitGraph(ctx context.Context, repo *localrepo.Repo, cfg WriteCommitGraphConfig) error

WriteCommitGraph updates the commit-graph in the given repository. The commit-graph is updated incrementally, except in the case where it doesn't exist yet or in case it is detected that the commit-graph is missing bloom filters.

Types

type EagerOptimizationStrategy added in v15.6.0

type EagerOptimizationStrategy struct {
	// contains filtered or unexported fields
}

EagerOptimizationStrategy is a strategy that will eagerly perform optimizations. All of the data structures will be optimized regardless of whether they already are in an optimal state or not.

func NewEagerOptimizationStrategy added in v15.6.0

func NewEagerOptimizationStrategy(info stats.RepositoryInfo) EagerOptimizationStrategy

NewEagerOptimizationStrategy creates a new EagerOptimizationStrategy.

func (EagerOptimizationStrategy) ShouldPruneObjects added in v15.6.0

func (s EagerOptimizationStrategy) ShouldPruneObjects(context.Context) bool

ShouldPruneObjects always instructs the caller to prune objects, unless the repository is an object pool.

func (EagerOptimizationStrategy) ShouldRepackObjects added in v15.6.0

func (s EagerOptimizationStrategy) ShouldRepackObjects(ctx context.Context) (bool, RepackObjectsConfig)

ShouldRepackObjects always instructs the caller to repack objects. The strategy will always be to repack all objects into a single packfile. The bitmap will be written in case the repository does not have any alterantes.

func (EagerOptimizationStrategy) ShouldRepackReferences added in v15.6.0

func (s EagerOptimizationStrategy) ShouldRepackReferences(context.Context) bool

ShouldRepackReferences always instructs the caller to repack references.

func (EagerOptimizationStrategy) ShouldWriteCommitGraph added in v15.6.0

ShouldWriteCommitGraph always instructs the caller to write the commit-graph. The strategy will always be to completely rewrite the commit-graph chain.

type HeuristicalOptimizationStrategy added in v15.6.0

type HeuristicalOptimizationStrategy struct {
	// contains filtered or unexported fields
}

HeuristicalOptimizationStrategy is an optimization strategy that is based on a set of heuristics.

func NewHeuristicalOptimizationStrategy added in v15.6.0

func NewHeuristicalOptimizationStrategy(info stats.RepositoryInfo) HeuristicalOptimizationStrategy

NewHeuristicalOptimizationStrategy constructs a heuristicalOptimizationStrategy for the given repository info. It derives all data from the repository so that the heuristics used by this repository can be decided without further disk reads.

func (HeuristicalOptimizationStrategy) ShouldPruneObjects added in v15.6.0

func (s HeuristicalOptimizationStrategy) ShouldPruneObjects(context.Context) bool

ShouldPruneObjects determines whether the repository has stale objects that should be pruned. Object pools are never pruned to not lose data in them, but otherwise we prune when we've found enough stale objects that might in fact get pruned.

func (HeuristicalOptimizationStrategy) ShouldRepackObjects added in v15.6.0

ShouldRepackObjects checks whether the repository's objects need to be repacked. This uses a set of heuristics that scales with the size of the object database: the larger the repository, the less frequent does it get a full repack.

func (HeuristicalOptimizationStrategy) ShouldRepackReferences added in v15.6.0

func (s HeuristicalOptimizationStrategy) ShouldRepackReferences(context.Context) bool

ShouldRepackReferences determines whether the repository's references need to be repacked based on heuristics. The more references there are, the more loose referencos may exist until they are packed again.

func (HeuristicalOptimizationStrategy) ShouldWriteCommitGraph added in v15.6.0

ShouldWriteCommitGraph determines whether we need to write the commit-graph and how it should be written.

type Manager

type Manager interface {
	// CleanStaleData removes any stale data in the repository.
	CleanStaleData(context.Context, *localrepo.Repo) error
	// OptimizeRepository optimizes the repository's data structures such that it can be more
	// efficiently served.
	OptimizeRepository(context.Context, *localrepo.Repo, ...OptimizeRepositoryOption) error
}

Manager is a housekeeping manager. It is supposed to handle housekeeping tasks for repositories such as the cleanup of unneeded files and optimizations for the repository's data structures.

type OptimizationStrategy added in v15.6.0

type OptimizationStrategy interface {
	// ShouldRepackObjects determines whether the repository needs to be repacked and, if so,
	// how it should be done.
	ShouldRepackObjects(context.Context) (bool, RepackObjectsConfig)
	// ShouldPruneObjects determines whether the repository has stale objects that should be
	// pruned.
	ShouldPruneObjects(context.Context) bool
	// ShouldRepackReferences determines whether the repository's references need to be
	// repacked.
	ShouldRepackReferences(context.Context) bool
	// ShouldWriteCommitGraph determines whether we need to write the commit-graph and how it
	// should be written.
	ShouldWriteCommitGraph(context.Context) (bool, WriteCommitGraphConfig)
}

OptimizationStrategy is an interface to determine which parts of a repository should be optimized.

type OptimizationStrategyConstructor added in v15.9.0

type OptimizationStrategyConstructor func(stats.RepositoryInfo) OptimizationStrategy

OptimizationStrategyConstructor is a constructor for an OptimizationStrategy that is being informed by the passed-in RepositoryInfo.

type OptimizeRepositoryConfig added in v15.6.0

type OptimizeRepositoryConfig struct {
	StrategyConstructor OptimizationStrategyConstructor
}

OptimizeRepositoryConfig is the configuration used by OptimizeRepository that is computed by applying all the OptimizeRepositoryOption modifiers.

type OptimizeRepositoryOption added in v15.6.0

type OptimizeRepositoryOption func(cfg *OptimizeRepositoryConfig)

OptimizeRepositoryOption is an option that can be passed to OptimizeRepository.

func WithOptimizationStrategyConstructor added in v15.9.0

func WithOptimizationStrategyConstructor(strategyConstructor OptimizationStrategyConstructor) OptimizeRepositoryOption

WithOptimizationStrategyConstructor changes the constructor for the optimization strategy.that is used to determine which parts of the repository will be optimized. By default the HeuristicalOptimizationStrategy is used.

type RepackObjectsConfig

type RepackObjectsConfig struct {
	// FullRepack determines whether all reachable objects should be repacked into a single
	// packfile. This is much less efficient than doing incremental repacks, which only soak up
	// all loose objects into a new packfile.
	FullRepack bool
	// WriteBitmap determines whether reachability bitmaps should be written or not. There is no
	// reason to set this to `false`, except for legacy compatibility reasons with existing RPC
	// behaviour
	WriteBitmap bool
	// WriteMultiPackIndex determines whether a multi-pack index should be written or not.
	WriteMultiPackIndex bool
}

RepackObjectsConfig is configuration for RepackObjects.

type RepositoryManager

type RepositoryManager struct {
	// contains filtered or unexported fields
}

RepositoryManager is an implementation of the Manager interface.

func NewManager

func NewManager(promCfg gitalycfgprom.Config, txManager transaction.Manager) *RepositoryManager

NewManager creates a new RepositoryManager.

func (*RepositoryManager) CleanStaleData

func (m *RepositoryManager) CleanStaleData(ctx context.Context, repo *localrepo.Repo) error

CleanStaleData cleans up any stale data in the repository.

func (*RepositoryManager) Collect

func (m *RepositoryManager) Collect(metrics chan<- prometheus.Metric)

Collect is used to collect Prometheus metrics.

func (*RepositoryManager) Describe

func (m *RepositoryManager) Describe(descs chan<- *prometheus.Desc)

Describe is used to describe Prometheus metrics.

func (*RepositoryManager) OptimizeRepository

func (m *RepositoryManager) OptimizeRepository(
	ctx context.Context,
	repo *localrepo.Repo,
	opts ...OptimizeRepositoryOption,
) error

OptimizeRepository performs optimizations on the repository. Whether optimizations are performed or not depends on a set of heuristics.

type WriteCommitGraphConfig added in v15.2.0

type WriteCommitGraphConfig struct {
	// ReplaceChain causes WriteCommitGraph to rewrite the complete commit-graph chain. This is
	// a lot more expensive than the default, incremental update of the commit-graph chains but
	// may be required in certain cases to fix up commit-graphs.
	ReplaceChain bool
}

WriteCommitGraphConfig contains configuration that can be passed to WriteCommitGraph to alter its default behaviour.

func WriteCommitGraphConfigForRepository added in v15.2.0

func WriteCommitGraphConfigForRepository(ctx context.Context, repo *localrepo.Repo) (WriteCommitGraphConfig, error)

WriteCommitGraphConfigForRepository returns the optimal default-configuration for the given repo. By default, the configuration will ask for an incremental commit-graph update. If the preexisting commit-graph is missing bloom filters though then the whole commit-graph chain will be rewritten.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL