IArchiveLifecycleService
Namespace: Meshmakers.Octo.Runtime.Contracts.StreamData
Orchestrates state-machine transitions for CkArchive entities. DB-neutral: delegates
DDL to IStreamDataRepository and entity reads/writes to the runtime repository
stack. Status changes are audit-trailed via the existing event infrastructure.
public interface IArchiveLifecycleService
Remarks:
Transition rules (see streamdata-archive-concept §3, §11):
Created → Activated: provision Crate table; on DDL failure transition to Failed.
Activated → Disabled: status only, no Crate side-effect. Disabled → Activated runs the
idempotent provisioning again.
Activated → Activated: no transition; the idempotent provisioning runs again so that a
column declared after the table was created is added to it. A failure is thrown to the caller and
leaves the archive Activated.
Failed → Activated: retry DDL; idempotent.
Delete from any state: drop the Crate table and soft-delete the entity (rtState = Archived).
Operation order is always Crate first, Mongo last so retries converge after transient Mongo failures without leaving inconsistent state visible to callers.
Methods
ActivateAsync(OctoObjectId)
Activates the archive: provisions the Crate table and sets status = Activated.
Allowed from Created, Disabled, and Failed. Re-validates all column
paths against the current CK model before any DDL runs. On an archive that is already
Activated it changes no status and adds the declared columns the table does not have yet;
if that fails, ArchiveActivationFailedException is thrown and the archive stays
Activated.
Task ActivateAsync(OctoObjectId archiveRtId)
Parameters
archiveRtId OctoObjectId
Returns
DisableAsync(OctoObjectId)
Sets status = Disabled. Allowed from Activated. The Crate table is preserved.
Task DisableAsync(OctoObjectId archiveRtId)
Parameters
archiveRtId OctoObjectId
Returns
EnableAsync(OctoObjectId)
Sets status = Activated from Disabled. Re-validates column paths against the
current CK model; performs no DDL because the table already exists.
Task EnableAsync(OctoObjectId archiveRtId)
Parameters
archiveRtId OctoObjectId
Returns
RetryActivationAsync(OctoObjectId)
Retries activation after a previous DDL failure. Allowed only from Failed; identical
effect to IArchiveLifecycleService.ActivateAsync(OctoObjectId).
Task RetryActivationAsync(OctoObjectId archiveRtId)
Parameters
archiveRtId OctoObjectId
Returns
DeleteAsync(OctoObjectId)
Drops the Crate table (idempotent) and soft-deletes the CkArchive entity by setting
rtState = Archived. Allowed from any status.
Task DeleteAsync(OctoObjectId archiveRtId)
Parameters
archiveRtId OctoObjectId
Returns
RevalidateAccessAsync(OctoObjectId)
CK v2 (review G3 E-M2): re-checks an archive against attribute access after a CK model change. When an
ingested column now reaches a Hidden attribute (directly or through a record), an activated archive is set
to CkArchiveStatus.Failed so it stops ingesting; returns false. The transition records
the reason and every offending column (ArchiveSnapshot.StatusReason,
ArchiveSnapshot.HiddenColumns); the history stays queryable without those columns. Call it for
the archives of a tenant after a CK model import. Without a CK cache the check is skipped (true).
Task<bool> RevalidateAccessAsync(OctoObjectId archiveRtId)
Parameters
archiveRtId OctoObjectId
Returns
RedactHiddenColumnsAsync(OctoObjectId)
The documented way out of a Hidden-column failure. Drops every ingested column of the archive that reaches a Hidden attribute under the current CK model — first the physical columns (IStreamDataRepository.DropIngestedColumnStorageAsync(ArchiveSnapshot, IReadOnlyCollection<String>, CancellationToken)), then the definition — and records the redaction in the audit trail. Destructive: the values stored in these columns are lost; all other columns and rows are kept. An archive the re-validation had set to CkArchiveStatus.Failed on Hidden columns is activated again; any other archive keeps its status. Never called automatically. Refused with HiddenColumnRedactionBlockedException while a rollup aggregates one of the columns. Idempotent: without a Hidden column it changes nothing (a Failed-on-Hidden archive whose columns are no longer Hidden is still activated again). The default implementation throws NotSupportedException.
Task<ArchiveRedactionResult> RedactHiddenColumnsAsync(OctoObjectId archiveRtId)
Parameters
archiveRtId OctoObjectId
Returns
RedactConfirmedHiddenColumnsAsync(OctoObjectId, IReadOnlyCollection<String>)
The redaction of IArchiveLifecycleService.RedactHiddenColumnsAsync(OctoObjectId), guarded by the columns the caller confirmed: it drops
only when the columns that reach a Hidden attribute at execution time are exactly
expectedColumns (compared ignoring case, order and duplicates; an empty collection confirms
that no column is Hidden). Otherwise it throws HiddenColumnRedactionColumnsChangedException before
the state, conflict-key, computed-column and rollup refusals, the audit entry and the drop (a missing archive, a
missing CK cache and a rollup archive are refused first). Between the caller's read and the call another CK model change
can make more columns Hidden; without this guard they would be dropped too. Every other rule, the audit entry,
the drop and the resume are those of IArchiveLifecycleService.RedactHiddenColumnsAsync(OctoObjectId). The default implementation throws
NotSupportedException.
Task<ArchiveRedactionResult> RedactConfirmedHiddenColumnsAsync(OctoObjectId archiveRtId, IReadOnlyCollection<string> expectedColumns)
Parameters
archiveRtId OctoObjectId
expectedColumns IReadOnlyCollection<String>
Returns
Exceptions
HiddenColumnRedactionColumnsChangedException
The Hidden columns at execution time differ from expectedColumns; nothing was dropped.
AddArchiveColumnAsync(OctoObjectId, String, Boolean, CancellationToken)
Adds an ingested column for the CK attribute at path to an Activated raw or
time-range archive without recreating it. The physical column is added first (nullable: existing rows
keep their data and read NULL for it), then the archive definition; the next ingested rows fill it. Returns
false when the archive already captures the path (idempotent), true when the column was added.
Task<bool> AddArchiveColumnAsync(OctoObjectId archiveRtId, string path, bool indexed, CancellationToken cancellationToken)
Parameters
archiveRtId OctoObjectId
path String
indexed Boolean
cancellationToken CancellationToken
Returns
Exceptions
ArchiveNotFoundException
The archive does not exist.
InvalidArchiveStateTransitionException
The archive is not Activated.
ArchivePathInvalidException
The path is empty, does not resolve against the archive's target type, the archive is a rollup (its columns are
derived), or a computed column already uses the name the path maps to.
HiddenAttributeInArchiveException
The path reaches a Hidden attribute.
AddComputedColumnAsync(OctoObjectId, String, String, FormulaResultType, Boolean)
Adds a computed column to an Activated raw or time-range archive and backfills it
. Validates the prospective column set, persists the column
Pending, adds the physical column, backfills the existing rows while the column stays
hidden, then flips it to Active atomically. A backfill failure leaves the column
Failed and the previous archive state intact. Idempotent re-add of the same name reuses
the orphaned physical column.
Task AddComputedColumnAsync(OctoObjectId archiveRtId, string name, string formula, FormulaResultType resultType, bool indexed)
Parameters
archiveRtId OctoObjectId
name String
formula String
resultType FormulaResultType
indexed Boolean
Returns
RemoveComputedColumnAsync(OctoObjectId, String)
Removes a computed column from an archive. Validates that no remaining computed column references it, then drops it from the logical column set; the physical CrateDB column is left as a harmless orphan the read path no longer projects.
Task RemoveComputedColumnAsync(OctoObjectId archiveRtId, string name)
Parameters
archiveRtId OctoObjectId
name String
Returns
UpdateComputedColumnFormulaAsync(OctoObjectId, String, String)
Changes the formula of an existing computed column on an active archive with optimistic / atomic semantics: readers keep seeing the previous formula's values while a backfill populates the new formula into a fresh versioned physical column, then the column-version pointer is swapped atomically. A backfill failure reverts to the previous formula. The result type is unchanged (a formula edit cannot retype the column). No-op when the formula is unchanged.
Task UpdateComputedColumnFormulaAsync(OctoObjectId archiveRtId, string name, string formula)
Parameters
archiveRtId OctoObjectId
name String
formula String
Returns
EnqueueAddComputedColumnAsync(OctoObjectId, String, String, FormulaResultType, Boolean, CancellationToken)
Adds a computed column like IArchiveLifecycleService.AddComputedColumnAsync(OctoObjectId, String, String, FormulaResultType, Boolean), but does not backfill inside
the call: it validates the column, persists it, adds the physical column, queues a
backfill job and returns with the column in Backfilling. The background backfill drain
(IArchiveLifecycleService.RunPendingComputedColumnBackfillsAsync(CancellationToken)) runs the job and ends the column
Active or Failed. Validation and DDL errors are thrown to the caller. Returns the
queued job, or null when no job store is wired.
Task<RecomputeJobSnapshot> EnqueueAddComputedColumnAsync(OctoObjectId archiveRtId, string name, string formula, FormulaResultType resultType, bool indexed, CancellationToken cancellationToken)
Parameters
archiveRtId OctoObjectId
name String
formula String
resultType FormulaResultType
indexed Boolean
cancellationToken CancellationToken
Returns
EnqueueUpdateComputedColumnFormulaAsync(OctoObjectId, String, String, CancellationToken)
Changes a computed column's formula like IArchiveLifecycleService.UpdateComputedColumnFormulaAsync(OctoObjectId, String, String), but
queues the backfill of the new formula as a background job instead of running it inside the
call. Readers keep seeing the previous formula until the job swaps the column version;
a failed job reverts to the previous formula. Rejected while a backfill of the column is still
queued or running. Returns the queued job, or null when the formula is unchanged (no-op)
or no job store is wired.
Task<RecomputeJobSnapshot> EnqueueUpdateComputedColumnFormulaAsync(OctoObjectId archiveRtId, string name, string formula, CancellationToken cancellationToken)
Parameters
archiveRtId OctoObjectId
name String
formula String
cancellationToken CancellationToken
Returns
RetryComputedColumnBackfillAsync(OctoObjectId, String, CancellationToken)
Queues the backfill of a computed column again, for a column that ended
Failed, was left Pending by an interrupted add, or sits in Backfilling
without a live job. Sets the column Backfilling and returns the queued job (an already
queued job of the column is returned as is). Throws when the column is Active and has no
formula change in progress — there is nothing to retry.
Task<RecomputeJobSnapshot> RetryComputedColumnBackfillAsync(OctoObjectId archiveRtId, string name, CancellationToken cancellationToken)
Parameters
archiveRtId OctoObjectId
name String
cancellationToken CancellationToken
Returns
RepairComputedColumnAsync(OctoObjectId, String, Nullable<DateTime>, Nullable<DateTime>, CancellationToken)
Queues a repair of an Active computed column as a background job: the job
re-evaluates the rows in [from, to) whose cell is NULL while an operand of the formula is not
NULL (e.g. rows that an aborted evaluation left NULL) and writes the results; the column stays
Active and readable. from defaults to the first row, to
to now. Runs on the backfill drain (IArchiveLifecycleService.RunPendingComputedColumnBackfillsAsync(CancellationToken)); follow it
with the recompute jobs of the archive. An already queued or running repair of the column is returned
as is. Throws when the column does not exist or is not Active. Returns null when no job
store is wired.
Task<RecomputeJobSnapshot> RepairComputedColumnAsync(OctoObjectId archiveRtId, string name, Nullable<DateTime> from, Nullable<DateTime> to, CancellationToken cancellationToken)
Parameters
archiveRtId OctoObjectId
name String
from Nullable<DateTime>
cancellationToken CancellationToken
Returns
RunPendingComputedColumnBackfillsAsync(CancellationToken)
Runs the queued computed-column backfills of this tenant one after the other: every
computed column in Backfilling or with a formula change in progress on an
Activated archive, oldest job first, then the queued repairs of active columns. Called by the background service, never by a
request, so a client disconnect cannot cancel a backfill. Returns the number of backfills that
completed.
Task<int> RunPendingComputedColumnBackfillsAsync(CancellationToken cancellationToken)
Parameters
cancellationToken CancellationToken