use of org.opensearch.index.mapper.Mapping in project OpenSearch by opensearch-project.
the class InternalEngineTests method dynamicUpdate.
private Mapping dynamicUpdate() {
BuilderContext context = new BuilderContext(Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).build(), new ContentPath());
final RootObjectMapper root = new RootObjectMapper.Builder("some_type").build(context);
return new Mapping(Version.CURRENT, root, new MetadataFieldMapper[0], emptyMap());
}
use of org.opensearch.index.mapper.Mapping in project OpenSearch by opensearch-project.
the class TransportShardBulkActionTests method testRetries.
public void testRetries() throws Exception {
IndexSettings indexSettings = new IndexSettings(indexMetadata(), Settings.EMPTY);
UpdateRequest writeRequest = new UpdateRequest("index", "id").doc(Requests.INDEX_CONTENT_TYPE, "field", "value");
// the beating will continue until success has come.
writeRequest.retryOnConflict(Integer.MAX_VALUE);
BulkItemRequest primaryRequest = new BulkItemRequest(0, writeRequest);
IndexRequest updateResponse = new IndexRequest("index").id("id").source(Requests.INDEX_CONTENT_TYPE, "field", "value");
Exception err = new VersionConflictEngineException(shardId, "id", "I'm conflicted <(;_;)>");
Engine.IndexResult conflictedResult = new Engine.IndexResult(err, 0);
Engine.IndexResult mappingUpdate = new Engine.IndexResult(new Mapping(null, mock(RootObjectMapper.class), new MetadataFieldMapper[0], Collections.emptyMap()));
Translog.Location resultLocation = new Translog.Location(42, 42, 42);
Engine.IndexResult success = new FakeIndexResult(1, 1, 13, true, resultLocation);
IndexShard shard = mock(IndexShard.class);
when(shard.applyIndexOperationOnPrimary(anyLong(), any(), any(), anyLong(), anyLong(), anyLong(), anyBoolean())).thenAnswer(ir -> {
if (randomBoolean()) {
return conflictedResult;
}
if (randomBoolean()) {
return mappingUpdate;
} else {
return success;
}
});
when(shard.indexSettings()).thenReturn(indexSettings);
when(shard.shardId()).thenReturn(shardId);
when(shard.mapperService()).thenReturn(mock(MapperService.class));
UpdateHelper updateHelper = mock(UpdateHelper.class);
when(updateHelper.prepare(any(), eq(shard), any())).thenReturn(new UpdateHelper.Result(updateResponse, randomBoolean() ? DocWriteResponse.Result.CREATED : DocWriteResponse.Result.UPDATED, Collections.singletonMap("field", "value"), Requests.INDEX_CONTENT_TYPE));
BulkItemRequest[] items = new BulkItemRequest[] { primaryRequest };
BulkShardRequest bulkShardRequest = new BulkShardRequest(shardId, RefreshPolicy.NONE, items);
final CountDownLatch latch = new CountDownLatch(1);
TransportShardBulkAction.performOnPrimary(bulkShardRequest, shard, updateHelper, threadPool::absoluteTimeInMillis, new NoopMappingUpdatePerformer(), listener -> listener.onResponse(null), new LatchedActionListener<>(ActionTestUtils.assertNoFailureListener(result -> {
assertThat(((WritePrimaryResult<BulkShardRequest, BulkShardResponse>) result).location, equalTo(resultLocation));
BulkItemResponse primaryResponse = result.replicaRequest().items()[0].getPrimaryResponse();
assertThat(primaryResponse.getItemId(), equalTo(0));
assertThat(primaryResponse.getId(), equalTo("id"));
assertThat(primaryResponse.getOpType(), equalTo(DocWriteRequest.OpType.UPDATE));
DocWriteResponse response = primaryResponse.getResponse();
assertThat(response.status(), equalTo(RestStatus.CREATED));
assertThat(response.getSeqNo(), equalTo(13L));
}), latch), threadPool, Names.WRITE);
latch.await();
}
use of org.opensearch.index.mapper.Mapping in project OpenSearch by opensearch-project.
the class MappingUpdatedActionTests method testMappingUpdatedActionBlocks.
public void testMappingUpdatedActionBlocks() throws Exception {
List<ActionListener<Void>> inFlightListeners = new CopyOnWriteArrayList<>();
final MappingUpdatedAction mua = new MappingUpdatedAction(Settings.builder().put(MappingUpdatedAction.INDICES_MAX_IN_FLIGHT_UPDATES_SETTING.getKey(), 1).build(), new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), null) {
@Override
protected void sendUpdateMapping(Index index, Mapping mappingUpdate, ActionListener<Void> listener) {
inFlightListeners.add(listener);
}
};
PlainActionFuture<Void> fut1 = new PlainActionFuture<>();
mua.updateMappingOnMaster(null, null, fut1);
assertEquals(1, inFlightListeners.size());
assertEquals(0, mua.blockedThreads());
PlainActionFuture<Void> fut2 = new PlainActionFuture<>();
Thread thread = new Thread(() -> {
// blocked
mua.updateMappingOnMaster(null, null, fut2);
});
thread.start();
assertBusy(() -> assertEquals(1, mua.blockedThreads()));
assertEquals(1, inFlightListeners.size());
assertFalse(fut1.isDone());
inFlightListeners.remove(0).onResponse(null);
assertTrue(fut1.isDone());
thread.join();
assertEquals(0, mua.blockedThreads());
assertEquals(1, inFlightListeners.size());
assertFalse(fut2.isDone());
inFlightListeners.remove(0).onResponse(null);
assertTrue(fut2.isDone());
}
use of org.opensearch.index.mapper.Mapping in project OpenSearch by opensearch-project.
the class IndexShard method applyDeleteOperation.
private Engine.DeleteResult applyDeleteOperation(Engine engine, long seqNo, long opPrimaryTerm, long version, String type, String id, @Nullable VersionType versionType, long ifSeqNo, long ifPrimaryTerm, Engine.Operation.Origin origin) throws IOException {
assert opPrimaryTerm <= getOperationPrimaryTerm() : "op term [ " + opPrimaryTerm + " ] > shard term [" + getOperationPrimaryTerm() + "]";
ensureWriteAllowed(origin);
// TODO: clean this up when types are gone
try {
Mapping update = docMapper(type).getMapping();
if (update != null) {
return new Engine.DeleteResult(update);
}
} catch (MapperParsingException | IllegalArgumentException | TypeMissingException e) {
return new Engine.DeleteResult(e, version, getOperationPrimaryTerm(), seqNo, false);
}
if (mapperService.resolveDocumentType(type).equals(mapperService.documentMapper().type()) == false) {
// document in the wrong type.
throw new IllegalStateException("Deleting document from type [" + mapperService.resolveDocumentType(type) + "] while current type is [" + mapperService.documentMapper().type() + "]");
}
final Term uid = new Term(IdFieldMapper.NAME, Uid.encodeId(id));
final Engine.Delete delete = prepareDelete(type, id, uid, seqNo, opPrimaryTerm, version, versionType, origin, ifSeqNo, ifPrimaryTerm);
return delete(engine, delete);
}
use of org.opensearch.index.mapper.Mapping in project OpenSearch by opensearch-project.
the class TranslogHandler method applyOperation.
private void applyOperation(Engine engine, Engine.Operation operation) throws IOException {
switch(operation.operationType()) {
case INDEX:
Engine.Index engineIndex = (Engine.Index) operation;
Mapping update = engineIndex.parsedDoc().dynamicMappingsUpdate();
if (engineIndex.parsedDoc().dynamicMappingsUpdate() != null) {
recoveredTypes.compute(engineIndex.type(), (k, mapping) -> mapping == null ? update : mapping.merge(update, MapperService.MergeReason.MAPPING_RECOVERY));
}
engine.index(engineIndex);
break;
case DELETE:
engine.delete((Engine.Delete) operation);
break;
case NO_OP:
engine.noOp((Engine.NoOp) operation);
break;
default:
throw new IllegalStateException("No operation defined for [" + operation + "]");
}
}
Aggregations