You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/10/01 16:52:07 UTC
[31/35] git commit: Added additional logging and a short circuit test
Added additional logging and a short circuit 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/87c51ae5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/87c51ae5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/87c51ae5
Branch: refs/heads/two-dot-o-rebuildable-index
Commit: 87c51ae581aa5f676af0e2f2dcbd876cf8a16da1
Parents: 9ce8346
Author: Todd Nine <to...@apache.org>
Authored: Tue Sep 30 14:03:12 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Tue Sep 30 14:03:12 2014 -0600
----------------------------------------------------------------------
.../mq/cassandra/io/AbstractSearch.java | 42 +++++++++++++++-----
1 file changed, 32 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/87c51ae5/stack/core/src/main/java/org/apache/usergrid/mq/cassandra/io/AbstractSearch.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/mq/cassandra/io/AbstractSearch.java b/stack/core/src/main/java/org/apache/usergrid/mq/cassandra/io/AbstractSearch.java
index b0b5ac7..ffda843 100644
--- a/stack/core/src/main/java/org/apache/usergrid/mq/cassandra/io/AbstractSearch.java
+++ b/stack/core/src/main/java/org/apache/usergrid/mq/cassandra/io/AbstractSearch.java
@@ -37,6 +37,8 @@ import org.apache.usergrid.persistence.exceptions.QueueException;
import org.apache.usergrid.persistence.hector.CountingMutator;
import org.apache.usergrid.utils.UUIDUtils;
+import com.fasterxml.uuid.UUIDComparator;
+
import me.prettyprint.hector.api.Keyspace;
import me.prettyprint.hector.api.beans.ColumnSlice;
import me.prettyprint.hector.api.beans.HColumn;
@@ -63,6 +65,7 @@ import static org.apache.usergrid.persistence.cassandra.Serializers.be;
import static org.apache.usergrid.persistence.cassandra.Serializers.se;
import static org.apache.usergrid.persistence.cassandra.Serializers.ue;
import static org.apache.usergrid.utils.NumberUtils.roundLong;
+import static org.apache.usergrid.utils.UUIDUtils.compare;
import static org.apache.usergrid.utils.UUIDUtils.getTimestampInMillis;
@@ -181,25 +184,26 @@ public abstract class AbstractSearch implements QueueSearch {
current_ts_shard = finish_ts_shard;
}
+ final MessageIdComparator comparator = new MessageIdComparator(params.reversed);
+
//should be start < finish
- if ( !params.reversed && UUIDUtils.compare( start, finish_uuid ) > 0 ) {
+ if ( comparator.compare( start, finish_uuid ) > 0 ) {
logger.warn( "Tried to perform a slice with start UUID {} after finish UUID {}.", start, finish_uuid );
- throw new IllegalArgumentException( String.format("You cannot specify a start value of %s after finish value of %s", start, finish_uuid) );
+ throw new IllegalArgumentException(
+ String.format( "You cannot specify a start value of %s after finish value of %s", start,
+ finish_uuid ) );
}
- // should be finish < start
- else if ( params.reversed && UUIDUtils.compare( start, finish_uuid ) < 0 ) {
- logger.warn( "Tried to perform a slice with start UUID {} after finish UUID {}.", start, finish_uuid );
- throw new IllegalArgumentException( String.format("You cannot specify a start value of %s after finish value of %s", start, finish_uuid) );
- }
UUID lastValue = start;
boolean firstPage = true;
- while ( ( current_ts_shard >= start_ts_shard ) && ( current_ts_shard <= finish_ts_shard ) ) {
+ while ( ( current_ts_shard >= start_ts_shard ) && ( current_ts_shard <= finish_ts_shard ) && comparator.compare(start, finish_uuid) < 1 ) {
+
+ logger.info( "Starting search with start UUID {}, finish UUID {}, and reversed {}", new Object[]{lastValue, finish_uuid, params.reversed });
SliceQuery<ByteBuffer, UUID, ByteBuffer> q = createSliceQuery( ko, be, ue, be );
@@ -215,8 +219,8 @@ public abstract class AbstractSearch implements QueueSearch {
final UUID columnName = column.getName();
// skip the first one, we've already read it
- if ( i == 0 && (firstPage && params.skipFirst && params.startId.equals( columnName ))
- || (!firstPage && lastValue != null && lastValue.equals(columnName)) ) {
+ if ( i == 0 && ( firstPage && params.skipFirst && params.startId.equals( columnName ) ) || ( !firstPage
+ && lastValue != null && lastValue.equals( columnName ) ) ) {
continue;
}
@@ -333,4 +337,22 @@ public abstract class AbstractSearch implements QueueSearch {
return o1Idx - o2Idx;
}
}
+
+
+ private static final class MessageIdComparator implements Comparator<UUID> {
+
+ private final int comparator;
+
+
+ private MessageIdComparator( final boolean reversed ) {
+
+ this.comparator = reversed ? -1 : 1;
+ }
+
+
+ @Override
+ public int compare( final UUID o1, final UUID o2 ) {
+ return UUIDUtils.compare( o1, o2 )*comparator;
+ }
+ }
}