migrations

package
v3.0.0-alpha5.0...-c974331 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: LGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMigrationNonUniqueName   = errors.New("please provide unique migration name")
	ErrMigrationCommitNotCalled = errors.New("migration before-commit function was not called")
	ErrMigrationETLFilesDeleted = errors.New(
		"db migration progress was interrupted after extraction step and ETL files was deleted, please contact development team for help or re-sync from scratch",
	)
)
View Source
var ClearBorTables = Migration{

	Name: "clear_bor_tables",
	Up: func(db kv.RwDB, dirs datadir.Dirs, progress []byte, BeforeCommit Callback, logger log.Logger) (err error) {
		tx, err := db.BeginRw(context.Background())
		if err != nil {
			return err
		}
		defer tx.Rollback()

		if err := BeforeCommit(tx, nil, true); err != nil {
			return err
		}

		if err := reset2.ResetBorHeimdall(context.Background(), tx); err != nil {
			return err
		}

		return tx.Commit()
	},
}
View Source
var ProhibitNewDownloadsLock = Migration{
	Name: "prohibit_new_downloads_lock",
	Up: func(db kv.RwDB, dirs datadir.Dirs, progress []byte, BeforeCommit Callback, logger log.Logger) (err error) {
		tx, err := db.BeginRw(context.Background())
		if err != nil {
			return err
		}
		defer tx.Rollback()

		snapshotsStageProgress, err := stages.GetStageProgress(tx, stages.Snapshots)
		if err != nil {
			return err
		}
		if snapshotsStageProgress > 0 {
			fPath := filepath.Join(dirs.Snap, downloader.ProhibitNewDownloadsFileName)
			exists, err := dir.FileExist(fPath)
			if err != nil {
				return err
			}
			if !exists {
				f, err := os.Create(fPath)
				if err != nil {
					return err
				}
				defer f.Close()
				if err := f.Sync(); err != nil {
					return err
				}
			}
		}

		if err := BeforeCommit(tx, nil, true); err != nil {
			return err
		}
		return tx.Commit()
	},
}
View Source
var ProhibitNewDownloadsLock2 = Migration{
	Name: "prohibit_new_downloads_lock2",
	Up: func(db kv.RwDB, dirs datadir.Dirs, progress []byte, BeforeCommit Callback, logger log.Logger) (err error) {
		tx, err := db.BeginRw(context.Background())
		if err != nil {
			return err
		}
		defer tx.Rollback()
		fPath := filepath.Join(dirs.Snap, downloader.ProhibitNewDownloadsFileName)
		exists, err := dir.FileExist(fPath)
		if err != nil {
			return err
		}
		if !exists {
			if err := BeforeCommit(tx, nil, true); err != nil {
				return err
			}
			return tx.Commit()

		}
		content, err := os.ReadFile(fPath)
		if err != nil {
			return err
		}
		if len(content) == 0 {
			locked := []string{}

			for _, t := range coresnaptype.BlockSnapshotTypes {
				locked = append(locked, t.Name())
			}

			for _, t := range coresnaptype.E3StateTypes {
				locked = append(locked, t.Name())
			}

			for _, t := range heimdall.SnapshotTypes() {
				locked = append(locked, t.Name())
			}

			for _, t := range snaptype.CaplinSnapshotTypes {
				if t.Name() != snaptype.BlobSidecars.Name() {
					locked = append(locked, t.Name())
				}
			}

			newContent, err := json.Marshal(locked)
			if err != nil {
				return err
			}
			if err := os.WriteFile(fPath, newContent, fs.FileMode(os.O_TRUNC|os.O_WRONLY)); err != nil {
				return err
			}
		}

		if err := BeforeCommit(tx, nil, true); err != nil {
			return err
		}
		return tx.Commit()
	},
}

Switch to the second version of download.lock.

Functions

func AppliedMigrations

func AppliedMigrations(tx kv.Tx, withPayload bool) (map[string][]byte, error)

func MarshalMigrationPayload

func MarshalMigrationPayload(db kv.Getter) ([]byte, error)

func UnmarshalMigrationPayload

func UnmarshalMigrationPayload(data []byte) (map[string][]byte, error)

Types

type Callback

type Callback func(tx kv.RwTx, progress []byte, isDone bool) error

type Migration

type Migration struct {
	Name string
	Up   func(db kv.RwDB, dirs datadir.Dirs, progress []byte, BeforeCommit Callback, logger log.Logger) error
}

type Migrator

type Migrator struct {
	Migrations []Migration
}

func NewMigrator

func NewMigrator(label kv.Label) *Migrator

func (*Migrator) Apply

func (m *Migrator) Apply(db kv.RwDB, dataDir, chaindata string, logger log.Logger) error

func (*Migrator) HasPendingMigrations

func (m *Migrator) HasPendingMigrations(db kv.RwDB) (bool, error)

func (*Migrator) PendingMigrations

func (m *Migrator) PendingMigrations(tx kv.Tx) ([]Migration, error)

func (*Migrator) VerifyVersion

func (m *Migrator) VerifyVersion(db kv.RwDB, chaindata string) error

Jump to

Keyboard shortcuts

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