Skip to content

Commit

Permalink
Don't block, just return null if not known
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveCTurner committed Dec 4, 2020
1 parent 4c59e23 commit d44afc0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,14 @@ private static DateFieldMapper.DateFieldType fromMapperService(MapperService map
/**
* @return the field type of the {@code @timestamp} field of the given index, or {@code null} if:
* - the index is not found,
* - the field is not found, or
* - the field is not found,
* - the mapping is not known yet, or
* - the field is not a timestamp field.
*/
@Nullable
public DateFieldMapper.DateFieldType getTimestampFieldType(Index index) {
final PlainActionFuture<DateFieldMapper.DateFieldType> future = fieldTypesByIndex.get(index);
if (future == null) {
if (future == null || future.isDone() == false) {
return null;
}
return future.actionGet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.cluster.metadata.DataStream;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.routing.allocation.command.AllocateStalePrimaryAllocationCommand;
Expand All @@ -22,7 +23,6 @@
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.InternalTestCluster;
import org.elasticsearch.test.junit.annotations.TestLogging;
import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin;
import org.elasticsearch.xpack.core.frozen.action.FreezeIndexAction;
import org.elasticsearch.xpack.frozen.FrozenIndices;
Expand Down Expand Up @@ -102,7 +102,7 @@ public void testTimestampRangeRecalculatedOnStalePrimaryAllocation() throws IOEx
assertThat(timestampFieldRange.getMax(), equalTo(Instant.parse("2010-01-06T02:03:04.567Z").getMillis()));
}

public void testTimestampFieldTypeExposedByAllIndicesServices() throws IOException {
public void testTimestampFieldTypeExposedByAllIndicesServices() throws Exception {
internalCluster().startNodes(between(2, 4));

final String locale = randomFrom("", "en_GB", "fr_FR");
Expand Down Expand Up @@ -134,9 +134,14 @@ public void testTimestampFieldTypeExposedByAllIndicesServices() throws IOExcepti
assertAcked(client().execute(FreezeIndexAction.INSTANCE, new FreezeRequest("index")).actionGet());
ensureGreen("index");
for (final IndicesService indicesService : internalCluster().getInstances(IndicesService.class)) {
final DateFieldMapper.DateFieldType timestampFieldType = indicesService.getTimestampFieldType(index);
assertNotNull(timestampFieldType);
assertThat(timestampFieldType.dateTimeFormatter().locale().toString(), equalTo(locale));
final PlainActionFuture<DateFieldMapper.DateFieldType> timestampFieldTypeFuture = new PlainActionFuture<>();
assertBusy(() -> {
final DateFieldMapper.DateFieldType timestampFieldType = indicesService.getTimestampFieldType(index);
assertNotNull(timestampFieldType);
timestampFieldTypeFuture.onResponse(timestampFieldType);
});
assertTrue(timestampFieldTypeFuture.isDone());
assertThat(timestampFieldTypeFuture.get().dateTimeFormatter().locale().toString(), equalTo(locale));
}

assertAcked(client().execute(FreezeIndexAction.INSTANCE, new FreezeRequest("index").setFreeze(false)).actionGet());
Expand Down

0 comments on commit d44afc0

Please sign in to comment.