Clean up em.removeFromCollection and fix UniqueValueScanner to just log duplicates if scanning all of unique values.
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/58039166 Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/58039166 Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/58039166 Branch: refs/heads/usergrid-1268-akka-211 Commit: 58039166b9b119eb0766b473e43a8a732f3cbd00 Parents: 724968a Author: Michael Russo <[email protected]> Authored: Wed Jun 29 10:39:04 2016 -0700 Committer: Michael Russo <[email protected]> Committed: Wed Jun 29 10:39:04 2016 -0700 ---------------------------------------------------------------------- .../usergrid/tools/UniqueValueScanner.java | 69 +++++++++++--------- 1 file changed, 38 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/usergrid/blob/58039166/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueValueScanner.java ---------------------------------------------------------------------- diff --git a/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueValueScanner.java b/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueValueScanner.java index bdebd01..182e692 100644 --- a/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueValueScanner.java +++ b/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueValueScanner.java @@ -17,9 +17,7 @@ package org.apache.usergrid.tools; -import java.util.Collections; -import java.util.Iterator; -import java.util.UUID; +import java.util.*; import com.netflix.astyanax.connectionpool.exceptions.ConnectionException; import com.netflix.astyanax.model.Column; @@ -208,9 +206,11 @@ public class UniqueValueScanner extends ToolBase { UUID finalAppToFilter = appToFilter; rows.forEachRemaining(row -> { - String fieldName = row.getKey().getKey().getField().getName(); - String scopeType = row.getKey().getScope().getType(); - UUID scopeUUID = row.getKey().getScope().getUuid(); + final String fieldName = row.getKey().getKey().getField().getName(); + final String fieldValue = row.getKey().getKey().getField().getValue().toString(); + final String scopeType = row.getKey().getScope().getType(); + final UUID scopeUUID = row.getKey().getScope().getUuid(); + if (!fieldName.equalsIgnoreCase(fieldType) || (finalAppToFilter != null && !finalAppToFilter.equals(scopeUUID)) @@ -223,16 +223,19 @@ public class UniqueValueScanner extends ToolBase { em = emf.getEntityManager(scopeUUID); } - Iterator<Column<EntityVersion>> columns = row.getColumns().iterator(); - columns.forEachRemaining(column -> { + // if we have more than 1 column, let's check for a duplicate + if(row.getColumns().size() > 1) { + + final List<EntityVersion> values = new ArrayList<>(row.getColumns().size()); + + Iterator<Column<EntityVersion>> columns = row.getColumns().iterator(); + columns.forEachRemaining(column -> { + - EntityVersion entityVersion = column.getName(); - if (entityType != null && - entityVersion.getEntityId().getType().equalsIgnoreCase(entityType) - ) { + final EntityVersion entityVersion = column.getName(); + - String fieldValue = row.getKey().getKey().getField().getValue().toString(); logger.trace( scopeType + ": " + scopeUUID + ", " + @@ -242,30 +245,34 @@ public class UniqueValueScanner extends ToolBase { ); - Entity entity = em.getUniqueEntityFromAlias(entityType, fieldValue, false); + if (entityType != null && + entityVersion.getEntityId().getType().equalsIgnoreCase(entityType) + ) { -// Optional<MvccEntity> entity = mvccEntitySerializationStrategy. -// load(new ApplicationScopeImpl(new SimpleId(scopeUUID, scopeType)), entityVersion.getEntityId()); -// -// if(!entity.isPresent()){ + // add the first value into the list + if(values.size() == 0 ) { - if (entity == null) { + values.add(entityVersion); - logger.error("{}: {}. Entity with type=[{}], name=[{}], and uuid=[{}] has a unique value entry " + - "but cannot be loaded from Mvcc entity serialization", - scopeType, - scopeUUID, - entityVersion.getEntityId().getType(), - fieldValue, - entityVersion.getEntityId().getUuid()); - } - } else { - // do nothing - } + }else{ + + if( !values.get(0).getEntityId().getUuid().equals(entityVersion.getEntityId().getUuid())){ + values.add(entityVersion); - }); + logger.error("Duplicate found for field [{}={}]. Entry 1: [{}], Entry 2: [{}]", + fieldName, fieldValue, values.get(0).getEntityId(), entityVersion.getEntityId()); + + } + + } + + + } + + }); + } }
