utils

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BytesPerMB is the number of bytes in a megabyte.
	BytesPerMB = 1_048_576
)

Variables

View Source
var PossibleDBTypes = map[string]tmdb.BackendType{}

PossibleDBTypes is a map of strings to BackendTypes representing the Backend types that can be used by this utility.

Functions

func AddPossibleDBType

func AddPossibleDBType(dbType tmdb.BackendType)

AddPossibleDBType adds a possible db backend type.

func DetectDBType

func DetectDBType(name, dir string) (tmdb.BackendType, bool)

DetectDBType attempts to identify the type database in the given dir with the given name. The name and dir would be the same things that would be provided to tmdb.NewDB.

The return bool indicates whether or not the DB type was identified.

The only types this detects are LevelDB, RocksDB, and BadgerDB. If the DB is another type, the behavior of this is unknown. There's a chance this will return false, but there's also a chance it is falsely identified as something else.

func GetDataDirContents

func GetDataDirContents(dataDirPath string) ([]string, []string, error)

GetDataDirContents gets the contents of a directory separated into database directories and non-database entries. The first return value will contain an entry for each database directory (including if they are in sub-directories). The second return value will contain all entries (files or directories) under dataDirPath that are not part of a database directory. Returned strings are relative to dataDirPath.

Example return values:

return param 1: []string{"application.db", "blockstore.db", "evidence.db", "snapshots/metadata.db", "state.db", "tx_index.db"}
return param 2: []string{"cs.wal", "priv_validator_state.json", "wasm"}

func GetPossibleDBTypes

func GetPossibleDBTypes() []string

GetPossibleDBTypes gets a slice of strings listing all db types that this can use.

func IsPossibleDBType

func IsPossibleDBType(dbType string) bool

IsPossibleDBType checks if the given dbType string is one that this migrator can handle.

Types

type Migrator

type Migrator struct {
	// HomePath is the path to the home directory (should contain the config and data directories).
	HomePath string
	// StagingDir is the directory that will hold the staging data directory.
	// Default is HomePath
	StagingDir string
	// BackupDir is the directory that will hold the backup data directory.
	// Default is HomePath
	BackupDir string

	// TargetDBType is the type of the target (new) DB.
	TargetDBType string

	// SourceDBType is the type of the source (old) DB.
	SourceDBType string

	// SourceDataDir is the path to the source (current) data directory.
	// Default is { HomePath }/data
	SourceDataDir string
	// StagingDataDir is the path to the staging (new) data directory.
	// Default is { StagingDir }/data-dbmigrate-tmp-{timestamp}-{ TargetDBType }
	StagingDataDir string
	// BackupDataDir is the path to where the current data directory will be moved when done.
	// Default is { BackupDir }/data-dbmigrate-backup-{timestamp}-{dbtypes}
	BackupDataDir string

	// BatchSize is the threshold (in bytes) after which a batch is written and a new batch is created.
	// Batch sizes are measured using only key and value lengths (as opposed to disk space).
	// Default is 0 (unlimited)
	BatchSize uint

	// StageOnly indicates that only the data migration and data copying should happen.
	// If true, the migrator should stop after finishing the staging data directory.
	// That is, it won't move the data dir to the backup location, move the staging directory into place, or update the config.
	StageOnly bool

	// ToConvert is all of the DB directories to migrate/convert.
	// Each entry is relative to the data directory.
	ToConvert []string
	// ToCopy is all the non-DB files and directories that should be copied from the source to the new data directory.
	// Each entry is relative to the data directory.
	ToCopy []string

	// Permissions are the permissions to use on any directories created.
	// Default is to match the source directory, or else 0700.
	Permissions os.FileMode

	// StatusPeriod is the max time period between status messages.
	// Must be at least 1 second. Default is 5 seconds.
	StatusPeriod time.Duration
	// DirDateFormat is the format string used in dated directory names.
	// Default is "2006-01-02-15-04-05".
	DirDateFormat string
}

Migrator is an object to help guide a migration. TargetDBType must be defined. All others can be left unset, or can use defaults from ApplyDefaults(). If using defaults for any directories, you probably need to set HomePath too though.

func (*Migrator) ApplyDefaults

func (m *Migrator) ApplyDefaults()

ApplyDefaults fills in the defaults that it can, for values that aren't set yet.

func (*Migrator) Initialize

func (m *Migrator) Initialize() error

Initialize prepares this Migrator by doing the following:

  1. Calls ApplyDefaults()
  2. Checks ValidateBasic()
  3. Calls ReadSourceDataDir()

func (*Migrator) Migrate

func (m *Migrator) Migrate(logger tmlog.Logger) (errRv error)

Migrate converts all database dirs in ToConvert from the source underlying type in the SourceDataDir to the target type in the StagingDataDir. It then copies everything in ToCopy from the SourceDataDir to the StagingDataDir. It then moves the SourceDataDir to BackupDataDir and moves StagingDataDir into place where SourceDataDir was.

func (*Migrator) ReadSourceDataDir

func (m *Migrator) ReadSourceDataDir() error

ReadSourceDataDir gets the contents of the SourceDataDir and populates ToConvert and ToCopy. Anything in those two fields prior to calling this, will be overwritten.

Does nothing if SourceDataDir is not set.

func (Migrator) ValidateBasic

func (m Migrator) ValidateBasic() error

ValidateBasic makes sure that everything is set in this Migrator.

Jump to

Keyboard shortcuts

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