Class LucenePartitioner
java.lang.Object
com.apple.foundationdb.record.lucene.LucenePartitioner
Manage partitioning info for a logical, partitioned lucene index, in which each partition is a separate physical lucene index.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
encapsulate and manage additional log messages when repartitioning. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<M extends Message>
CompletableFuture<Integer>addToAndSavePartitionMetadata
(FDBIndexableRecord<M> newRecord, Tuple groupingKey, Integer assignedPartitionId) add a new written record to its partition metadata.CompletableFuture<List<com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo>>
getAllPartitionMetaInfo
(Tuple groupingKey) Get all partition metadata for a given grouping key.getNewestNDocuments
(com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo partitionInfo, Tuple groupingKey, int count) get the newest N index entries in a given Lucene partition.static CompletableFuture<com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo>
getNextNewerPartitionInfo
(FDBRecordContext context, Tuple groupingKey, Tuple currentPartitionKey, Subspace indexSubspace) get the next "newer" partition for a given partition key.static CompletableFuture<com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo>
getNextOlderPartitionInfo
(FDBRecordContext context, Tuple groupingKey, Tuple previousKey, Subspace indexSubspace) get the next "older" partition for a given partition key.getOldestNDocuments
(com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo partitionInfo, Tuple groupingKey, int count) get the oldest N index entries in a given Lucene partition.get the document field name the contains the document partition field, as it is stored in Lucene.static Tuple
getPartitionKey
(com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo partitionInfo) convenience function that returns the partitioning key of a given partition metadata object.CompletableFuture<com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo>
getPartitionMetaInfoById
(int partitionId, Tuple groupingKey) find the partition metadata for a given partition id.static com.apple.foundationdb.record.util.pair.Pair<com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo,
com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo> getPartitionNeighbors
(List<com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo> allPartitions, int currentPartitionPosition) return the neighbors of a given partition in a list.static Tuple
getToTuple
(com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo partitionInfo) convenience function that returns theto
value of a given partition metadata object.static boolean
isNewerThan
(Tuple key, com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo partitionInfo) convenience function that evaluates whether a given partitioning key tuple is "newer" than the given partitioning metadata.static boolean
isOlderThan
(Tuple key, com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo partitionInfo) convenience function that evaluates whether a given partitioning key tuple is "older" than the given partitioning metadata.boolean
get whether this index has partitioning enabled.static boolean
isPrefixOlderThanPartition
(Tuple prefix, com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo partitionInfo) com.apple.foundationdb.record.lucene.LucenePartitioner.PartitionedSortContext
isSortedByPartitionField
(org.apache.lucene.search.Sort sort) checks whether the providedSort
is by the partitioning field and whether it's in reverse order.processPartitionRebalancing
(Tuple groupingKey, int repartitionDocumentCount, LucenePartitioner.RepartitioningLogMessages logMessages) Re-balance the first partition in a given grouping key by moving documents out of it.rebalancePartitions
(RecordCursorContinuation start, int documentCount, LucenePartitioner.RepartitioningLogMessages logMessages) Re-balance full partitions, if applicable.com.apple.foundationdb.record.lucene.LucenePartitioner.PartitionedQueryHint
selectQueryPartition
(Tuple groupKey, LuceneScanQuery luceneScanQuery) Synchronous counterpart ofselectQueryPartitionAsync(Tuple, LuceneScanQuery)
.CompletableFuture<com.apple.foundationdb.record.lucene.LucenePartitioner.PartitionedQueryHint>
selectQueryPartitionAsync
(Tuple groupKey, LuceneScanQuery luceneScanQuery) Return the partition ID on which to run a query, given a grouping key.selectQueryPartitionId
(Tuple groupKey) return the partition ID on which to run a query, given a grouping key.toPartitionKey
(Object partitioningFieldValue, Tuple primaryKey) convenience function that builds a partitioning key value from a partitioning field value and a primary key.
-
Field Details
-
DEFAULT_PARTITION_LOW_WATERMARK
public static final int DEFAULT_PARTITION_LOW_WATERMARK- See Also:
-
PARTITION_META_SUBSPACE
public static final int PARTITION_META_SUBSPACE- See Also:
-
PARTITION_DATA_SUBSPACE
public static final int PARTITION_DATA_SUBSPACE- See Also:
-
-
Constructor Details
-
LucenePartitioner
-
-
Method Details
-
selectQueryPartitionId
return the partition ID on which to run a query, given a grouping key. For now, the most recent partition is returned.- Parameters:
groupKey
- group key- Returns:
- partition id, or
null
if partitioning isn't enabled
-
selectQueryPartition
public com.apple.foundationdb.record.lucene.LucenePartitioner.PartitionedQueryHint selectQueryPartition(@Nonnull Tuple groupKey, @Nullable LuceneScanQuery luceneScanQuery) Synchronous counterpart ofselectQueryPartitionAsync(Tuple, LuceneScanQuery)
.- Parameters:
groupKey
- group keyluceneScanQuery
- query- Returns:
- partition query hint, or
null
if partitioning isn't enabled or no partitioning metadata exist for the given query
-
selectQueryPartitionAsync
public CompletableFuture<com.apple.foundationdb.record.lucene.LucenePartitioner.PartitionedQueryHint> selectQueryPartitionAsync(@Nonnull Tuple groupKey, @Nullable LuceneScanQuery luceneScanQuery) Return the partition ID on which to run a query, given a grouping key. If no partitioning field predicate can be used to determine a particular starting partition, the most recent partition is returned, unless the query is sorted by the partitioning field in ascending order, in which case the oldest partition is returned. If the query contains a top level partitioning field predicate in conjunction with the rest of the predicates, and the predicate can be used to determine a specific starting partition, that partition will be computed and returned.- Parameters:
groupKey
- group keyluceneScanQuery
- query- Returns:
- partition query hint, or
null
if partitioning isn't enabled or no partitioning metadata exist for the given query
-
isSortedByPartitionField
@Nonnull public com.apple.foundationdb.record.lucene.LucenePartitioner.PartitionedSortContext isSortedByPartitionField(@Nonnull org.apache.lucene.search.Sort sort) checks whether the providedSort
is by the partitioning field and whether it's in reverse order.- Parameters:
sort
- sort- Returns:
- PartitionedSortContext object
-
isPartitioningEnabled
public boolean isPartitioningEnabled()get whether this index has partitioning enabled.- Returns:
- true if partitioning is enabled
-
getPartitionFieldNameInLucene
get the document field name the contains the document partition field, as it is stored in Lucene.- Returns:
- Lucene document field name, or
null
-
addToAndSavePartitionMetadata
@Nonnull public <M extends Message> CompletableFuture<Integer> addToAndSavePartitionMetadata(@Nonnull FDBIndexableRecord<M> newRecord, @Nonnull Tuple groupingKey, @Nullable Integer assignedPartitionId) add a new written record to its partition metadata.- Type Parameters:
M
- message- Parameters:
newRecord
- record to be writtengroupingKey
- grouping keyassignedPartitionId
- assigned partition override, if not null- Returns:
- partition id or
null
if partitioning isn't enabled on index
-
rebalancePartitions
@Nonnull public CompletableFuture<RecordCursorContinuation> rebalancePartitions(RecordCursorContinuation start, int documentCount, LucenePartitioner.RepartitioningLogMessages logMessages) Re-balance full partitions, if applicable.- Parameters:
start
- The continuation at which to resume rebalancing, as returned from a previous call torebalancePartitions
.documentCount
- max number of documents to move in each transactionlogMessages
-FDBDatabaseRunner
additional log messages- Returns:
- a continuation at which to resume rebalancing in another call to
rebalancePartitions
-
processPartitionRebalancing
@Nonnull public CompletableFuture<Integer> processPartitionRebalancing(@Nonnull Tuple groupingKey, int repartitionDocumentCount, LucenePartitioner.RepartitioningLogMessages logMessages) Re-balance the first partition in a given grouping key by moving documents out of it. Note that in order to finish the task within the bounds of a single transaction, only the first partition needing re-balancing will be processed. If there are other partitions that need re-balancing, they will be processed during subsequent calls.- Parameters:
groupingKey
- grouping keyrepartitionDocumentCount
- max number of documents to move in each transactionlogMessages
-FDBDatabaseRunner
additional log messages- Returns:
- future count of documents rebalanced in this group. If zero, no more re-balancing needed
-
getNewestNDocuments
@Nonnull public LuceneRecordCursor getNewestNDocuments(@Nonnull com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo partitionInfo, @Nonnull Tuple groupingKey, int count) get the newest N index entries in a given Lucene partition.- Parameters:
partitionInfo
- partition metadatagroupingKey
- grouping keycount
- count of index entries to return- Returns:
- cursor over the N (or fewer) newest index entries
-
getOldestNDocuments
@Nonnull public LuceneRecordCursor getOldestNDocuments(@Nonnull com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo partitionInfo, @Nonnull Tuple groupingKey, int count) get the oldest N index entries in a given Lucene partition.- Parameters:
partitionInfo
- partition metadatagroupingKey
- grouping keycount
- count of index entries to return- Returns:
- cursor over the N (or fewer) oldest index entries
-
getAllPartitionMetaInfo
public CompletableFuture<List<com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo>> getAllPartitionMetaInfo(@Nonnull Tuple groupingKey) Get all partition metadata for a given grouping key.- Parameters:
groupingKey
- grouping key- Returns:
- future list of partition metadata
-
getPartitionMetaInfoById
@Nonnull public CompletableFuture<com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo> getPartitionMetaInfoById(int partitionId, @Nonnull Tuple groupingKey) find the partition metadata for a given partition id.- Parameters:
partitionId
- partition idgroupingKey
- grouping key- Returns:
- future of: partition info, or null if not found
-
getNextOlderPartitionInfo
@Nonnull public static CompletableFuture<com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo> getNextOlderPartitionInfo(@Nonnull FDBRecordContext context, @Nonnull Tuple groupingKey, @Nullable Tuple previousKey, @Nonnull Subspace indexSubspace) get the next "older" partition for a given partition key.- Parameters:
context
- FDB record contextgroupingKey
- grouping keypreviousKey
- partition keyindexSubspace
- index subspace- Returns:
- partition future
-
getNextNewerPartitionInfo
@Nonnull public static CompletableFuture<com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo> getNextNewerPartitionInfo(@Nonnull FDBRecordContext context, @Nonnull Tuple groupingKey, @Nullable Tuple currentPartitionKey, @Nonnull Subspace indexSubspace) get the next "newer" partition for a given partition key.- Parameters:
context
- FDB record contextgroupingKey
- grouping keycurrentPartitionKey
- current partition keyindexSubspace
- index subspace- Returns:
- partition future
-
toPartitionKey
@Nonnull public Tuple toPartitionKey(@Nonnull Object partitioningFieldValue, @Nonnull Tuple primaryKey) convenience function that builds a partitioning key value from a partitioning field value and a primary key.- Parameters:
partitioningFieldValue
- partitioning field valueprimaryKey
- record primary key- Returns:
- partitioning key value tuple
-
isOlderThan
public static boolean isOlderThan(@Nonnull Tuple key, @Nonnull com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo partitionInfo) convenience function that evaluates whether a given partitioning key tuple is "older" than the given partitioning metadata.- Parameters:
key
- partitioning key tuplepartitionInfo
- partitioning meta data- Returns:
- true if key is "older" than partitionInfo
-
isPrefixOlderThanPartition
public static boolean isPrefixOlderThanPartition(@Nonnull Tuple prefix, @Nonnull com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo partitionInfo) -
isNewerThan
public static boolean isNewerThan(@Nonnull Tuple key, @Nonnull com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo partitionInfo) convenience function that evaluates whether a given partitioning key tuple is "newer" than the given partitioning metadata.- Parameters:
key
- partitioning key tuplepartitionInfo
- partitioning meta data- Returns:
- true if key is "newer" than partitionInfo
-
getPartitionKey
@Nonnull public static Tuple getPartitionKey(@Nonnull com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo partitionInfo) convenience function that returns the partitioning key of a given partition metadata object.- Parameters:
partitionInfo
- partition metadata- Returns:
- partition key tuple
-
getToTuple
@Nonnull public static Tuple getToTuple(@Nonnull com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo partitionInfo) convenience function that returns theto
value of a given partition metadata object.- Parameters:
partitionInfo
- partition metadata- Returns:
- to tuple
-
getPartitionNeighbors
@Nonnull public static com.apple.foundationdb.record.util.pair.Pair<com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo,com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo> getPartitionNeighbors(@Nonnull List<com.apple.foundationdb.record.lucene.LucenePartitionInfoProto.LucenePartitionInfo> allPartitions, int currentPartitionPosition) return the neighbors of a given partition in a list.- Parameters:
allPartitions
- all partitionscurrentPartitionPosition
- current partition's position in the list- Returns:
- pair of left and right neighbors
-