Repository: incubator-usergrid Updated Branches: refs/heads/USERGRID-250-buffer-size-fix bc0a90056 -> 262ad8ba3
Reverted removal of load method in commit 8beab4489672e403462ecdc9bfe6f3061954c076. This should not be removed Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/eb91d13e Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/eb91d13e Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/eb91d13e Branch: refs/heads/USERGRID-250-buffer-size-fix Commit: eb91d13eed6deab5b5bb94ccb31add69a04c104a Parents: bc0a900 Author: Todd Nine <[email protected]> Authored: Thu Nov 20 09:56:22 2014 -0700 Committer: Todd Nine <[email protected]> Committed: Thu Nov 20 09:56:22 2014 -0700 ---------------------------------------------------------------------- .../mvcc/MvccEntitySerializationStrategy.java | 14 ++++++++- .../mvcc/stage/delete/MarkCommit.java | 2 +- .../serialization/impl/EntityRepairImpl.java | 2 +- .../MvccEntitySerializationStrategyImpl.java | 30 ++++++++++++++++++++ ...vccEntitySerializationStrategyProxyImpl.java | 9 ++++++ ...MvccEntitySerializationStrategyImplTest.java | 17 ++++++----- 6 files changed, 62 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/eb91d13e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/MvccEntitySerializationStrategy.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/MvccEntitySerializationStrategy.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/MvccEntitySerializationStrategy.java index faa76a3..3c694c5 100644 --- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/MvccEntitySerializationStrategy.java +++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/MvccEntitySerializationStrategy.java @@ -56,9 +56,21 @@ public interface MvccEntitySerializationStrategy extends Migration { */ public EntitySet load( CollectionScope scope, Collection<Id> entityIds, UUID maxVersion); + /** + * Load a list, from highest to lowest of the entity with versions <= version up to maxSize elements + * + * @param context The context to persist the entity into + * @param entityId The entity id to load + * @param version The max version to seek from. I.E a stored version <= this argument + * @param fetchSize The maximum size to return. If you receive this size, there may be more versions to load. + * + * @return A list of entities up to max size ordered from max(UUID)=> min(UUID). The return value should be null + * safe and return an empty list when there are no matches + */ + public Iterator<MvccEntity> load( CollectionScope context, Id entityId, UUID version, int fetchSize ); /** - * Load a historical list of entities, from highest to lowest of the entity with versions <= version up to maxSize elements + * Load a historical list of entities, from highest to lowest of the entity with versions < version up to maxSize elements * * @param context The context to persist the entity into * @param entityId The entity id to load http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/eb91d13e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/delete/MarkCommit.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/delete/MarkCommit.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/delete/MarkCommit.java index fab904d..5bcb9f8 100644 --- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/delete/MarkCommit.java +++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/delete/MarkCommit.java @@ -129,7 +129,7 @@ public class MarkCommit implements Action1<CollectionIoEvent<MvccEntity>> { @Override protected Iterator<MvccEntity> getIterator() { Iterator<MvccEntity> entities = - entityStrat.loadHistory( collectionScope, entityId, entity.getVersion(), 100 ); + entityStrat.load( collectionScope, entityId, entity.getVersion(), 100 ); return entities; } http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/eb91d13e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/EntityRepairImpl.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/EntityRepairImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/EntityRepairImpl.java index a01ffdb..a94c688 100644 --- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/EntityRepairImpl.java +++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/EntityRepairImpl.java @@ -69,7 +69,7 @@ public class EntityRepairImpl implements EntityRepair { partialEntities.add( targetEntity ); final Iterator<MvccEntity> results = mvccEntitySerializationStrategy - .loadHistory( collectionScope, targetEntity.getId(), targetEntity.getVersion(), + .load( collectionScope, targetEntity.getId(), targetEntity.getVersion(), serializationFig.getBufferSize() ); http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/eb91d13e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImpl.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImpl.java index c964b68..1ec027f 100644 --- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImpl.java +++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImpl.java @@ -209,6 +209,36 @@ public abstract class MvccEntitySerializationStrategyImpl implements MvccEntityS @Override + public Iterator<MvccEntity> load( final CollectionScope collectionScope, final Id entityId, final UUID version, + final int fetchSize ) { + + Preconditions.checkNotNull( collectionScope, "collectionScope is required" ); + Preconditions.checkNotNull( entityId, "entity id is required" ); + Preconditions.checkNotNull( version, "version is required" ); + Preconditions.checkArgument( fetchSize > 0, "max Size must be greater than 0" ); + + + final Id applicationId = collectionScope.getApplication(); + final Id ownerId = collectionScope.getOwner(); + final String collectionName = collectionScope.getName(); + + final CollectionPrefixedKey<Id> collectionPrefixedKey = + new CollectionPrefixedKey<>( collectionName, ownerId, entityId ); + + + final ScopedRowKey<CollectionPrefixedKey<Id>> rowKey = + ScopedRowKey.fromKey( applicationId, collectionPrefixedKey ); + + + RowQuery<ScopedRowKey<CollectionPrefixedKey<Id>>, UUID> query = + keyspace.prepareQuery( CF_ENTITY_DATA ).getKey( rowKey ) + .withColumnRange( version, null, false, fetchSize ); + + return new ColumnNameIterator( query, new MvccColumnParser( entityId, entityJsonSerializer ), false ); + } + + + @Override public Iterator<MvccEntity> loadHistory( final CollectionScope collectionScope, final Id entityId, final UUID version, final int fetchSize ) { http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/eb91d13e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyProxyImpl.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyProxyImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyProxyImpl.java index f5cf642..a9e01b1 100644 --- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyProxyImpl.java +++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyProxyImpl.java @@ -95,6 +95,15 @@ public class MvccEntitySerializationStrategyProxyImpl implements MvccEntitySeria } + @Override + public Iterator<MvccEntity> load( final CollectionScope context, final Id entityId, final UUID version, + final int fetchSize ) { + if ( isOldVersion() ) { + return previous.load( context, entityId, version, fetchSize ); + } + + return current.load( context, entityId, version, fetchSize ); + } @Override http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/eb91d13e/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImplTest.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImplTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImplTest.java index bc7c783..4b5ea7a 100644 --- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImplTest.java +++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImplTest.java @@ -402,7 +402,7 @@ public abstract class MvccEntitySerializationStrategyImplTest { //now ask for up to 10 versions from the current version, we should get cleared, v2, v1 UUID current = UUIDGenerator.newTimeUUID(); - Iterator<MvccEntity> entities = serializationStrategy.loadHistory( context, id, current, 3 ); + Iterator<MvccEntity> entities = serializationStrategy.load( context, id, current, 3 ); MvccEntity first = entities.next(); assertEquals( clearedV3, first); @@ -422,7 +422,7 @@ public abstract class MvccEntitySerializationStrategyImplTest { serializationStrategy.delete( context, id , version1 ).execute(); serializationStrategy.delete( context, id , version2 ).execute(); - entities = serializationStrategy.loadHistory( context, id, current, 3 ); + entities = serializationStrategy.load( context, id, current, 3 ); first = entities.next(); assertEquals( clearedV3, first ); @@ -432,7 +432,7 @@ public abstract class MvccEntitySerializationStrategyImplTest { serializationStrategy.delete( context, id , version3 ).execute(); - entities = serializationStrategy.loadHistory( context, id, current, 3 ); + entities = serializationStrategy.load( context, id, current, 3 ); Assert.assertTrue( !entities.hasNext()); } @@ -639,7 +639,7 @@ public abstract class MvccEntitySerializationStrategyImplTest { @Test(expected = NullPointerException.class) public void loadListParamContext() throws ConnectionException { - serializationStrategy.loadHistory( null, new SimpleId( "test" ), UUIDGenerator.newTimeUUID(), 1 ); + serializationStrategy.load( null, new SimpleId( "test" ), UUIDGenerator.newTimeUUID(), 1 ); } @@ -647,8 +647,8 @@ public abstract class MvccEntitySerializationStrategyImplTest { public void loadListParamEntityId() throws ConnectionException { serializationStrategy - .loadHistory( new CollectionScopeImpl( new SimpleId( "organization" ), new SimpleId( "test" ), "test" ), - null, UUIDGenerator.newTimeUUID(), 1 ); + .load( new CollectionScopeImpl(new SimpleId( "organization" ), new SimpleId( "test" ), "test" ), null, UUIDGenerator.newTimeUUID(), + 1 ); } @@ -656,15 +656,14 @@ public abstract class MvccEntitySerializationStrategyImplTest { public void loadListParamVersion() throws ConnectionException { serializationStrategy - .loadHistory( new CollectionScopeImpl( new SimpleId( "organization" ), new SimpleId( "test" ), "test" ), - new SimpleId( "test" ), null, 1 ); + .load( new CollectionScopeImpl(new SimpleId( "organization" ), new SimpleId( "test" ), "test" ), new SimpleId( "test" ), null, 1 ); } @Test(expected = IllegalArgumentException.class) public void loadListParamSize() throws ConnectionException { - serializationStrategy.loadHistory( new CollectionScopeImpl(new SimpleId( "organization" ), new SimpleId( "test" ), "test" ), new SimpleId( "test" ), + serializationStrategy.load( new CollectionScopeImpl(new SimpleId( "organization" ), new SimpleId( "test" ), "test" ), new SimpleId( "test" ), UUIDGenerator.newTimeUUID(), 0 ); }
