Interface PartitionMapper

  • All Known Implementing Classes:
    PartitionMapperBase, RendezvousHashMapper, UpdatablePartitionMapper

    public interface PartitionMapper
    Partition mapper.

    This interface represents a data partition mapper that is responsible for mapping user-provided data to cluster partitions.

    
    // Prepare mapper.
    PartitionMapper mapper = RendezvousHashMapper.of(hekate.cluster())
        .withPartitions(128)
        .withBackupNodes(2)
        .build();
    
    // Map some imaginary data key to a partition.
    Partition partition = mapper.map("someDataKey1");
    
    System.out.println("Primary node: " + partition.primaryNode());
    System.out.println("Backup nodes: " + partition.backupNodes());
    

    See Also:
    RendezvousHashMapper
    • Method Detail

      • partitions

        int partitions()
        Returns the total amount of partitions.
        Returns:
        Total amount of partitions
      • backupNodes

        int backupNodes()
        Returns the amount of backup nodes that should be assigned to each partition.
        Returns:
        Amount of backup nodes that should be assigned to each partition.
      • topology

        ClusterTopology topology()
        Returns the cluster topology as it is visible to this mapper.

        If mapper is a snapshot then this method will always return the same topology at the time when the snapshot was created. If mapper is a live mapper then it will always return the latest cluster topology.

        Returns:
        Cluster topology.
      • snapshot

        PartitionMapper snapshot()
        Creates a point in time snapshot of this mapper. The returned snapshot is immutable and will not change its partitions mapping even if cluster topology changes.
        Returns:
        New snapshot or the same instance if this instance is already a snapshot.
        See Also:
        isSnapshot()
      • isSnapshot

        boolean isSnapshot()
        Returns true if this instance is a snapshot.
        Returns:
        true if this instance is a snapshot.
        See Also:
        snapshot()