Class IndexRouting

java.lang.Object
org.elasticsearch.cluster.routing.IndexRouting
Direct Known Subclasses:
IndexRouting.ExtractFromSource

public abstract class IndexRouting extends Object
Generates the shard id for (id, routing) pairs.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final String
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Check if the _split index operation is allowed for an index
    abstract void
    Collect all of the shard ids that *may* contain documents with the provided routing.
    abstract int
    deleteShard(String id, String routing)
    Called when deleting a document to generate the shard id that should contain a document with the provided _id and (optional) _routing.
    Build the routing from IndexMetadata.
    abstract int
    getShard(String id, String routing)
    Called when getting a document to generate the shard id that should contain a document with the provided _id and (optional) _routing.
    protected final int
    hashToShardId(int hash)
    Convert a hash generated from an (id, routing) pair into a shard id.
    abstract int
    indexShard(String id, String routing, XContentType sourceType, BytesReference source)
    Called when indexing a document to generate the shard id that should contain a document with the provided parameters.
    void
    postProcess(IndexRequest indexRequest)
    Finalize the request after routing, incorporating data produced by the routing logic.
    void
    preProcess(IndexRequest indexRequest)
    Finalize the request before routing, with data needed for routing decisions.
    protected final int
    rerouteIfResharding(int shardId)
    If this index is in the process of resharding, and the shard to which this request is being routed, is a target shard that is not yet in HANDOFF state, then route it to the source shard.
    abstract int
    updateShard(String id, String routing)
    Called when updating a document to generate the shard id that should contain a document with the provided _id and (optional) _routing.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • indexName

      protected final String indexName
  • Method Details

    • fromIndexMetadata

      public static IndexRouting fromIndexMetadata(IndexMetadata metadata)
      Build the routing from IndexMetadata.
    • preProcess

      public void preProcess(IndexRequest indexRequest)
      Finalize the request before routing, with data needed for routing decisions.
    • postProcess

      public void postProcess(IndexRequest indexRequest)
      Finalize the request after routing, incorporating data produced by the routing logic.
    • indexShard

      public abstract int indexShard(String id, @Nullable String routing, XContentType sourceType, BytesReference source)
      Called when indexing a document to generate the shard id that should contain a document with the provided parameters.
    • updateShard

      public abstract int updateShard(String id, @Nullable String routing)
      Called when updating a document to generate the shard id that should contain a document with the provided _id and (optional) _routing.
    • deleteShard

      public abstract int deleteShard(String id, @Nullable String routing)
      Called when deleting a document to generate the shard id that should contain a document with the provided _id and (optional) _routing.
    • getShard

      public abstract int getShard(String id, @Nullable String routing)
      Called when getting a document to generate the shard id that should contain a document with the provided _id and (optional) _routing.
    • collectSearchShards

      public abstract void collectSearchShards(String routing, IntConsumer consumer)
      Collect all of the shard ids that *may* contain documents with the provided routing. Indices with a routing_partition will collect more than one shard. Indices without a partition will collect the same shard id as would be returned by getShard(java.lang.String, java.lang.String).

      Note: This is called for any search-like requests that have a routing specified but only if they have a routing specified. If they do not have a routing they just use all shards in the index.

    • hashToShardId

      protected final int hashToShardId(int hash)
      Convert a hash generated from an (id, routing) pair into a shard id.
    • checkIndexSplitAllowed

      public void checkIndexSplitAllowed()
      Check if the _split index operation is allowed for an index
      Throws:
      IllegalArgumentException - if the operation is not allowed
    • rerouteIfResharding

      protected final int rerouteIfResharding(int shardId)
      If this index is in the process of resharding, and the shard to which this request is being routed, is a target shard that is not yet in HANDOFF state, then route it to the source shard.
      Parameters:
      shardId - shardId to which the current document is routed based on hashing
      Returns:
      Updated shardId