[26/39] usergrid git commit: Added fix for rows that contain duplicate valid existing columns.

2015-11-17 Thread snoopdave
Added fix for rows that contain duplicate valid existing columns.


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/3d5ae464
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/3d5ae464
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/3d5ae464

Branch: refs/heads/1.x
Commit: 3d5ae464766a12b3fac1d82b67da667ef28d17fd
Parents: 00171f0
Author: George Reyes 
Authored: Tue Nov 10 14:49:40 2015 -0800
Committer: George Reyes 
Committed: Tue Nov 10 14:49:40 2015 -0800

--
 .../cassandra/EntityManagerImpl.java| 52 +++-
 1 file changed, 41 insertions(+), 11 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/usergrid/blob/3d5ae464/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
--
diff --git 
a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
 
b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
index ecd0f0a..76cb6d7 100644
--- 
a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
+++ 
b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
@@ -559,27 +559,45 @@ public class EntityManagerImpl implements EntityManager {
 + "property {} with value {}",
 new Object[] { ownerEntityId, collectionNameInternal, 
propertyName, propertyValue } );
 
-//retreive up to 100 columns
+//retrieve up to 100 columns
 List> indexingColumns = 
cass.getColumns( cass.getApplicationKeyspace( applicationId ), ENTITY_UNIQUE, 
key, null, null, 100,
 false );
 
 
+Entity[] entities = new Entity[cols.size()];
+int index = 0;
 
-//go through it column
 for ( HColumn col : indexingColumns ) {
 UUID indexCorruptionUuid = ue.fromByteBuffer( col.getName());
-if (get( indexCorruptionUuid ) == null ) {
-UUID timestampUuid = newTimeUUID();
-long timestamp = getTimestampInMicros( timestampUuid );
-Keyspace ko = cass.getApplicationKeyspace( ownerEntityId );
-Mutator mutator = createMutator( ko, be );
-
-addDeleteToMutator( mutator, ENTITY_UNIQUE, key, 
indexCorruptionUuid, timestamp );
-mutator.execute();
+
+entities[index] = get(indexCorruptionUuid);
+
+if (entities[index] == null ) {
+deleteUniqueColumn( ownerEntityId, key, 
indexCorruptionUuid );
 cols.remove( col );
 }
 else{
-
+index++;
+}
+}
+//this means that the same unique rowkey has two values associated 
with it
+if(entities[0]!=null && entities[1]!=null){
+Entity mostRecentEntity = entities[0];
+for(Entity entity: entities){
+if(mostRecentEntity.getModified() > entity.getModified()){
+deleteEntity( entity.getUuid() );
+logger.info( "Deleting " + entity.getUuid().toString()
++ " because it shares older unique value with: 
" + propertyValue );
+}
+else if (mostRecentEntity.getModified() < 
entity.getModified()){
+logger.info("Deleting 
"+mostRecentEntity.getUuid().toString()+" because it shares older unique value 
with: "+propertyValue);
+deleteEntity( mostRecentEntity.getUuid() );
+mostRecentEntity = entity;
+}
+else if (mostRecentEntity.getModified() == 
entity.getModified() && !mostRecentEntity.getUuid().equals( entity.getUuid() )){
+logger.info("Entities with unique value: 
"+propertyValue+" has two or more entities with the same modified time."
++ "Please manually resolve by query or 
changing names. ");
+}
 }
 }
 }
@@ -603,6 +621,18 @@ public class EntityManagerImpl implements EntityManager {
 }
 
 
+private void deleteUniqueColumn( final UUID ownerEntityId, final Object 
key, final UUID indexCorruptionUuid )
+throws Exception {
+UUID timestampUuid = newTimeUUID();
+long timestamp = getTimestampInMicros( timestampUuid );
+Keyspace ko = cass.getApplicationKeyspace( ownerEntityId );
+

usergrid git commit: Added fix for rows that contain duplicate valid existing columns.

2015-11-10 Thread grey
Repository: usergrid
Updated Branches:
  refs/heads/readRepairForIndexValues 00171f07b -> 3d5ae4647


Added fix for rows that contain duplicate valid existing columns.


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/3d5ae464
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/3d5ae464
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/3d5ae464

Branch: refs/heads/readRepairForIndexValues
Commit: 3d5ae464766a12b3fac1d82b67da667ef28d17fd
Parents: 00171f0
Author: George Reyes 
Authored: Tue Nov 10 14:49:40 2015 -0800
Committer: George Reyes 
Committed: Tue Nov 10 14:49:40 2015 -0800

--
 .../cassandra/EntityManagerImpl.java| 52 +++-
 1 file changed, 41 insertions(+), 11 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/usergrid/blob/3d5ae464/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
--
diff --git 
a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
 
b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
index ecd0f0a..76cb6d7 100644
--- 
a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
+++ 
b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
@@ -559,27 +559,45 @@ public class EntityManagerImpl implements EntityManager {
 + "property {} with value {}",
 new Object[] { ownerEntityId, collectionNameInternal, 
propertyName, propertyValue } );
 
-//retreive up to 100 columns
+//retrieve up to 100 columns
 List> indexingColumns = 
cass.getColumns( cass.getApplicationKeyspace( applicationId ), ENTITY_UNIQUE, 
key, null, null, 100,
 false );
 
 
+Entity[] entities = new Entity[cols.size()];
+int index = 0;
 
-//go through it column
 for ( HColumn col : indexingColumns ) {
 UUID indexCorruptionUuid = ue.fromByteBuffer( col.getName());
-if (get( indexCorruptionUuid ) == null ) {
-UUID timestampUuid = newTimeUUID();
-long timestamp = getTimestampInMicros( timestampUuid );
-Keyspace ko = cass.getApplicationKeyspace( ownerEntityId );
-Mutator mutator = createMutator( ko, be );
-
-addDeleteToMutator( mutator, ENTITY_UNIQUE, key, 
indexCorruptionUuid, timestamp );
-mutator.execute();
+
+entities[index] = get(indexCorruptionUuid);
+
+if (entities[index] == null ) {
+deleteUniqueColumn( ownerEntityId, key, 
indexCorruptionUuid );
 cols.remove( col );
 }
 else{
-
+index++;
+}
+}
+//this means that the same unique rowkey has two values associated 
with it
+if(entities[0]!=null && entities[1]!=null){
+Entity mostRecentEntity = entities[0];
+for(Entity entity: entities){
+if(mostRecentEntity.getModified() > entity.getModified()){
+deleteEntity( entity.getUuid() );
+logger.info( "Deleting " + entity.getUuid().toString()
++ " because it shares older unique value with: 
" + propertyValue );
+}
+else if (mostRecentEntity.getModified() < 
entity.getModified()){
+logger.info("Deleting 
"+mostRecentEntity.getUuid().toString()+" because it shares older unique value 
with: "+propertyValue);
+deleteEntity( mostRecentEntity.getUuid() );
+mostRecentEntity = entity;
+}
+else if (mostRecentEntity.getModified() == 
entity.getModified() && !mostRecentEntity.getUuid().equals( entity.getUuid() )){
+logger.info("Entities with unique value: 
"+propertyValue+" has two or more entities with the same modified time."
++ "Please manually resolve by query or 
changing names. ");
+}
 }
 }
 }
@@ -603,6 +621,18 @@ public class EntityManagerImpl implements EntityManager {
 }
 
 
+private void deleteUniqueColumn( final UUID ownerEntityId, final Object 
key, final UUID indexCorruptionUuid )
+throws Exception {
+UUID timestampUuid = newTimeUUID();
+long