git commit: PHOENIX-1188 Performance regression for non-aggregate queries

2014-08-21 Thread jamestaylor
Repository: phoenix
Updated Branches:
  refs/heads/4.0 e2922d43c - 1987fba12


PHOENIX-1188 Performance regression for non-aggregate queries

Conflicts:

phoenix-core/src/main/java/org/apache/phoenix/iterate/ChunkedResultIterator.java


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/1987fba1
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/1987fba1
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/1987fba1

Branch: refs/heads/4.0
Commit: 1987fba121dd693c5b26f364dc2081176f15bb38
Parents: e2922d4
Author: James Taylor jtay...@salesforce.com
Authored: Thu Aug 21 00:04:12 2014 -0700
Committer: James Taylor jtay...@salesforce.com
Committed: Thu Aug 21 00:44:08 2014 -0700

--
 .../phoenix/iterate/ChunkedResultIterator.java  | 85 +++-
 .../apache/phoenix/jdbc/PhoenixConnection.java  |  6 --
 .../phoenix/query/QueryServicesOptions.java |  9 ++-
 .../apache/phoenix/trace/TraceMetricSource.java |  4 +-
 4 files changed, 38 insertions(+), 66 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/1987fba1/phoenix-core/src/main/java/org/apache/phoenix/iterate/ChunkedResultIterator.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/iterate/ChunkedResultIterator.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/iterate/ChunkedResultIterator.java
index 3f6ed81..c702e99 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/iterate/ChunkedResultIterator.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/iterate/ChunkedResultIterator.java
@@ -23,15 +23,19 @@ import java.util.List;
 
 import org.apache.hadoop.hbase.client.Scan;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.compile.StatementContext;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.query.QueryServicesOptions;
 import org.apache.phoenix.schema.TableRef;
 import org.apache.phoenix.schema.tuple.Tuple;
+import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.ScanUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Preconditions;
+
 /**
  * {@code PeekingResultIterator} implementation that loads data in chunks. 
This is intended for
  * basic scan plans, to avoid loading large quantities of data from HBase in 
one go.
@@ -40,7 +44,7 @@ public class ChunkedResultIterator implements 
PeekingResultIterator {
 private static final Logger logger = 
LoggerFactory.getLogger(ChunkedResultIterator.class);
 
 private final ParallelIterators.ParallelIteratorFactory 
delegateIteratorFactory;
-private SingleChunkResultIterator singleChunkResultIterator;
+private ImmutableBytesWritable lastKey = new ImmutableBytesWritable();
 private final StatementContext context;
 private final TableRef tableRef;
 private Scan scan;
@@ -70,12 +74,19 @@ public class ChunkedResultIterator implements 
PeekingResultIterator {
 }
 
 public ChunkedResultIterator(ParallelIterators.ParallelIteratorFactory 
delegateIteratorFactory,
-StatementContext context, TableRef tableRef, Scan scan, long 
chunkSize) {
+StatementContext context, TableRef tableRef, Scan scan, long 
chunkSize) throws SQLException {
 this.delegateIteratorFactory = delegateIteratorFactory;
 this.context = context;
 this.tableRef = tableRef;
 this.scan = scan;
 this.chunkSize = chunkSize;
+// Instantiate single chunk iterator and the delegate iterator in 
constructor
+// to get parallel scans kicked off in separate threads. If we delay 
this,
+// we'll get serialized behavior (see PHOENIX-
+if (logger.isDebugEnabled()) logger.debug(Get first chunked result 
iterator over  + tableRef.getTable().getName().getString() +  with  + scan);
+ResultIterator singleChunkResultIterator = new 
SingleChunkResultIterator(
+new TableResultIterator(context, tableRef, scan), chunkSize);
+resultIterator = delegateIteratorFactory.newIterator(context, 
singleChunkResultIterator, scan);
 }
 
 @Override
@@ -95,26 +106,16 @@ public class ChunkedResultIterator implements 
PeekingResultIterator {
 
 @Override
 public void close() throws SQLException {
-if (resultIterator != null) {
-resultIterator.close();
-}
-if (singleChunkResultIterator != null) {
-singleChunkResultIterator.close();
-}
+resultIterator.close();
 }
 
 private PeekingResultIterator getResultIterator() throws SQLException {
-if (resultIterator == null) {
-if (logger.isDebugEnabled()) 

git commit: PHOENIX-1188 Performance regression for non-aggregate queries

2014-08-21 Thread jamestaylor
Repository: phoenix
Updated Branches:
  refs/heads/master 52b0e0050 - 29a7be42b


PHOENIX-1188 Performance regression for non-aggregate queries

Conflicts:

phoenix-core/src/main/java/org/apache/phoenix/iterate/ChunkedResultIterator.java


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/29a7be42
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/29a7be42
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/29a7be42

Branch: refs/heads/master
Commit: 29a7be42bfa468b12d16fd0756b987f5359c45c4
Parents: 52b0e00
Author: James Taylor jtay...@salesforce.com
Authored: Thu Aug 21 00:04:12 2014 -0700
Committer: James Taylor jtay...@salesforce.com
Committed: Thu Aug 21 00:45:27 2014 -0700

--
 .../phoenix/iterate/ChunkedResultIterator.java  | 85 +++-
 .../apache/phoenix/jdbc/PhoenixConnection.java  |  6 --
 .../phoenix/query/QueryServicesOptions.java |  9 ++-
 .../apache/phoenix/trace/TraceMetricSource.java |  4 +-
 4 files changed, 38 insertions(+), 66 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/29a7be42/phoenix-core/src/main/java/org/apache/phoenix/iterate/ChunkedResultIterator.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/iterate/ChunkedResultIterator.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/iterate/ChunkedResultIterator.java
index 3f6ed81..c702e99 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/iterate/ChunkedResultIterator.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/iterate/ChunkedResultIterator.java
@@ -23,15 +23,19 @@ import java.util.List;
 
 import org.apache.hadoop.hbase.client.Scan;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.compile.StatementContext;
 import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.query.QueryServicesOptions;
 import org.apache.phoenix.schema.TableRef;
 import org.apache.phoenix.schema.tuple.Tuple;
+import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.ScanUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Preconditions;
+
 /**
  * {@code PeekingResultIterator} implementation that loads data in chunks. 
This is intended for
  * basic scan plans, to avoid loading large quantities of data from HBase in 
one go.
@@ -40,7 +44,7 @@ public class ChunkedResultIterator implements 
PeekingResultIterator {
 private static final Logger logger = 
LoggerFactory.getLogger(ChunkedResultIterator.class);
 
 private final ParallelIterators.ParallelIteratorFactory 
delegateIteratorFactory;
-private SingleChunkResultIterator singleChunkResultIterator;
+private ImmutableBytesWritable lastKey = new ImmutableBytesWritable();
 private final StatementContext context;
 private final TableRef tableRef;
 private Scan scan;
@@ -70,12 +74,19 @@ public class ChunkedResultIterator implements 
PeekingResultIterator {
 }
 
 public ChunkedResultIterator(ParallelIterators.ParallelIteratorFactory 
delegateIteratorFactory,
-StatementContext context, TableRef tableRef, Scan scan, long 
chunkSize) {
+StatementContext context, TableRef tableRef, Scan scan, long 
chunkSize) throws SQLException {
 this.delegateIteratorFactory = delegateIteratorFactory;
 this.context = context;
 this.tableRef = tableRef;
 this.scan = scan;
 this.chunkSize = chunkSize;
+// Instantiate single chunk iterator and the delegate iterator in 
constructor
+// to get parallel scans kicked off in separate threads. If we delay 
this,
+// we'll get serialized behavior (see PHOENIX-
+if (logger.isDebugEnabled()) logger.debug(Get first chunked result 
iterator over  + tableRef.getTable().getName().getString() +  with  + scan);
+ResultIterator singleChunkResultIterator = new 
SingleChunkResultIterator(
+new TableResultIterator(context, tableRef, scan), chunkSize);
+resultIterator = delegateIteratorFactory.newIterator(context, 
singleChunkResultIterator, scan);
 }
 
 @Override
@@ -95,26 +106,16 @@ public class ChunkedResultIterator implements 
PeekingResultIterator {
 
 @Override
 public void close() throws SQLException {
-if (resultIterator != null) {
-resultIterator.close();
-}
-if (singleChunkResultIterator != null) {
-singleChunkResultIterator.close();
-}
+resultIterator.close();
 }
 
 private PeekingResultIterator getResultIterator() throws SQLException {
-if (resultIterator == null) {
-if (logger.isDebugEnabled())