Skip to content

Commit

Permalink
Don't expect a writeModelCount for ThingDeleteModel
Browse files Browse the repository at this point in the history
* In case of a retry, the entry could already be deleted and therefore
  the deleted count is 0 but the expected writeModelCount is 1.
  This will lead to an infinite loop

Signed-off-by: Yannic Klem <Yannic.Klem@bosch.io>
  • Loading branch information
Yannic92 committed Feb 1, 2022
1 parent 52245df commit 0bc9017
Showing 1 changed file with 6 additions and 3 deletions.
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.ditto.thingsearch.api.commands.sudo.UpdateThingResponse;
import org.eclipse.ditto.thingsearch.service.persistence.write.model.AbstractWriteModel;
import org.eclipse.ditto.thingsearch.service.persistence.write.model.Metadata;
import org.eclipse.ditto.thingsearch.service.persistence.write.model.ThingDeleteModel;
import org.eclipse.ditto.thingsearch.service.persistence.write.model.WriteResultAndErrors;

import com.mongodb.ErrorCategory;
Expand Down Expand Up @@ -199,9 +200,11 @@ private static ConsistencyCheckResult checkForConsistencyError(final WriteResult

private static boolean areUpdatesMissing(final WriteResultAndErrors resultAndErrors) {
final var result = resultAndErrors.getBulkWriteResult();
final int writeModelCount = resultAndErrors.getWriteModels().size();
final int matchedCount = result.getMatchedCount();
final int upsertCount = result.getUpserts().size();
final long writeModelCount = resultAndErrors.getWriteModels().stream()
.filter(writeModel -> !(writeModel instanceof ThingDeleteModel))
.count();
final long matchedCount = result.getMatchedCount();
final long upsertCount = result.getUpserts().size();
return matchedCount + upsertCount < writeModelCount;
}

Expand Down

0 comments on commit 0bc9017

Please sign in to comment.