@Override public void postDelete(ShardId shardId, Engine.Delete delete, Engine.DeleteResult result) { ChangeEvent change=new ChangeEvent( shardId.getIndex().getName(), delete.type(), delete.id(), new DateTime(), ChangeEvent.Operation.DELETE, result.getVersion(), null ); addChange(change); }
deleteResult = deleteInLucene(delete, plan); } else { deleteResult = new DeleteResult(plan.versionOfDeletion, plan.currentlyDeleted == false); if (!deleteResult.hasFailure() && delete.origin() != Operation.Origin.LOCAL_TRANSLOG_RECOVERY) { Translog.Location location = translog.add(new Translog.Delete(delete, deleteResult)); deleteResult.setTranslogLocation(location); deleteResult.setTook(System.nanoTime() - delete.startTime()); deleteResult.freeze(); } catch (RuntimeException | IOException e) { try {
deleteResult = deleteInLucene(delete, plan); } else { deleteResult = new DeleteResult( plan.versionOfDeletion, getPrimaryTerm(), plan.seqNoOfDeletion, plan.currentlyDeleted == false); if (deleteResult.getResultType() == Result.Type.SUCCESS) { location = translog.add(new Translog.Delete(delete, deleteResult)); } else if (deleteResult.getSeqNo() != SequenceNumbers.UNASSIGNED_SEQ_NO) { final NoOp noOp = new NoOp(deleteResult.getSeqNo(), delete.primaryTerm(), delete.origin(), delete.startTime(), deleteResult.getFailure().toString()); location = innerNoOp(noOp).getTranslogLocation(); } else { location = null; deleteResult.setTranslogLocation(location); if (deleteResult.getSeqNo() != SequenceNumbers.UNASSIGNED_SEQ_NO) { localCheckpointTracker.markSeqNoAsCompleted(deleteResult.getSeqNo()); deleteResult.setTook(System.nanoTime() - delete.startTime()); deleteResult.freeze(); } catch (RuntimeException | IOException e) { try {
this(delete.type(), delete.id(), delete.uid(), deleteResult.getSeqNo(), delete.primaryTerm(), deleteResult.getVersion(), delete.versionType());
DeleteResponse deleteResponse = new DeleteResponse(primary.shardId(), updateDeleteRequest.type(), updateDeleteRequest.id(), updateOperationResult.getVersion(), ((Engine.DeleteResult) updateOperationResult).isFound()); updateResponse = new UpdateResponse(deleteResponse.getShardInfo(), deleteResponse.getShardId(), deleteResponse.getType(), deleteResponse.getId(),
final DeleteRequest deleteRequest = (DeleteRequest) itemRequest; Engine.DeleteResult deleteResult = executeDeleteRequestOnPrimary(deleteRequest, primary, mappingUpdatedAction, clusterService); if (deleteResult.hasFailure()) { response = null; } else { deleteRequest.version(deleteResult.getVersion()); assert deleteRequest.versionType().validateVersionForWrites(deleteRequest.version()); response = new DeleteResponse(request.shardId(), deleteRequest.type(), deleteRequest.id(), deleteResult.getVersion(), deleteResult.isFound());
deleteResult = deleteInLucene(delete, plan); } else { deleteResult = new DeleteResult( plan.versionOfDeletion, getPrimaryTerm(), plan.seqNoOfDeletion, plan.currentlyDeleted == false); if (deleteResult.getResultType() == Result.Type.SUCCESS) { location = translog.add(new Translog.Delete(delete, deleteResult)); } else if (deleteResult.getSeqNo() != SequenceNumbers.UNASSIGNED_SEQ_NO) { final NoOp noOp = new NoOp(deleteResult.getSeqNo(), delete.primaryTerm(), delete.origin(), delete.startTime(), deleteResult.getFailure().toString()); location = innerNoOp(noOp).getTranslogLocation(); } else { location = null; deleteResult.setTranslogLocation(location); if (deleteResult.getSeqNo() != SequenceNumbers.UNASSIGNED_SEQ_NO) { localCheckpointTracker.markSeqNoAsCompleted(deleteResult.getSeqNo()); deleteResult.setTook(System.nanoTime() - delete.startTime()); deleteResult.freeze(); } catch (RuntimeException | IOException e) { try {
engineConfig.getThreadPool().relativeTimeInMillis())); return new DeleteResult( plan.versionOfDeletion, getPrimaryTerm(), plan.seqNoOfDeletion, plan.currentlyDeleted == false); } catch (Exception ex) { if (indexWriter.getTragicException() == null) { return new DeleteResult( ex, plan.versionOfDeletion, getPrimaryTerm(), plan.seqNoOfDeletion, plan.currentlyDeleted == false); } else {
Engine.DeleteResult deleteResult = (Engine.DeleteResult) result; response = new DeleteResponse(primary.shardId(), requestToExecute.type(), requestToExecute.id(), deleteResult.getSeqNo(), result.getTerm(), deleteResult.getVersion(), deleteResult.isFound());
Engine.DeleteResult deleteResult = (Engine.DeleteResult) result; response = new DeleteResponse(primary.shardId(), requestToExecute.type(), requestToExecute.id(), deleteResult.getSeqNo(), result.getTerm(), deleteResult.getVersion(), deleteResult.isFound());
return new Engine.DeleteResult(e, request.version(), false); return new Engine.DeleteResult(1L, true);
deleteResult = deleteInLucene(delete, plan); } else { deleteResult = new DeleteResult(plan.versionOfDeletion, plan.currentlyDeleted == false); if (!deleteResult.hasFailure() && delete.origin() != Operation.Origin.LOCAL_TRANSLOG_RECOVERY) { deleteResult.setTranslogLocation( translog.add( delete.estimatedSizeInBytes() )); deleteResult.setTook(System.nanoTime() - delete.startTime()); deleteResult.freeze(); } catch (RuntimeException | IOException e) { try {
private Engine.DeleteResult applyDeleteOperation(long seqNo, long opPrimaryTerm, long version, String type, String id, VersionType versionType, Engine.Operation.Origin origin) throws IOException { assert opPrimaryTerm <= this.operationPrimaryTerm : "op term [ " + opPrimaryTerm + " ] > shard term [" + this.operationPrimaryTerm + "]"; assert versionType.validateVersionForWrites(version); ensureWriteAllowed(origin); if (indexSettings().isSingleType()) { // When there is a single type, the unique identifier is only composed of the _id, // so there is no way to differenciate foo#1 from bar#1. This is especially an issue // if a user first deletes foo#1 and then indexes bar#1: since we do not encode the // _type in the uid it might look like we are reindexing the same document, which // would fail if bar#1 is indexed with a lower version than foo#1 was deleted with. // In order to work around this issue, we make deletions create types. This way, we // fail if index and delete operations do not use the same type. 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, operationPrimaryTerm, seqNo, false); } } final Term uid = extractUidForDelete(type, id); final Engine.Delete delete = prepareDelete(type, id, uid, seqNo, opPrimaryTerm, version, versionType, origin); return delete(getEngine(), delete); }
private Engine.DeleteResult applyDeleteOperation(long seqNo, long opPrimaryTerm, long version, String type, String id, VersionType versionType, Engine.Operation.Origin origin) throws IOException { assert opPrimaryTerm <= this.operationPrimaryTerm : "op term [ " + opPrimaryTerm + " ] > shard term [" + this.operationPrimaryTerm + "]"; assert versionType.validateVersionForWrites(version); ensureWriteAllowed(origin); if (indexSettings().isSingleType()) { // When there is a single type, the unique identifier is only composed of the _id, // so there is no way to differentiate foo#1 from bar#1. This is especially an issue // if a user first deletes foo#1 and then indexes bar#1: since we do not encode the // _type in the uid it might look like we are reindexing the same document, which // would fail if bar#1 is indexed with a lower version than foo#1 was deleted with. // In order to work around this issue, we make deletions create types. This way, we // fail if index and delete operations do not use the same type. 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, operationPrimaryTerm, seqNo, false); } } final Term uid = extractUidForDelete(type, id); final Engine.Delete delete = prepareDelete(type, id, uid, seqNo, opPrimaryTerm, version, versionType, origin); return delete(getEngine(), delete); }
public static Engine.DeleteResult executeDeleteRequestOnReplica(DeleteRequest request, IndexShard replica) throws IOException { if (replica.indexSettings().isSingleType()) { // We need to wait for the replica to have the mappings Mapping update; try { update = replica.mapperService().documentMapperWithAutoCreate(request.type()).getMapping(); } catch (MapperParsingException | IllegalArgumentException e) { return new Engine.DeleteResult(e, request.version(), false); } if (update != null) { final ShardId shardId = replica.shardId(); throw new RetryOnReplicaException(shardId, "Mappings are not available on the replica yet, triggered update: " + update); } } final Engine.Delete delete = replica.prepareDeleteOnReplica(request.type(), request.id(), request.version(), request.versionType()); return replica.delete(delete); } }
private DeleteResult deleteInLucene(Delete delete, DeletionStrategy plan) throws IOException { try { if (plan.currentlyDeleted == false) { // any exception that comes from this is a either an ACE or a fatal exception there // can't be any document failures coming from this indexWriter.deleteDocuments(delete.uid()); } /* versionMap.putUnderLock(delete.uid().bytes(), new DeleteVersionValue(plan.versionOfDeletion, engineConfig.getThreadPool().relativeTimeInMillis())); */ return new DeleteResult(plan.versionOfDeletion, plan.currentlyDeleted == false); } catch (Exception ex) { if (indexWriter.getTragicException() == null) { // there is no tragic event and such it must be a document level failure return new DeleteResult(ex, plan.versionOfDeletion, plan.currentlyDeleted == false); } else { throw ex; } } }
private DeleteResult deleteInLucene(Delete delete, DeletionStrategy plan) throws IOException { try { if (plan.currentlyDeleted == false) { // any exception that comes from this is a either an ACE or a fatal exception there // can't be any document failures coming from this indexWriter.deleteDocuments(delete.uid()); } versionMap.putUnderLock(delete.uid().bytes(), new DeleteVersionValue(plan.versionOfDeletion, engineConfig.getThreadPool().relativeTimeInMillis())); return new DeleteResult(plan.versionOfDeletion, plan.currentlyDeleted == false); } catch (Exception ex) { if (indexWriter.getTragicException() == null) { // there is no tragic event and such it must be a document level failure return new DeleteResult(ex, plan.versionOfDeletion, plan.currentlyDeleted == false); } else { throw ex; } } }
@Override public void postDelete(ShardId shardId, Engine.Delete delete, Engine.DeleteResult result) { switch (result.getResultType()) { case SUCCESS: if (!delete.origin().isRecovery()) { long took = result.getTook(); totalStats.deleteMetric.inc(took); totalStats.deleteCurrent.dec(); StatsHolder typeStats = typeStats(delete.type()); typeStats.deleteMetric.inc(took); typeStats.deleteCurrent.dec(); } break; case FAILURE: postDelete(shardId, delete, result.getFailure()); break; default: throw new IllegalArgumentException("unknown result type: " + result.getResultType()); } }
@Override public void postDelete(ShardId shardId, Engine.Delete delete, Engine.DeleteResult result) { switch (result.getResultType()) { case SUCCESS: if (!delete.origin().isRecovery()) { long took = result.getTook(); totalStats.deleteMetric.inc(took); totalStats.deleteCurrent.dec(); StatsHolder typeStats = typeStats(delete.type()); typeStats.deleteMetric.inc(took); typeStats.deleteCurrent.dec(); } break; case FAILURE: postDelete(shardId, delete, result.getFailure()); break; default: throw new IllegalArgumentException("unknown result type: " + result.getResultType()); } }
public Engine.DeleteResult getFailedDeleteResult(Exception e, long version) { return new Engine.DeleteResult(e, version, operationPrimaryTerm); }