You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by to...@apache.org on 2014/10/08 18:27:47 UTC
[1/9] git commit: Added TODO's
Repository: incubator-usergrid
Updated Branches:
refs/heads/two-dot-o df8e6a291 -> 185ecefbd
Added TODO's
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/17cc01dc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/17cc01dc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/17cc01dc
Branch: refs/heads/two-dot-o
Commit: 17cc01dc92c39878c7f917d4f361f129dee162ad
Parents: c0c30a9
Author: Todd Nine <to...@apache.org>
Authored: Mon Oct 6 15:39:13 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Mon Oct 6 15:39:13 2014 -0600
----------------------------------------------------------------------
.../persistence/collection/EntityCollectionManager.java | 5 +++++
.../org/apache/usergrid/persistence/index/EntityIndexBatch.java | 3 +++
2 files changed, 8 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/17cc01dc/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManager.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManager.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManager.java
index ee3a5d1..b49989f 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManager.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManager.java
@@ -51,6 +51,11 @@ public interface EntityCollectionManager {
*/
public Observable<Entity> load( Id entityId );
+ //TODO TN Change load to use multiget and return multiple entities. Only supports loading 1k per load operation.
+
+
+ //TODO Dave add a load versions using a multiget that will return a latest version structure for a collection of entity Ids
+
/**
* Takes the change and reloads an entity with all changes applied in this entity applied.
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/17cc01dc/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndexBatch.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndexBatch.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndexBatch.java
index 643174c..f98025b 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndexBatch.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndexBatch.java
@@ -59,6 +59,9 @@ public interface EntityIndexBatch {
*/
public EntityIndexBatch deindex(final IndexScope scope, final Id id, final UUID version);
+
+ //TODO: Create a delete method that delete's by Id. This will delete all documents from ES with the same entity Id
+
/**
* Execute the batch
*/
[9/9] git commit: Updated test
Posted by to...@apache.org.
Updated test
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/185ecefb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/185ecefb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/185ecefb
Branch: refs/heads/two-dot-o
Commit: 185ecefbd253dd8897a58ffde93a6019f672ad93
Parents: ed30e87
Author: Todd Nine <to...@apache.org>
Authored: Wed Oct 8 10:21:32 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Wed Oct 8 10:21:32 2014 -0600
----------------------------------------------------------------------
.../collection/EntityCollectionManagerIT.java | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/185ecefb/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
index 256079c..9e8bbe3 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
@@ -36,6 +36,7 @@ import org.apache.usergrid.persistence.model.field.IntegerField;
import org.apache.usergrid.persistence.model.field.StringField;
import com.fasterxml.uuid.UUIDComparator;
+import com.fasterxml.uuid.impl.UUIDUtil;
import com.google.inject.Inject;
import rx.Observable;
@@ -318,7 +319,7 @@ public class EntityCollectionManagerIT {
@Test
public void partialUpdateDelete() {
- StringField testField1 = new StringField("testField","value");
+ StringField testField = new StringField("testField","value");
StringField addedField = new StringField( "testFud", "NEWPARTIALUPDATEZOMG" );
CollectionScope context = new CollectionScopeImpl(
@@ -335,7 +336,7 @@ public class EntityCollectionManagerIT {
assertNotNull( "Returned has a uuid", returned.getId() );
- oldEntity.getFields().remove( testField1 );
+ oldEntity.getFields().remove( testField );
oldEntity.setField( addedField );
//Entity is deleted then updated right afterwards.
@@ -352,7 +353,7 @@ public class EntityCollectionManagerIT {
Entity newEntity = newEntityObs.toBlocking().last();
assertNotNull( "Returned has a uuid", returned.getId() );
- assertEquals( addedField, newEntity.getField( "testFud" ));
+ assertEquals( addedField, newEntity.getField( addedField.getName()) );
}
@@ -368,22 +369,27 @@ public class EntityCollectionManagerIT {
CollectionScope context = new CollectionScopeImpl(
new SimpleId( "organization" ), new SimpleId( "testUpdate" ), "testUpdate" );
EntityCollectionManager manager = factory.createCollectionManager( context );
- Entity returned = manager.write(origEntity).toBlocking().lastOrDefault(null);
+ Entity returned = manager.write(origEntity).toBlocking().lastOrDefault( null );
// note its version
UUID oldVersion = returned.getVersion();
// partial update entity but with new entity that has version = null
+ assertNotNull( "A version must be assigned", oldVersion );
+
+ // partial update entity but we don't have version number
Entity updateEntity = new Entity( origEntity.getId() );
updateEntity.setField( new StringField("addedField", "other value" ) );
manager.update(origEntity).toBlocking().lastOrDefault(null);
// get entity now, it must have a new version
- returned = manager.load(origEntity.getId() ).toBlocking().lastOrDefault(null);
+ returned = manager.load(origEntity.getId() ).toBlocking().lastOrDefault( null );
UUID newVersion = returned.getVersion();
- // this assert fails
- assertNotEquals( newVersion, oldVersion );
+ assertNotNull( "A new version must be assigned", newVersion );
+
+ // new Version should be > old version
+ assertTrue( UUIDComparator.staticCompare( newVersion, oldVersion ) > 0);
}
}
[3/9] git commit: First pass at updating interfaces
Posted by to...@apache.org.
First pass at updating interfaces
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/fd841758
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/fd841758
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/fd841758
Branch: refs/heads/two-dot-o
Commit: fd841758a0649474337f9522d5f21a51fb439933
Parents: 17cc01d
Author: Todd Nine <to...@apache.org>
Authored: Tue Oct 7 13:33:08 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Tue Oct 7 13:33:08 2014 -0600
----------------------------------------------------------------------
.../collection/guice/CollectionModule.java | 5 +-
.../impl/EntityCollectionManagerImpl.java | 37 ++--
.../mvcc/event/PostProcessObserver.java | 39 ----
.../mvcc/stage/delete/MarkCommit.java | 153 +++++++------
.../mvcc/stage/write/EntityVersion.java | 64 ------
.../stage/write/EntityVersionSerializer.java | 71 ------
.../mvcc/stage/write/FieldSerializer.java | 107 ---------
.../mvcc/stage/write/RollbackAction.java | 3 +
.../mvcc/stage/write/UniqueValue.java | 39 ----
.../mvcc/stage/write/UniqueValueImpl.java | 124 -----------
.../write/UniqueValueSerializationStrategy.java | 66 ------
.../UniqueValueSerializationStrategyImpl.java | 194 ----------------
.../mvcc/stage/write/WriteCommit.java | 5 +-
.../mvcc/stage/write/WriteOptimisticVerify.java | 10 +-
.../mvcc/stage/write/WriteUniqueVerify.java | 206 ++++++++---------
.../collection/serialization/UniqueValue.java | 55 +++++
.../UniqueValueSerializationStrategy.java | 68 ++++++
.../serialization/UniqueValueSet.java | 32 +++
.../serialization/impl/EntityVersion.java | 64 ++++++
.../impl/EntityVersionSerializer.java | 71 ++++++
.../serialization/impl/FieldSerializer.java | 107 +++++++++
.../serialization/impl/SerializationModule.java | 3 +-
.../serialization/impl/UniqueValueImpl.java | 125 +++++++++++
.../UniqueValueSerializationStrategyImpl.java | 219 +++++++++++++++++++
.../serialization/impl/UniqueValueSetImpl.java | 85 +++++++
.../mvcc/stage/delete/MarkCommitTest.java | 10 +-
.../write/EntityVersionSerializerTest.java | 2 +
.../mvcc/stage/write/FieldSerializerTest.java | 1 +
...niqueValueSerializationStrategyImplTest.java | 50 +++--
.../mvcc/stage/write/WriteCommitTest.java | 1 +
.../stage/write/WriteOptimisticVerifyTest.java | 17 +-
.../stage/write/WriteUniqueVerifyStageTest.java | 48 ----
.../mvcc/stage/write/WriteUniqueVerifyTest.java | 48 +---
33 files changed, 1101 insertions(+), 1028 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/guice/CollectionModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/guice/CollectionModule.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/guice/CollectionModule.java
index 9d949e8..3336166 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/guice/CollectionModule.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/guice/CollectionModule.java
@@ -29,12 +29,11 @@ import org.apache.usergrid.persistence.collection.mvcc.MvccLogEntrySerialization
import org.apache.usergrid.persistence.collection.mvcc.changelog.ChangeLogGenerator;
import org.apache.usergrid.persistence.collection.mvcc.changelog.ChangeLogGeneratorImpl;
import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
-import org.apache.usergrid.persistence.collection.mvcc.stage.write.UniqueValueSerializationStrategy;
-import org.apache.usergrid.persistence.collection.mvcc.stage.write.UniqueValueSerializationStrategyImpl;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValueSerializationStrategy;
+import org.apache.usergrid.persistence.collection.serialization.impl.UniqueValueSerializationStrategyImpl;
import org.apache.usergrid.persistence.collection.mvcc.stage.write.WriteStart;
import org.apache.usergrid.persistence.collection.serialization.SerializationFig;
import org.apache.usergrid.persistence.collection.serialization.impl.SerializationModule;
-import org.apache.usergrid.persistence.collection.service.UUIDService;
import org.apache.usergrid.persistence.collection.service.impl.ServiceModule;
import org.apache.usergrid.persistence.core.task.NamedTaskExecutorImpl;
import org.apache.usergrid.persistence.core.task.TaskExecutor;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
index 094baa6..6299acb 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
@@ -138,7 +138,7 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
// create our observable and start the write
- CollectionIoEvent<Entity> writeData = new CollectionIoEvent<Entity>( collectionScope, entity );
+ final CollectionIoEvent<Entity> writeData = new CollectionIoEvent<Entity>( collectionScope, entity );
Observable<CollectionIoEvent<MvccEntity>> observable = stageRunner( writeData,writeStart );
@@ -147,15 +147,10 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
// observable = Concurrent.concurrent( observable, Schedulers.io(), new WaitZip(),
// writeVerifyUnique, writeOptimisticVerify );
- observable.doOnNext( new Action1<CollectionIoEvent<MvccEntity>>() {
- @Override
- public void call( final CollectionIoEvent<MvccEntity> mvccEntityCollectionIoEvent ) {
- //Queue future write here (verify)
- }
- } ).map( writeCommit ).doOnNext( new Action1<Entity>() {
+ observable.map( writeCommit ).doOnNext( new Action1<Entity>() {
@Override
public void call( final Entity entity ) {
- //fork background processing here (start)
+ //TODO fire a task here
//post-processing to come later. leave it empty for now.
}
@@ -175,7 +170,13 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
Preconditions.checkNotNull( entityId.getType(), "Entity type is required in this stage" );
return Observable.from( new CollectionIoEvent<Id>( collectionScope, entityId ) )
- .map( markStart ).map( markCommit );
+ .map( markStart ).doOnNext( markCommit ).map( new Func1<CollectionIoEvent<MvccEntity>,
+ Void>() {
+ @Override
+ public Void call( final CollectionIoEvent<MvccEntity> mvccEntityCollectionIoEvent ) {
+ return null;
+ }
+ } );
}
@@ -217,7 +218,7 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
//we an update, signal the fix
- //TODO T.N Change this to use request collapsing
+ //TODO T.N Change this to fire a task
Observable.from( new CollectionIoEvent<Id>(collectionScope, entityId ) ).map( load ).subscribeOn( Schedulers.io() ).subscribe();
@@ -226,27 +227,29 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
}
// fire the stages
- public Observable<CollectionIoEvent<MvccEntity>> stageRunner( CollectionIoEvent<Entity> writeData,WriteStart writeState ) {
+ public Observable<CollectionIoEvent<MvccEntity>> stageRunner( CollectionIoEvent<Entity> writeData, WriteStart writeState ) {
- return Observable.from( writeData ).map( writeState ).flatMap(
- new Func1<CollectionIoEvent<MvccEntity>, Observable<CollectionIoEvent<MvccEntity>>>() {
+ return Observable.from( writeData ).map( writeState ).doOnNext( new Action1<CollectionIoEvent<MvccEntity>>() {
@Override
- public Observable<CollectionIoEvent<MvccEntity>> call(
+ public void call(
final CollectionIoEvent<MvccEntity> mvccEntityCollectionIoEvent ) {
Observable<CollectionIoEvent<MvccEntity>> unique =
Observable.from( mvccEntityCollectionIoEvent ).subscribeOn( Schedulers.io() )
- .flatMap( writeVerifyUnique );
+ .doOnNext( writeVerifyUnique );
// optimistic verification
Observable<CollectionIoEvent<MvccEntity>> optimistic =
Observable.from( mvccEntityCollectionIoEvent ).subscribeOn( Schedulers.io() )
- .map( writeOptimisticVerify );
+ .doOnNext( writeOptimisticVerify );
+
+
+ //wait for both to finish
+ Observable.merge( unique, optimistic ).toBlocking().last();
- return Observable.merge( unique, optimistic).last();
}
} );
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/event/PostProcessObserver.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/event/PostProcessObserver.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/event/PostProcessObserver.java
deleted file mode 100644
index b06957d..0000000
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/event/PostProcessObserver.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.usergrid.persistence.collection.mvcc.event;
-
-import org.apache.usergrid.persistence.collection.CollectionScope;
-import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
-
-
-/**
- * @author: tnine
- */
-public interface PostProcessObserver {
-
-
- /**
- * The entity was comitted by the MVCC system. Post processing needs to occur
- *
- * @param scope The scope used in the write pipeline
- * @param entity The entity used in the write pipeline
- *
- */
- public void postCommit(CollectionScope scope, MvccEntity entity );
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/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 4e8d6d5..61a2a36 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
@@ -19,7 +19,6 @@
package org.apache.usergrid.persistence.collection.mvcc.stage.delete;
-import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
@@ -28,7 +27,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.usergrid.persistence.collection.CollectionScope;
-import org.apache.usergrid.persistence.collection.exception.CollectionRuntimeException;
import org.apache.usergrid.persistence.collection.mvcc.MvccEntitySerializationStrategy;
import org.apache.usergrid.persistence.collection.mvcc.MvccLogEntrySerializationStrategy;
import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
@@ -37,31 +35,31 @@ import org.apache.usergrid.persistence.collection.mvcc.entity.MvccValidationUtil
import org.apache.usergrid.persistence.collection.mvcc.entity.Stage;
import org.apache.usergrid.persistence.collection.mvcc.entity.impl.MvccLogEntryImpl;
import org.apache.usergrid.persistence.collection.mvcc.stage.CollectionIoEvent;
-import org.apache.usergrid.persistence.collection.mvcc.stage.write.UniqueValue;
-import org.apache.usergrid.persistence.collection.mvcc.stage.write.UniqueValueSerializationStrategy;
import org.apache.usergrid.persistence.collection.serialization.SerializationFig;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValue;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValueSerializationStrategy;
+import org.apache.usergrid.persistence.collection.serialization.impl.UniqueValueImpl;
import org.apache.usergrid.persistence.core.rx.ObservableIterator;
import org.apache.usergrid.persistence.model.entity.Entity;
import org.apache.usergrid.persistence.model.entity.Id;
import org.apache.usergrid.persistence.model.field.Field;
-import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.inject.Inject;
import com.google.inject.Singleton;
+import com.netflix.astyanax.Keyspace;
import com.netflix.astyanax.MutationBatch;
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
import rx.Observable;
-import rx.functions.Func1;
+import rx.functions.Action1;
/**
- * This phase should invoke any finalization, and mark the entity
- * as committed in the data store before returning
+ * This phase should invoke any finalization, and mark the entity as committed in the data store before returning
*/
@Singleton
-public class MarkCommit implements Func1<CollectionIoEvent<MvccEntity>, Void> {
+public class MarkCommit implements Action1<CollectionIoEvent<MvccEntity>> {
private static final Logger LOG = LoggerFactory.getLogger( MarkCommit.class );
@@ -69,28 +67,29 @@ public class MarkCommit implements Func1<CollectionIoEvent<MvccEntity>, Void> {
private final MvccEntitySerializationStrategy entityStrat;
private final SerializationFig serializationFig;
private final UniqueValueSerializationStrategy uniqueValueStrat;
+ private final Keyspace keyspace;
+
@Inject
public MarkCommit( final MvccLogEntrySerializationStrategy logStrat,
final MvccEntitySerializationStrategy entityStrat,
- final UniqueValueSerializationStrategy uniqueValueStrat,
- final SerializationFig serializationFig) {
+ final UniqueValueSerializationStrategy uniqueValueStrat, final SerializationFig serializationFig,
+ final Keyspace keyspace ) {
+
- Preconditions.checkNotNull(
- logStrat, "logEntrySerializationStrategy is required" );
- Preconditions.checkNotNull(
- entityStrat, "entitySerializationStrategy is required" );
+ Preconditions.checkNotNull( logStrat, "logEntrySerializationStrategy is required" );
+ Preconditions.checkNotNull( entityStrat, "entitySerializationStrategy is required" );
this.logStrat = logStrat;
this.entityStrat = entityStrat;
this.serializationFig = serializationFig;
this.uniqueValueStrat = uniqueValueStrat;
+ this.keyspace = keyspace;
}
-
@Override
- public Void call( final CollectionIoEvent<MvccEntity> idIoEvent ) {
+ public void call( final CollectionIoEvent<MvccEntity> idIoEvent ) {
final MvccEntity entity = idIoEvent.getEvent();
@@ -103,64 +102,86 @@ public class MarkCommit implements Func1<CollectionIoEvent<MvccEntity>, Void> {
final CollectionScope collectionScope = idIoEvent.getEntityCollection();
- final MvccLogEntry startEntry = new MvccLogEntryImpl( entityId, version,
- Stage.COMMITTED, MvccLogEntry.State.DELETED );
+ LOG.debug("Inserting tombstone for entity {} at version {}", entityId, version );
- final MutationBatch logMutation = logStrat.write( collectionScope, startEntry );
+ final MvccLogEntry startEntry =
+ new MvccLogEntryImpl( entityId, version, Stage.COMMITTED, MvccLogEntry.State.DELETED );
+
+ final MutationBatch entityStateBatch = logStrat.write( collectionScope, startEntry );
//insert a "cleared" value into the versions. Post processing should actually delete
- MutationBatch entityMutation = entityStrat.mark( collectionScope, entityId, version );
-
- //merge the 2 into 1 mutation
- logMutation.mergeShallow( entityMutation );
-
- //set up the post processing queue
- //delete unique fields
- Observable<List<Field>> deleteFieldsObservable = Observable.create(new ObservableIterator<Field>("deleteColumns") {
- @Override
- protected Iterator<Field> getIterator() {
- Iterator<MvccEntity> entities = entityStrat.load(collectionScope, entityId, entity.getVersion(), 1);
- Iterator<Field> fieldIterator = Collections.emptyIterator();
- if (entities.hasNext()) {
- Optional<Entity> oe = entities.next().getEntity();
- if (oe.isPresent()) {
- fieldIterator = oe.get().getFields().iterator();
- }
- }
- return fieldIterator;
- }
- }).buffer(serializationFig.getBufferSize())
- .map(new Func1<List<Field>, List<Field>>() {
- @Override
- public List<Field> call(List<Field> fields) {
- for (Field field : fields) {
- try {
- UniqueValue value = uniqueValueStrat.load(collectionScope, field);
- if (value != null) {
- logMutation.mergeShallow(uniqueValueStrat.delete(value));
- }
- } catch (ConnectionException ce) {
- LOG.error("Failed to delete Unique Value", ce);
- }
- }
- return fields;
- }
- });
- deleteFieldsObservable.toBlocking().firstOrDefault(null);
try {
- logMutation.execute();
+ final MutationBatch entityBatch = entityStrat.mark( collectionScope, entityId, version );
+ entityStateBatch.mergeShallow( entityBatch );
+ entityStateBatch.execute();
}
catch ( ConnectionException e ) {
- LOG.error( "Failed to execute write asynchronously ", e );
- throw new CollectionRuntimeException( entity, collectionScope,
- "Failed to execute write asynchronously ", e );
+ throw new RuntimeException( "Unable to mark entry as deleted" );
}
- /**
- * We're done executing.
- */
- return null;
+ //TODO Refactor this logic into a a class that can be invoked from anywhere
+ //load every entity we have history of
+ Observable<List<MvccEntity>> deleteFieldsObservable =
+ Observable.create( new ObservableIterator<MvccEntity>( "deleteColumns" ) {
+ @Override
+ protected Iterator<MvccEntity> getIterator() {
+ Iterator<MvccEntity> entities =
+ entityStrat.load( collectionScope, entityId, entity.getVersion(), 100 );
+
+ return entities;
+ }
+ } ) //buffer them for efficiency
+ .buffer( serializationFig.getBufferSize() ).doOnNext(
+
+ new Action1<List<MvccEntity>>() {
+ @Override
+ public void call( final List<MvccEntity> mvccEntities ) {
+
+
+ final MutationBatch batch = keyspace.prepareMutationBatch();
+
+ for ( MvccEntity mvccEntity : mvccEntities ) {
+ if ( !mvccEntity.getEntity().isPresent() ) {
+ continue;
+ }
+
+ final UUID entityVersion = mvccEntity.getVersion();
+
+ final Entity entity = mvccEntity.getEntity().get();
+
+ //remove all unique fields from the index
+ for ( final Field field : entity.getFields() ) {
+
+ if(!field.isUnique()){
+ continue;
+ }
+
+ final UniqueValue unique = new UniqueValueImpl( collectionScope, field, entityId, entityVersion );
+
+ final MutationBatch deleteMutation = uniqueValueStrat.delete( unique );
+
+ batch.mergeShallow( deleteMutation );
+ }
+ }
+
+ try {
+ batch.execute();
+ }
+ catch ( ConnectionException e1 ) {
+ throw new RuntimeException( "Unable to execute " +
+ "unique value " +
+ "delete", e1 );
+ }
+ }
+ }
+
+
+ );
+
+ final int removedCount = deleteFieldsObservable.count().toBlocking().last();
+
+ LOG.debug("Removed unique values for {} entities of entity {}", removedCount, entityId );
}
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/EntityVersion.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/EntityVersion.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/EntityVersion.java
deleted file mode 100644
index d62ae87..0000000
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/EntityVersion.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.collection.mvcc.stage.write;
-
-
-import java.util.UUID;
-
-import org.apache.usergrid.persistence.model.entity.Id;
-
-/**
- * Combine entity ID and entity version for use as column name for UniqueValues Column Family.
- */
-class EntityVersion {
- private final Id entityId;
- private final UUID entityVersion;
-
- public EntityVersion(Id id, UUID uuid) {
- this.entityId = id;
- this.entityVersion = uuid;
- }
-
- public Id getEntityId() {
- return entityId;
- }
-
- public UUID getEntityVersion() {
- return entityVersion;
- }
-
- public boolean equals( Object o ) {
-
- if ( o == null || !(o instanceof EntityVersion) ) {
- return false;
- }
-
- EntityVersion other = (EntityVersion)o;
-
- if ( !other.getEntityId().equals( getEntityId() )) {
- return false;
- }
-
- if ( !other.getEntityVersion().equals( getEntityVersion() )) {
- return false;
- }
-
- return true;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/EntityVersionSerializer.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/EntityVersionSerializer.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/EntityVersionSerializer.java
deleted file mode 100644
index 86b5aff..0000000
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/EntityVersionSerializer.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.collection.mvcc.stage.write;
-
-
-import java.nio.ByteBuffer;
-import java.util.UUID;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.usergrid.persistence.model.entity.SimpleId;
-
-import com.google.common.base.Preconditions;
-import com.netflix.astyanax.model.CompositeBuilder;
-import com.netflix.astyanax.model.Composites;
-import com.netflix.astyanax.model.DynamicComposite;
-import com.netflix.astyanax.serializers.AbstractSerializer;
-import com.netflix.astyanax.serializers.StringSerializer;
-import com.netflix.astyanax.serializers.UUIDSerializer;
-
-/**
- * Serialize EntityVersion, entity ID and version, for use a column name in Unique Values Column Family.
- */
-public class EntityVersionSerializer extends AbstractSerializer<EntityVersion> {
-
- private static final Logger LOG = LoggerFactory.getLogger( EntityVersionSerializer.class );
-
- @Override
- public ByteBuffer toByteBuffer(final EntityVersion ev) {
-
- CompositeBuilder builder = Composites.newDynamicCompositeBuilder();
-
- builder.addTimeUUID( ev.getEntityVersion() );
- builder.addTimeUUID( ev.getEntityId().getUuid() );
- builder.addString( ev.getEntityId().getType() );
-
- return builder.build();
- }
-
- @Override
- public EntityVersion fromByteBuffer(final ByteBuffer byteBuffer) {
-
- // would use Composites.newDynamicCompositeParser(byteBuffer) but it is not implemented
-
- DynamicComposite composite = DynamicComposite.fromByteBuffer(byteBuffer);
- Preconditions.checkArgument(composite.size() == 3, "Composite should have 3 elements");
-
- final UUID version = composite.get( 0, UUIDSerializer.get() );
- final UUID entityId = composite.get( 1, UUIDSerializer.get() );
- final String entityType = composite.get( 2, StringSerializer.get() );
-
- return new EntityVersion( new SimpleId( entityId, entityType ), version);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/FieldSerializer.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/FieldSerializer.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/FieldSerializer.java
deleted file mode 100644
index 3719e3e..0000000
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/FieldSerializer.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.collection.mvcc.stage.write;
-
-
-import java.util.UUID;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.commons.lang3.StringUtils;
-
-import org.apache.usergrid.persistence.core.astyanax.CompositeFieldSerializer;
-import org.apache.usergrid.persistence.model.field.DoubleField;
-import org.apache.usergrid.persistence.model.field.Field;
-import org.apache.usergrid.persistence.model.field.IntegerField;
-import org.apache.usergrid.persistence.model.field.LongField;
-import org.apache.usergrid.persistence.model.field.StringField;
-import org.apache.usergrid.persistence.model.field.UUIDField;
-
-import com.netflix.astyanax.model.CompositeBuilder;
-import com.netflix.astyanax.model.CompositeParser;
-
-// TODO: replace with "real" serializer
-
-/**
- * Serialize Field for use as part of row-key in Unique Values Column Family.
- */
-public class FieldSerializer implements CompositeFieldSerializer<Field> {
-
- private static final Logger LOG = LoggerFactory.getLogger( FieldSerializer.class );
-
- public enum FieldType {
- BOOLEAN_FIELD,
- DOUBLE_FIELD,
- INTEGER_FIELD,
- LONG_FIELD,
- STRING_FIELD,
- UUID_FIELD
- };
-
- private static final FieldSerializer INSTANCE = new FieldSerializer();
-
- @Override
- public void toComposite( final CompositeBuilder builder, final Field field ) {
-
- builder.addString( field.getName() );
-
- // TODO: use the real field value serializer(s) here? Store hash instead?
- builder.addString( field.getValue().toString() );
-
- String simpleName = field.getClass().getSimpleName();
- int nameIndex = simpleName.lastIndexOf(".");
- String fieldType = simpleName.substring(nameIndex + 1, simpleName.length() - "Field".length());
- fieldType = StringUtils.upperCase( fieldType + "_FIELD" );
-
- builder.addString( fieldType );
- }
-
- @Override
- public Field fromComposite( final CompositeParser composite ) {
-
- final String name = composite.readString();
- final String value = composite.readString();
- final String typeString = composite.readString();
-
- final FieldType fieldType = FieldType.valueOf( typeString );
-
- switch (fieldType) {
- case DOUBLE_FIELD:
- return new DoubleField(name, Double.parseDouble(value));
- case INTEGER_FIELD:
- return new IntegerField(name, Integer.parseInt(value));
- case LONG_FIELD:
- return new LongField(name, Long.parseLong(value));
- case STRING_FIELD:
- return new StringField(name, value);
- case UUID_FIELD:
- return new UUIDField(name, UUID.fromString(value));
- default:
- throw new RuntimeException("Unknown unique field type");
- }
- }
-
-
- /**
- * Get the singleton serializer
- */
- public static FieldSerializer get() {
- return INSTANCE;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/RollbackAction.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/RollbackAction.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/RollbackAction.java
index 7448816..dfccb34 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/RollbackAction.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/RollbackAction.java
@@ -25,6 +25,9 @@ import org.apache.usergrid.persistence.collection.CollectionScope;
import org.apache.usergrid.persistence.collection.exception.CollectionRuntimeException;
import org.apache.usergrid.persistence.collection.mvcc.MvccLogEntrySerializationStrategy;
import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValue;
+import org.apache.usergrid.persistence.collection.serialization.impl.UniqueValueImpl;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValueSerializationStrategy;
import org.apache.usergrid.persistence.model.entity.Entity;
import org.apache.usergrid.persistence.model.field.Field;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/UniqueValue.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/UniqueValue.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/UniqueValue.java
deleted file mode 100644
index de1594a..0000000
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/UniqueValue.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.collection.mvcc.stage.write;
-
-
-import java.util.UUID;
-
-import org.apache.usergrid.persistence.collection.CollectionScope;
-import org.apache.usergrid.persistence.model.entity.Id;
-import org.apache.usergrid.persistence.model.field.Field;
-
-/**
- * Represents a Unique Value of a field within a collection.
- */
-public interface UniqueValue {
-
- public CollectionScope getCollectionScope();
-
- public Id getEntityId();
-
- public Field getField();
-
- public UUID getEntityVersion();
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/UniqueValueImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/UniqueValueImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/UniqueValueImpl.java
deleted file mode 100644
index 7c86491..0000000
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/UniqueValueImpl.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.collection.mvcc.stage.write;
-
-
-import java.util.UUID;
-
-import org.apache.usergrid.persistence.collection.CollectionScope;
-import org.apache.usergrid.persistence.model.entity.Id;
-import org.apache.usergrid.persistence.model.field.Field;
-
-import com.google.common.base.Preconditions;
-
-/**
- * Represents a Unique Value of a field within a collection.
- */
-public class UniqueValueImpl implements UniqueValue {
- private final CollectionScope collectionScope;
- private final Field field;
- private final Id entityId;
- private final UUID entityVersion;
-
- public UniqueValueImpl(
- final CollectionScope scope, final Field field, Id entityId, final UUID version ) {
-
- Preconditions.checkNotNull( scope, "scope is required" );
- Preconditions.checkNotNull( field, "field is required" );
-// Preconditions.checkNotNull( version, "version is required" );
- Preconditions.checkNotNull( entityId, "entityId is required" );
-
- this.collectionScope = scope;
- this.field = field;
- this.entityVersion = version;
- this.entityId = entityId;
- }
-
- @Override
- public CollectionScope getCollectionScope() {
- return collectionScope;
- }
-
- @Override
- public Field getField() {
- return field;
- }
-
- @Override
- public UUID getEntityVersion() {
- return entityVersion;
- }
-
- @Override
- public Id getEntityId() {
- return entityId;
- }
-
-
- @Override
- public boolean equals( final Object o ) {
- if ( this == o ) {
- return true;
- }
- if ( o == null || getClass() != o.getClass() ) {
- return false;
- }
-
- final UniqueValueImpl that = ( UniqueValueImpl ) o;
-
- if ( !getCollectionScope().equals( that.getCollectionScope() ) ) {
- return false;
- }
-
- if ( !getField().equals( that.getField()) ) {
- return false;
- }
-
- if ( !getEntityVersion().equals( that.getEntityVersion() ) ) {
- return false;
- }
-
- if ( !getEntityId().equals( that.getEntityId() ) ) {
- return false;
- }
-
- return true;
- }
-
-
- @Override
- public int hashCode() {
- int result = 31 * getCollectionScope().hashCode();
- result = 31 * result + getField().hashCode();
- result = 31 * result + getEntityVersion().hashCode();
- result = 31 * result + getEntityId().hashCode();
- return result;
- }
-
-
- @Override
- public String toString() {
- return "UniqueValueImpl{" +
- ", collectionScope =" + collectionScope.getName() +
- ", field =" + field +
- ", entityVersion=" + entityVersion +
- ", entityId =" + entityId +
- '}';
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/UniqueValueSerializationStrategy.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/UniqueValueSerializationStrategy.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/UniqueValueSerializationStrategy.java
deleted file mode 100644
index 9773644..0000000
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/UniqueValueSerializationStrategy.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.collection.mvcc.stage.write;
-
-
-import com.netflix.astyanax.MutationBatch;
-import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
-import org.apache.usergrid.persistence.collection.CollectionScope;
-import org.apache.usergrid.persistence.model.field.Field;
-
-
-/**
- * Reads and writes to UniqueValues column family.
- */
-public interface UniqueValueSerializationStrategy {
-
- /**
- * Write the specified UniqueValue to Cassandra with optional timeToLive in milliseconds.
- *
- * @param uniqueValue Object to be written
- * @return MutatationBatch that encapsulates operation, caller may or may not execute.
- */
- public MutationBatch write( UniqueValue uniqueValue );
-
- /**
- * Write the specified UniqueValue to Cassandra with optional timeToLive in milliseconds.
- *
- * @param uniqueValue Object to be written
- * @param timeToLive How long object should live in seconds
- * @return MutatationBatch that encapsulates operation, caller may or may not execute.
- */
- public MutationBatch write( UniqueValue uniqueValue, Integer timeToLive );
-
- /**
- * Load UniqueValue that matches field from collection or null if that value does not exist.
- *
- * @param colScope Collection scope in which to look for field name/value
- * @param field Field name/value to search for
- * @return UniqueValue or null if not found
- * @throws ConnectionException on error connecting to Cassandra
- */
- public UniqueValue load( CollectionScope colScope, Field field ) throws ConnectionException;
-
- /**
- * Delete the specified Unique Value from Cassandra.
- *
- * @param uniqueValue Object to be deleted.
- * @return MutatationBatch that encapsulates operation, caller may or may not execute.
- */
- public MutationBatch delete( UniqueValue uniqueValue );
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/UniqueValueSerializationStrategyImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/UniqueValueSerializationStrategyImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/UniqueValueSerializationStrategyImpl.java
deleted file mode 100644
index b7e113e..0000000
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/UniqueValueSerializationStrategyImpl.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.collection.mvcc.stage.write;
-
-
-import com.google.common.base.Preconditions;
-import com.google.inject.Inject;
-import com.netflix.astyanax.ColumnListMutation;
-import com.netflix.astyanax.Keyspace;
-import com.netflix.astyanax.MutationBatch;
-import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
-import com.netflix.astyanax.connectionpool.exceptions.NotFoundException;
-import com.netflix.astyanax.model.ColumnList;
-import com.netflix.astyanax.util.RangeBuilder;
-import java.util.Collections;
-import org.apache.cassandra.db.marshal.BytesType;
-import org.apache.usergrid.persistence.collection.CollectionScope;
-import org.apache.usergrid.persistence.collection.serialization.impl.CollectionScopedRowKeySerializer;
-import org.apache.usergrid.persistence.core.astyanax.ColumnTypes;
-import org.apache.usergrid.persistence.core.astyanax.MultiTennantColumnFamily;
-import org.apache.usergrid.persistence.core.astyanax.MultiTennantColumnFamilyDefinition;
-import org.apache.usergrid.persistence.core.astyanax.ScopedRowKey;
-import org.apache.usergrid.persistence.core.migration.Migration;
-import org.apache.usergrid.persistence.model.field.Field;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-/**
- * Reads and writes to UniqueValues column family.
- */
-public class UniqueValueSerializationStrategyImpl
- implements UniqueValueSerializationStrategy, Migration {
-
- private static final Logger log =
- LoggerFactory.getLogger( UniqueValueSerializationStrategyImpl.class );
-
- // TODO: use "real" field serializer here instead once it is ready
- private static final CollectionScopedRowKeySerializer<Field> ROW_KEY_SER =
- new CollectionScopedRowKeySerializer<Field>( FieldSerializer.get() );
-
- private static final EntityVersionSerializer ENTITY_VERSION_SER = new EntityVersionSerializer();
-
- private static final MultiTennantColumnFamily<CollectionScope, Field, EntityVersion>
- CF_UNIQUE_VALUES =
- new MultiTennantColumnFamily<CollectionScope, Field, EntityVersion>( "Unique_Values",
- ROW_KEY_SER,
- ENTITY_VERSION_SER );
-
- protected final Keyspace keyspace;
-
-
- /**
- * Construct serialization strategy for keyspace.
- * @param keyspace Keyspace in which to store Unique Values.
- */
- @Inject
- public UniqueValueSerializationStrategyImpl( final Keyspace keyspace ) {
- this.keyspace = keyspace;
- }
-
-
- @Override
- public java.util.Collection getColumnFamilies() {
-
- MultiTennantColumnFamilyDefinition cf = new MultiTennantColumnFamilyDefinition(
- CF_UNIQUE_VALUES,
- BytesType.class.getSimpleName(),
- ColumnTypes.DYNAMIC_COMPOSITE_TYPE,
- BytesType.class.getSimpleName(), MultiTennantColumnFamilyDefinition.CacheOption.KEYS );
-
- return Collections.singleton( cf );
- }
-
-
- public MutationBatch write( UniqueValue uniqueValue ) {
- return write( uniqueValue, Integer.MAX_VALUE );
- }
-
-
- @Override
- public MutationBatch write( UniqueValue value, Integer timeToLive ) {
-
- Preconditions.checkNotNull( value, "value is required" );
- Preconditions.checkNotNull( timeToLive, "timeToLive is required" );
-
- log.debug("Writing unique value scope={} id={} version={} name={} value={} ttl={} ",
- new Object[] {
- value.getCollectionScope().getName(),
- value.getEntityId(),
- value.getEntityVersion(),
- value.getField().getName(),
- value.getField().getValue(),
- timeToLive
- });
-
- final EntityVersion ev = new EntityVersion( value.getEntityId(), value.getEntityVersion() );
-
- final Integer ttl;
- if ( timeToLive.equals( Integer.MAX_VALUE )) {
- ttl = null;
- } else {
- ttl = timeToLive;
- }
-
- return doWrite( value.getCollectionScope(), value.getField(),
- new UniqueValueSerializationStrategyImpl.RowOp() {
-
- @Override
- public void doOp( final ColumnListMutation<EntityVersion> colMutation ) {
- colMutation.putColumn( ev, 0x0, ttl );
- }
- } );
- }
-
-
- @Override
- public MutationBatch delete(UniqueValue value) {
-
- Preconditions.checkNotNull( value, "value is required" );
-
- final EntityVersion ev = new EntityVersion( value.getEntityId(), value.getEntityVersion() );
-
- return doWrite( value.getCollectionScope(), value.getField(),
- new UniqueValueSerializationStrategyImpl.RowOp() {
-
- @Override
- public void doOp( final ColumnListMutation<EntityVersion> colMutation ) {
- colMutation.deleteColumn(ev);
- }
- } );
- }
-
-
- /**
- * Do the column update or delete for the given column and row key
- * @param context We need to use this when getting the keyspace
- */
- private MutationBatch doWrite( CollectionScope context, Field field, RowOp op ) {
- final MutationBatch batch = keyspace.prepareMutationBatch();
- op.doOp( batch.withRow( CF_UNIQUE_VALUES, ScopedRowKey.fromKey( context, field ) ) );
- return batch;
- }
-
-
- @Override
- public UniqueValue load( CollectionScope colScope, Field field ) throws ConnectionException {
-
- Preconditions.checkNotNull( field, "field is required" );
-
- ColumnList<EntityVersion> result;
- try {
- result = keyspace.prepareQuery( CF_UNIQUE_VALUES )
- .getKey( ScopedRowKey.fromKey( colScope, field ) )
- .withColumnRange(new RangeBuilder().setLimit(1).build())
- .execute()
- .getResult();
- }
- catch ( NotFoundException nfe ) {
- return null;
- }
-
- if ( result.isEmpty() ) {
- return null;
- }
-
- EntityVersion ev = result.getColumnByIndex(0).getName();
-
- return new UniqueValueImpl( colScope, field, ev.getEntityId(), ev.getEntityVersion() );
- }
-
-
- /**
- * Simple callback to perform puts and deletes with a common row setup code
- */
- private static interface RowOp {
- void doOp( ColumnListMutation<EntityVersion> colMutation );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommit.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommit.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommit.java
index 0004ddb..49e967f 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommit.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommit.java
@@ -33,6 +33,9 @@ import org.apache.usergrid.persistence.collection.mvcc.entity.MvccValidationUtil
import org.apache.usergrid.persistence.collection.mvcc.entity.Stage;
import org.apache.usergrid.persistence.collection.mvcc.entity.impl.MvccLogEntryImpl;
import org.apache.usergrid.persistence.collection.mvcc.stage.CollectionIoEvent;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValue;
+import org.apache.usergrid.persistence.collection.serialization.impl.UniqueValueImpl;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValueSerializationStrategy;
import org.apache.usergrid.persistence.collection.util.EntityUtils;
import org.apache.usergrid.persistence.core.util.ValidationUtils;
import org.apache.usergrid.persistence.model.entity.Entity;
@@ -110,7 +113,7 @@ public class WriteCommit implements Func1<CollectionIoEvent<MvccEntity>, Entity>
if ( field.isUnique() ) {
- UniqueValue written = new UniqueValueImpl( ioEvent.getEntityCollection(), field,
+ UniqueValue written = new UniqueValueImpl( ioEvent.getEntityCollection(), field,
mvccEntity.getEntity().get().getId(), mvccEntity.getEntity().get().getVersion());
MutationBatch mb = uniqueValueStrat.write( written );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteOptimisticVerify.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteOptimisticVerify.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteOptimisticVerify.java
index b5e5873..dcdb408 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteOptimisticVerify.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteOptimisticVerify.java
@@ -38,6 +38,7 @@ import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
+import rx.functions.Action1;
import rx.functions.Func1;
@@ -46,7 +47,7 @@ import rx.functions.Func1;
*/
@Singleton
public class WriteOptimisticVerify
- implements Func1<CollectionIoEvent<MvccEntity>, CollectionIoEvent<MvccEntity>> {
+ implements Action1<CollectionIoEvent<MvccEntity>> {
private static final Logger log = LoggerFactory.getLogger( WriteOptimisticVerify.class );
@@ -59,7 +60,7 @@ public class WriteOptimisticVerify
@Override
- public CollectionIoEvent<MvccEntity> call( final CollectionIoEvent<MvccEntity> ioevent ) {
+ public void call( final CollectionIoEvent<MvccEntity> ioevent ) {
MvccValidationUtils.verifyMvccEntityWithEntity( ioevent.getEvent() );
// If the version was included on the entity write operation (delete or write) we need
@@ -74,7 +75,7 @@ public class WriteOptimisticVerify
CollectionScope collectionScope = ioevent.getEntityCollection();
if(entity.getVersion() == null){
- return ioevent;
+ return;
}
try {
@@ -98,8 +99,7 @@ public class WriteOptimisticVerify
"Error reading entity log", e );
}
- // No op, just emit the value
- return ioevent;
+
}
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerify.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerify.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerify.java
index 713703f..e6d37fc 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerify.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerify.java
@@ -18,36 +18,46 @@
package org.apache.usergrid.persistence.collection.mvcc.stage.write;
-import com.google.common.base.Preconditions;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import com.netflix.astyanax.MutationBatch;
-import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.usergrid.persistence.collection.CollectionScope;
import org.apache.usergrid.persistence.collection.exception.WriteUniqueVerifyException;
import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
import org.apache.usergrid.persistence.collection.mvcc.entity.MvccValidationUtils;
import org.apache.usergrid.persistence.collection.mvcc.stage.CollectionIoEvent;
import org.apache.usergrid.persistence.collection.serialization.SerializationFig;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValue;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValueSerializationStrategy;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValueSet;
+import org.apache.usergrid.persistence.collection.serialization.impl.UniqueValueImpl;
import org.apache.usergrid.persistence.model.entity.Entity;
+import org.apache.usergrid.persistence.model.entity.Id;
import org.apache.usergrid.persistence.model.field.Field;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import com.netflix.astyanax.Keyspace;
+import com.netflix.astyanax.MutationBatch;
+import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
+
import rx.Observable;
-import rx.functions.Func1;
-import rx.functions.FuncN;
-import rx.schedulers.Schedulers;
+import rx.functions.Action1;
/**
* This phase execute all unique value verification on the MvccEntity.
*/
@Singleton
-public class WriteUniqueVerify implements
- Func1<CollectionIoEvent<MvccEntity>, Observable<? extends CollectionIoEvent<MvccEntity>>> {
+public class WriteUniqueVerify implements Action1<CollectionIoEvent<MvccEntity>> {
private static final Logger LOG = LoggerFactory.getLogger( WriteUniqueVerify.class );
@@ -55,16 +65,16 @@ public class WriteUniqueVerify implements
protected final SerializationFig serializationFig;
+ protected final Keyspace keyspace;
+
@Inject
- public WriteUniqueVerify(
- final UniqueValueSerializationStrategy uniqueValueSerializiationStrategy,
- final SerializationFig serializationFig ) {
+ public WriteUniqueVerify( final UniqueValueSerializationStrategy uniqueValueSerializiationStrategy,
+ final SerializationFig serializationFig, final Keyspace keyspace ) {
+ this.keyspace = keyspace;
- Preconditions.checkNotNull( uniqueValueSerializiationStrategy,
- "uniqueValueSerializationStrategy is required" );
- Preconditions.checkNotNull( serializationFig,
- "serializationFig is required" );
+ Preconditions.checkNotNull( uniqueValueSerializiationStrategy, "uniqueValueSerializationStrategy is required" );
+ Preconditions.checkNotNull( serializationFig, "serializationFig is required" );
this.uniqueValueStrat = uniqueValueSerializiationStrategy;
this.serializationFig = serializationFig;
@@ -72,8 +82,7 @@ public class WriteUniqueVerify implements
@Override
- public Observable<? extends CollectionIoEvent<MvccEntity>>
- call(final CollectionIoEvent<MvccEntity> ioevent ) {
+ public void call( final CollectionIoEvent<MvccEntity> ioevent ) {
MvccValidationUtils.verifyMvccEntityWithEntity( ioevent.getEvent() );
@@ -81,131 +90,100 @@ public class WriteUniqueVerify implements
final Entity entity = mvccEntity.getEntity().get();
- // use simple thread pool to verify fields in parallel
+ final Id entityId = entity.getId();
+
+ final UUID entityVersion = entity.getVersion();
- // We want to use concurrent to fork all validations this way they're wrapped by timeouts
- // and Hystrix thread pools for JMX operations. See the WriteCommand in the
- // EntityCollectionManagerImpl.
+ final CollectionScope scope = ioevent.getEntityCollection();
+
+ // use simple thread pool to verify fields in parallel
- // TODO: still needs to be added to the Concurrent utility class?
+ final Collection<Field> entityFields = entity.getFields();
- final List<Observable<FieldUniquenessResult>> fields =
- new ArrayList<Observable<FieldUniquenessResult>>();
+ //allocate our max size, worst case
+ final List<Field> uniqueFields = new ArrayList<>( entityFields.size() );
+ final MutationBatch batch = keyspace.prepareMutationBatch();
//
// Construct all the functions for verifying we're unique
//
- for ( final Field field : entity.getFields() ) {
+ for ( final Field field : entityFields ) {
// if it's unique, create a function to validate it and add it to the list of
// concurrent validations
if ( field.isUnique() ) {
- Observable<FieldUniquenessResult> result = Observable.from( field )
- .subscribeOn( Schedulers.io() )
- .map(new Func1<Field, FieldUniquenessResult>() {
-
- @Override
- public FieldUniquenessResult call(Field field ) {
-
- // use write-first then read strategy
- UniqueValue written = new UniqueValueImpl(
- ioevent.getEntityCollection(), field, entity.getId(), mvccEntity.getVersion() );
-
- // use TTL in case something goes wrong before entity is finally committed
- MutationBatch mb = uniqueValueStrat.write( written, serializationFig.getTimeout() );
-
- try {
- mb.execute();
- }
- catch ( ConnectionException ex ) {
- throw new RuntimeException("Unable to write to cassandra", ex );
- }
-
- // does the database value match what we wrote?
- UniqueValue loaded;
- try {
- loaded = uniqueValueStrat.load( ioevent.getEntityCollection(), field );
- }
- catch ( ConnectionException ex ) {
- throw new RuntimeException("Unable to read from cassandra", ex );
- }
-
- return new FieldUniquenessResult(
- field, loaded.getEntityId().equals( written.getEntityId() ) );
- }
- } );
-
- fields.add(result);
+
+ // use write-first then read strategy
+ final UniqueValue written = new UniqueValueImpl( scope, field, entityId, entityVersion );
+
+ // use TTL in case something goes wrong before entity is finally committed
+ final MutationBatch mb = uniqueValueStrat.write( written, serializationFig.getTimeout() );
+
+ batch.mergeShallow( mb );
+
+
+ uniqueFields.add( field );
}
}
- //short circuit. If we zip up nothing, we block forever.
- if(fields.size() == 0){
- return Observable.from(ioevent );
+ //short circuit nothing to do
+ if ( uniqueFields.size() == 0 ) {
+ return;
}
- //
- // Zip the results up
- //
- final FuncN<CollectionIoEvent<MvccEntity>> zipFunction =
- new FuncN<CollectionIoEvent<MvccEntity>>() {
-
- @Override
- public CollectionIoEvent<MvccEntity> call( final Object... args ) {
-
- Map<String, Field> uniquenessVioloations = new HashMap<String, Field>();
-
- for ( Object resultObj : args ) {
- FieldUniquenessResult result = ( FieldUniquenessResult ) resultObj;
- if ( !result.isUnique() ) {
- Field field = result.getField();
- uniquenessVioloations.put( field.getName(), field );
- }
- }
-
- if ( !uniquenessVioloations.isEmpty() ) {
- throw new WriteUniqueVerifyException(
- mvccEntity, ioevent.getEntityCollection(), uniquenessVioloations );
- }
-
- //return the original event
- return ioevent;
- }
- };
- return Observable.zip( fields, zipFunction );
- }
+ //perform the write
+ try {
+ batch.execute();
+ }
+ catch ( ConnectionException ex ) {
+ throw new RuntimeException( "Unable to write to cassandra", ex );
+ }
- static class FieldUniquenessResult {
- private Field field;
- private Boolean unique;
+ //now get the set of fields back
+ final UniqueValueSet uniqueValues;
- public FieldUniquenessResult( Field f, Boolean u ) {
- this.field = f;
- this.unique = u;
+ try {
+ uniqueValues = uniqueValueStrat.load( scope, uniqueFields );
+ }
+ catch ( ConnectionException e ) {
+ throw new RuntimeException( "Unable to read from cassandra", e );
}
- public Boolean isUnique() {
- return unique;
- }
+ final Map<String, Field> uniquenessViolations = new HashMap<>( uniqueFields.size());
- public void setUnique( Boolean isUnique ) {
- this.unique = isUnique;
- }
+ //loop through each field that was unique
+ for ( final Field field : uniqueFields ) {
+
+ final UniqueValue uniqueValue = uniqueValues.getValue( field.getName() );
+
+ if ( uniqueValue == null ) {
+ throw new RuntimeException(
+ String.format( "Could not retrieve unique value for field %s, unable to verify",
+ field.getName() ) );
+ }
+
+ final Id returnedEntityId = uniqueValue.getEntityId();
- public Field getField() {
- return field;
+
+ if ( !entityId.equals( returnedEntityId ) ) {
+ uniquenessViolations.put( field.getName(), field );
+ }
}
- public void setField( Field field ) {
- this.field = field;
+ //We have violations, throw an exception
+ if ( !uniquenessViolations.isEmpty() ) {
+ throw new WriteUniqueVerifyException( mvccEntity, ioevent.getEntityCollection(), uniquenessViolations );
}
+
+
}
+
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/UniqueValue.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/UniqueValue.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/UniqueValue.java
new file mode 100644
index 0000000..9749101
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/UniqueValue.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.collection.serialization;
+
+
+import java.util.UUID;
+
+import org.apache.usergrid.persistence.collection.CollectionScope;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.field.Field;
+
+/**
+ * Represents a Unique Value of a field within a collection.
+ */
+public interface UniqueValue {
+
+ /**
+ * The scope of this value
+ * @return
+ */
+ public CollectionScope getCollectionScope();
+
+ /**
+ * The entity Id that owns this value
+ * @return
+ */
+ public Id getEntityId();
+
+ /**
+ * The field value
+ * @return
+ */
+ public Field getField();
+
+ /**
+ * The version of the entity that owns this value
+ * @return
+ */
+ public UUID getEntityVersion();
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/UniqueValueSerializationStrategy.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/UniqueValueSerializationStrategy.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/UniqueValueSerializationStrategy.java
new file mode 100644
index 0000000..efcc60d
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/UniqueValueSerializationStrategy.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.collection.serialization;
+
+
+import java.util.Collection;
+
+import com.netflix.astyanax.MutationBatch;
+import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
+import org.apache.usergrid.persistence.collection.CollectionScope;
+import org.apache.usergrid.persistence.model.field.Field;
+
+
+/**
+ * Reads and writes to UniqueValues column family.
+ */
+public interface UniqueValueSerializationStrategy {
+
+ /**
+ * Write the specified UniqueValue to Cassandra with optional timeToLive in milliseconds.
+ *
+ * @param uniqueValue Object to be written
+ * @return MutatationBatch that encapsulates operation, caller may or may not execute.
+ */
+ public MutationBatch write( UniqueValue uniqueValue );
+
+ /**
+ * Write the specified UniqueValue to Cassandra with optional timeToLive in milliseconds.
+ *
+ * @param uniqueValue Object to be written
+ * @param timeToLive How long object should live in seconds
+ * @return MutatationBatch that encapsulates operation, caller may or may not execute.
+ */
+ public MutationBatch write( UniqueValue uniqueValue, Integer timeToLive );
+
+ /**
+ * Load UniqueValue that matches field from collection or null if that value does not exist.
+ *
+ * @param colScope Collection scope in which to look for field name/value
+ * @param fields Field name/value to search for
+ * @return UniqueValueSet containing fields from the collection that exist in cassandra
+ * @throws ConnectionException on error connecting to Cassandra
+ */
+ public UniqueValueSet load( CollectionScope colScope, Collection<Field> fields ) throws ConnectionException;
+
+ /**
+ * Delete the specified Unique Value from Cassandra.
+ *
+ * @param uniqueValue Object to be deleted.
+ * @return MutatationBatch that encapsulates operation, caller may or may not execute.
+ */
+ public MutationBatch delete( UniqueValue uniqueValue );
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/UniqueValueSet.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/UniqueValueSet.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/UniqueValueSet.java
new file mode 100644
index 0000000..5436a11
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/UniqueValueSet.java
@@ -0,0 +1,32 @@
+package org.apache.usergrid.persistence.collection.serialization;/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+/**
+ * A read only view of unique values
+ */
+public interface UniqueValueSet extends Iterable<UniqueValue> {
+
+ /**
+ * Get the unique value for the field
+ * @param fieldName
+ * @return
+ */
+ public UniqueValue getValue(final String fieldName);
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/EntityVersion.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/EntityVersion.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/EntityVersion.java
new file mode 100644
index 0000000..274cf5d
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/EntityVersion.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.collection.serialization.impl;
+
+
+import java.util.UUID;
+
+import org.apache.usergrid.persistence.model.entity.Id;
+
+/**
+ * Combine entity ID and entity version for use as column name for UniqueValues Column Family.
+ */
+public class EntityVersion {
+ private final Id entityId;
+ private final UUID entityVersion;
+
+ public EntityVersion(Id id, UUID uuid) {
+ this.entityId = id;
+ this.entityVersion = uuid;
+ }
+
+ public Id getEntityId() {
+ return entityId;
+ }
+
+ public UUID getEntityVersion() {
+ return entityVersion;
+ }
+
+ public boolean equals( Object o ) {
+
+ if ( o == null || !(o instanceof EntityVersion) ) {
+ return false;
+ }
+
+ EntityVersion other = (EntityVersion)o;
+
+ if ( !other.getEntityId().equals( getEntityId() )) {
+ return false;
+ }
+
+ if ( !other.getEntityVersion().equals( getEntityVersion() )) {
+ return false;
+ }
+
+ return true;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/EntityVersionSerializer.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/EntityVersionSerializer.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/EntityVersionSerializer.java
new file mode 100644
index 0000000..810a1fc
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/EntityVersionSerializer.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.collection.serialization.impl;
+
+
+import java.nio.ByteBuffer;
+import java.util.UUID;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+
+import com.google.common.base.Preconditions;
+import com.netflix.astyanax.model.CompositeBuilder;
+import com.netflix.astyanax.model.Composites;
+import com.netflix.astyanax.model.DynamicComposite;
+import com.netflix.astyanax.serializers.AbstractSerializer;
+import com.netflix.astyanax.serializers.StringSerializer;
+import com.netflix.astyanax.serializers.UUIDSerializer;
+
+/**
+ * Serialize EntityVersion, entity ID and version, for use a column name in Unique Values Column Family.
+ */
+public class EntityVersionSerializer extends AbstractSerializer<EntityVersion> {
+
+ private static final Logger LOG = LoggerFactory.getLogger( EntityVersionSerializer.class );
+
+ @Override
+ public ByteBuffer toByteBuffer(final EntityVersion ev) {
+
+ CompositeBuilder builder = Composites.newDynamicCompositeBuilder();
+
+ builder.addTimeUUID( ev.getEntityVersion() );
+ builder.addTimeUUID( ev.getEntityId().getUuid() );
+ builder.addString( ev.getEntityId().getType() );
+
+ return builder.build();
+ }
+
+ @Override
+ public EntityVersion fromByteBuffer(final ByteBuffer byteBuffer) {
+
+ // would use Composites.newDynamicCompositeParser(byteBuffer) but it is not implemented
+
+ DynamicComposite composite = DynamicComposite.fromByteBuffer(byteBuffer);
+ Preconditions.checkArgument(composite.size() == 3, "Composite should have 3 elements");
+
+ final UUID version = composite.get( 0, UUIDSerializer.get() );
+ final UUID entityId = composite.get( 1, UUIDSerializer.get() );
+ final String entityType = composite.get( 2, StringSerializer.get() );
+
+ return new EntityVersion( new SimpleId( entityId, entityType ), version);
+ }
+
+}
[8/9] git commit: Merge branch 'two-dot-o' of
https://git-wip-us.apache.org/repos/asf/incubator-usergrid into two-dot-o
Posted by to...@apache.org.
Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into two-dot-o
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/ed30e872
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/ed30e872
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/ed30e872
Branch: refs/heads/two-dot-o
Commit: ed30e8723a813351140fab3ac86b56c83d0f27d2
Parents: 5070da9 df8e6a2
Author: Todd Nine <to...@apache.org>
Authored: Wed Oct 8 09:55:58 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Wed Oct 8 09:55:58 2014 -0600
----------------------------------------------------------------------
.../corepersistence/StaleIndexCleanupTest.java | 181 +++++++++++++++++++
.../collection/EntityCollectionManagerIT.java | 4 +-
.../notifications/ApplicationQueueManager.java | 7 +-
.../services/notifications/TaskManager.java | 85 +++++----
4 files changed, 233 insertions(+), 44 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ed30e872/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
----------------------------------------------------------------------
[2/9] First pass at updating interfaces
Posted by to...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/FieldSerializer.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/FieldSerializer.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/FieldSerializer.java
new file mode 100644
index 0000000..292f550
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/FieldSerializer.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.collection.serialization.impl;
+
+
+import java.util.UUID;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.commons.lang3.StringUtils;
+
+import org.apache.usergrid.persistence.core.astyanax.CompositeFieldSerializer;
+import org.apache.usergrid.persistence.model.field.DoubleField;
+import org.apache.usergrid.persistence.model.field.Field;
+import org.apache.usergrid.persistence.model.field.IntegerField;
+import org.apache.usergrid.persistence.model.field.LongField;
+import org.apache.usergrid.persistence.model.field.StringField;
+import org.apache.usergrid.persistence.model.field.UUIDField;
+
+import com.netflix.astyanax.model.CompositeBuilder;
+import com.netflix.astyanax.model.CompositeParser;
+
+// TODO: replace with "real" serializer
+
+/**
+ * Serialize Field for use as part of row-key in Unique Values Column Family.
+ */
+public class FieldSerializer implements CompositeFieldSerializer<Field> {
+
+ private static final Logger LOG = LoggerFactory.getLogger( FieldSerializer.class );
+
+ public enum FieldType {
+ BOOLEAN_FIELD,
+ DOUBLE_FIELD,
+ INTEGER_FIELD,
+ LONG_FIELD,
+ STRING_FIELD,
+ UUID_FIELD
+ };
+
+ private static final FieldSerializer INSTANCE = new FieldSerializer();
+
+ @Override
+ public void toComposite( final CompositeBuilder builder, final Field field ) {
+
+ builder.addString( field.getName() );
+
+ // TODO: use the real field value serializer(s) here? Store hash instead?
+ builder.addString( field.getValue().toString() );
+
+ String simpleName = field.getClass().getSimpleName();
+ int nameIndex = simpleName.lastIndexOf(".");
+ String fieldType = simpleName.substring(nameIndex + 1, simpleName.length() - "Field".length());
+ fieldType = StringUtils.upperCase( fieldType + "_FIELD" );
+
+ builder.addString( fieldType );
+ }
+
+ @Override
+ public Field fromComposite( final CompositeParser composite ) {
+
+ final String name = composite.readString();
+ final String value = composite.readString();
+ final String typeString = composite.readString();
+
+ final FieldType fieldType = FieldType.valueOf( typeString );
+
+ switch (fieldType) {
+ case DOUBLE_FIELD:
+ return new DoubleField(name, Double.parseDouble(value));
+ case INTEGER_FIELD:
+ return new IntegerField(name, Integer.parseInt(value));
+ case LONG_FIELD:
+ return new LongField(name, Long.parseLong(value));
+ case STRING_FIELD:
+ return new StringField(name, value);
+ case UUID_FIELD:
+ return new UUIDField(name, UUID.fromString(value));
+ default:
+ throw new RuntimeException("Unknown unique field type");
+ }
+ }
+
+
+ /**
+ * Get the singleton serializer
+ */
+ public static FieldSerializer get() {
+ return INSTANCE;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/SerializationModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/SerializationModule.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/SerializationModule.java
index 4d930f2..89012aa 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/SerializationModule.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/SerializationModule.java
@@ -20,8 +20,7 @@ package org.apache.usergrid.persistence.collection.serialization.impl;
import org.apache.usergrid.persistence.collection.mvcc.MvccEntitySerializationStrategy;
import org.apache.usergrid.persistence.collection.mvcc.MvccLogEntrySerializationStrategy;
-import org.apache.usergrid.persistence.collection.mvcc.stage.write.UniqueValueSerializationStrategy;
-import org.apache.usergrid.persistence.collection.mvcc.stage.write.UniqueValueSerializationStrategyImpl;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValueSerializationStrategy;
import org.apache.usergrid.persistence.core.migration.Migration;
import com.google.inject.AbstractModule;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueImpl.java
new file mode 100644
index 0000000..2fdae1a
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueImpl.java
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.collection.serialization.impl;
+
+
+import java.util.UUID;
+
+import org.apache.usergrid.persistence.collection.CollectionScope;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValue;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.field.Field;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Represents a Unique Value of a field within a collection.
+ */
+public class UniqueValueImpl implements UniqueValue {
+ private final CollectionScope collectionScope;
+ private final Field field;
+ private final Id entityId;
+ private final UUID entityVersion;
+
+ public UniqueValueImpl(
+ final CollectionScope scope, final Field field, Id entityId, final UUID version ) {
+
+ Preconditions.checkNotNull( scope, "scope is required" );
+ Preconditions.checkNotNull( field, "field is required" );
+// Preconditions.checkNotNull( version, "version is required" );
+ Preconditions.checkNotNull( entityId, "entityId is required" );
+
+ this.collectionScope = scope;
+ this.field = field;
+ this.entityVersion = version;
+ this.entityId = entityId;
+ }
+
+ @Override
+ public CollectionScope getCollectionScope() {
+ return collectionScope;
+ }
+
+ @Override
+ public Field getField() {
+ return field;
+ }
+
+ @Override
+ public UUID getEntityVersion() {
+ return entityVersion;
+ }
+
+ @Override
+ public Id getEntityId() {
+ return entityId;
+ }
+
+
+ @Override
+ public boolean equals( final Object o ) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() ) {
+ return false;
+ }
+
+ final UniqueValueImpl that = ( UniqueValueImpl ) o;
+
+ if ( !getCollectionScope().equals( that.getCollectionScope() ) ) {
+ return false;
+ }
+
+ if ( !getField().equals( that.getField()) ) {
+ return false;
+ }
+
+ if ( !getEntityVersion().equals( that.getEntityVersion() ) ) {
+ return false;
+ }
+
+ if ( !getEntityId().equals( that.getEntityId() ) ) {
+ return false;
+ }
+
+ return true;
+ }
+
+
+ @Override
+ public int hashCode() {
+ int result = 31 * getCollectionScope().hashCode();
+ result = 31 * result + getField().hashCode();
+ result = 31 * result + getEntityVersion().hashCode();
+ result = 31 * result + getEntityId().hashCode();
+ return result;
+ }
+
+
+ @Override
+ public String toString() {
+ return "UniqueValueImpl{" +
+ ", collectionScope =" + collectionScope.getName() +
+ ", field =" + field +
+ ", entityVersion=" + entityVersion +
+ ", entityId =" + entityId +
+ '}';
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueSerializationStrategyImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueSerializationStrategyImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueSerializationStrategyImpl.java
new file mode 100644
index 0000000..d480691
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueSerializationStrategyImpl.java
@@ -0,0 +1,219 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.collection.serialization.impl;
+
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.cassandra.db.marshal.BytesType;
+
+import org.apache.usergrid.persistence.collection.CollectionScope;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValue;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValueSerializationStrategy;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValueSet;
+import org.apache.usergrid.persistence.core.astyanax.ColumnTypes;
+import org.apache.usergrid.persistence.core.astyanax.MultiTennantColumnFamily;
+import org.apache.usergrid.persistence.core.astyanax.MultiTennantColumnFamilyDefinition;
+import org.apache.usergrid.persistence.core.astyanax.ScopedRowKey;
+import org.apache.usergrid.persistence.core.migration.Migration;
+import org.apache.usergrid.persistence.model.field.Field;
+
+import com.google.common.base.Preconditions;
+import com.google.inject.Inject;
+import com.netflix.astyanax.ColumnListMutation;
+import com.netflix.astyanax.Keyspace;
+import com.netflix.astyanax.MutationBatch;
+import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
+import com.netflix.astyanax.model.ColumnList;
+import com.netflix.astyanax.model.Row;
+import com.netflix.astyanax.util.RangeBuilder;
+
+
+/**
+ * Reads and writes to UniqueValues column family.
+ */
+public class UniqueValueSerializationStrategyImpl implements UniqueValueSerializationStrategy, Migration {
+
+ private static final Logger log = LoggerFactory.getLogger( UniqueValueSerializationStrategyImpl.class );
+
+ // TODO: use "real" field serializer here instead once it is ready
+ private static final CollectionScopedRowKeySerializer<Field> ROW_KEY_SER =
+ new CollectionScopedRowKeySerializer<Field>( FieldSerializer.get() );
+
+ private static final EntityVersionSerializer ENTITY_VERSION_SER = new EntityVersionSerializer();
+
+ private static final MultiTennantColumnFamily<CollectionScope, Field, EntityVersion> CF_UNIQUE_VALUES =
+ new MultiTennantColumnFamily<CollectionScope, Field, EntityVersion>( "Unique_Values", ROW_KEY_SER,
+ ENTITY_VERSION_SER );
+
+ protected final Keyspace keyspace;
+
+
+ /**
+ * Construct serialization strategy for keyspace.
+ *
+ * @param keyspace Keyspace in which to store Unique Values.
+ */
+ @Inject
+ public UniqueValueSerializationStrategyImpl( final Keyspace keyspace ) {
+ this.keyspace = keyspace;
+ }
+
+
+ @Override
+ public java.util.Collection getColumnFamilies() {
+
+ MultiTennantColumnFamilyDefinition cf =
+ new MultiTennantColumnFamilyDefinition( CF_UNIQUE_VALUES, BytesType.class.getSimpleName(),
+ ColumnTypes.DYNAMIC_COMPOSITE_TYPE, BytesType.class.getSimpleName(),
+ MultiTennantColumnFamilyDefinition.CacheOption.KEYS );
+
+ return Collections.singleton( cf );
+ }
+
+
+ public MutationBatch write( UniqueValue uniqueValue ) {
+ return write( uniqueValue, Integer.MAX_VALUE );
+ }
+
+
+ @Override
+ public MutationBatch write( UniqueValue value, Integer timeToLive ) {
+
+ Preconditions.checkNotNull( value, "value is required" );
+ Preconditions.checkNotNull( timeToLive, "timeToLive is required" );
+
+ log.debug( "Writing unique value scope={} id={} version={} name={} value={} ttl={} ", new Object[] {
+ value.getCollectionScope().getName(), value.getEntityId(), value.getEntityVersion(),
+ value.getField().getName(), value.getField().getValue(), timeToLive
+ } );
+
+ final EntityVersion ev = new EntityVersion( value.getEntityId(), value.getEntityVersion() );
+
+ final Integer ttl;
+ if ( timeToLive.equals( Integer.MAX_VALUE ) ) {
+ ttl = null;
+ }
+ else {
+ ttl = timeToLive;
+ }
+
+ return doWrite( value.getCollectionScope(), value.getField(), new UniqueValueSerializationStrategyImpl.RowOp() {
+
+ @Override
+ public void doOp( final ColumnListMutation<EntityVersion> colMutation ) {
+ colMutation.putColumn( ev, 0x0, ttl );
+ }
+ } );
+ }
+
+
+ @Override
+ public MutationBatch delete( UniqueValue value ) {
+
+ Preconditions.checkNotNull( value, "value is required" );
+
+ final EntityVersion ev = new EntityVersion( value.getEntityId(), value.getEntityVersion() );
+
+ return doWrite( value.getCollectionScope(), value.getField(), new UniqueValueSerializationStrategyImpl.RowOp() {
+
+ @Override
+ public void doOp( final ColumnListMutation<EntityVersion> colMutation ) {
+ colMutation.deleteColumn( ev );
+ }
+ } );
+ }
+
+
+ /**
+ * Do the column update or delete for the given column and row key
+ *
+ * @param context We need to use this when getting the keyspace
+ */
+ private MutationBatch doWrite( CollectionScope context, Field field, RowOp op ) {
+ final MutationBatch batch = keyspace.prepareMutationBatch();
+ op.doOp( batch.withRow( CF_UNIQUE_VALUES, ScopedRowKey.fromKey( context, field ) ) );
+ return batch;
+ }
+
+
+ @Override
+ public UniqueValueSet load( final CollectionScope colScope, final Collection<Field> fields )
+ throws ConnectionException {
+
+ Preconditions.checkNotNull( fields, "fields are required" );
+ Preconditions.checkArgument( fields.size() > 0, "More than 1 field msut be specified" );
+
+ final List<ScopedRowKey<CollectionScope, Field>> keys = new ArrayList<>( fields.size() );
+
+ for ( Field field : fields ) {
+ final ScopedRowKey<CollectionScope, Field> rowKey = ScopedRowKey.fromKey( colScope, field );
+
+ keys.add( rowKey );
+ }
+
+ final UniqueValueSetImpl uniqueValueSet = new UniqueValueSetImpl( fields.size() );
+
+ Iterator<Row<ScopedRowKey<CollectionScope, Field>, EntityVersion>> results =
+ keyspace.prepareQuery( CF_UNIQUE_VALUES ).getKeySlice( keys )
+ .withColumnRange( new RangeBuilder().setLimit( 1 ).build() ).execute().getResult().iterator();
+
+
+ while ( results.hasNext() )
+
+ {
+
+ final Row<ScopedRowKey<CollectionScope, Field>, EntityVersion> unique = results.next();
+
+
+ final Field field = unique.getKey().getKey();
+
+ final ColumnList<EntityVersion> columnList = unique.getColumns();
+
+ //sanity check, nothing to do, skip it
+ if ( columnList.size() < 1 ) {
+ continue;
+ }
+
+ final EntityVersion entityVersion = columnList.getColumnByIndex( 0 ).getName();
+
+
+ final UniqueValueImpl uniqueValue = new UniqueValueImpl( colScope, field, entityVersion.getEntityId(),
+ entityVersion.getEntityVersion() );
+
+ uniqueValueSet.addValue( uniqueValue );
+ }
+
+ return uniqueValueSet;
+ }
+
+
+ /**
+ * Simple callback to perform puts and deletes with a common row setup code
+ */
+ private static interface RowOp {
+ void doOp( ColumnListMutation<EntityVersion> colMutation );
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueSetImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueSetImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueSetImpl.java
new file mode 100644
index 0000000..8dd9528
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueSetImpl.java
@@ -0,0 +1,85 @@
+package org.apache.usergrid.persistence.collection.serialization.impl;/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.usergrid.persistence.collection.serialization.UniqueValue;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValueSet;
+
+
+public class UniqueValueSetImpl implements UniqueValueSet {
+
+ private final Map<String, UniqueValue> values;
+
+ public UniqueValueSetImpl(final int expectedMaxSize) {
+ values = new HashMap<>(expectedMaxSize);
+ }
+
+
+ public void addValue(UniqueValue value){
+ values.put( value.getField().getName(), value );
+ }
+
+ @Override
+ public UniqueValue getValue( final String fieldName ) {
+ return values.get( fieldName );
+ }
+
+
+ @Override
+ public Iterator<UniqueValue> iterator() {
+ return new UniqueValueIterator(values.entrySet());
+ }
+
+
+ /**
+ * Inner class of unique value iterator
+ */
+ private static final class
+ UniqueValueIterator implements Iterator<UniqueValue>{
+
+ private final Iterator<Map.Entry<String, UniqueValue>> sourceIterator;
+
+ public UniqueValueIterator( final Set<Map.Entry<String, UniqueValue>> entries ) {
+ this.sourceIterator = entries.iterator();
+ }
+
+
+ @Override
+ public boolean hasNext() {
+ return sourceIterator.hasNext();
+ }
+
+
+ @Override
+ public UniqueValue next() {
+ return sourceIterator.next().getValue();
+ }
+
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException( "Remove is unsupported" );
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/delete/MarkCommitTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/delete/MarkCommitTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/delete/MarkCommitTest.java
index c90d079..c2876b0 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/delete/MarkCommitTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/delete/MarkCommitTest.java
@@ -1,6 +1,8 @@
package org.apache.usergrid.persistence.collection.mvcc.stage.delete;
+import java.security.Key;
+
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -13,11 +15,12 @@ import org.apache.usergrid.persistence.collection.mvcc.entity.Stage;
import org.apache.usergrid.persistence.collection.mvcc.stage.AbstractMvccEntityStageTest;
import org.apache.usergrid.persistence.collection.mvcc.stage.CollectionIoEvent;
import org.apache.usergrid.persistence.collection.mvcc.stage.TestEntityGenerator;
-import org.apache.usergrid.persistence.collection.mvcc.stage.write.UniqueValueSerializationStrategy;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValueSerializationStrategy;
import org.apache.usergrid.persistence.collection.mvcc.stage.write.WriteCommit;
import org.apache.usergrid.persistence.collection.serialization.SerializationFig;
import org.apache.usergrid.persistence.model.entity.Entity;
+import com.netflix.astyanax.Keyspace;
import com.netflix.astyanax.MutationBatch;
import static org.junit.Assert.assertEquals;
@@ -111,13 +114,16 @@ public class MarkCommitTest extends AbstractMvccEntityStageTest {
final MutationBatch entityMutation = mock( MutationBatch.class );
final SerializationFig serializationFig = mock(SerializationFig.class);
final UniqueValueSerializationStrategy uniqueValueSerializationStrategy = mock(UniqueValueSerializationStrategy.class);
+ final Keyspace keyspace = mock( Keyspace.class );
+
+ when(keyspace.prepareMutationBatch()).thenReturn( entityMutation );
when( logStrategy.write( any( CollectionScope.class ), any( MvccLogEntry.class ) ) ).thenReturn( logMutation );
when( mvccEntityStrategy.write( any( CollectionScope.class ), any( MvccEntity.class ) ) )
.thenReturn( entityMutation );
- new MarkCommit( logStrategy, mvccEntityStrategy, uniqueValueSerializationStrategy, serializationFig ).call( event );
+ new MarkCommit( logStrategy, mvccEntityStrategy, uniqueValueSerializationStrategy, serializationFig, keyspace ).call( event );
//TODO: This doesn't assert anything, this needs fixed (should be a fail technically)
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/EntityVersionSerializerTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/EntityVersionSerializerTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/EntityVersionSerializerTest.java
index 42e481e..889cba9 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/EntityVersionSerializerTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/EntityVersionSerializerTest.java
@@ -23,6 +23,8 @@ import java.nio.ByteBuffer;
import org.junit.Assert;
import org.junit.Test;
+import org.apache.usergrid.persistence.collection.serialization.impl.EntityVersion;
+import org.apache.usergrid.persistence.collection.serialization.impl.EntityVersionSerializer;
import org.apache.usergrid.persistence.model.entity.SimpleId;
import org.apache.usergrid.persistence.model.util.UUIDGenerator;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/FieldSerializerTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/FieldSerializerTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/FieldSerializerTest.java
index e3ec59d..dcff324 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/FieldSerializerTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/FieldSerializerTest.java
@@ -23,6 +23,7 @@ import java.nio.ByteBuffer;
import org.junit.Assert;
import org.junit.Test;
+import org.apache.usergrid.persistence.collection.serialization.impl.FieldSerializer;
import org.apache.usergrid.persistence.model.field.Field;
import org.apache.usergrid.persistence.model.field.IntegerField;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/UniqueValueSerializationStrategyImplTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/UniqueValueSerializationStrategyImplTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/UniqueValueSerializationStrategyImplTest.java
index c323883..f03baba 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/UniqueValueSerializationStrategyImplTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/UniqueValueSerializationStrategyImplTest.java
@@ -18,11 +18,11 @@
package org.apache.usergrid.persistence.collection.mvcc.stage.write;
+import java.util.Collections;
import java.util.UUID;
import org.jukito.UseModules;
import org.junit.Assert;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -33,16 +33,21 @@ import org.apache.usergrid.persistence.collection.CollectionScope;
import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
import org.apache.usergrid.persistence.collection.guice.TestCollectionModule;
import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
-import org.apache.usergrid.persistence.core.cassandra.CassandraRule;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValue;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValueSerializationStrategy;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValueSet;
+import org.apache.usergrid.persistence.collection.serialization.impl.UniqueValueImpl;
import org.apache.usergrid.persistence.core.cassandra.ITRunner;
import org.apache.usergrid.persistence.model.entity.Id;
import org.apache.usergrid.persistence.model.entity.SimpleId;
+import org.apache.usergrid.persistence.model.field.Field;
import org.apache.usergrid.persistence.model.field.IntegerField;
import org.apache.usergrid.persistence.model.util.UUIDGenerator;
import com.google.inject.Inject;
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
+
@RunWith( ITRunner.class )
@UseModules( TestCollectionModule.class )
public class UniqueValueSerializationStrategyImplTest {
@@ -51,7 +56,7 @@ public class UniqueValueSerializationStrategyImplTest {
@Inject
@Rule
public MigrationManagerRule migrationManagerRule;
-
+
@Inject
UniqueValueSerializationStrategy strategy;
@@ -59,16 +64,18 @@ public class UniqueValueSerializationStrategyImplTest {
@Test
public void testBasicOperation() throws ConnectionException, InterruptedException {
- CollectionScope scope = new CollectionScopeImpl(
- new SimpleId( "organization" ), new SimpleId( "test" ), "test" );
+ CollectionScope scope =
+ new CollectionScopeImpl( new SimpleId( "organization" ), new SimpleId( "test" ), "test" );
IntegerField field = new IntegerField( "count", 5 );
- Id entityId = new SimpleId( UUIDGenerator.newTimeUUID(), "entity");
+ Id entityId = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" );
UUID version = UUIDGenerator.newTimeUUID();
UniqueValue stored = new UniqueValueImpl( scope, field, entityId, version );
strategy.write( stored ).execute();
- UniqueValue retrieved = strategy.load( scope, field );
+ UniqueValueSet fields = strategy.load( scope, Collections.<Field>singleton( field ) );
+
+ UniqueValue retrieved = fields.getValue( field.getName() );
Assert.assertNotNull( retrieved );
Assert.assertEquals( stored, retrieved );
}
@@ -76,13 +83,13 @@ public class UniqueValueSerializationStrategyImplTest {
@Test
public void testWriteWithTTL() throws InterruptedException, ConnectionException {
-
- CollectionScope scope = new CollectionScopeImpl(
- new SimpleId( "organization" ), new SimpleId( "test" ), "test" );
+
+ CollectionScope scope =
+ new CollectionScopeImpl( new SimpleId( "organization" ), new SimpleId( "test" ), "test" );
// write object that lives 2 seconds
IntegerField field = new IntegerField( "count", 5 );
- Id entityId = new SimpleId( UUIDGenerator.newTimeUUID(), "entity");
+ Id entityId = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" );
UUID version = UUIDGenerator.newTimeUUID();
UniqueValue stored = new UniqueValueImpl( scope, field, entityId, version );
strategy.write( stored, 2 ).execute();
@@ -90,14 +97,19 @@ public class UniqueValueSerializationStrategyImplTest {
Thread.sleep( 1000 );
// waited one sec, should be still here
- UniqueValue retrieved = strategy.load( scope, field );
+ UniqueValueSet fields = strategy.load( scope, Collections.<Field>singleton( field ) );
+
+ UniqueValue retrieved = fields.getValue( field.getName() );
+
Assert.assertNotNull( retrieved );
Assert.assertEquals( stored, retrieved );
Thread.sleep( 1500 );
// wait another second, should be gone now
- UniqueValue nullExpected = strategy.load( scope, field );
+ fields = strategy.load( scope, Collections.<Field>singleton( field ) );
+
+ UniqueValue nullExpected = fields.getValue( field.getName() );
Assert.assertNull( nullExpected );
}
@@ -105,18 +117,22 @@ public class UniqueValueSerializationStrategyImplTest {
@Test
public void testDelete() throws ConnectionException {
- CollectionScope scope = new CollectionScopeImpl(
- new SimpleId( "organization" ), new SimpleId( "test" ), "test" );
+ CollectionScope scope =
+ new CollectionScopeImpl( new SimpleId( "organization" ), new SimpleId( "test" ), "test" );
IntegerField field = new IntegerField( "count", 5 );
- Id entityId = new SimpleId( UUIDGenerator.newTimeUUID(), "entity");
+ Id entityId = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" );
UUID version = UUIDGenerator.newTimeUUID();
UniqueValue stored = new UniqueValueImpl( scope, field, entityId, version );
strategy.write( stored ).execute();
strategy.delete( stored ).execute();
- UniqueValue nullExpected = strategy.load( scope, field );
+ UniqueValueSet fields = strategy.load( scope, Collections.<Field>singleton( field ) );
+
+ UniqueValue nullExpected = fields.getValue( field.getName() );
+
+
Assert.assertNull( nullExpected );
}
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommitTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommitTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommitTest.java
index 981a14d..b0ccb4f 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommitTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommitTest.java
@@ -30,6 +30,7 @@ import org.apache.usergrid.persistence.collection.mvcc.entity.Stage;
import org.apache.usergrid.persistence.collection.mvcc.stage.AbstractMvccEntityStageTest;
import org.apache.usergrid.persistence.collection.mvcc.stage.CollectionIoEvent;
import org.apache.usergrid.persistence.collection.mvcc.stage.TestEntityGenerator;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValueSerializationStrategy;
import org.apache.usergrid.persistence.model.entity.Entity;
import com.netflix.astyanax.MutationBatch;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteOptimisticVerifyTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteOptimisticVerifyTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteOptimisticVerifyTest.java
index 64e5e2e..6f31412 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteOptimisticVerifyTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteOptimisticVerifyTest.java
@@ -36,6 +36,9 @@ import org.apache.usergrid.persistence.collection.mvcc.entity.Stage;
import org.apache.usergrid.persistence.collection.mvcc.entity.impl.MvccLogEntryImpl;
import org.apache.usergrid.persistence.collection.mvcc.stage.AbstractMvccEntityStageTest;
import org.apache.usergrid.persistence.collection.mvcc.stage.CollectionIoEvent;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValue;
+import org.apache.usergrid.persistence.collection.serialization.impl.UniqueValueImpl;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValueSerializationStrategy;
import org.apache.usergrid.persistence.model.entity.Entity;
import org.apache.usergrid.persistence.model.entity.SimpleId;
import org.apache.usergrid.persistence.model.field.StringField;
@@ -96,20 +99,10 @@ public class WriteOptimisticVerifyTest extends AbstractMvccEntityStageTest {
// Run the stage
WriteOptimisticVerify newStage = new WriteOptimisticVerify( noConflictLog );
- CollectionIoEvent<MvccEntity> result;
- result = newStage.call( new CollectionIoEvent<MvccEntity>( collectionScope, mvccEntity ) );
- assertSame("Context was correct", collectionScope, result.getEntityCollection()) ;
+ newStage.call( new CollectionIoEvent<>( collectionScope, mvccEntity ) );
- // Verify the entity is correct
- MvccEntity entry = result.getEvent();
- // Verify UUID and version in both the MvccEntity and the entity itself. Here assertSame
- // is used on purpose as we want to make sure the same instance is used, not a copy.
- // This way the caller's runtime type is retained.
- assertSame( "Id correct", entity.getId(), entry.getId() );
- assertSame( "Version did not not match entityId", entity.getVersion(), entry.getVersion() );
- assertSame( "Entity correct", entity, entry.getEntity().get() );
}
@Test
@@ -159,7 +152,7 @@ public class WriteOptimisticVerifyTest extends AbstractMvccEntityStageTest {
RollbackAction rollbackAction = new RollbackAction( mvccLog, uvstrat );
try {
- newStage.call( new CollectionIoEvent<MvccEntity>(scope, mvccEntity));
+ newStage.call( new CollectionIoEvent<>(scope, mvccEntity));
} catch (WriteOptimisticVerifyException e) {
log.info("Error", e);
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyStageTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyStageTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyStageTest.java
deleted file mode 100644
index d4f6507..0000000
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyStageTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.collection.mvcc.stage.write;
-
-
-import org.jukito.UseModules;
-
-import org.apache.usergrid.persistence.collection.guice.TestCollectionModule;
-import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
-import org.apache.usergrid.persistence.collection.mvcc.stage.AbstractMvccEntityStageTest;
-import org.apache.usergrid.persistence.collection.mvcc.stage.CollectionIoEvent;
-import org.apache.usergrid.persistence.collection.serialization.SerializationFig;
-
-import static org.mockito.Mockito.mock;
-
-
-/**
- * TODO: Update the test to correctly test for detecting more than 1 duplicate and exception handling correctly
- *
- * @author tnine
- */
-@UseModules( TestCollectionModule.class )
-public class WriteUniqueVerifyStageTest extends AbstractMvccEntityStageTest {
-
- @Override
- protected void validateStage( final CollectionIoEvent<MvccEntity> event ) {
- UniqueValueSerializationStrategy uvstrat = mock( UniqueValueSerializationStrategy.class );
- SerializationFig fig = mock( SerializationFig.class );
- new WriteUniqueVerify( uvstrat, fig ).call( event );
- }
-}
-
-
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd841758/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyTest.java
index 15aff3d..ba89503 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyTest.java
@@ -29,15 +29,19 @@ import org.apache.usergrid.persistence.collection.guice.TestCollectionModule;
import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
import org.apache.usergrid.persistence.collection.mvcc.stage.CollectionIoEvent;
import org.apache.usergrid.persistence.collection.serialization.SerializationFig;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValueSerializationStrategy;
import org.apache.usergrid.persistence.core.cassandra.ITRunner;
import org.apache.usergrid.persistence.model.entity.Entity;
import com.google.inject.Inject;
+import com.netflix.astyanax.Keyspace;
import static org.apache.usergrid.persistence.collection.mvcc.stage.TestEntityGenerator.fromEntity;
import static org.apache.usergrid.persistence.collection.mvcc.stage.TestEntityGenerator.generateEntity;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
@RunWith( ITRunner.class )
@@ -58,43 +62,12 @@ public class WriteUniqueVerifyTest {
private SerializationFig fig;
- /**
- * Standard flow
- */
- @Test( timeout = 5000 )
- public void testStartStage() throws Exception {
-
- final CollectionScope collectionScope = mock( CollectionScope.class );
-
- // set up the mock to return the entity from the start phase
- final Entity entity = generateEntity();
-
- final MvccEntity mvccEntity = fromEntity( entity );
-
- // run the stage
- WriteUniqueVerify newStage = new WriteUniqueVerify( uvstrat, fig );
-
- CollectionIoEvent<MvccEntity> result = newStage.call(
- new CollectionIoEvent<MvccEntity>( collectionScope, mvccEntity ) )
- .toBlocking().last();
-
- assertSame( "Context was correct", collectionScope, result.getEntityCollection() );
-
- // verify the entity is correct
- MvccEntity entry = result.getEvent();
-
- // verify uuid and version in both the MvccEntity and the entity itself. assertSame is
- // used on purpose. We want to make sure the same instance is used, not a copy.
- // this way the caller's runtime type is retained.
- assertSame( "id correct", entity.getId(), entry.getId() );
- assertSame( "version did not not match entityId", entity.getVersion(), entry.getVersion() );
- assertSame( "Entity correct", entity, entry.getEntity().get() );
- }
@Test
public void testNoFields() {
final CollectionScope collectionScope = mock( CollectionScope.class );
+ final Keyspace keyspace = mock(Keyspace.class);
// set up the mock to return the entity from the start phase
final Entity entity = generateEntity();
@@ -102,13 +75,14 @@ public class WriteUniqueVerifyTest {
final MvccEntity mvccEntity = fromEntity( entity );
// run the stage
- WriteUniqueVerify newStage = new WriteUniqueVerify( uvstrat, fig );
+ WriteUniqueVerify newStage = new WriteUniqueVerify( uvstrat, fig, keyspace );
+
+ newStage.call(
+ new CollectionIoEvent<>( collectionScope, mvccEntity ) ) ;
- CollectionIoEvent<MvccEntity> result = newStage.call(
- new CollectionIoEvent<MvccEntity>( collectionScope, mvccEntity ) )
- .toBlocking().last();
+ //if we get here, it's a success. We want to test no exceptions are thrown
- assertSame( "Context was correct", collectionScope, result.getEntityCollection() );
+ verify(keyspace, never()).prepareMutationBatch();
}
}
[5/9] git commit: Fixed issue with UUID not being generated on write
Posted by to...@apache.org.
Fixed issue with UUID not being generated on write
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/792b2b2c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/792b2b2c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/792b2b2c
Branch: refs/heads/two-dot-o
Commit: 792b2b2c6fafb5c09ceb6c5c0786ac5572e09ff5
Parents: 150897d
Author: Todd Nine <to...@apache.org>
Authored: Tue Oct 7 17:56:32 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Tue Oct 7 17:56:32 2014 -0600
----------------------------------------------------------------------
.../mvcc/entity/MvccValidationUtils.java | 3 ++
.../mvcc/stage/delete/MarkCommit.java | 4 +-
.../mvcc/stage/write/RollbackAction.java | 4 +-
.../mvcc/stage/write/WriteCommit.java | 7 ++--
.../collection/mvcc/stage/write/WriteStart.java | 9 +++--
.../mvcc/stage/write/WriteUniqueVerify.java | 19 ++++-----
.../collection/serialization/UniqueValue.java | 6 ---
.../UniqueValueSerializationStrategy.java | 6 +--
.../impl/EntityVersionSerializer.java | 16 ++++++--
.../serialization/impl/FieldSerializer.java | 23 ++++++-----
.../serialization/impl/UniqueValueImpl.java | 21 +++-------
.../UniqueValueSerializationStrategyImpl.java | 42 +++++++++++++-------
.../collection/EntityCollectionManagerIT.java | 2 +-
...niqueValueSerializationStrategyImplTest.java | 14 +++----
.../stage/write/WriteOptimisticVerifyTest.java | 14 +++----
15 files changed, 102 insertions(+), 88 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/792b2b2c/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccValidationUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccValidationUtils.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccValidationUtils.java
index e03def7..f40572a 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccValidationUtils.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccValidationUtils.java
@@ -28,6 +28,8 @@ import static org.apache.usergrid.persistence.core.util.ValidationUtils.verifyEn
import static org.apache.usergrid.persistence.core.util.ValidationUtils.verifyIdentity;
import static org.apache.usergrid.persistence.core.util.ValidationUtils.verifyString;
import static org.apache.usergrid.persistence.core.util.ValidationUtils.verifyTimeUuid;
+import static org.apache.usergrid.persistence.core.util.ValidationUtils.verifyVersion;
+
/**
* Validation Utilities for collection
@@ -42,6 +44,7 @@ public class MvccValidationUtils {
Preconditions.checkNotNull( entity.getEntity().isPresent(), "Entity is required" );
+ verifyVersion( entity.getVersion() );
verifyMvccEntityOptionalEntity( entity );
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/792b2b2c/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 61a2a36..1e01c02 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
@@ -158,9 +158,9 @@ public class MarkCommit implements Action1<CollectionIoEvent<MvccEntity>> {
continue;
}
- final UniqueValue unique = new UniqueValueImpl( collectionScope, field, entityId, entityVersion );
+ final UniqueValue unique = new UniqueValueImpl( field, entityId, entityVersion );
- final MutationBatch deleteMutation = uniqueValueStrat.delete( unique );
+ final MutationBatch deleteMutation = uniqueValueStrat.delete(collectionScope, unique );
batch.mergeShallow( deleteMutation );
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/792b2b2c/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/RollbackAction.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/RollbackAction.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/RollbackAction.java
index dfccb34..8561708 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/RollbackAction.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/RollbackAction.java
@@ -83,9 +83,9 @@ public class RollbackAction implements Action1<Throwable> {
if ( field.isUnique() ) {
UniqueValue toDelete =
- new UniqueValueImpl( scope, field, entity.get().getId(), mvccEntity.getVersion() );
+ new UniqueValueImpl( field, entity.get().getId(), mvccEntity.getVersion() );
- MutationBatch deleteMb = uniqueValueStrat.delete( toDelete );
+ MutationBatch deleteMb = uniqueValueStrat.delete(scope, toDelete );
if ( rollbackMb == null ) {
rollbackMb = deleteMb;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/792b2b2c/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommit.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommit.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommit.java
index 49e967f..584d7f1 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommit.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommit.java
@@ -113,9 +113,10 @@ public class WriteCommit implements Func1<CollectionIoEvent<MvccEntity>, Entity>
if ( field.isUnique() ) {
- UniqueValue written = new UniqueValueImpl( ioEvent.getEntityCollection(), field,
- mvccEntity.getEntity().get().getId(), mvccEntity.getEntity().get().getVersion());
- MutationBatch mb = uniqueValueStrat.write( written );
+ UniqueValue written = new UniqueValueImpl( field,
+ entityId,version);
+
+ MutationBatch mb = uniqueValueStrat.write(collectionScope, written );
LOG.debug("Finalizing {} unqiue value {}", field.getName(), field.getValue().toString());
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/792b2b2c/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteStart.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteStart.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteStart.java
index ad335a0..20fad0e 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteStart.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteStart.java
@@ -11,9 +11,11 @@ import org.apache.usergrid.persistence.collection.exception.WriteStartException;
import org.apache.usergrid.persistence.collection.mvcc.MvccLogEntrySerializationStrategy;
import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
import org.apache.usergrid.persistence.collection.mvcc.entity.MvccLogEntry;
+import org.apache.usergrid.persistence.collection.mvcc.entity.Stage;
import org.apache.usergrid.persistence.collection.mvcc.entity.impl.MvccEntityImpl;
import org.apache.usergrid.persistence.collection.mvcc.entity.impl.MvccLogEntryImpl;
import org.apache.usergrid.persistence.collection.mvcc.stage.CollectionIoEvent;
+import org.apache.usergrid.persistence.collection.util.EntityUtils;
import org.apache.usergrid.persistence.model.entity.Entity;
import org.apache.usergrid.persistence.model.entity.Id;
import org.apache.usergrid.persistence.model.util.UUIDGenerator;
@@ -63,12 +65,11 @@ public class WriteStart implements Func1<CollectionIoEvent<Entity>, CollectionIo
//TODO update this when merged with George's changes
final MvccLogEntry startEntry = new MvccLogEntryImpl( entityId, version,
- org.apache.usergrid.persistence.collection.mvcc.entity.Stage.ACTIVE, MvccLogEntry.State.COMPLETE);
+ Stage.ACTIVE, MvccLogEntry.State.COMPLETE);
MutationBatch write = logStrategy.write( collectionScope, startEntry );
- final MvccEntityImpl nextStage =
- new MvccEntityImpl( entityId, version, status, entity );
+ final MvccEntityImpl nextStage = new MvccEntityImpl( entityId, version, status, entity );
try {
@@ -86,6 +87,8 @@ public class WriteStart implements Func1<CollectionIoEvent<Entity>, CollectionIo
}
+ EntityUtils.setVersion(entity, version);
+
//create the mvcc entity for the next stage
//todo, we need to create a complete or partial update here (or sooner)
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/792b2b2c/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerify.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerify.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerify.java
index e6d37fc..6ca3445 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerify.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerify.java
@@ -49,7 +49,6 @@ import com.netflix.astyanax.Keyspace;
import com.netflix.astyanax.MutationBatch;
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
-import rx.Observable;
import rx.functions.Action1;
@@ -88,11 +87,13 @@ public class WriteUniqueVerify implements Action1<CollectionIoEvent<MvccEntity>>
final MvccEntity mvccEntity = ioevent.getEvent();
- final Entity entity = mvccEntity.getEntity().get();
+ final Id entityId = mvccEntity.getId();
+
+ final UUID entityVersion = mvccEntity.getVersion();
- final Id entityId = entity.getId();
- final UUID entityVersion = entity.getVersion();
+ final Entity entity = mvccEntity.getEntity().get();
+
final CollectionScope scope = ioevent.getEntityCollection();
@@ -115,10 +116,10 @@ public class WriteUniqueVerify implements Action1<CollectionIoEvent<MvccEntity>>
// use write-first then read strategy
- final UniqueValue written = new UniqueValueImpl( scope, field, entityId, entityVersion );
+ final UniqueValue written = new UniqueValueImpl( field, entityId, entityVersion );
// use TTL in case something goes wrong before entity is finally committed
- final MutationBatch mb = uniqueValueStrat.write( written, serializationFig.getTimeout() );
+ final MutationBatch mb = uniqueValueStrat.write( scope, written, serializationFig.getTimeout() );
batch.mergeShallow( mb );
@@ -142,7 +143,6 @@ public class WriteUniqueVerify implements Action1<CollectionIoEvent<MvccEntity>>
}
-
//now get the set of fields back
final UniqueValueSet uniqueValues;
@@ -154,7 +154,7 @@ public class WriteUniqueVerify implements Action1<CollectionIoEvent<MvccEntity>>
}
- final Map<String, Field> uniquenessViolations = new HashMap<>( uniqueFields.size());
+ final Map<String, Field> uniquenessViolations = new HashMap<>( uniqueFields.size() );
//loop through each field that was unique
@@ -182,8 +182,5 @@ public class WriteUniqueVerify implements Action1<CollectionIoEvent<MvccEntity>>
if ( !uniquenessViolations.isEmpty() ) {
throw new WriteUniqueVerifyException( mvccEntity, ioevent.getEntityCollection(), uniquenessViolations );
}
-
-
}
-
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/792b2b2c/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/UniqueValue.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/UniqueValue.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/UniqueValue.java
index 9749101..2ba927c 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/UniqueValue.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/UniqueValue.java
@@ -30,12 +30,6 @@ import org.apache.usergrid.persistence.model.field.Field;
public interface UniqueValue {
/**
- * The scope of this value
- * @return
- */
- public CollectionScope getCollectionScope();
-
- /**
* The entity Id that owns this value
* @return
*/
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/792b2b2c/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/UniqueValueSerializationStrategy.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/UniqueValueSerializationStrategy.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/UniqueValueSerializationStrategy.java
index efcc60d..4ceb407 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/UniqueValueSerializationStrategy.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/UniqueValueSerializationStrategy.java
@@ -37,7 +37,7 @@ public interface UniqueValueSerializationStrategy {
* @param uniqueValue Object to be written
* @return MutatationBatch that encapsulates operation, caller may or may not execute.
*/
- public MutationBatch write( UniqueValue uniqueValue );
+ public MutationBatch write( CollectionScope scope, UniqueValue uniqueValue );
/**
* Write the specified UniqueValue to Cassandra with optional timeToLive in milliseconds.
@@ -46,7 +46,7 @@ public interface UniqueValueSerializationStrategy {
* @param timeToLive How long object should live in seconds
* @return MutatationBatch that encapsulates operation, caller may or may not execute.
*/
- public MutationBatch write( UniqueValue uniqueValue, Integer timeToLive );
+ public MutationBatch write( CollectionScope scope, UniqueValue uniqueValue, Integer timeToLive );
/**
* Load UniqueValue that matches field from collection or null if that value does not exist.
@@ -64,5 +64,5 @@ public interface UniqueValueSerializationStrategy {
* @param uniqueValue Object to be deleted.
* @return MutatationBatch that encapsulates operation, caller may or may not execute.
*/
- public MutationBatch delete( UniqueValue uniqueValue );
+ public MutationBatch delete( CollectionScope scope, UniqueValue uniqueValue );
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/792b2b2c/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/EntityVersionSerializer.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/EntityVersionSerializer.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/EntityVersionSerializer.java
index 810a1fc..dc4efde 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/EntityVersionSerializer.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/EntityVersionSerializer.java
@@ -24,6 +24,10 @@ import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.apache.usergrid.persistence.collection.mvcc.entity.MvccValidationUtils;
+import org.apache.usergrid.persistence.collection.util.EntityUtils;
+import org.apache.usergrid.persistence.core.util.ValidationUtils;
+import org.apache.usergrid.persistence.model.entity.Id;
import org.apache.usergrid.persistence.model.entity.SimpleId;
import com.google.common.base.Preconditions;
@@ -44,11 +48,17 @@ public class EntityVersionSerializer extends AbstractSerializer<EntityVersion> {
@Override
public ByteBuffer toByteBuffer(final EntityVersion ev) {
+ final UUID entityVersion = ev.getEntityVersion();
+
+ final Id entityId = ev.getEntityId();
+ final UUID entityUuid = entityId.getUuid();
+ final String entityType = entityId.getType();
+
CompositeBuilder builder = Composites.newDynamicCompositeBuilder();
- builder.addTimeUUID( ev.getEntityVersion() );
- builder.addTimeUUID( ev.getEntityId().getUuid() );
- builder.addString( ev.getEntityId().getType() );
+ builder.addUUID( entityVersion );
+ builder.addUUID( entityUuid );
+ builder.addString(entityType );
return builder.build();
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/792b2b2c/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/FieldSerializer.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/FieldSerializer.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/FieldSerializer.java
index 7eb8216..1d28bf5 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/FieldSerializer.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/FieldSerializer.java
@@ -20,9 +20,6 @@ package org.apache.usergrid.persistence.collection.serialization.impl;
import java.util.UUID;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import org.apache.usergrid.persistence.core.astyanax.CompositeFieldSerializer;
import org.apache.usergrid.persistence.model.field.BooleanField;
import org.apache.usergrid.persistence.model.field.DoubleField;
@@ -51,12 +48,13 @@ public class FieldSerializer implements CompositeFieldSerializer<Field> {
@Override
public void toComposite( final CompositeBuilder builder, final Field field ) {
- builder.addString( field.getName() );
-
- builder.addString( field.getValue().toString() );
final FieldTypeName fieldType = field.getTypeName();
+
+ /**
+ * Validation we only support a subset
+ */
switch ( fieldType ) {
case BOOLEAN:
case DOUBLE:
@@ -67,19 +65,27 @@ public class FieldSerializer implements CompositeFieldSerializer<Field> {
break;
default:
throw new RuntimeException(
- String.format( "Type %s is not a supported type for unique values", fieldType ));
+ String.format( "Type %s is not a supported type for unique values", fieldType ) );
}
+
builder.addString( fieldType.name() );
+
+ builder.addString( field.getName() );
+
+ builder.addString( field.getValue().toString() );
}
@Override
public Field fromComposite( final CompositeParser composite ) {
+ final String typeString = composite.readString();
+
final String name = composite.readString();
+
final String value = composite.readString();
- final String typeString = composite.readString();
+
final FieldTypeName fieldType = FieldTypeName.valueOf( typeString );
@@ -102,7 +108,6 @@ public class FieldSerializer implements CompositeFieldSerializer<Field> {
}
-
/**
* Get the singleton serializer
*/
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/792b2b2c/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueImpl.java
index 2fdae1a..862d8b1 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueImpl.java
@@ -31,29 +31,22 @@ import com.google.common.base.Preconditions;
* Represents a Unique Value of a field within a collection.
*/
public class UniqueValueImpl implements UniqueValue {
- private final CollectionScope collectionScope;
private final Field field;
private final Id entityId;
private final UUID entityVersion;
- public UniqueValueImpl(
- final CollectionScope scope, final Field field, Id entityId, final UUID version ) {
+ public UniqueValueImpl(final Field field, Id entityId, final UUID version ) {
- Preconditions.checkNotNull( scope, "scope is required" );
Preconditions.checkNotNull( field, "field is required" );
-// Preconditions.checkNotNull( version, "version is required" );
+ Preconditions.checkNotNull( version, "version is required" );
Preconditions.checkNotNull( entityId, "entityId is required" );
- this.collectionScope = scope;
this.field = field;
this.entityVersion = version;
this.entityId = entityId;
}
- @Override
- public CollectionScope getCollectionScope() {
- return collectionScope;
- }
+
@Override
public Field getField() {
@@ -82,9 +75,7 @@ public class UniqueValueImpl implements UniqueValue {
final UniqueValueImpl that = ( UniqueValueImpl ) o;
- if ( !getCollectionScope().equals( that.getCollectionScope() ) ) {
- return false;
- }
+
if ( !getField().equals( that.getField()) ) {
return false;
@@ -104,8 +95,7 @@ public class UniqueValueImpl implements UniqueValue {
@Override
public int hashCode() {
- int result = 31 * getCollectionScope().hashCode();
- result = 31 * result + getField().hashCode();
+ int result = 31 * getField().hashCode();
result = 31 * result + getEntityVersion().hashCode();
result = 31 * result + getEntityId().hashCode();
return result;
@@ -115,7 +105,6 @@ public class UniqueValueImpl implements UniqueValue {
@Override
public String toString() {
return "UniqueValueImpl{" +
- ", collectionScope =" + collectionScope.getName() +
", field =" + field +
", entityVersion=" + entityVersion +
", entityId =" + entityId +
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/792b2b2c/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueSerializationStrategyImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueSerializationStrategyImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueSerializationStrategyImpl.java
index d480691..95c83f3 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueSerializationStrategyImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueSerializationStrategyImpl.java
@@ -23,6 +23,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,6 +39,8 @@ import org.apache.usergrid.persistence.core.astyanax.MultiTennantColumnFamily;
import org.apache.usergrid.persistence.core.astyanax.MultiTennantColumnFamilyDefinition;
import org.apache.usergrid.persistence.core.astyanax.ScopedRowKey;
import org.apache.usergrid.persistence.core.migration.Migration;
+import org.apache.usergrid.persistence.core.util.ValidationUtils;
+import org.apache.usergrid.persistence.model.entity.Id;
import org.apache.usergrid.persistence.model.field.Field;
import com.google.common.base.Preconditions;
@@ -46,6 +49,7 @@ import com.netflix.astyanax.ColumnListMutation;
import com.netflix.astyanax.Keyspace;
import com.netflix.astyanax.MutationBatch;
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
+import com.netflix.astyanax.model.Column;
import com.netflix.astyanax.model.ColumnList;
import com.netflix.astyanax.model.Row;
import com.netflix.astyanax.util.RangeBuilder;
@@ -60,7 +64,7 @@ public class UniqueValueSerializationStrategyImpl implements UniqueValueSerializ
// TODO: use "real" field serializer here instead once it is ready
private static final CollectionScopedRowKeySerializer<Field> ROW_KEY_SER =
- new CollectionScopedRowKeySerializer<Field>( FieldSerializer.get() );
+ new CollectionScopedRowKeySerializer<>( FieldSerializer.get() );
private static final EntityVersionSerializer ENTITY_VERSION_SER = new EntityVersionSerializer();
@@ -83,7 +87,7 @@ public class UniqueValueSerializationStrategyImpl implements UniqueValueSerializ
@Override
- public java.util.Collection getColumnFamilies() {
+ public Collection<MultiTennantColumnFamilyDefinition> getColumnFamilies() {
MultiTennantColumnFamilyDefinition cf =
new MultiTennantColumnFamilyDefinition( CF_UNIQUE_VALUES, BytesType.class.getSimpleName(),
@@ -94,19 +98,29 @@ public class UniqueValueSerializationStrategyImpl implements UniqueValueSerializ
}
- public MutationBatch write( UniqueValue uniqueValue ) {
- return write( uniqueValue, Integer.MAX_VALUE );
+ public MutationBatch write(final CollectionScope scope, UniqueValue uniqueValue ) {
+ return write( scope, uniqueValue, Integer.MAX_VALUE );
}
@Override
- public MutationBatch write( UniqueValue value, Integer timeToLive ) {
+ public MutationBatch write(final CollectionScope scope, UniqueValue value, Integer timeToLive ) {
Preconditions.checkNotNull( value, "value is required" );
Preconditions.checkNotNull( timeToLive, "timeToLive is required" );
+ final Field field = value.getField();
+
+
+
+ final Id entityId = value.getEntityId();
+ final UUID entityVersion = value.getEntityVersion();
+
+ ValidationUtils.verifyIdentity( entityId );
+ ValidationUtils.verifyVersion( entityVersion );
+
log.debug( "Writing unique value scope={} id={} version={} name={} value={} ttl={} ", new Object[] {
- value.getCollectionScope().getName(), value.getEntityId(), value.getEntityVersion(),
+ scope.getName(), entityId, entityVersion,
value.getField().getName(), value.getField().getValue(), timeToLive
} );
@@ -120,7 +134,7 @@ public class UniqueValueSerializationStrategyImpl implements UniqueValueSerializ
ttl = timeToLive;
}
- return doWrite( value.getCollectionScope(), value.getField(), new UniqueValueSerializationStrategyImpl.RowOp() {
+ return doWrite( scope, value.getField(), new UniqueValueSerializationStrategyImpl.RowOp() {
@Override
public void doOp( final ColumnListMutation<EntityVersion> colMutation ) {
@@ -131,13 +145,13 @@ public class UniqueValueSerializationStrategyImpl implements UniqueValueSerializ
@Override
- public MutationBatch delete( UniqueValue value ) {
+ public MutationBatch delete(final CollectionScope scope, UniqueValue value ) {
Preconditions.checkNotNull( value, "value is required" );
final EntityVersion ev = new EntityVersion( value.getEntityId(), value.getEntityVersion() );
- return doWrite( value.getCollectionScope(), value.getField(), new UniqueValueSerializationStrategyImpl.RowOp() {
+ return doWrite( scope, value.getField(), new UniqueValueSerializationStrategyImpl.RowOp() {
@Override
public void doOp( final ColumnListMutation<EntityVersion> colMutation ) {
@@ -160,7 +174,7 @@ public class UniqueValueSerializationStrategyImpl implements UniqueValueSerializ
@Override
- public UniqueValueSet load( final CollectionScope colScope, final Collection<Field> fields )
+ public UniqueValueSet load(final CollectionScope colScope, final Collection<Field> fields )
throws ConnectionException {
Preconditions.checkNotNull( fields, "fields are required" );
@@ -190,17 +204,17 @@ public class UniqueValueSerializationStrategyImpl implements UniqueValueSerializ
final Field field = unique.getKey().getKey();
- final ColumnList<EntityVersion> columnList = unique.getColumns();
+ final Iterator<Column<EntityVersion>> columnList = unique.getColumns().iterator();
//sanity check, nothing to do, skip it
- if ( columnList.size() < 1 ) {
+ if ( !columnList.hasNext()) {
continue;
}
- final EntityVersion entityVersion = columnList.getColumnByIndex( 0 ).getName();
+ final EntityVersion entityVersion = columnList.next().getName();
- final UniqueValueImpl uniqueValue = new UniqueValueImpl( colScope, field, entityVersion.getEntityId(),
+ final UniqueValueImpl uniqueValue = new UniqueValueImpl(field, entityVersion.getEntityId(),
entityVersion.getEntityVersion() );
uniqueValueSet.addValue( uniqueValue );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/792b2b2c/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
index 1639d17..7a725a9 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
@@ -77,7 +77,7 @@ public class EntityCollectionManagerIT {
Entity returned = observable.toBlocking().lastOrDefault( null );
assertNotNull( "Returned has a uuid", returned.getId() );
- assertNotNull( "Version exists" );
+ assertNotNull( "Version exists", returned.getVersion() );
}
@Test
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/792b2b2c/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/UniqueValueSerializationStrategyImplTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/UniqueValueSerializationStrategyImplTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/UniqueValueSerializationStrategyImplTest.java
index f03baba..d5fee64 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/UniqueValueSerializationStrategyImplTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/UniqueValueSerializationStrategyImplTest.java
@@ -70,8 +70,8 @@ public class UniqueValueSerializationStrategyImplTest {
IntegerField field = new IntegerField( "count", 5 );
Id entityId = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" );
UUID version = UUIDGenerator.newTimeUUID();
- UniqueValue stored = new UniqueValueImpl( scope, field, entityId, version );
- strategy.write( stored ).execute();
+ UniqueValue stored = new UniqueValueImpl( field, entityId, version );
+ strategy.write(scope, stored ).execute();
UniqueValueSet fields = strategy.load( scope, Collections.<Field>singleton( field ) );
@@ -91,8 +91,8 @@ public class UniqueValueSerializationStrategyImplTest {
IntegerField field = new IntegerField( "count", 5 );
Id entityId = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" );
UUID version = UUIDGenerator.newTimeUUID();
- UniqueValue stored = new UniqueValueImpl( scope, field, entityId, version );
- strategy.write( stored, 2 ).execute();
+ UniqueValue stored = new UniqueValueImpl( field, entityId, version );
+ strategy.write(scope, stored, 2 ).execute();
Thread.sleep( 1000 );
@@ -123,10 +123,10 @@ public class UniqueValueSerializationStrategyImplTest {
IntegerField field = new IntegerField( "count", 5 );
Id entityId = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" );
UUID version = UUIDGenerator.newTimeUUID();
- UniqueValue stored = new UniqueValueImpl( scope, field, entityId, version );
- strategy.write( stored ).execute();
+ UniqueValue stored = new UniqueValueImpl( field, entityId, version );
+ strategy.write(scope, stored ).execute();
- strategy.delete( stored ).execute();
+ strategy.delete(scope, stored ).execute();
UniqueValueSet fields = strategy.load( scope, Collections.<Field>singleton( field ) );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/792b2b2c/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteOptimisticVerifyTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteOptimisticVerifyTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteOptimisticVerifyTest.java
index 6f31412..c64fe23 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteOptimisticVerifyTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteOptimisticVerifyTest.java
@@ -136,13 +136,11 @@ public class WriteOptimisticVerifyTest extends AbstractMvccEntityStageTest {
// mock up unique values interface
UniqueValueSerializationStrategy uvstrat = mock( UniqueValueSerializationStrategy.class);
- UniqueValue uv1 = new UniqueValueImpl(
- scope, entity.getField("name"), entity.getId(), entity.getVersion());
- UniqueValue uv2 = new UniqueValueImpl(
- scope, entity.getField("identifier"), entity.getId(), entity.getVersion());
+ UniqueValue uv1 = new UniqueValueImpl(entity.getField("name"), entity.getId(), entity.getVersion());
+ UniqueValue uv2 = new UniqueValueImpl( entity.getField("identifier"), entity.getId(), entity.getVersion());
MutationBatch mb = mock( MutationBatch.class );
- when( uvstrat.delete(uv1) ).thenReturn(mb);
- when( uvstrat.delete(uv2) ).thenReturn(mb);
+ when( uvstrat.delete(scope, uv1) ).thenReturn(mb);
+ when( uvstrat.delete(scope, uv2) ).thenReturn(mb);
// Run the stage, conflict should be detected
final MvccEntity mvccEntity = fromEntity( entity );
@@ -162,8 +160,8 @@ public class WriteOptimisticVerifyTest extends AbstractMvccEntityStageTest {
assertTrue( conflictDetected );
// check that unique values were deleted
- verify( uvstrat, times(1) ).delete( uv1 );
- verify( uvstrat, times(1) ).delete( uv2 );
+ verify( uvstrat, times(1) ).delete(scope, uv1 );
+ verify( uvstrat, times(1) ).delete(scope, uv2 );
}
}
[4/9] git commit: Changed the unique field serialization to work when
class names are changed.
Posted by to...@apache.org.
Changed the unique field serialization to work when class names are changed.
Upgraded jackson and smile versions
Removed pretty print during serialization for efficiency
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/150897d6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/150897d6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/150897d6
Branch: refs/heads/two-dot-o
Commit: 150897d61445b4fb6778b0094846b3a9857fb6b0
Parents: fd84175
Author: Todd Nine <to...@apache.org>
Authored: Tue Oct 7 16:04:26 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Tue Oct 7 16:04:26 2014 -0600
----------------------------------------------------------------------
.../serialization/impl/FieldSerializer.java | 71 +++++++++++---------
.../MvccEntitySerializationStrategyImpl.java | 9 +--
.../mvcc/stage/write/WriteUniqueVerifyTest.java | 10 ++-
.../persistence/model/field/AbstractField.java | 4 ++
.../persistence/model/field/ArrayField.java | 3 +
.../persistence/model/field/BooleanField.java | 6 ++
.../persistence/model/field/ByteArrayField.java | 6 ++
.../persistence/model/field/DoubleField.java | 6 ++
.../model/field/EntityObjectField.java | 6 ++
.../usergrid/persistence/model/field/Field.java | 8 +++
.../persistence/model/field/FieldTypeName.java | 42 ++++++++++++
.../persistence/model/field/FloatField.java | 6 ++
.../persistence/model/field/IntegerField.java | 6 ++
.../persistence/model/field/ListField.java | 7 ++
.../persistence/model/field/LocationField.java | 6 ++
.../persistence/model/field/LongField.java | 6 ++
.../persistence/model/field/SetField.java | 6 ++
.../persistence/model/field/StringField.java | 6 ++
.../persistence/model/field/UUIDField.java | 6 ++
stack/corepersistence/pom.xml | 4 +-
20 files changed, 183 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/150897d6/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/FieldSerializer.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/FieldSerializer.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/FieldSerializer.java
index 292f550..7eb8216 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/FieldSerializer.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/FieldSerializer.java
@@ -23,11 +23,11 @@ import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.commons.lang3.StringUtils;
-
import org.apache.usergrid.persistence.core.astyanax.CompositeFieldSerializer;
+import org.apache.usergrid.persistence.model.field.BooleanField;
import org.apache.usergrid.persistence.model.field.DoubleField;
import org.apache.usergrid.persistence.model.field.Field;
+import org.apache.usergrid.persistence.model.field.FieldTypeName;
import org.apache.usergrid.persistence.model.field.IntegerField;
import org.apache.usergrid.persistence.model.field.LongField;
import org.apache.usergrid.persistence.model.field.StringField;
@@ -38,40 +38,42 @@ import com.netflix.astyanax.model.CompositeParser;
// TODO: replace with "real" serializer
+
/**
* Serialize Field for use as part of row-key in Unique Values Column Family.
*/
public class FieldSerializer implements CompositeFieldSerializer<Field> {
- private static final Logger LOG = LoggerFactory.getLogger( FieldSerializer.class );
-
- public enum FieldType {
- BOOLEAN_FIELD,
- DOUBLE_FIELD,
- INTEGER_FIELD,
- LONG_FIELD,
- STRING_FIELD,
- UUID_FIELD
- };
private static final FieldSerializer INSTANCE = new FieldSerializer();
+
@Override
public void toComposite( final CompositeBuilder builder, final Field field ) {
builder.addString( field.getName() );
- // TODO: use the real field value serializer(s) here? Store hash instead?
builder.addString( field.getValue().toString() );
-
- String simpleName = field.getClass().getSimpleName();
- int nameIndex = simpleName.lastIndexOf(".");
- String fieldType = simpleName.substring(nameIndex + 1, simpleName.length() - "Field".length());
- fieldType = StringUtils.upperCase( fieldType + "_FIELD" );
- builder.addString( fieldType );
+ final FieldTypeName fieldType = field.getTypeName();
+
+ switch ( fieldType ) {
+ case BOOLEAN:
+ case DOUBLE:
+ case INTEGER:
+ case LONG:
+ case STRING:
+ case UUID:
+ break;
+ default:
+ throw new RuntimeException(
+ String.format( "Type %s is not a supported type for unique values", fieldType ));
+ }
+
+ builder.addString( fieldType.name() );
}
+
@Override
public Field fromComposite( final CompositeParser composite ) {
@@ -79,25 +81,28 @@ public class FieldSerializer implements CompositeFieldSerializer<Field> {
final String value = composite.readString();
final String typeString = composite.readString();
- final FieldType fieldType = FieldType.valueOf( typeString );
-
- switch (fieldType) {
- case DOUBLE_FIELD:
- return new DoubleField(name, Double.parseDouble(value));
- case INTEGER_FIELD:
- return new IntegerField(name, Integer.parseInt(value));
- case LONG_FIELD:
- return new LongField(name, Long.parseLong(value));
- case STRING_FIELD:
- return new StringField(name, value);
- case UUID_FIELD:
- return new UUIDField(name, UUID.fromString(value));
+ final FieldTypeName fieldType = FieldTypeName.valueOf( typeString );
+
+ switch ( fieldType ) {
+ case BOOLEAN:
+ return new BooleanField( name, Boolean.parseBoolean( value ) );
+ case DOUBLE:
+ return new DoubleField( name, Double.parseDouble( value ) );
+ case INTEGER:
+ return new IntegerField( name, Integer.parseInt( value ) );
+ case LONG:
+ return new LongField( name, Long.parseLong( value ) );
+ case STRING:
+ return new StringField( name, value );
+ case UUID:
+ return new UUIDField( name, UUID.fromString( value ) );
default:
- throw new RuntimeException("Unknown unique field type");
+ throw new RuntimeException( "Unknown unique field type" );
}
}
+
/**
* Get the singleton serializer
*/
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/150897d6/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 a9e087b..419d0f0 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
@@ -324,8 +324,8 @@ public class MvccEntitySerializationStrategyImpl implements MvccEntitySerializat
public EntitySerializer() {
try {
mapper = new ObjectMapper( f );
- mapper.enable(SerializationFeature.INDENT_OUTPUT);
- mapper.enableDefaultTypingAsProperty(ObjectMapper.DefaultTyping.JAVA_LANG_OBJECT, "@class");
+// mapper.enable(SerializationFeature.INDENT_OUTPUT); don't indent output, causes slowness
+ mapper.enableDefaultTypingAsProperty(ObjectMapper.DefaultTyping.JAVA_LANG_OBJECT, "@class");
} catch ( Exception e ) {
throw new RuntimeException("Error setting up mapper", e);
}
@@ -340,6 +340,7 @@ public class MvccEntitySerializationStrategyImpl implements MvccEntitySerializat
CompositeBuilder builder = Composites.newCompositeBuilder();
builder.addBytes( VERSION );
+
//mark this version as empty
if ( !wrapper.entity.isPresent() ) {
//we're empty
@@ -362,7 +363,7 @@ public class MvccEntitySerializationStrategyImpl implements MvccEntitySerializat
builder.addBytes( mapper.writeValueAsBytes( wrapper.entity.get() ) );
}
catch ( Exception e ) {
- throw new RuntimeException(e.getMessage());
+ throw new RuntimeException("Unable to serialize entity", e);
}
return builder.build();
@@ -397,7 +398,7 @@ public class MvccEntitySerializationStrategyImpl implements MvccEntitySerializat
storedEntity = mapper.readValue( array, start, length, Entity.class );
}
catch ( Exception e ) {
- throw new RuntimeException(e.getMessage());
+ throw new RuntimeException("Unable to read entity data", e);
}
final Optional<Entity> entity = Optional.of( storedEntity);
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/150897d6/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyTest.java
index ba89503..1dc2f32 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyTest.java
@@ -35,6 +35,8 @@ import org.apache.usergrid.persistence.model.entity.Entity;
import com.google.inject.Inject;
import com.netflix.astyanax.Keyspace;
+import com.netflix.astyanax.MutationBatch;
+import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
import static org.apache.usergrid.persistence.collection.mvcc.stage.TestEntityGenerator.fromEntity;
import static org.apache.usergrid.persistence.collection.mvcc.stage.TestEntityGenerator.generateEntity;
@@ -42,6 +44,7 @@ import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
@RunWith( ITRunner.class )
@@ -65,9 +68,12 @@ public class WriteUniqueVerifyTest {
@Test
- public void testNoFields() {
+ public void testNoFields() throws ConnectionException {
final CollectionScope collectionScope = mock( CollectionScope.class );
final Keyspace keyspace = mock(Keyspace.class);
+ final MutationBatch batch = mock(MutationBatch.class);
+
+ when(keyspace.prepareMutationBatch()).thenReturn(batch);
// set up the mock to return the entity from the start phase
final Entity entity = generateEntity();
@@ -82,7 +88,7 @@ public class WriteUniqueVerifyTest {
//if we get here, it's a success. We want to test no exceptions are thrown
- verify(keyspace, never()).prepareMutationBatch();
+ verify(batch, never()).execute();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/150897d6/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/AbstractField.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/AbstractField.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/AbstractField.java
index 0283277..ad5c764 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/AbstractField.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/AbstractField.java
@@ -20,12 +20,14 @@ package org.apache.usergrid.persistence.model.field;
import org.apache.usergrid.persistence.model.field.value.EntityObject;
+import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
/**
* Base class for data information
*/
@JsonTypeInfo( use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY, property="@class" )
+
public abstract class AbstractField<T> implements Field<T> {
/**
@@ -108,4 +110,6 @@ public abstract class AbstractField<T> implements Field<T> {
public int hashCode() {
return name.hashCode();
}
+
+
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/150897d6/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/ArrayField.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/ArrayField.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/ArrayField.java
index 452eb49..0e7bc4a 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/ArrayField.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/ArrayField.java
@@ -46,4 +46,7 @@ public class ArrayField<T> extends ListField<T> {
public void add( T listItem ) {
value.add( listItem );
}
+
+
+
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/150897d6/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/BooleanField.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/BooleanField.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/BooleanField.java
index fed011d..7965855 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/BooleanField.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/BooleanField.java
@@ -32,4 +32,10 @@ public class BooleanField extends AbstractField<Boolean> {
public BooleanField() {
}
+
+
+ @Override
+ public FieldTypeName getTypeName() {
+ return FieldTypeName.BOOLEAN;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/150897d6/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/ByteArrayField.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/ByteArrayField.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/ByteArrayField.java
index ad850f6..2e116d7 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/ByteArrayField.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/ByteArrayField.java
@@ -43,4 +43,10 @@ public class ByteArrayField extends AbstractField<byte[]> {
public Class getClassinfo() {
return classinfo;
}
+
+
+ @Override
+ public FieldTypeName getTypeName() {
+ return FieldTypeName.BYTE_ARRAY;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/150897d6/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/DoubleField.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/DoubleField.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/DoubleField.java
index 2f358bd..ccbc3e2 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/DoubleField.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/DoubleField.java
@@ -32,4 +32,10 @@ public class DoubleField extends AbstractField<Double> {
public DoubleField() {
}
+
+
+ @Override
+ public FieldTypeName getTypeName() {
+ return FieldTypeName.DOUBLE;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/150897d6/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/EntityObjectField.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/EntityObjectField.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/EntityObjectField.java
index 7739291..ace9841 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/EntityObjectField.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/EntityObjectField.java
@@ -32,4 +32,10 @@ public class EntityObjectField extends AbstractField<EntityObject> {
public EntityObjectField() {
}
+
+
+ @Override
+ public FieldTypeName getTypeName() {
+ return FieldTypeName.OBJECT;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/150897d6/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/Field.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/Field.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/Field.java
index 9da0d4e..c0a111f 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/Field.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/Field.java
@@ -20,6 +20,7 @@ package org.apache.usergrid.persistence.model.field;
import java.io.Serializable;
+import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
@@ -52,4 +53,11 @@ public interface Field<T> extends Serializable {
*/
public boolean isUnique();
+ /**
+ * Get the type of the field as a string. string, boolean, long, integer etc
+ * @return
+ */
+ @JsonIgnore
+ public FieldTypeName getTypeName();
+
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/150897d6/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/FieldTypeName.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/FieldTypeName.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/FieldTypeName.java
new file mode 100644
index 0000000..7bba4c9
--- /dev/null
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/FieldTypeName.java
@@ -0,0 +1,42 @@
+package org.apache.usergrid.persistence.model.field;/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+
+
+/**
+ * Enum of all field types. DO NOT change these names, they're used in persistence, and will result in
+ * unique checks failing
+ */
+public enum FieldTypeName {
+ ARRAY,
+ BOOLEAN,
+ BYTE_ARRAY,
+ DOUBLE,
+ OBJECT,
+ FLOAT,
+ INTEGER,
+ LIST,
+ LOCATION,
+ LONG,
+ SET,
+ STRING,
+ UUID
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/150897d6/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/FloatField.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/FloatField.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/FloatField.java
index 71729b3..28c6f36 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/FloatField.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/FloatField.java
@@ -32,4 +32,10 @@ public class FloatField extends AbstractField<Float> {
public FloatField() {
}
+
+
+ @Override
+ public FieldTypeName getTypeName() {
+ return FieldTypeName.FLOAT;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/150897d6/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/IntegerField.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/IntegerField.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/IntegerField.java
index 6412b35..3eb0330 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/IntegerField.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/IntegerField.java
@@ -32,4 +32,10 @@ public class IntegerField extends AbstractField<Integer> {
public IntegerField() {
}
+
+
+ @Override
+ public FieldTypeName getTypeName() {
+ return FieldTypeName.INTEGER;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/150897d6/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/ListField.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/ListField.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/ListField.java
index abd7d8a..b746dc4 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/ListField.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/ListField.java
@@ -48,4 +48,11 @@ public class ListField<T> extends AbstractField<List<T>> {
public void add( T listItem ) {
value.add( listItem );
}
+
+
+ @Override
+ public FieldTypeName getTypeName() {
+ return FieldTypeName.LIST;
+
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/150897d6/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/LocationField.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/LocationField.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/LocationField.java
index 29e3169..e220099 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/LocationField.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/LocationField.java
@@ -35,4 +35,10 @@ public class LocationField extends AbstractField<Location> {
public LocationField() {
}
+
+
+ @Override
+ public FieldTypeName getTypeName() {
+ return FieldTypeName.LOCATION;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/150897d6/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/LongField.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/LongField.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/LongField.java
index faa45a4..d4b6297 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/LongField.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/LongField.java
@@ -35,4 +35,10 @@ public class LongField extends AbstractField<Long> {
public LongField() {
}
+
+ @Override
+ public FieldTypeName getTypeName() {
+ return FieldTypeName.LONG;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/150897d6/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/SetField.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/SetField.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/SetField.java
index f93c9db..47a9c7c 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/SetField.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/SetField.java
@@ -47,4 +47,10 @@ public class SetField<T> extends AbstractField<Set<T>> {
public void addEntry( T setItem ) {
value.add( setItem );
}
+
+
+ @Override
+ public FieldTypeName getTypeName() {
+ return FieldTypeName.SET;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/150897d6/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/StringField.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/StringField.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/StringField.java
index 1bc94da..a3a9339 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/StringField.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/StringField.java
@@ -32,4 +32,10 @@ public class StringField extends AbstractField<String> {
public StringField() {
}
+
+
+ @Override
+ public FieldTypeName getTypeName() {
+ return FieldTypeName.STRING;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/150897d6/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/UUIDField.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/UUIDField.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/UUIDField.java
index 19602d2..4c67447 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/UUIDField.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/UUIDField.java
@@ -34,4 +34,10 @@ public class UUIDField extends AbstractField<UUID> {
public UUIDField() {
}
+
+
+ @Override
+ public FieldTypeName getTypeName() {
+ return FieldTypeName.UUID;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/150897d6/stack/corepersistence/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/pom.xml b/stack/corepersistence/pom.xml
index 7482271..fac5db9 100644
--- a/stack/corepersistence/pom.xml
+++ b/stack/corepersistence/pom.xml
@@ -65,8 +65,8 @@ limitations under the License.
<guice.version>3.0</guice.version>
<guicyfig.version>3.2</guicyfig.version>
<hystrix.version>1.3.16</hystrix.version>
- <jackson-2-version>2.3.1</jackson-2-version>
- <jackson-smile.verson>1.9.9</jackson-smile.verson>
+ <jackson-2-version>2.4.1</jackson-2-version>
+ <jackson-smile.verson>2.4.3</jackson-smile.verson>
<jukito.version>1.4-UG</jukito.version>
<junit.version>4.11</junit.version>
<kryo-serializers.version>0.26</kryo-serializers.version>
[7/9] git commit: Merge branch 'two-dot-o' of
https://git-wip-us.apache.org/repos/asf/incubator-usergrid into two-dot-o
Posted by to...@apache.org.
Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into two-dot-o
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/5070da9c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/5070da9c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/5070da9c
Branch: refs/heads/two-dot-o
Commit: 5070da9c8e1e2aebf1ba31fc381c4682befd53e4
Parents: 2828e91 66c377d
Author: Todd Nine <to...@apache.org>
Authored: Wed Oct 8 09:09:48 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Wed Oct 8 09:09:48 2014 -0600
----------------------------------------------------------------------
.../CpEntityIndexDeleteListener.java | 23 +-
.../corepersistence/CpEntityManager.java | 45 +++-
.../corepersistence/CpEntityManagerFactory.java | 5 +-
.../corepersistence/CpManagerCache.java | 29 ++-
.../usergrid/corepersistence/GuiceModule.java | 12 +-
.../persistence/entities/Notification.java | 13 ++
.../collection/EntityCollectionManagerIT.java | 32 ++-
.../core/util/AvailablePortFinder.java | 188 -----------------
.../usergrid/persistence/map/MapManager.java | 1 -
.../persistence/map/MapManagerFactory.java | 2 +-
.../persistence/map/impl/MapManagerImpl.java | 24 ---
.../persistence/map/impl/MapScopeImpl.java | 1 -
.../map/impl/MapSerializationImpl.java | 48 +++--
.../persistence/map/MapManagerTest.java | 21 +-
.../index/impl/EsEntityIndexImpl.java | 208 ++++++++++---------
.../persistence/queue/QueueManager.java | 4 +-
.../queue/impl/SQSQueueManagerImpl.java | 70 ++++---
.../persistence/queue/QueueManagerTest.java | 25 +++
.../notifications/ApplicationQueueManager.java | 33 ++-
.../notifications/NotificationsService.java | 3 +-
.../services/notifications/QueueListener.java | 22 +-
.../services/notifications/TaskManager.java | 52 +++--
.../usergrid/services/TestQueueManager.java | 67 ++++++
.../AbstractServiceNotificationIT.java | 1 -
.../apns/NotificationsServiceIT.java | 21 +-
.../gcm/NotificationsServiceIT.java | 17 +-
.../java/org/apache/usergrid/tools/ApiDoc.java | 5 +-
27 files changed, 508 insertions(+), 464 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5070da9c/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
----------------------------------------------------------------------
[6/9] git commit: Fixes rolling version bug when merge occurs.
Posted by to...@apache.org.
Fixes rolling version bug when merge occurs.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/2828e911
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/2828e911
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/2828e911
Branch: refs/heads/two-dot-o
Commit: 2828e911e5888e5a2f26ff412c3182c22cbf09c2
Parents: 792b2b2
Author: Todd Nine <to...@apache.org>
Authored: Tue Oct 7 19:32:44 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Tue Oct 7 19:32:44 2014 -0600
----------------------------------------------------------------------
.../impl/EntityCollectionManagerImpl.java | 7 -----
.../mvcc/stage/write/WriteCommit.java | 2 ++
.../collection/mvcc/stage/write/WriteStart.java | 4 +--
.../persistence/collection/util/RepairUtil.java | 33 ++++++++++----------
.../collection/EntityCollectionManagerIT.java | 15 +++++++++
5 files changed, 35 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2828e911/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
index 6299acb..b2b07e9 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
@@ -19,16 +19,11 @@
package org.apache.usergrid.persistence.collection.impl;
-import java.util.List;
-import java.util.UUID;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.usergrid.persistence.collection.CollectionScope;
import org.apache.usergrid.persistence.collection.EntityCollectionManager;
-import org.apache.usergrid.persistence.collection.event.EntityVersionCreated;
-import org.apache.usergrid.persistence.collection.event.EntityVersionDeleted;
import org.apache.usergrid.persistence.collection.guice.CollectionTaskExecutor;
import org.apache.usergrid.persistence.collection.guice.Write;
import org.apache.usergrid.persistence.collection.guice.WriteUpdate;
@@ -44,7 +39,6 @@ import org.apache.usergrid.persistence.collection.mvcc.stage.write.WriteOptimist
import org.apache.usergrid.persistence.collection.mvcc.stage.write.WriteStart;
import org.apache.usergrid.persistence.collection.mvcc.stage.write.WriteUniqueVerify;
import org.apache.usergrid.persistence.collection.service.UUIDService;
-import org.apache.usergrid.persistence.core.task.Task;
import org.apache.usergrid.persistence.core.task.TaskExecutor;
import org.apache.usergrid.persistence.core.util.ValidationUtils;
import org.apache.usergrid.persistence.model.entity.Entity;
@@ -65,7 +59,6 @@ import rx.schedulers.Schedulers;
*
* TODO: maybe refactor the stage operations into their own classes for clarity and organization?
*
- * @author tnine
*/
public class EntityCollectionManagerImpl implements EntityCollectionManager {
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2828e911/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommit.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommit.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommit.java
index 584d7f1..82ef74c 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommit.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommit.java
@@ -93,6 +93,7 @@ public class WriteCommit implements Func1<CollectionIoEvent<MvccEntity>, Entity>
final UUID version = mvccEntity.getVersion();
final CollectionScope collectionScope = ioEvent.getEntityCollection();
+ //set the version into the entity
EntityUtils.setVersion( mvccEntity.getEntity().get(), version );
MvccValidationUtils.verifyMvccEntityWithEntity( ioEvent.getEvent() );
@@ -135,6 +136,7 @@ public class WriteCommit implements Func1<CollectionIoEvent<MvccEntity>, Entity>
"Failed to execute write asynchronously ", e );
}
+
return mvccEntity.getEntity().get();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2828e911/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteStart.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteStart.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteStart.java
index 20fad0e..e2bad71 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteStart.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteStart.java
@@ -87,9 +87,7 @@ public class WriteStart implements Func1<CollectionIoEvent<Entity>, CollectionIo
}
- EntityUtils.setVersion(entity, version);
-
- //create the mvcc entity for the next stage
+ //create the mvcc entity for the next stage
//todo, we need to create a complete or partial update here (or sooner)
return new CollectionIoEvent<MvccEntity>( collectionScope, nextStage );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2828e911/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/util/RepairUtil.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/util/RepairUtil.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/util/RepairUtil.java
index 8268d22..aac5794 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/util/RepairUtil.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/util/RepairUtil.java
@@ -39,28 +39,29 @@ public class RepairUtil {
return null;
}
- MvccEntity mvccEntity = results.next();
+ final MvccEntity partialEntity = results.next();
List<MvccEntity> partialEntities = new ArrayList<>();
//this entity has been marked as cleared.(deleted)
//The version exists, but does not have entity data
- if ( !mvccEntity.getEntity().isPresent() && ( mvccEntity.getStatus() == MvccEntity.Status.DELETED
- || mvccEntity.getStatus() == MvccEntity.Status.COMPLETE ) ) {
+ if ( !partialEntity.getEntity().isPresent() && ( partialEntity.getStatus() == MvccEntity.Status.DELETED
+ || partialEntity.getStatus() == MvccEntity.Status.COMPLETE ) ) {
return null;
}
- if ( mvccEntity.getStatus() == MvccEntity.Status.COMPLETE ) {
- return mvccEntity;
+ if ( partialEntity.getStatus() == MvccEntity.Status.COMPLETE ) {
+ return partialEntity;
}
- partialEntities.add( mvccEntity );
+
+ partialEntities.add( partialEntity );
while ( results.hasNext() ) {
- mvccEntity = results.next();
- partialEntities.add( mvccEntity );
+ final MvccEntity previousEntity = results.next();
+ partialEntities.add( previousEntity );
- if ( mvccEntity.getStatus() != MvccEntity.Status.PARTIAL ) {
- return repairAndWrite( partialEntities, mvccEntity, entitySerializationStrategy, collectionScope );
+ if ( previousEntity.getStatus() != MvccEntity.Status.PARTIAL ) {
+ return repairAndWrite( partialEntities, partialEntity, entitySerializationStrategy, collectionScope );
}
}
return null;
@@ -70,28 +71,28 @@ public class RepairUtil {
/**
* Repairs the entity then overwrites the previous entity to become the new completed entity.
* @param partialEntities
- * @param mvccEntity
+ * @param targetEntity The entity that should ultimately contain all merged data
* @param entitySerializationStrategy
* @param collectionScope
* @return
*/
- private static MvccEntity repairAndWrite( List<MvccEntity> partialEntities, MvccEntity mvccEntity,
+ private static MvccEntity repairAndWrite( List<MvccEntity> partialEntities, MvccEntity targetEntity,
MvccEntitySerializationStrategy entitySerializationStrategy,
CollectionScope collectionScope ) {
Collections.reverse( partialEntities );
//repair
- mvccEntity = entityRepair( changeLogGenerator.getChangeLog( partialEntities.iterator(),
- partialEntities.get( partialEntities.size() - 1 ).getVersion() ), partialEntities, mvccEntity
+ final MvccEntity mergedEntity = entityRepair( changeLogGenerator.getChangeLog( partialEntities.iterator(),
+ partialEntities.get( partialEntities.size() - 1 ).getVersion() ), partialEntities, targetEntity
);
try {
- entitySerializationStrategy.write( collectionScope, mvccEntity ).execute();
+ entitySerializationStrategy.write( collectionScope, mergedEntity ).execute();
}
catch ( Exception e ) {
throw new RuntimeException( "Couldn't rewrite repaired entity", e );
}
- return mvccEntity;
+ return mergedEntity;
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2828e911/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
index 7a725a9..527099f 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
@@ -36,6 +36,7 @@ import org.apache.usergrid.persistence.model.entity.SimpleId;
import org.apache.usergrid.persistence.model.field.IntegerField;
import org.apache.usergrid.persistence.model.field.StringField;
+import com.fasterxml.uuid.UUIDComparator;
import com.google.inject.Inject;
import rx.Observable;
@@ -283,6 +284,10 @@ public class EntityCollectionManagerIT {
assertNotNull( "Returned has a uuid", returned.getId() );
+ final UUID writeVersion = returned.getVersion();
+
+ assertNotNull("Write version was set", writeVersion);
+
/**
* Modify the oldEntity
*/
@@ -296,9 +301,19 @@ public class EntityCollectionManagerIT {
assertNotNull( "Returned has a uuid", returned.getId() );
assertEquals( oldEntity.getField( "testFud" ), returned.getField( "testFud" ) );
+ final UUID updatedVersion = updateReturned.getVersion();
+
+ assertNotNull("Updated version returned", updatedVersion);
+
+ assertTrue( "Updated version higher", UUIDComparator.staticCompare( updatedVersion, writeVersion ) > 0 );
+
Observable<Entity> newEntityObs = manager.load( updateReturned.getId() );
Entity newEntity = newEntityObs.toBlocking().last();
+ final UUID returnedVersion = newEntity.getVersion();
+
+ assertEquals("Loaded version matches updated version", updatedVersion, returnedVersion);
+
assertNotNull( "Returned has a uuid", returned.getId() );
assertEquals( addedField, newEntity.getField( "testFud" ));