Skip to content

Commit

Permalink
HSEARCH-3836 Accept routing keys in PojoScopeWorkspace.purge() and Se…
Browse files Browse the repository at this point in the history
…archWorkspace.purge()
  • Loading branch information
yrodiere committed Feb 21, 2020
1 parent feb5b7c commit e94e4e1
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,20 @@ without waiting for the transaction commit.
This interface offers the following methods:

`purge()`::
Purge the indexes targeted by this workspace, removing all documents.
Delete all documents from indexes targeted by this workspace.
+
When using multi-tenancy, only documents of one tenant will be removed:
With multi-tenancy enabled, only documents of the current tenant will be removed:
the tenant of the session from which this workspace originated.
`purgeAsync()`::
Asynchronous version of `purge()` returning a `CompletableFuture`.
`purge(Set<String> routingKeys)`::
Delete documents from indexes targeted by this workspace
that were indexed with any of the given routing keys.
+
With multi-tenancy enabled, only documents of the current tenant will be removed:
the tenant of the session from which this workspace originated.
`purgeAsync(Set<String> routingKeys)`::
Asynchronous version of `purge(Set<String>)` returning a `CompletableFuture`.
[[mapper-orm-indexing-manual-flush]]`flush()`::
Flush to disk the changes to indexes that have not been committed yet.
In the case of backends with a transaction log (Elasticsearch),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.hibernate.search.mapper.orm.massindexing.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -178,7 +179,7 @@ private void afterBatchOnInterruption() throws InterruptedException {
*/
private void beforeBatch() throws InterruptedException {
if ( this.purgeAtStart ) {
Futures.unwrappedExceptionGet( scopeWorkspace.purge() );
Futures.unwrappedExceptionGet( scopeWorkspace.purge( Collections.emptySet() ) );
if ( this.mergeSegmentsAfterPurge ) {
Futures.unwrappedExceptionGet( scopeWorkspace.mergeSegments() );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package org.hibernate.search.mapper.orm.work;

import java.util.Set;
import java.util.concurrent.CompletableFuture;

/**
Expand All @@ -23,9 +24,9 @@
public interface SearchWorkspace {

/**
* Purge the data targeted by this workspaces, removing all documents.
* Delete all documents from indexes targeted by this workspace.
* <p>
* When using multi-tenancy, only documents of one tenant will be removed:
* With multi-tenancy enabled, only documents of the current tenant will be removed:
* the tenant that was targeted by the session from where this workspace originated.
*/
void purge();
Expand All @@ -38,6 +39,28 @@ public interface SearchWorkspace {
*/
CompletableFuture<?> purgeAsync();

/**
* Delete documents from indexes targeted by this workspace
* that were indexed with any of the given routing keys.
* <p>
* With multi-tenancy enabled, only documents of the current tenant will be removed:
* the tenant that was targeted by the session from where this workspace originated.
*
* @param routingKeys The set of routing keys.
* If non-empty, only documents that were indexed with these routing keys will be deleted.
* If empty, documents will be deleted regardless of their routing key.
*/
void purge(Set<String> routingKeys);

/**
* Asynchronous version of {@link #purge(Set)}, returning as soon as the operation is queued.
*
* @param routingKeys The set of routing keys.
* @return A {@link CompletableFuture} reflecting the completion state of the operation.
* @see #purge(Set)
*/
CompletableFuture<?> purgeAsync(Set<String> routingKeys);

/**
* Flush to disk the changes to indexes that were not committed yet.
* In the case of backends with a transaction log (Elasticsearch),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
package org.hibernate.search.mapper.orm.work.impl;

import java.util.Collections;
import java.util.Set;
import java.util.concurrent.CompletableFuture;

import org.hibernate.search.mapper.orm.work.SearchWorkspace;
Expand All @@ -31,12 +33,22 @@ public CompletableFuture<?> mergeSegmentsAsync() {

@Override
public void purge() {
Futures.unwrappedExceptionJoin( purgeAsync() );
purge( Collections.emptySet() );
}

@Override
public CompletableFuture<?> purgeAsync() {
return delegate.purge();
return purgeAsync( Collections.emptySet() );
}

@Override
public void purge(Set<String> routingKeys) {
Futures.unwrappedExceptionJoin( purgeAsync() );
}

@Override
public CompletableFuture<?> purgeAsync(Set<String> routingKeys) {
return delegate.purge( routingKeys );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package org.hibernate.search.mapper.pojo.work.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
Expand All @@ -34,9 +33,8 @@ public CompletableFuture<?> mergeSegments() {
}

@Override
public CompletableFuture<?> purge() {
// TODO HSEARCH-3836 expose the routingKey parameter
return doOperationOnTypes( indexWorkspace -> indexWorkspace.purge( Collections.emptySet() ) );
public CompletableFuture<?> purge(Set<String> routingKeys) {
return doOperationOnTypes( indexWorkspace -> indexWorkspace.purge( routingKeys ) );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
*/
package org.hibernate.search.mapper.pojo.work.spi;

import java.util.Set;
import java.util.concurrent.CompletableFuture;

public interface PojoScopeWorkspace {

CompletableFuture<?> mergeSegments();

CompletableFuture<?> purge();
CompletableFuture<?> purge(Set<String> routingKeys);

CompletableFuture<?> flush();

Expand Down

0 comments on commit e94e4e1

Please sign in to comment.