LargeMigrator

zio.blocks.data.migration.LargeMigrator
final class LargeMigrator[A, B, ID1, ID2](repoV1: Repo[A, ID1], repoV2: Repo[B, ID2], migration: Migration[A, B], queueTable: String, batchSize: Int, target: TargetStrategy, captureTriggers: Boolean = ...)(using transactor: Transactor, codecId: DbCodec[ID1], dialect: Dialect, ev: ID1 =:= ID2)

B-Large: incremental worker that processes migration queue until empty. Supports pause/resume and progress reporting.

The lifecycle methods (init, fence, drain, complete) are internally consistent but are expected to be driven from a single thread; pause and resume are safe to call from other threads while run() or drain() is in flight.

Attributes

Source
LargeMigrator.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def complete(): Unit

Finalize the migration by swapping the shadow table. Requires Drained state (fence() + drain() completed successfully). After complete(), the shadow table becomes the live table and the old table is renamed to {table}_old_{suffix}.

Finalize the migration by swapping the shadow table. Requires Drained state (fence() + drain() completed successfully). After complete(), the shadow table becomes the live table and the old table is renamed to {table}_old_{suffix}.

Attributes

Source
LargeMigrator.scala
def drain(): Int

Drain remaining queue items until pendingCount confirms the queue is truly empty. Uses a separate COUNT query for verification, not just the dequeue result. If batches come back empty while items remain pending for more than MaxEmptyDrainRounds consecutive rounds (e.g. a stuck concurrent worker holding row locks), drain() fails loudly instead of spinning.

Drain remaining queue items until pendingCount confirms the queue is truly empty. Uses a separate COUNT query for verification, not just the dequeue result. If batches come back empty while items remain pending for more than MaxEmptyDrainRounds consecutive rounds (e.g. a stuck concurrent worker holding row locks), drain() fails loudly instead of spinning.

Attributes

Returns

total items processed during drain

Source
LargeMigrator.scala
def fence(): Unit

Signal cutover: no more producers will write to the old table. After fence(), drain() will process remaining items and verify emptiness via COUNT query before allowing complete().

Signal cutover: no more producers will write to the old table. After fence(), drain() will process remaining items and verify emptiness via COUNT query before allowing complete().

The application MUST ensure that producers stop writing to the old table before calling fence(). Writes arriving after fence() may be lost or require a separate reconciliation.

Attributes

Source
LargeMigrator.scala
def init(): Unit

Prepare the target table. For ShadowTable strategy, creates the shadow table via TargetStrategyApplier.prepare. When captureTriggers is enabled, installs capture triggers on the source table. Safe to call multiple times (idempotent after first success).

Prepare the target table. For ShadowTable strategy, creates the shadow table via TargetStrategyApplier.prepare. When captureTriggers is enabled, installs capture triggers on the source table. Safe to call multiple times (idempotent after first success).

Attributes

Source
LargeMigrator.scala
def isPaused: Boolean

Whether the migrator is currently paused (checked inside run()).

Whether the migrator is currently paused (checked inside run()).

Attributes

Source
LargeMigrator.scala
def pause(): Unit

Pause the migrator loop. In-flight batches complete before exit.

Pause the migrator loop. In-flight batches complete before exit.

Attributes

Source
LargeMigrator.scala
def pendingCount: Long

Returns queue size estimate (pending items).

Returns queue size estimate (pending items).

Attributes

Source
LargeMigrator.scala
def previewSql(): Vector[String]

Pure preview of init/run SQL without opening any connection.

Pure preview of init/run SQL without opening any connection.

Returns init/run statement texts (queue DDL, shadow create/rename, triggers, dequeue template) rendered against the ambient dialect. Does NOT call Transactor.

Attributes

Source
LargeMigrator.scala
def resume(): Unit

Resume processing after a pause.

Resume processing after a pause.

Attributes

Source
LargeMigrator.scala
def run(): Int

Runs worker loop until queue is empty or paused. Returns total migrated. Does not auto-complete; caller must use fence/drain/complete protocol for safe cutover.

Runs worker loop until queue is empty or paused. Returns total migrated. Does not auto-complete; caller must use fence/drain/complete protocol for safe cutover.

Attributes

Source
LargeMigrator.scala