Wraps a non-transactional LDFeatureStore and makes it transactional through an in-memory store acting as a cache.

It also monitors the mirrored writes to the persistence store. A failed write marks the store unavailable. When the store recovers, this writes the full in-memory data set back to it.

At most one full-store write is in flight at a time: a new write-back starts only after the previous write-back's store call has answered. A write-back is never abandoned. Its answer, however late, decides the outcome.

Hierarchy

  • TransactionalFeatureStore

Implements

Constructors

Properties

_activeStore: LDFeatureStore
_backoff: Pick<DefaultBackoff, "fail" | "success"> = ...
_basePersistenceStore: LDFeatureStore
_closed: boolean = false
_embargoRetryHandle?: Timeout
_failureLoggedThisOutage: boolean = false
_logger?: LDLogger
_memoryStore: default
_persistenceAvailable: boolean = true
_pollHandle?: Timeout
_probe: default = ...
_slowWriteBackWarnedThisOutage: boolean = false
_slowWriteBackWarningHandle?: Timeout
_writeBackCallOutstanding: boolean = false
_writeBackEmbargoUntil: number = 0
_writeBackOp: default = ...
_writeFailedDuringWriteBack: boolean = false

Methods

  • Records a failed write-back attempt: backs off the next attempt and logs.

    Only the first failure of an outage logs at error level. Later failures in the same outage log at debug level, so an unhealthy store cannot flood the log every poll tick.

    Returns void

  • Record the result of a mirrored write to the persistence store.

    The first failed write marks the store unavailable. A successful write while the store is unavailable starts recovery.

    A basis write already wrote the full data set, so it recovers directly. Any other write starts a write-back of the full in-memory data set instead.

    Parameters

    • err: undefined | Error
    • isBasisWrite: boolean

    Returns void

  • Abandons the outstanding availability probe once it is past its deadline.

    Bumps the generation so a late answer is ignored, and clears the in-flight flag so a fresh probe can be issued. Returns whether it was released.

    Returns boolean

  • Schedules the next write-back attempt at the embargo deadline.

    Without this timer, a recovery signal that arrived during the embargo, or a failed write-back with no follow-up write, could leave no later trigger: a store without an availability check has no poller, and a poller's probe can disagree with the write path. At most one timer runs. Recovery and close cancel it. A duplicate trigger with the poll tick is harmless: whichever fires second finds the attempt already in flight or the store recovered.

    Returns void

  • Poll the persistence store availability check, when it has one, until the store recovers. Stores without an availability check recover through the next successful mirrored write instead. The check is read-only. A write is never used as a check.

    Returns void

  • Get all entities from a collection.

    The store should filter out any entities with the property deleted: true.

    Parameters

    • kind: DataKind

      The type of data to be accessed. The store should not make any assumptions about the format of the data, but just return an object in which each key is the key property of an entity and the value is the entity. The actual type of this parameter is interfaces.DataKind.

    • callback: ((res) => void)

      Will be called with the resulting map. The actual type of the result value is interfaces.KeyedItems<VersionedData>.

    Returns void

  • Applies the provided data onto the existing data, replacing all data or upserting depending on the basis parameter. Must call applyChanges providing basis before calling applyChanges that is not a basis.

    Parameters

    • basis: boolean

      If true, completely overwrites the current contents of the data store with the provided data. If false, upserts the items in the provided data. Upserts are made only if provided items have newer versions than existing items.

    • data: LDFeatureStoreDataStorage

      An object in which each key is the "namespace" of a collection (e.g. "features") and the value is an object that maps keys to entities. The actual type of this parameter is interfaces.FullDataSet<VersionedData>.

    • callback: (() => void)

      Will be called after the changes are applied.

        • (): void
        • Returns void

    • Optional initMetadata: InitMetadata

      Optional metadata to initialize the feature store with.

      Optional
    • Optional selector: string

      opaque string that uniquely identifies the state that contains the changes

      Optional

    Returns void

  • Delete an entity from the store.

    Deletion should be implemented by storing a placeholder object with the property deleted: true and a version property equal to the provided version. In other words, it should be exactly the same as calling upsert with such an object.

    Parameters

    • kind: DataKind

      The type of data to be accessed. The actual type of this parameter is interfaces.DataKind.

    • key: string

      The unique key of the entity within the specified collection.

    • version: number

      A number that must be greater than the version property of the existing entity in order for it to be deleted. If it is less than or equal to the existing version, the method should do nothing.

    • callback: (() => void)

      Will be called when the delete operation is complete.

        • (): void
        • Returns void

    Returns void

  • Initialize the store, overwriting any existing data.

    Parameters

    • allData: LDFeatureStoreDataStorage

      An object in which each key is the "namespace" of a collection (e.g. "features") and the value is an object that maps keys to entities. The actual type of this parameter is interfaces.FullDataSet<VersionedData>.

    • callback: (() => void)

      Will be called when the store has been initialized. If the store could not apply the data, then it may be called with an error. Implementations are not required to report errors.

        • (): void
        • Returns void

    Returns void

  • Tests whether the store is initialized.

    "Initialized" means that the store has been populated with data, either by the client having called init() within this process, or by another process (if this is a shared database).

    Parameters

    • callback: ((isInitialized) => void)

      Will be called back with the boolean result.

        • (isInitialized): void
        • Parameters

          • isInitialized: boolean

          Returns void

    Returns void

  • Add an entity or update an existing entity.

    Parameters

    • kind: DataKind

      The type of data to be accessed. The actual type of this parameter is interfaces.DataKind.

    • data: LDKeyedFeatureStoreItem

      The contents of the entity, as an object that can be converted to JSON. The store should check the version property of this object, and should not overwrite any existing data if the existing version is greater than or equal to that value. The actual type of this parameter is interfaces.VersionedData.

    • callback: (() => void)

      Will be called after the upsert operation is complete. If the store could not apply the update, then it may be called with an error. Implementations are not required to report errors.

        • (): void
        • Returns void

    Returns void

Generated using TypeDoc