Skip to content

Commit

Permalink
HSEARCH-1429 Allow advanced implementors of DynamicShardingStrategy t…
Browse files Browse the repository at this point in the history
…o narrow down shards id set on delete operations
  • Loading branch information
Sanne committed Oct 7, 2013
1 parent 4ccf8eb commit 9a1a542
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
Expand Up @@ -78,7 +78,7 @@ public IndexManager getIndexManagerForAddition(Class<?> entity, Serializable id,

@Override
public IndexManager[] getIndexManagersForDeletion(Class<?> entity, Serializable id, String idInString) {
Set<String> shardIdentifiers = shardIdentifierProvider.getAllShardIdentifiers();
Set<String> shardIdentifiers = shardIdentifierProvider.getShardIdentifiersForDeletion( entity, id, idInString );
return getIndexManagersFromShards( shardIdentifiers );
}

Expand Down
Expand Up @@ -41,6 +41,8 @@
* Instead of implementing this interface directly, implementations should be derived from
* {@link ShardIdentifierProviderTemplate} as new methods might be added to this interface in future releases.
*
* @experimental The exact method signatures are likely to change in future.
*
* @author Emmanuel Bernard <emmanuel@hibernate.org>
* @author Hardy Ferentschik
* @author Sanne Grinovero <sanne@hibernate.org> (C) 2013 Red Hat Inc.
Expand All @@ -65,7 +67,7 @@ public interface ShardIdentifierProvider {
* <br/>
* Concurrency: this method could be invoked concurrently. That means you could have multiple invocations of
* {@link #getShardIdentifier(Class, Serializable, String, Document)}, {@link #getShardIdentifiersForQuery(FullTextFilterImplementor[])},
* {@link #getAllShardIdentifiers()}.
* {@link #getAllShardIdentifiers()}, {@link #getShardIdentifiersForDeletion(Class, Serializable, String)}.
*
* @param entityType the type of the entity
* @param id the id of the entity
Expand All @@ -83,7 +85,7 @@ public interface ShardIdentifierProvider {
* <br/>
* Concurrency: this method could be invoked concurrently. That means you could have multiple invocations of
* {@link #getShardIdentifier(Class, Serializable, String, Document)}, {@link #getShardIdentifiersForQuery(FullTextFilterImplementor[])},
* {@link #getAllShardIdentifiers()}.
* {@link #getAllShardIdentifiers()}, {@link #getShardIdentifiersForDeletion(Class, Serializable, String)}.
*
* @param fullTextFilters the filters which are applied to the current query
*
Expand All @@ -98,9 +100,28 @@ public interface ShardIdentifierProvider {
* <br/>
* Concurrency: this method could be invoked concurrently. That means you could have multiple invocations of
* {@link #getShardIdentifier(Class, Serializable, String, Document)}, {@link #getShardIdentifiersForQuery(FullTextFilterImplementor[])},
* {@link #getAllShardIdentifiers()}.
* {@link #getAllShardIdentifiers()}, {@link #getShardIdentifiersForDeletion(Class, Serializable, String)}.
*
* @return the list of all currently known shard identifiers.
* @return the set of all currently known shard identifiers.
*/
Set<String> getAllShardIdentifiers();

/**
* Determine the shard identifiers of indexes which might contain an entity identified solely by its id.
* This is needed for purge and delete operations, as no more context is available in such cases.
* <br/>
* This method is made available as some strategies might be able to provide a deterministic answer, but in
* most cases you can safely return the same set as returned by {@link #getAllShardIdentifiers()}.
* <br/>
* Concurrency: this method could be invoked concurrently. That means you could have multiple invocations of
* {@link #getShardIdentifier(Class, Serializable, String, Document)}, {@link #getShardIdentifiersForQuery(FullTextFilterImplementor[])},
* {@link #getAllShardIdentifiers()}, {@link #getShardIdentifiersForDeletion(Class, Serializable, String)}.
*
* @param entityType the type of the entity
* @param id the id of the entity
* @param idAsString the entity id transformed as string via the appropriate document id bridge
*
* @return the set of shards which might contain the document, narrowing down from the given parameters.
*/
Set<String> getShardIdentifiersForDeletion(Class<?> entityType, Serializable id, String idAsString);
}
Expand Up @@ -20,6 +20,7 @@
*/
package org.hibernate.search.store;

import java.io.Serializable;
import java.util.Collections;
import java.util.HashSet;
import java.util.Properties;
Expand All @@ -32,6 +33,8 @@
* Recommended parent class to create custom {@link ShardIdentifierProvider} implementations. Sub-classes must provide a
* no-arg constructor.
*
* @experimental The exact method signatures are likely to change in future.
*
* @author Sanne Grinovero
*/
public abstract class ShardIdentifierProviderTemplate implements ShardIdentifierProvider {
Expand Down Expand Up @@ -72,4 +75,14 @@ public Set<String> getShardIdentifiersForQuery(FullTextFilterImplementor[] fullT
return getAllShardIdentifiers();
}

/**
* Extension point for the case in which you are able to narrow down the shard selection
* to a subset of all shards.
* The default implementation returns all known shard identifiers.
*/
@Override
public Set<String> getShardIdentifiersForDeletion(Class<?> entityType, Serializable id, String idAsString) {
return getAllShardIdentifiers();
}

}
Expand Up @@ -338,5 +338,10 @@ public Set<String> getShardIdentifiersForQuery(FullTextFilterImplementor[] fullT
public Set<String> getAllShardIdentifiers() {
return shards;
}

@Override
public Set<String> getShardIdentifiersForDeletion(Class<?> entityType, Serializable id, String idAsString) {
return shards;
}
}
}

0 comments on commit 9a1a542

Please sign in to comment.