migration

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MigrationBackendService

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

MigrationBackendService manages dual-backend behaviour and migration.

func NewMigrationBackend

func NewMigrationBackend(logger domain.BucktLogger, primary domain.FileBackend, secondary domain.FileBackend) *MigrationBackendService

NewMigrationBackend unchanged except returns *MigrationBackendService

Example usage:

var logger = domain.NewLogger() var localBackend = domain.NewLocalFileBackend() var s3Backend = domain.NewS3FileBackend()

var mgr = NewMigrationBackend(logger, localBackend, s3Backend)

mgr.EnableMigration(ctx, s3Backend, MigrateModeToSecondary, &MigrationConfig{
    Concurrency: 16,
    DeleteAfterCopy: false,
    PersistPath: "/var/run/bucket_migration_state.json",
})
go func() {
    err := mgr.MigrateTo(ctx, "images/", func(p string){ fmt.Println("migrated", p) }, func(p string, e error){ fmt.Println("err", p, e) })
    if err != nil {
       log.Println("migration finished with error", err)
    }
}()
defer func() {
	mgr.DisableMigration(ctx)
}()

func (*MigrationBackendService) Delete

func (d *MigrationBackendService) Delete(ctx context.Context, path string) error

func (*MigrationBackendService) DisableMigration

func (d *MigrationBackendService) DisableMigration(ctx context.Context)

func (*MigrationBackendService) EnableMigration

func (d *MigrationBackendService) EnableMigration(ctx context.Context, target domain.FileBackend, mode MigrationMode, cfg *MigrationConfig) error

func (*MigrationBackendService) Get

func (d *MigrationBackendService) Get(ctx context.Context, path string) ([]byte, error)

func (*MigrationBackendService) IsMigrating

func (d *MigrationBackendService) IsMigrating() bool

func (*MigrationBackendService) MigrateTo

func (d *MigrationBackendService) MigrateTo(ctx context.Context, prefix string, onProgress func(file string), onError func(file string, err error)) error

func (*MigrationBackendService) MigrationStatus

func (d *MigrationBackendService) MigrationStatus(ctx context.Context) (completed int64, total int64)

func (*MigrationBackendService) Put

func (d *MigrationBackendService) Put(ctx context.Context, path string, data []byte) error

type MigrationConfig

type MigrationConfig struct {
	Concurrency     int
	RetryCount      int
	RetryBackoff    time.Duration
	DeleteAfterCopy bool   // remove source after successful migration
	PersistPath     string // where to store checkpoint file if primary is local
}

type MigrationMode

type MigrationMode int
const (
	MigrateModeNone          MigrationMode = iota
	MigrateModeToSecondary                 // primary --> secondary (e.g., local -> s3)
	MigrateModeFromSecondary               // secondary --> primary (e.g., s3 -> local)
)

Jump to

Keyboard shortcuts

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