You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by gr...@apache.org on 2015/11/11 23:50:17 UTC

[1/2] usergrid git commit: Added in extra logic to handle legacy entities and re added in the single case repair.

Repository: usergrid
Updated Branches:
  refs/heads/USERGRID-1076 1fab1db94 -> 80ffb3548


Added in extra logic to handle legacy entities and re added in the single case repair.


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

Branch: refs/heads/USERGRID-1076
Commit: 6acc8d3b5eddbe5a449dee70fe910f8098cf5baf
Parents: 1fab1db
Author: George Reyes <gr...@apache.org>
Authored: Wed Nov 11 14:42:48 2015 -0800
Committer: George Reyes <gr...@apache.org>
Committed: Wed Nov 11 14:42:48 2015 -0800

----------------------------------------------------------------------
 .../usergrid/tools/UniqueIndexCleanup.java      | 70 +++++++++++++++++---
 .../usergrid/tools/UniqueIndexCleanupTest.java  | 20 +++++-
 2 files changed, 78 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/6acc8d3b/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueIndexCleanup.java
----------------------------------------------------------------------
diff --git a/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueIndexCleanup.java b/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueIndexCleanup.java
index d1a63b6..82378cd 100644
--- a/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueIndexCleanup.java
+++ b/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueIndexCleanup.java
@@ -208,7 +208,7 @@ public class UniqueIndexCleanup extends ToolBase {
                                 deleteRow( m, applicationId, collectionName, uniqueValueKey, uniqueValue );
                             }
                             else {
-                                entityUUIDDelete( m, applicationId, collectionName, uniqueValueKey, uniqueValue, cols );
+                                entityUUIDDelete( m, applicationId, collectionName, uniqueValueKey, uniqueValue, cols,returnedRowKey );
                             }
                         }
                     }
@@ -275,7 +275,7 @@ public class UniqueIndexCleanup extends ToolBase {
 
     private void entityUUIDDelete( final Mutator<ByteBuffer> m, final UUID applicationId, final String collectionName,
                                    final String uniqueValueKey, final String uniqueValue,
-                                   final List<HColumn<ByteBuffer, ByteBuffer>> cols ) throws Exception {
+                                   final List<HColumn<ByteBuffer, ByteBuffer>> cols, String rowKey ) throws Exception {
         Boolean cleanup = false;
         EntityManagerImpl em = ( EntityManagerImpl ) emf.getEntityManager( applicationId );
         int numberOfColumnsDeleted = 0;
@@ -320,16 +320,43 @@ public class UniqueIndexCleanup extends ToolBase {
         }
 
         //this means that the same unique rowkey has two values associated with it
-        if(entities[0]!=null && entities[1]!=null){
+        if(index>2){
             Entity mostRecentEntity = entities[0];
             for(Entity entity: entities){
+                if(mostRecentEntity == null){
+                    System.out.println( "Most Recent entity is null and is being replaced by regular entity" );
+                    mostRecentEntity = entity;
+                }
+                if(entity == null){
+                    System.out.println("Entity we're cycling through is null and we need more new entities");
+                    continue;
+                }
+
+                mostRecentEntity = verifyModifiedTimestamp( mostRecentEntity );
+                entity = verifyModifiedTimestamp( entity );
+
+
                 if(mostRecentEntity.getModified() > entity.getModified()){
-                    em.deleteEntity( entity.getUuid() );
-                    System.out.println("Deleting "+entity.getUuid().toString()+" because it shares older unique value with: "+uniqueValue);
+                    System.out.println("Deleting "+entity.getUuid().toString()+" because it is the older column in the following rowkey: "+rowKey);
+                    System.out.flush();
+                    //                    try {
+                        em.deleteEntity( entity.getUuid() );
+//                    }catch(Exception e){
+//                        System.out.println("Found error when trying to delete the following uuid: "+entity.getUuid()+" Please repair manually or remote debug.");
+//                        System.out.println(e.getMessage());
+//                        break;
+//                    }
                 }
                 else if (mostRecentEntity.getModified() < entity.getModified()){
-                    System.out.println("Deleting "+mostRecentEntity.getUuid().toString()+" because it shares older unique value with: "+uniqueValue);
-                    em.deleteEntity( mostRecentEntity.getUuid() );
+                    System.out.println("Deleting "+mostRecentEntity.getUuid().toString()+" because it is the older column in the following rowkey: "+rowKey);
+                    System.out.flush();
+                    //try {
+                        em.deleteEntity( mostRecentEntity.getUuid() );
+//                    }catch(Exception e){
+//                        System.out.println("Found error when trying to delete the following uuid: "+mostRecentEntity.getUuid()+" Please repair manually or remote debug.");
+//                        System.out.println(e.getMessage());
+//                        break;
+//                    }
                     mostRecentEntity = entity;
                 }
                 else if (mostRecentEntity.getModified() == entity.getModified() && !mostRecentEntity.getUuid().equals( entity.getUuid() )){
@@ -349,6 +376,26 @@ public class UniqueIndexCleanup extends ToolBase {
     }
 
 
+    private Entity verifyModifiedTimestamp( final Entity unverifiedEntity ) {
+        Entity entity = unverifiedEntity;
+        if(entity !=null && entity.getModified()==null) {
+            if(entity.getCreated()!=null){
+                System.out.println("Setting modified timestamp to created for comparison purposes");
+                entity.setModified( entity.getCreated() );
+                return entity;
+            }
+            else{
+                System.out.println("Please delete or remake: "+entity.getUuid());
+                System.out.println("Setting timestamps to 1");
+                entity.setCreated( 1L );
+                entity.setModified( 1L );
+                return entity;
+            }
+        }
+        return entity;
+    }
+
+
     //really only deletes ones that aren't existant for a specific value
     private void deleteInvalidValuesForUniqueProperty( Mutator<ByteBuffer> m, CommandLine line ) throws Exception {
         UUID applicationId = UUID.fromString( line.getOptionValue( APPLICATION_ARG ) );
@@ -365,12 +412,13 @@ public class UniqueIndexCleanup extends ToolBase {
 
 
         if ( cols.size() == 0 ) {
-            System.out.println(
-                    "Zero entities were found for this unique value. Its possible it doesn't exist or you typed in in"
-                            + " wrong :p." );
+            System.out.println("Zero columns were found for "+ key.toString()+ ". Will delete rowkey.");
+//            System.out.println(
+//                    "Zero entities were found for this unique value. Its possible it doesn't exist or you typed in in"
+//                            + " wrong :p." );
         }
 
-        entityUUIDDelete( m, applicationId, collectionName, uniqueValueKey, uniqueValue, cols );
+        entityUUIDDelete( m, applicationId, collectionName, uniqueValueKey, uniqueValue, cols,key.toString() );
     }
 
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/6acc8d3b/stack/tools/src/test/java/org/apache/usergrid/tools/UniqueIndexCleanupTest.java
----------------------------------------------------------------------
diff --git a/stack/tools/src/test/java/org/apache/usergrid/tools/UniqueIndexCleanupTest.java b/stack/tools/src/test/java/org/apache/usergrid/tools/UniqueIndexCleanupTest.java
index 088d7e8..e016284 100644
--- a/stack/tools/src/test/java/org/apache/usergrid/tools/UniqueIndexCleanupTest.java
+++ b/stack/tools/src/test/java/org/apache/usergrid/tools/UniqueIndexCleanupTest.java
@@ -444,7 +444,8 @@ public class UniqueIndexCleanupTest {
     }
 
     //POinting at single values is broken now but not entirely used right now anyways.
-    @Ignore
+    //@Ignore
+    @Test
     public void testRepairOfOnlyOneOfTwoColumnsWhilePointingAtSingleValue() throws Exception{
         String rand = RandomStringUtils.randomAlphanumeric( 10 );
 
@@ -509,10 +510,12 @@ public class UniqueIndexCleanupTest {
 //                .get( entityManager.getAlias( applicationInfo.getId(), collectionName, username ).getUuid() ) );
 
 
+        //NEED TO FAIL MORE GRACEFULLY
         //run the cleanup
         UniqueIndexCleanup uniqueIndexCleanup = new UniqueIndexCleanup();
         uniqueIndexCleanup.startTool( new String[] {
                 "-host", "localhost:"+ ServiceITSuite.cassandraResource.getRpcPort(),
+                "-col",collectionName,
                 "-app",applicationInfo.getId().toString(),
                 "-property","username",
                 "-value",username
@@ -524,5 +527,20 @@ public class UniqueIndexCleanupTest {
 
     }
 
+    @Test
+    public void errorchecker(){
+        System.out.println( "Started" );
+
+        UniqueIndexCleanup uniqueIndexCleanup = new UniqueIndexCleanup();
+        uniqueIndexCleanup.startTool( new String[] {
+                "-host", "localhost:9160",
+                "-col","users",
+                "-app","00000000-0000-0000-0000-000000000001",
+                "-property","username",
+                "-value","jromero"
+        }, false );
+        System.out.println( "Finished" );
+    }
+
 }
 


[2/2] usergrid git commit: Removed some comments.

Posted by gr...@apache.org.
Removed some comments.


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

Branch: refs/heads/USERGRID-1076
Commit: 80ffb35481740cde38b17d82cec699ac8992d009
Parents: 6acc8d3
Author: George Reyes <gr...@apache.org>
Authored: Wed Nov 11 14:50:12 2015 -0800
Committer: George Reyes <gr...@apache.org>
Committed: Wed Nov 11 14:50:12 2015 -0800

----------------------------------------------------------------------
 .../usergrid/tools/UniqueIndexCleanup.java      | 25 ++++----------------
 1 file changed, 5 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/80ffb354/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueIndexCleanup.java
----------------------------------------------------------------------
diff --git a/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueIndexCleanup.java b/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueIndexCleanup.java
index 82378cd..7c1fadd 100644
--- a/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueIndexCleanup.java
+++ b/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueIndexCleanup.java
@@ -339,24 +339,13 @@ public class UniqueIndexCleanup extends ToolBase {
                 if(mostRecentEntity.getModified() > entity.getModified()){
                     System.out.println("Deleting "+entity.getUuid().toString()+" because it is the older column in the following rowkey: "+rowKey);
                     System.out.flush();
-                    //                    try {
-                        em.deleteEntity( entity.getUuid() );
-//                    }catch(Exception e){
-//                        System.out.println("Found error when trying to delete the following uuid: "+entity.getUuid()+" Please repair manually or remote debug.");
-//                        System.out.println(e.getMessage());
-//                        break;
-//                    }
+                    em.deleteEntity( entity.getUuid() );
+
                 }
                 else if (mostRecentEntity.getModified() < entity.getModified()){
                     System.out.println("Deleting "+mostRecentEntity.getUuid().toString()+" because it is the older column in the following rowkey: "+rowKey);
                     System.out.flush();
-                    //try {
-                        em.deleteEntity( mostRecentEntity.getUuid() );
-//                    }catch(Exception e){
-//                        System.out.println("Found error when trying to delete the following uuid: "+mostRecentEntity.getUuid()+" Please repair manually or remote debug.");
-//                        System.out.println(e.getMessage());
-//                        break;
-//                    }
+                    em.deleteEntity( mostRecentEntity.getUuid() );
                     mostRecentEntity = entity;
                 }
                 else if (mostRecentEntity.getModified() == entity.getModified() && !mostRecentEntity.getUuid().equals( entity.getUuid() )){
@@ -366,8 +355,7 @@ public class UniqueIndexCleanup extends ToolBase {
             }
         }
 
-
-
+        
         //a safer way to do this would be to try to do another get and verify there is nothing left in the column
         //instead of just doing a simple check since the column check happens anywhere between 2 to 1000 times.
         if ( cols.size() == numberOfColumnsDeleted ) {
@@ -412,10 +400,7 @@ public class UniqueIndexCleanup extends ToolBase {
 
 
         if ( cols.size() == 0 ) {
-            System.out.println("Zero columns were found for "+ key.toString()+ ". Will delete rowkey.");
-//            System.out.println(
-//                    "Zero entities were found for this unique value. Its possible it doesn't exist or you typed in in"
-//                            + " wrong :p." );
+            System.out.println( "Zero columns were found for " + key.toString() + ". Will delete rowkey." );
         }
 
         entityUUIDDelete( m, applicationId, collectionName, uniqueValueKey, uniqueValue, cols,key.toString() );