Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

package org.elasticsearch.action.admin.indices.mapping.put;

import org.apache.logging.log4j.Level;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.test.ESSingleNodeTestCase;
import org.elasticsearch.test.MockLog;
import org.elasticsearch.test.junit.annotations.TestLogging;

import static org.hamcrest.Matchers.equalTo;

public class PutMappingIT extends ESSingleNodeTestCase {

@TestLogging(
reason = "testing DEBUG logging",
value = "org.elasticsearch.action.admin.indices.mapping.put.TransportPutMappingAction:DEBUG"
)
public void testFailureLogging() {
final var indexName = randomIdentifier();
createIndex(indexName);
final var fieldName = randomIdentifier();
safeGet(client().execute(TransportPutMappingAction.TYPE, new PutMappingRequest(indexName).source(fieldName, "type=keyword")));
MockLog.assertThatLogger(
() -> assertThat(
asInstanceOf(
IllegalArgumentException.class,
safeAwaitFailure(
AcknowledgedResponse.class,
l -> client().execute(
TransportPutMappingAction.TYPE,
new PutMappingRequest(indexName).source(fieldName, "type=long"),
l
)
)
).getMessage(),
equalTo("mapper [" + fieldName + "] cannot be changed from type [keyword] to [long]")
),
TransportPutMappingAction.class,
new MockLog.SeenEventExpectation(
"failure message",
TransportPutMappingAction.class.getCanonicalName(),
Level.DEBUG,
"failed to put mappings on indices [[" + indexName
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -126,7 +125,7 @@ protected void masterOperation(

performMappingUpdate(concreteIndices, request, listener, metadataMappingService, false);
} catch (IndexNotFoundException ex) {
logger.debug(() -> "failed to put mappings on indices [" + Arrays.asList(request.indices() + "]"), ex);
logger.debug(() -> "failed to put mappings on indices " + Arrays.toString(request.indices()), ex);
throw ex;
}
}
Expand Down Expand Up @@ -162,25 +161,21 @@ static void performMappingUpdate(
MetadataMappingService metadataMappingService,
boolean autoUpdate
) {
final ActionListener<AcknowledgedResponse> wrappedListener = listener.delegateResponse((l, e) -> {
logger.debug(() -> "failed to put mappings on indices [" + Arrays.asList(concreteIndices) + "]", e);
ActionListener.run(listener.delegateResponse((l, e) -> {
logger.debug(() -> "failed to put mappings on indices " + Arrays.toString(concreteIndices), e);
l.onFailure(e);
});
final PutMappingClusterStateUpdateRequest updateRequest;
try {
updateRequest = new PutMappingClusterStateUpdateRequest(
request.masterNodeTimeout(),
request.ackTimeout(),
request.source(),
autoUpdate,
concreteIndices
);
} catch (IOException e) {
wrappedListener.onFailure(e);
return;
}

metadataMappingService.putMapping(updateRequest, wrappedListener);
}),
wrappedListener -> metadataMappingService.putMapping(
new PutMappingClusterStateUpdateRequest(
request.masterNodeTimeout(),
request.ackTimeout(),
request.source(),
autoUpdate,
concreteIndices
),
wrappedListener
)
);
}

static String checkForFailureStoreViolations(ClusterState clusterState, Index[] concreteIndices, PutMappingRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class MetadataMappingService {
public MetadataMappingService(ClusterService clusterService, IndicesService indicesService) {
this.clusterService = clusterService;
this.indicesService = indicesService;
taskQueue = clusterService.createTaskQueue("put-mapping", Priority.HIGH, new PutMappingExecutor());
this.taskQueue = clusterService.createTaskQueue("put-mapping", Priority.HIGH, new PutMappingExecutor());
}

record PutMappingClusterStateUpdateTask(PutMappingClusterStateUpdateRequest request, ActionListener<AcknowledgedResponse> listener)
Expand Down