Skip to content

Commit

Permalink
HSEARCH-3857 In some cases the SearchIndexingPlan generate a Concurre…
Browse files Browse the repository at this point in the history
…ntModificiationException if an embedded entities is not listed in the addOrUpdate or on specific order (if only the last entity is concern this case)
  • Loading branch information
acucumel authored and yrodiere committed Mar 9, 2020
1 parent 100ee0c commit 9236a78
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Expand Up @@ -7,8 +7,10 @@
package org.hibernate.search.mapper.pojo.work.impl;

import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;
Expand Down Expand Up @@ -66,7 +68,10 @@ void purge(Object providedId, String providedRoutingKey) {
}

void resolveDirty(PojoReindexingCollector containingEntityCollector) {
for ( ContainedEntityIndexingPlan plan : indexingPlansPerId.values() ) {
// We need to iterate on a "frozen snapshot" of the indexingPlansPerId values
// because of HSEARCH-3857
List<ContainedEntityIndexingPlan> frozenIndexingPlansPerId = new ArrayList<>( indexingPlansPerId.values() );
for ( ContainedEntityIndexingPlan plan : frozenIndexingPlansPerId ) {
plan.resolveDirty( containingEntityCollector );
}
}
Expand Down
Expand Up @@ -6,8 +6,10 @@
*/
package org.hibernate.search.mapper.pojo.work.impl;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -84,7 +86,10 @@ void updateBecauseOfContained(Object entity) {
}

void resolveDirty(PojoReindexingCollector containingEntityCollector) {
for ( IndexedEntityIndexingPlan plan : indexingPlansPerId.values() ) {
// We need to iterate on a "frozen snapshot" of the indexingPlansPerId values
// because of HSEARCH-3857
List<IndexedEntityIndexingPlan> frozenIndexingPlansPerId = new ArrayList<>( indexingPlansPerId.values() );
for ( IndexedEntityIndexingPlan plan : frozenIndexingPlansPerId ) {
plan.resolveDirty( containingEntityCollector );
}
}
Expand Down Expand Up @@ -230,7 +235,8 @@ void resolveDirty(PojoReindexingCollector containingEntityCollector) {
void sendCommandsToDelegate() {
if ( add ) {
if ( delete ) {
if ( considerAllDirty || updatedBecauseOfContained || typeContext.requiresSelfReindexing( dirtyPaths ) ) {
if ( considerAllDirty || updatedBecauseOfContained || typeContext.requiresSelfReindexing(
dirtyPaths ) ) {
delegate.update(
typeContext.toDocumentReferenceProvider( sessionContext, identifier, entitySupplier ),
typeContext.toDocumentContributor( entitySupplier, sessionContext )
Expand All @@ -247,7 +253,8 @@ void sendCommandsToDelegate() {
else if ( delete ) {
DocumentReferenceProvider referenceProvider =
entitySupplier == null
? typeContext.toDocumentReferenceProvider( sessionContext, identifier, providedRoutingKey )
? typeContext.toDocumentReferenceProvider(
sessionContext, identifier, providedRoutingKey )
: typeContext.toDocumentReferenceProvider( sessionContext, identifier, entitySupplier );
delegate.delete( referenceProvider );
}
Expand Down

0 comments on commit 9236a78

Please sign in to comment.