Class ClientPrimaryReplicaTracker

java.lang.Object
org.apache.ignite.client.handler.ClientPrimaryReplicaTracker

public class ClientPrimaryReplicaTracker extends Object
Primary partition replica tracker. Shared by all instances of ClientInboundMessageHandler.

Keeps up-to-date lists of primary replicas by partition for every zone, avoiding expensive placement driver calls in most cases.

Every "assignment" (set of primary replicas per partition) is identified by a maxStartTime - latest known lease start time.

Assumptions: - Primary replicas are not changed often. - We do "best effort" partition awareness - it is ok if we don't have the latest primary replicas at some point or don't have them at all. What matters is that we have the correct assignment eventually. - It is allowed to return incomplete assignment (null for some partitions) - better than nothing. - We don't know which tables the client is going to use, so we track a common maxStartTime for all tables.

Tracking logic: - Listen to election events from placement driver, update primary replicas. This is the main source of information. - When we have not yet received events for all partitions of a certain table, and the client requests the assignment, load it from the placement driver. Wait for a limited amount of time (in getPrimaryReplica) and return what we have. Don't block the client for too long, it is better to miss the primary than to delay the request.

  • Constructor Details

    • ClientPrimaryReplicaTracker

      public ClientPrimaryReplicaTracker(org.apache.ignite.internal.placementdriver.PlacementDriver placementDriver, org.apache.ignite.internal.catalog.CatalogService catalogService, org.apache.ignite.internal.hlc.ClockService clockService, org.apache.ignite.internal.schema.SchemaSyncService schemaSyncService, org.apache.ignite.internal.lowwatermark.LowWatermark lowWatermark)
      Constructor.
      Parameters:
      placementDriver - Placement driver.
      catalogService - Catalog.
      clockService - Clock service.
      schemaSyncService - Schema synchronization service.
      lowWatermark - Low watermark.
  • Method Details

    • primaryReplicasAsync

      public CompletableFuture<ClientPrimaryReplicaTracker.PrimaryReplicasResult> primaryReplicasAsync(int tableId, @Nullable @Nullable Long maxStartTime)
      Gets primary replicas by partition for the table.
      Parameters:
      tableId - Table ID.
      maxStartTime - Timestamp.
      Returns:
      Primary replicas for the table, or null when not yet known.
    • primaryReplicasAsync

      public CompletableFuture<ClientPrimaryReplicaTracker.PrimaryReplicasResult> primaryReplicasAsync(int tableId, @Nullable @Nullable Long maxStartTime, int @Nullable [] partitionIds)
      Gets primary replicas for the given partitions of the table.

      Only the requested partitions are resolved and awaited, so a partition outside the requested set does not delay or fail the call. The result list still has one entry per partition of the table; entries for partitions that were not requested are null.

      The result's timestamp comes from the tracker-wide counter, but only the requested partitions are checked against it. Never cache a scoped result as the table's full assignment at that timestamp: the tracker may have older data for the partitions that were not requested.

      Parameters:
      tableId - Table ID.
      maxStartTime - Timestamp.
      partitionIds - Partitions to resolve, null to resolve all partitions of the table.
      Returns:
      Primary replicas for the table, or null when not yet known.