Class MultiTenantSnapshotStore

java.lang.Object
io.axoniq.framework.messaging.multitenancy.eventsourcing.MultiTenantSnapshotStore
All Implemented Interfaces:
DescribableComponent, SnapshotStore

@Internal public class MultiTenantSnapshotStore extends Object implements SnapshotStore
Tenant-routing SnapshotStore. Snapshot load and store operations are routed to the store of the one tenant resolved from the ProcessingContext, so each tenant's snapshots live in its own store.

Snapshot operations therefore require a tenant-carrying processing context. When none is available, or the tenant cannot be resolved from it, the operation completes exceptionally.

Registered as the application's SnapshotStore, so snapshots written for an entity land in the store of the tenant the entity belongs to. Snapshot reads while sourcing do not travel through here: those stay with MultiTenantEventStorageEngine, which routes them to the tenant's own engine.

Since:
5.3.0
Author:
Jakob Hatzl, Laura Devriendt
  • Constructor Details

    • MultiTenantSnapshotStore

      public MultiTenantSnapshotStore(TenantSnapshotStoreFactory snapshotStoreFactory, TenantRouter tenantRouter)
      Constructs a MultiTenantSnapshotStore.
      Parameters:
      snapshotStoreFactory - the factory providing each tenant's SnapshotStore
      tenantRouter - the router deciding which tenant a snapshot operation is routed to
  • Method Details

    • store

      public CompletableFuture<Void> store(QualifiedName qualifiedName, Object identifier, Snapshot snapshot, @Nullable ProcessingContext context)
      Description copied from interface: SnapshotStore
      Persists a snapshot under the given name and identifier. This replaces any previous snapshot(s) with the same name and identifier.

      This method is asynchronous and returns a CompletableFuture that completes when the snapshot has been durably stored.

      Specified by:
      store in interface SnapshotStore
      Parameters:
      qualifiedName - the name of the snapshot to persist, cannot be null
      identifier - the identifier of the snapshot to persist, cannot be null
      snapshot - the snapshot to persist, cannot be null
      context - the ProcessingContext active while storing, used by decorators (e.g. tracing) to correlate the operation with the surrounding unit of work; may be null
      Returns:
      a CompletableFuture that completes when the snapshot has been stored
    • load

      public CompletableFuture<@Nullable Snapshot> load(QualifiedName qualifiedName, Object identifier, @Nullable ProcessingContext context)
      Description copied from interface: SnapshotStore
      Loads the latest snapshot for a given name and identifier.

      The returned snapshot may have an older or newer version relative to what is expected. The caller is responsible for handling version compatibility or ignoring unusable snapshots.

      This method is asynchronous and returns a CompletableFuture that completes with the snapshot if one exists, or null if no snapshot is available.

      Specified by:
      load in interface SnapshotStore
      Parameters:
      qualifiedName - the name of the snapshot, cannot be null
      identifier - the identifier of the snapshot, cannot be null
      context - the ProcessingContext active while loading, used by decorators (e.g. tracing) to correlate the operation with the surrounding unit of work; may be null
      Returns:
      a CompletableFuture containing the snapshot, or containing null if no matching snapshot exists
    • describeTo

      public void describeTo(ComponentDescriptor descriptor)
      Description copied from interface: DescribableComponent
      Describe the properties of this DescribableComponent with the given descriptor.

      Components should call the appropriate describeProperty methods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.

      Best Practices: As a general rule, all relevant fields of a DescribableComponent implementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing the describeTo method, who should focus on providing information that is useful for understanding the component's configuration and state.

      Example implementation:

       public void describeTo(ComponentDescriptor descriptor) {
           descriptor.describeProperty("name", this.name);
           descriptor.describeProperty("enabled", this.enabled);
           descriptor.describeProperty("configuration", this.configuration); // A nested component
           descriptor.describeProperty("handlers", this.eventHandlers);      // A collection
       }
       
      Specified by:
      describeTo in interface DescribableComponent
      Parameters:
      descriptor - The component descriptor to describe this DescribableComponentn its properties in.