Skip to content

Commit

Permalink
Consolidate some reindex utility classes (#22666)
Browse files Browse the repository at this point in the history
Everything that extended `AbstractAsyncBulkByScrollAction` also
extended `AbstractAsyncBulkIndexByScrollAction` so this removes
`AbstractAsyncBulkIndexByScrollAction`, merging it into
`AbstractAsyncBulkByScrollAction`.
  • Loading branch information
nik9000 authored Jan 18, 2017
1 parent 51e80e7 commit ee5f8c4
Show file tree
Hide file tree
Showing 13 changed files with 591 additions and 638 deletions.

Large diffs are not rendered by default.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public void doExecute(Task task, DeleteByQueryRequest request, ActionListener<Bu
} else {
ClusterState state = clusterService.state();
ParentTaskAssigningClient client = new ParentTaskAssigningClient(this.client, clusterService.localNode(), task);
new AsyncDeleteBySearchAction((WorkingBulkByScrollTask) task, logger, client, threadPool, request, listener, scriptService,
state).start();
new AsyncDeleteBySearchAction((WorkingBulkByScrollTask) task, logger, client, threadPool, request, scriptService, state,
listener).start();
}
}

Expand All @@ -72,12 +72,11 @@ protected void doExecute(DeleteByQueryRequest request, ActionListener<BulkIndexB
/**
* Implementation of delete-by-query using scrolling and bulk.
*/
static class AsyncDeleteBySearchAction extends AbstractAsyncBulkIndexByScrollAction<DeleteByQueryRequest> {

static class AsyncDeleteBySearchAction extends AbstractAsyncBulkByScrollAction<DeleteByQueryRequest> {
public AsyncDeleteBySearchAction(WorkingBulkByScrollTask task, Logger logger, ParentTaskAssigningClient client,
ThreadPool threadPool, DeleteByQueryRequest request, ActionListener<BulkIndexByScrollResponse> listener,
ScriptService scriptService, ClusterState clusterState) {
super(task, logger, client, threadPool, request, listener, scriptService, clusterState);
ThreadPool threadPool, DeleteByQueryRequest request, ScriptService scriptService, ClusterState clusterState,
ActionListener<BulkIndexByScrollResponse> listener) {
super(task, logger, client, threadPool, request, scriptService, clusterState, listener);
}

@Override
Expand Down Expand Up @@ -107,8 +106,7 @@ protected RequestWrapper<DeleteRequest> buildRequest(ScrollableHitSource.Hit doc
}

/**
* Overrides the parent {@link AbstractAsyncBulkIndexByScrollAction#copyMetadata(RequestWrapper, ScrollableHitSource.Hit)}
* method that is much more Update/Reindex oriented and so also copies things like timestamp/ttl which we
* Overrides the parent's implementation is much more Update/Reindex oriented and so also copies things like timestamp/ttl which we
* don't care for a deletion.
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ protected void doExecute(Task task, ReindexRequest request, ActionListener<BulkI
validateAgainstAliases(request.getSearchRequest(), request.getDestination(), request.getRemoteInfo(),
indexNameExpressionResolver, autoCreateIndex, state);
ParentTaskAssigningClient client = new ParentTaskAssigningClient(this.client, clusterService.localNode(), task);
new AsyncIndexBySearchAction((WorkingBulkByScrollTask) task, logger, client, threadPool, request, listener, scriptService,
state).start();
new AsyncIndexBySearchAction((WorkingBulkByScrollTask) task, logger, client, threadPool, request, scriptService, state,
listener).start();
}
}

Expand Down Expand Up @@ -230,7 +230,7 @@ static RestClient buildRestClient(RemoteInfo remoteInfo, long taskId, List<Threa
* but this makes no attempt to do any of them so it can be as simple
* possible.
*/
static class AsyncIndexBySearchAction extends AbstractAsyncBulkIndexByScrollAction<ReindexRequest> {
static class AsyncIndexBySearchAction extends AbstractAsyncBulkByScrollAction<ReindexRequest> {
/**
* List of threads created by this process. Usually actions don't create threads in Elasticsearch. Instead they use the builtin
* {@link ThreadPool}s. But reindex-from-remote uses Elasticsearch's {@link RestClient} which doesn't use the
Expand All @@ -240,9 +240,9 @@ static class AsyncIndexBySearchAction extends AbstractAsyncBulkIndexByScrollActi
private List<Thread> createdThreads = emptyList();

public AsyncIndexBySearchAction(WorkingBulkByScrollTask task, Logger logger, ParentTaskAssigningClient client,
ThreadPool threadPool, ReindexRequest request, ActionListener<BulkIndexByScrollResponse> listener,
ScriptService scriptService, ClusterState clusterState) {
super(task, logger, client, threadPool, request, listener, scriptService, clusterState);
ThreadPool threadPool, ReindexRequest request, ScriptService scriptService, ClusterState clusterState,
ActionListener<BulkIndexByScrollResponse> listener) {
super(task, logger, client, threadPool, request, scriptService, clusterState, listener);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ protected void doExecute(Task task, UpdateByQueryRequest request, ActionListener
} else {
ClusterState state = clusterService.state();
ParentTaskAssigningClient client = new ParentTaskAssigningClient(this.client, clusterService.localNode(), task);
new AsyncIndexBySearchAction((WorkingBulkByScrollTask) task, logger, client, threadPool, request, listener, scriptService,
state).start();
new AsyncIndexBySearchAction((WorkingBulkByScrollTask) task, logger, client, threadPool, request, scriptService, state,
listener).start();
}
}

Expand All @@ -83,12 +83,11 @@ protected void doExecute(UpdateByQueryRequest request, ActionListener<BulkIndexB
/**
* Simple implementation of update-by-query using scrolling and bulk.
*/
static class AsyncIndexBySearchAction extends AbstractAsyncBulkIndexByScrollAction<UpdateByQueryRequest> {

static class AsyncIndexBySearchAction extends AbstractAsyncBulkByScrollAction<UpdateByQueryRequest> {
public AsyncIndexBySearchAction(WorkingBulkByScrollTask task, Logger logger, ParentTaskAssigningClient client,
ThreadPool threadPool, UpdateByQueryRequest request, ActionListener<BulkIndexByScrollResponse> listener,
ScriptService scriptService, ClusterState clusterState) {
super(task, logger, client, threadPool, request, listener, scriptService, clusterState);
ThreadPool threadPool, UpdateByQueryRequest request, ScriptService scriptService, ClusterState clusterState,
ActionListener<BulkIndexByScrollResponse> listener) {
super(task, logger, client, threadPool, request, scriptService, clusterState, listener);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

package org.elasticsearch.index.reindex;

public abstract class AbstractAsyncBulkIndexbyScrollActionMetadataTestCase<
public abstract class AbstractAsyncBulkByScrollActionMetadataTestCase<
Request extends AbstractBulkIndexByScrollRequest<Request>,
Response extends BulkIndexByScrollResponse>
extends AbstractAsyncBulkIndexByScrollActionTestCase<Request, Response> {
extends AbstractAsyncBulkByScrollActionTestCase<Request, Response> {

protected ScrollableHitSource.BasicHit doc() {
return new ScrollableHitSource.BasicHit("index", "type", "id", 0);
}

protected abstract AbstractAsyncBulkIndexByScrollAction<Request> action();
protected abstract AbstractAsyncBulkByScrollAction<Request> action();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.index.reindex.AbstractAsyncBulkIndexByScrollAction.OpType;
import org.elasticsearch.index.reindex.AbstractAsyncBulkIndexByScrollAction.RequestWrapper;
import org.elasticsearch.index.reindex.AbstractAsyncBulkByScrollAction.OpType;
import org.elasticsearch.index.reindex.AbstractAsyncBulkByScrollAction.RequestWrapper;
import org.elasticsearch.script.CompiledScript;
import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.script.Script;
Expand All @@ -40,10 +40,10 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public abstract class AbstractAsyncBulkIndexByScrollActionScriptTestCase<
public abstract class AbstractAsyncBulkByScrollActionScriptTestCase<
Request extends AbstractBulkIndexByScrollRequest<Request>,
Response extends BulkIndexByScrollResponse>
extends AbstractAsyncBulkIndexByScrollActionTestCase<Request, Response> {
extends AbstractAsyncBulkByScrollActionTestCase<Request, Response> {

private static final Script EMPTY_SCRIPT = new Script("");

Expand All @@ -62,8 +62,8 @@ protected <T extends ActionRequest> T applyScript(Consumer<Map<String, Object>>

when(scriptService.executable(any(CompiledScript.class), Matchers.<Map<String, Object>>any()))
.thenReturn(executableScript);
AbstractAsyncBulkIndexByScrollAction<Request> action = action(scriptService, request().setScript(EMPTY_SCRIPT));
RequestWrapper<?> result = action.buildScriptApplier().apply(AbstractAsyncBulkIndexByScrollAction.wrap(index), doc);
AbstractAsyncBulkByScrollAction<Request> action = action(scriptService, request().setScript(EMPTY_SCRIPT));
RequestWrapper<?> result = action.buildScriptApplier().apply(AbstractAsyncBulkByScrollAction.wrap(index), doc);
return (result != null) ? (T) result.self() : null;
}

Expand Down Expand Up @@ -104,5 +104,5 @@ public void testSetOpTypeUnknown() throws Exception {
assertThat(e.getMessage(), equalTo("Operation type [unknown] not allowed, only [noop, index, delete] are allowed"));
}

protected abstract AbstractAsyncBulkIndexByScrollAction<Request> action(ScriptService scriptService, Request request);
protected abstract AbstractAsyncBulkByScrollAction<Request> action(ScriptService scriptService, Request request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.junit.After;
import org.junit.Before;

public abstract class AbstractAsyncBulkIndexByScrollActionTestCase<
public abstract class AbstractAsyncBulkByScrollActionTestCase<
Request extends AbstractBulkIndexByScrollRequest<Request>,
Response extends BulkIndexByScrollResponse>
extends ESTestCase {
Expand Down
Loading

0 comments on commit ee5f8c4

Please sign in to comment.