Repository: usergrid Updated Branches: refs/heads/USERGRID-1076 48a8006d4 -> dde3ea668
Added ability to delete rows that contained 0 columns. Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/dde3ea66 Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/dde3ea66 Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/dde3ea66 Branch: refs/heads/USERGRID-1076 Commit: dde3ea668cd9608b2614002b66c1a0469fae71ae Parents: 48a8006 Author: George Reyes <[email protected]> Authored: Thu Nov 5 11:38:24 2015 -0800 Committer: George Reyes <[email protected]> Committed: Thu Nov 5 11:38:24 2015 -0800 ---------------------------------------------------------------------- .../usergrid/tools/UniqueIndexCleanup.java | 43 ++++++++++++-------- 1 file changed, 27 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/usergrid/blob/dde3ea66/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 f795a20..b60981b 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 @@ -68,7 +68,7 @@ public class UniqueIndexCleanup extends ToolBase { /** * */ - private static final int PAGE_SIZE = 1; + private static final int PAGE_SIZE = 100; private static final Logger logger = LoggerFactory.getLogger( UniqueIndexCleanup.class ); @@ -85,6 +85,8 @@ public class UniqueIndexCleanup extends ToolBase { OptionBuilder.withArgName( "host" ).hasArg().isRequired( true ).withDescription( "Cassandra host" ) .create( "host" ); + + options.addOption( hostOption ); return options; @@ -136,30 +138,39 @@ public class UniqueIndexCleanup extends ToolBase { EntityManagerImpl em = ( EntityManagerImpl ) emf.getEntityManager( applicationId ); Boolean cleanup = false; - //TODO: make parsed row key more human friendly. Anybody looking at it doesn't know what value means what. - if ( parsedRowKey[1].equals( "users" ) ) { + if ( collectionName.equals( "users" ) ) { ColumnSlice<ByteBuffer, ByteBuffer> columnSlice = rangeSliceValue.getColumnSlice(); if ( columnSlice.getColumns().size() != 0 ) { System.out.println( returnedRowKey ); List<HColumn<ByteBuffer, ByteBuffer>> cols = columnSlice.getColumns(); + if(cols.size()==0){ + System.out.println("Found 0 uuid's associated with: "+uniqueValue); + UUID timestampUuid = newTimeUUID(); + long timestamp = getTimestampInMicros( timestampUuid ); + Object key = key( applicationId, collectionName, uniqueValueKey, uniqueValue ); + addDeleteToMutator( m,ENTITY_UNIQUE,key,timestamp ); + m.execute(); - for ( HColumn<ByteBuffer, ByteBuffer> col : cols ) { - UUID entityId = ue.fromByteBuffer( col.getName() ); - - if ( applicationId.equals( MANAGEMENT_APPLICATION_ID ) ) { - if ( managementService.getAdminUserByUuid( entityId ) == null ) { + } + else { + for ( HColumn<ByteBuffer, ByteBuffer> col : cols ) { + UUID entityId = ue.fromByteBuffer( col.getName() ); + + if ( applicationId.equals( MANAGEMENT_APPLICATION_ID ) ) { + if ( managementService.getAdminUserByUuid( entityId ) == null ) { + cleanup = true; + } + } + else if ( em.get( entityId ) == null ) { cleanup = true; } - } - else if ( em.get( entityId ) == null ) { - cleanup = true; - } - if ( cleanup == true ) { - DeleteUniqueValue( m, applicationId, collectionName, uniqueValueKey, uniqueValue, - entityId ); - cleanup = false; + if ( cleanup == true ) { + DeleteUniqueValue( m, applicationId, collectionName, uniqueValueKey, uniqueValue, + entityId ); + cleanup = false; + } } } }
