You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by je...@apache.org on 2014/03/10 07:20:48 UTC
[31/50] merge master to 4.0 branch
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/b3a330ca/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/filter/ColumnTrackingNextLargestTimestampFilter.java
----------------------------------------------------------------------
diff --cc phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/filter/ColumnTrackingNextLargestTimestampFilter.java
index 0000000,2ad04ff..8febc5e
mode 000000,100644..100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/filter/ColumnTrackingNextLargestTimestampFilter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/filter/ColumnTrackingNextLargestTimestampFilter.java
@@@ -1,0 -1,72 +1,60 @@@
+ /*
+ * 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.phoenix.hbase.index.covered.filter;
+
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-
++import org.apache.hadoop.hbase.Cell;
+ import org.apache.hadoop.hbase.KeyValue;
+ import org.apache.hadoop.hbase.filter.FilterBase;
+
+ import org.apache.phoenix.hbase.index.covered.update.ColumnTracker;
+
+ /**
+ * Similar to the {@link MaxTimestampFilter}, but also updates the 'next largest' timestamp seen
+ * that is not skipped by the below criteria. Note that it isn't as quick as the
+ * {@link MaxTimestampFilter} as we can't just seek ahead to a key with the matching timestamp, but
+ * have to iterate each kv until we find the right one with an allowed timestamp.
+ * <p>
+ * Inclusively filter on the maximum timestamp allowed. Excludes all elements greater than (but not
+ * equal to) the given timestamp, so given ts = 5, a {@link KeyValue} with ts 6 is excluded, but not
+ * one with ts = 5.
+ * <p>
+ * This filter generally doesn't make sense on its own - it should follow a per-column filter and
+ * possible a per-delete filter to only track the most recent (but not exposed to the user)
+ * timestamp.
+ */
+ public class ColumnTrackingNextLargestTimestampFilter extends FilterBase {
+
+ private long ts;
+ private ColumnTracker column;
+
+ public ColumnTrackingNextLargestTimestampFilter(long maxTime, ColumnTracker toTrack) {
+ this.ts = maxTime;
+ this.column = toTrack;
+ }
+
+ @Override
- public ReturnCode filterKeyValue(KeyValue v) {
++ public ReturnCode filterKeyValue(Cell v) {
+ long timestamp = v.getTimestamp();
+ if (timestamp > ts) {
+ this.column.setTs(timestamp);
+ return ReturnCode.SKIP;
+ }
+ return ReturnCode.INCLUDE;
+ }
+
- @Override
- public void write(DataOutput out) throws IOException {
- throw new UnsupportedOperationException("Server-side only filter, cannot be serialized!");
- }
-
- @Override
- public void readFields(DataInput in) throws IOException {
- throw new UnsupportedOperationException("Server-side only filter, cannot be deserialized!");
- }
+ }
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/b3a330ca/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/filter/FamilyOnlyFilter.java
----------------------------------------------------------------------
diff --cc phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/filter/FamilyOnlyFilter.java
index 0000000,080bf92..68555ef
mode 000000,100644..100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/filter/FamilyOnlyFilter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/filter/FamilyOnlyFilter.java
@@@ -1,0 -1,80 +1,80 @@@
+ /**
+ * 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.phoenix.hbase.index.covered.filter;
+
-import org.apache.hadoop.hbase.KeyValue;
++import org.apache.hadoop.hbase.Cell;
+ import org.apache.hadoop.hbase.filter.BinaryComparator;
++import org.apache.hadoop.hbase.filter.ByteArrayComparable;
+ import org.apache.hadoop.hbase.filter.FamilyFilter;
-import org.apache.hadoop.hbase.filter.WritableByteArrayComparable;
+
+ /**
+ * Similar to the {@link FamilyFilter} but stops when the end of the family is reached and only
+ * supports equality
+ */
+ public class FamilyOnlyFilter extends FamilyFilter {
+
+ boolean done = false;
+ private boolean previousMatchFound;
+
+ /**
+ * Filter on exact binary matches to the passed family
+ * @param family to compare against
+ */
+ public FamilyOnlyFilter(final byte[] family) {
+ this(new BinaryComparator(family));
+ }
+
- public FamilyOnlyFilter(final WritableByteArrayComparable familyComparator) {
++ public FamilyOnlyFilter(final ByteArrayComparable familyComparator) {
+ super(CompareOp.EQUAL, familyComparator);
+ }
+
+
+ @Override
+ public boolean filterAllRemaining() {
+ return done;
+ }
+
+ @Override
+ public void reset() {
+ done = false;
+ previousMatchFound = false;
+ }
+
+ @Override
- public ReturnCode filterKeyValue(KeyValue v) {
++ public ReturnCode filterKeyValue(Cell v) {
+ if (done) {
+ return ReturnCode.SKIP;
+ }
+ ReturnCode code = super.filterKeyValue(v);
+ if (previousMatchFound) {
+ // we found a match before, and now we are skipping the key because of the family, therefore
+ // we are done (no more of the family).
+ if (code.equals(ReturnCode.SKIP)) {
+ done = true;
+ }
+ } else {
+ // if we haven't seen a match before, then it doesn't matter what we see now, except to mark
+ // if we've seen a match
+ if (code.equals(ReturnCode.INCLUDE)) {
+ previousMatchFound = true;
+ }
+ }
+ return code;
+ }
+
+ }
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/b3a330ca/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/filter/MaxTimestampFilter.java
----------------------------------------------------------------------
diff --cc phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/filter/MaxTimestampFilter.java
index 0000000,e8e6347..4a3a540
mode 000000,100644..100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/filter/MaxTimestampFilter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/filter/MaxTimestampFilter.java
@@@ -1,0 -1,74 +1,70 @@@
+ /*
+ * 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.phoenix.hbase.index.covered.filter;
+
+ import java.io.DataInput;
+ import java.io.DataOutput;
+ import java.io.IOException;
+
++import org.apache.hadoop.hbase.Cell;
+ import org.apache.hadoop.hbase.KeyValue;
+ import org.apache.hadoop.hbase.filter.FilterBase;
+ import org.apache.hadoop.hbase.util.Bytes;
+
+ /**
+ * Inclusive filter on the maximum timestamp allowed. Excludes all elements greater than (but not
+ * equal to) the given timestamp, so given ts = 5, a {@link KeyValue} with ts 6 is excluded, but not
+ * one with ts = 5.
+ */
+ public class MaxTimestampFilter extends FilterBase {
+
+ private long ts;
+
+ public MaxTimestampFilter(long maxTime) {
+ this.ts = maxTime;
+ }
+
+ @Override
+ public KeyValue getNextKeyHint(KeyValue currentKV) {
+ // this might be a little excessive right now - better safe than sorry though, so we don't mess
+ // with other filters too much.
- KeyValue kv = currentKV.deepCopy();
++ KeyValue kv = null;
++ try {
++ kv = currentKV.clone();
++ } catch (CloneNotSupportedException e) {
++ // the exception should not happen at all
++ throw new IllegalArgumentException(e);
++ }
+ int offset =kv.getTimestampOffset();
+ //set the timestamp in the buffer
+ byte[] buffer = kv.getBuffer();
+ byte[] ts = Bytes.toBytes(this.ts);
+ System.arraycopy(ts, 0, buffer, offset, ts.length);
+
+ return kv;
+ }
+
+ @Override
- public ReturnCode filterKeyValue(KeyValue v) {
++ public ReturnCode filterKeyValue(Cell v) {
+ long timestamp = v.getTimestamp();
+ if (timestamp > ts) {
+ return ReturnCode.SEEK_NEXT_USING_HINT;
+ }
+ return ReturnCode.INCLUDE;
+ }
-
- @Override
- public void write(DataOutput out) throws IOException {
- throw new UnsupportedOperationException("Server-side only filter, cannot be serialized!");
-
- }
-
- @Override
- public void readFields(DataInput in) throws IOException {
- throw new UnsupportedOperationException("Server-side only filter, cannot be deserialized!");
- }
+ }
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/b3a330ca/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/filter/NewerTimestampFilter.java
----------------------------------------------------------------------
diff --cc phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/filter/NewerTimestampFilter.java
index 0000000,7209ee2..1ed3e48
mode 000000,100644..100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/filter/NewerTimestampFilter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/filter/NewerTimestampFilter.java
@@@ -1,0 -1,55 +1,47 @@@
+ /*
+ * 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.phoenix.hbase.index.covered.filter;
+
+ import java.io.DataInput;
+ import java.io.DataOutput;
+ import java.io.IOException;
+
++import org.apache.hadoop.hbase.Cell;
+ import org.apache.hadoop.hbase.KeyValue;
+ import org.apache.hadoop.hbase.filter.FilterBase;
+
+ /**
+ * Server-side only class used in the indexer to filter out keyvalues newer than a given timestamp
+ * (so allows anything <code><=</code> timestamp through).
+ * <p>
- * Note,<tt>this</tt> doesn't support {@link #write(DataOutput)} or {@link #readFields(DataInput)}.
+ */
+ public class NewerTimestampFilter extends FilterBase {
+
+ private long timestamp;
+
+ public NewerTimestampFilter(long timestamp) {
+ this.timestamp = timestamp;
+ }
+
+ @Override
- public ReturnCode filterKeyValue(KeyValue ignored) {
++ public ReturnCode filterKeyValue(Cell ignored) {
+ return ignored.getTimestamp() > timestamp ? ReturnCode.SKIP : ReturnCode.INCLUDE;
+ }
+
- @Override
- public void write(DataOutput out) throws IOException {
- throw new UnsupportedOperationException("TimestampFilter is server-side only!");
- }
- @Override
- public void readFields(DataInput in) throws IOException {
- throw new UnsupportedOperationException("TimestampFilter is server-side only!");
- }
+ }
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/b3a330ca/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/update/IndexUpdateManager.java
----------------------------------------------------------------------
diff --cc phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/update/IndexUpdateManager.java
index 0000000,c8a188d..d09498a
mode 000000,100644..100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/update/IndexUpdateManager.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/update/IndexUpdateManager.java
@@@ -1,0 -1,239 +1,240 @@@
+ /*
+ * 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.phoenix.hbase.index.covered.update;
+
+ import java.util.Collection;
+ import java.util.Comparator;
+ import java.util.HashMap;
+ import java.util.List;
+ import java.util.Map;
+ import java.util.Map.Entry;
+
-import org.apache.hadoop.hbase.KeyValue;
++import org.apache.hadoop.hbase.Cell;
+ import org.apache.hadoop.hbase.client.Delete;
+ import org.apache.hadoop.hbase.client.Mutation;
+ import org.apache.hadoop.hbase.client.Put;
+ import org.apache.hadoop.hbase.util.Bytes;
+ import org.apache.hadoop.hbase.util.Pair;
+
+ import com.google.common.collect.Lists;
+ import com.google.common.primitives.Longs;
+
+ import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
+
+ /**
+ * Keeps track of the index updates
+ */
+ public class IndexUpdateManager {
+
+ public Comparator<Mutation> COMPARATOR = new MutationComparator();
+ class MutationComparator implements Comparator<Mutation> {
+
+ @Override
+ public int compare(Mutation o1, Mutation o2) {
+ // always sort rows first
+ int compare = o1.compareTo(o2);
+ if (compare != 0) {
+ return compare;
+ }
+
+ // if same row, sort by reverse timestamp (larger first)
+ compare = Longs.compare(o2.getTimeStamp(), o1.getTimeStamp());
+ if (compare != 0) {
+ return compare;
+ }
+ // deletes always sort before puts for the same row
+ if (o1 instanceof Delete) {
+ // same row, same ts == same delete since we only delete rows
+ if (o2 instanceof Delete) {
+ return 0;
+ } else {
+ // o2 has to be a put
+ return -1;
+ }
+ }
+ // o1 must be a put
+ if (o2 instanceof Delete) {
+ return 1;
+ } else if (o2 instanceof Put) {
+ return comparePuts((Put) o1, (Put) o2);
+ }
+
+ throw new RuntimeException(
+ "Got unexpected mutation types! Can only be Put or Delete, but got: " + o1 + ", and "
+ + o2);
+ }
+
+ private int comparePuts(Put p1, Put p2) {
+ int p1Size = p1.size();
+ int p2Size = p2.size();
+ int compare = p1Size - p2Size;
+ if (compare == 0) {
+ // TODO: make this a real comparison
+ // this is a little cheating, but we don't really need to worry too much about this being
+ // the same - chances are that exact matches here are really the same update.
+ return Longs.compare(p1.heapSize(), p2.heapSize());
+ }
+ return compare;
+ }
+
+ }
+
+ private static final String PHOENIX_HBASE_TEMP_DELETE_MARKER = "phoenix.hbase.temp.delete.marker";
+ private static final byte[] TRUE_MARKER = new byte[] { 1 };
+
+ protected final Map<ImmutableBytesPtr, Collection<Mutation>> map =
+ new HashMap<ImmutableBytesPtr, Collection<Mutation>>();
+
+ /**
+ * Add an index update. Keeps the latest {@link Put} for a given timestamp
+ * @param tableName
+ * @param m
+ */
+ public void addIndexUpdate(byte[] tableName, Mutation m) {
+ // we only keep the most recent update
+ ImmutableBytesPtr key = new ImmutableBytesPtr(tableName);
+ Collection<Mutation> updates = map.get(key);
+ if (updates == null) {
+ updates = new SortedCollection<Mutation>(COMPARATOR);
+ map.put(key, updates);
+ }
+ fixUpCurrentUpdates(updates, m);
+ }
+
+ /**
+ * Fix up the current updates, given the pending mutation.
+ * @param updates current updates
+ * @param pendingMutation
+ */
+ protected void fixUpCurrentUpdates(Collection<Mutation> updates, Mutation pendingMutation) {
+ // need to check for each entry to see if we have a duplicate
+ Mutation toRemove = null;
+ Delete pendingDelete = pendingMutation instanceof Delete ? (Delete) pendingMutation : null;
+ boolean sawRowMatch = false;
+ for (Mutation stored : updates) {
+ int compare = pendingMutation.compareTo(stored);
+ // skip to the right row
+ if (compare < 0) {
+ continue;
+ } else if (compare > 0) {
+ if (sawRowMatch) {
+ break;
+ }
+ continue;
+ }
+
+ // set that we saw a row match, so any greater row will necessarily be the wrong
+ sawRowMatch = true;
+
+ // skip until we hit the right timestamp
+ if (stored.getTimeStamp() < pendingMutation.getTimeStamp()) {
+ continue;
+ }
+
+ if (stored instanceof Delete) {
+ // we already have a delete for this row, so we are done.
+ if (pendingDelete != null) {
+ return;
+ }
+ // pending update must be a Put, so we ignore the Put.
+ // add a marker in the this delete that it has been canceled out already. We need to keep
+ // the delete around though so we can figure out if other Puts would also be canceled out.
+ markMutationForRemoval(stored);
+ return;
+ }
+
+ // otherwise, the stored mutation is a Put. Either way, we want to remove it. If the pending
+ // update is a delete, we need to remove the entry (no longer applies - covered by the
+ // delete), or its an older version of the row, so we cover it with the newer.
+ toRemove = stored;
+ if (pendingDelete != null) {
+ // the pending mutation, but we need to mark the mutation for removal later
+ markMutationForRemoval(pendingMutation);
+ break;
+ }
+ }
+
+ updates.remove(toRemove);
+ updates.add(pendingMutation);
+ }
+
+ private void markMutationForRemoval(Mutation m) {
+ m.setAttribute(PHOENIX_HBASE_TEMP_DELETE_MARKER, TRUE_MARKER);
+ }
+
+ public List<Pair<Mutation, byte[]>> toMap() {
+ List<Pair<Mutation, byte[]>> updateMap = Lists.newArrayList();
+ for (Entry<ImmutableBytesPtr, Collection<Mutation>> updates : map.entrySet()) {
+ // get is ok because we always set with just the bytes
+ byte[] tableName = updates.getKey().get();
+ // TODO replace this as just storing a byte[], to avoid all the String <-> byte[] swapping
+ // HBase does
+ for (Mutation m : updates.getValue()) {
+ // skip elements that have been marked for delete
+ if (shouldBeRemoved(m)) {
+ continue;
+ }
+ updateMap.add(new Pair<Mutation, byte[]>(m, tableName));
+ }
+ }
+ return updateMap;
+ }
+
+ /**
+ * @param updates
+ */
+ public void addAll(Collection<Pair<Mutation, String>> updates) {
+ for (Pair<Mutation, String> update : updates) {
+ addIndexUpdate(Bytes.toBytes(update.getSecond()), update.getFirst());
+ }
+ }
+
+ private boolean shouldBeRemoved(Mutation m) {
+ return m.getAttribute(PHOENIX_HBASE_TEMP_DELETE_MARKER) != null;
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer sb = new StringBuffer("Pending Index Updates:\n");
+ for (Entry<ImmutableBytesPtr, Collection<Mutation>> entry : map.entrySet()) {
+ String tableName = Bytes.toString(entry.getKey().get());
+ sb.append(" Table: '" + tableName + "'\n");
+ for (Mutation m : entry.getValue()) {
+ sb.append("\t");
+ if (shouldBeRemoved(m)) {
+ sb.append("[REMOVED]");
+ }
+ sb.append(m.getClass().getSimpleName() + ":"
+ + ((m instanceof Put) ? m.getTimeStamp() + " " : ""));
+ sb.append(" row=" + Bytes.toString(m.getRow()));
+ sb.append("\n");
- if (m.getFamilyMap().isEmpty()) {
++ if (m.getFamilyCellMap().isEmpty()) {
+ sb.append("\t\t=== EMPTY ===\n");
+ }
- for (List<KeyValue> kvs : m.getFamilyMap().values()) {
- for (KeyValue kv : kvs) {
- sb.append("\t\t" + kv.toString() + "/value=" + Bytes.toStringBinary(kv.getValue()));
++ for (List<Cell> kvs : m.getFamilyCellMap().values()) {
++ for (Cell kv : kvs) {
++ sb.append("\t\t" + kv.toString() + "/value=" + Bytes.toStringBinary(kv.getValueArray(),
++ kv.getValueOffset(), kv.getValueLength()));
+ sb.append("\n");
+ }
+ }
+ }
+ }
+ return sb.toString();
+ }
+ }
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/b3a330ca/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/parallel/ThreadPoolManager.java
----------------------------------------------------------------------
diff --cc phoenix-core/src/main/java/org/apache/phoenix/hbase/index/parallel/ThreadPoolManager.java
index 0000000,efde03e..db3b845
mode 000000,100644..100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/parallel/ThreadPoolManager.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/parallel/ThreadPoolManager.java
@@@ -1,0 -1,146 +1,145 @@@
+ /*
+ * 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.phoenix.hbase.index.parallel;
+
+ import java.util.Collections;
+ import java.util.List;
+ import java.util.Map;
+ import java.util.concurrent.BlockingQueue;
+ import java.util.concurrent.LinkedBlockingQueue;
+ import java.util.concurrent.ThreadFactory;
+ import java.util.concurrent.ThreadPoolExecutor;
+ import java.util.concurrent.TimeUnit;
+ import java.util.concurrent.atomic.AtomicInteger;
+
+ import org.apache.commons.logging.Log;
+ import org.apache.commons.logging.LogFactory;
+ import org.apache.hadoop.conf.Configuration;
+ import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
+ import org.apache.hadoop.hbase.util.Threads;
+
+ /**
+ * Manage access to thread pools
+ */
+ public class ThreadPoolManager {
+
+ private static final Log LOG = LogFactory.getLog(ThreadPoolManager.class);
+
+ /**
+ * Get an executor for the given name, based on the passed {@link Configuration}. If a thread pool
+ * already exists with that name, it will be returned.
+ * @param builder
+ * @param env
+ * @return a {@link ThreadPoolExecutor} for the given name. Thread pool that only shuts down when
+ * there are no more explicit references to it. You do not need to shutdown the threadpool
+ * on your own - it is managed for you. When you are done, you merely need to release your
+ * reference. If you do attempt to shutdown the pool, you should be careful to call
+ * {@link ThreadPoolExecutor#shutdown()} XOR {@link ThreadPoolExecutor#shutdownNow()} - extra calls to either can lead to
+ * early shutdown of the pool.
+ */
+ public static synchronized ThreadPoolExecutor getExecutor(ThreadPoolBuilder builder,
+ RegionCoprocessorEnvironment env) {
+ return getExecutor(builder, env.getSharedData());
+ }
+
+ static synchronized ThreadPoolExecutor getExecutor(ThreadPoolBuilder builder,
+ Map<String, Object> poolCache) {
+ ThreadPoolExecutor pool = (ThreadPoolExecutor) poolCache.get(builder.getName());
+ if (pool == null || pool.isTerminating() || pool.isShutdown()) {
+ pool = getDefaultExecutor(builder);
+ LOG.info("Creating new pool for " + builder.getName());
+ poolCache.put(builder.getName(), pool);
+ }
+ ((ShutdownOnUnusedThreadPoolExecutor) pool).addReference();
+
+ return pool;
+ }
+
+ /**
+ * @param conf
- * @return
+ */
+ private static ShutdownOnUnusedThreadPoolExecutor getDefaultExecutor(ThreadPoolBuilder builder) {
+ int maxThreads = builder.getMaxThreads();
+ long keepAliveTime = builder.getKeepAliveTime();
+
+ // we prefer starting a new thread to queuing (the opposite of the usual ThreadPoolExecutor)
+ // since we are probably writing to a bunch of index tables in this case. Any pending requests
+ // are then queued up in an infinite (Integer.MAX_VALUE) queue. However, we allow core threads
+ // to timeout, to we tune up/down for bursty situations. We could be a bit smarter and more
+ // closely manage the core-thread pool size to handle the bursty traffic (so we can always keep
+ // some core threads on hand, rather than starting from scratch each time), but that would take
+ // even more time. If we shutdown the pool, but are still putting new tasks, we can just do the
+ // usual policy and throw a RejectedExecutionException because we are shutting down anyways and
+ // the worst thing is that this gets unloaded.
+ ShutdownOnUnusedThreadPoolExecutor pool =
+ new ShutdownOnUnusedThreadPoolExecutor(maxThreads, maxThreads, keepAliveTime,
+ TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(),
+ Threads.newDaemonThreadFactory(builder.getName() + "-"), builder.getName());
+ pool.allowCoreThreadTimeOut(true);
+ return pool;
+ }
+
+ /**
+ * Thread pool that only shuts down when there are no more explicit references to it. A reference
+ * is when obtained and released on calls to {@link #shutdown()} or {@link #shutdownNow()}.
+ * Therefore, users should be careful to call {@link #shutdown()} XOR {@link #shutdownNow()} -
+ * extra calls to either can lead to early shutdown of the pool.
+ */
+ private static class ShutdownOnUnusedThreadPoolExecutor extends ThreadPoolExecutor {
+
+ private AtomicInteger references;
+ private String poolName;
+
+ public ShutdownOnUnusedThreadPoolExecutor(int coreThreads, int maxThreads, long keepAliveTime,
+ TimeUnit timeUnit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory,
+ String poolName) {
+ super(coreThreads, maxThreads, keepAliveTime, timeUnit, workQueue, threadFactory);
+ this.references = new AtomicInteger();
+ this.poolName = poolName;
+ }
+
+ public void addReference() {
+ this.references.incrementAndGet();
+ }
+
+ @Override
+ protected void finalize() {
+ // override references counter if we go out of scope - ensures the pool gets cleaned up
+ LOG.info("Shutting down pool '" + poolName + "' because no more references");
+ super.finalize();
+ }
+
+ @Override
+ public void shutdown() {
+ if (references.decrementAndGet() <= 0) {
+ LOG.debug("Shutting down pool " + this.poolName);
+ super.shutdown();
+ }
+ }
+
+ @Override
+ public List<Runnable> shutdownNow() {
+ if (references.decrementAndGet() <= 0) {
+ LOG.debug("Shutting down pool " + this.poolName + " NOW!");
+ return super.shutdownNow();
+ }
+ return Collections.emptyList();
+ }
+
+ }
+ }
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/b3a330ca/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/scanner/FilteredKeyValueScanner.java
----------------------------------------------------------------------
diff --cc phoenix-core/src/main/java/org/apache/phoenix/hbase/index/scanner/FilteredKeyValueScanner.java
index 0000000,d91aaaf..bbd0bc7
mode 000000,100644..100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/scanner/FilteredKeyValueScanner.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/scanner/FilteredKeyValueScanner.java
@@@ -1,0 -1,162 +1,160 @@@
+ /*
+ * 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.phoenix.hbase.index.scanner;
+
+ import java.io.IOException;
+ import java.util.SortedSet;
+
+ import org.apache.hadoop.hbase.KeyValue;
+ import org.apache.hadoop.hbase.client.Scan;
+ import org.apache.hadoop.hbase.filter.Filter;
+ import org.apache.hadoop.hbase.filter.Filter.ReturnCode;
+ import org.apache.hadoop.hbase.regionserver.KeyValueScanner;
+
+ import org.apache.phoenix.hbase.index.covered.KeyValueStore;
+
+ /**
+ * Combine a simplified version of the logic in the ScanQueryMatcher and the KeyValueScanner. We can get away with this
+ * here because we are only concerned with a single MemStore for the index; we don't need to worry about multiple column
+ * families or minimizing seeking through file - we just want to iterate the kvs quickly, in-memory.
+ */
+ public class FilteredKeyValueScanner implements KeyValueScanner {
+
+ private KeyValueScanner delegate;
+ private Filter filter;
+
+ public FilteredKeyValueScanner(Filter filter, KeyValueStore store) {
+ this(filter, store.getScanner());
+ }
+
+ private FilteredKeyValueScanner(Filter filter, KeyValueScanner delegate) {
+ this.delegate = delegate;
+ this.filter = filter;
+ }
+
+ @Override
+ public KeyValue peek() {
+ return delegate.peek();
+ }
+
+ /**
+ * Same a {@link KeyValueScanner#next()} except that we filter out the next {@link KeyValue} until we find one that
+ * passes the filter.
+ *
+ * @return the next {@link KeyValue} or <tt>null</tt> if no next {@link KeyValue} is present and passes all the
+ * filters.
+ */
+ @Override
+ public KeyValue next() throws IOException {
+ seekToNextUnfilteredKeyValue();
+ return delegate.next();
+ }
+
+ @Override
+ public boolean seek(KeyValue key) throws IOException {
+ if (filter.filterAllRemaining()) { return false; }
+ // see if we can seek to the next key
+ if (!delegate.seek(key)) { return false; }
+
+ return seekToNextUnfilteredKeyValue();
+ }
+
+ private boolean seekToNextUnfilteredKeyValue() throws IOException {
+ while (true) {
+ KeyValue peeked = delegate.peek();
+ // no more key values, so we are done
+ if (peeked == null) { return false; }
+
+ // filter the peeked value to see if it should be served
+ ReturnCode code = filter.filterKeyValue(peeked);
+ switch (code) {
+ // included, so we are done
+ case INCLUDE:
+ case INCLUDE_AND_NEXT_COL:
+ return true;
+ // not included, so we need to go to the next row
+ case SKIP:
+ case NEXT_COL:
+ case NEXT_ROW:
+ delegate.next();
+ break;
+ // use a seek hint to find out where we should go
+ case SEEK_NEXT_USING_HINT:
+ delegate.seek(filter.getNextKeyHint(peeked));
+ }
+ }
+ }
+
+ @Override
+ public boolean reseek(KeyValue key) throws IOException {
+ this.delegate.reseek(key);
+ return this.seekToNextUnfilteredKeyValue();
+ }
+
+ @Override
+ public boolean requestSeek(KeyValue kv, boolean forward, boolean useBloom) throws IOException {
+ return this.reseek(kv);
+ }
+
+ @Override
+ public boolean isFileScanner() {
+ return false;
+ }
+
+ @Override
+ public long getSequenceID() {
+ return this.delegate.getSequenceID();
+ }
+
+ @Override
+ public boolean shouldUseScanner(Scan scan, SortedSet<byte[]> columns, long oldestUnexpiredTS) {
+ throw new UnsupportedOperationException(this.getClass().getName()
+ + " doesn't support checking to see if it should use a scanner!");
+ }
+
+ @Override
+ public boolean realSeekDone() {
+ return this.delegate.realSeekDone();
+ }
+
+ @Override
+ public void enforceSeek() throws IOException {
+ this.delegate.enforceSeek();
+ }
+
+ @Override
+ public void close() {
+ this.delegate.close();
+ }
+
- /*
+ @Override
+ public boolean backwardSeek(KeyValue arg0) throws IOException {
+ return this.delegate.backwardSeek(arg0);
+ }
+
+ @Override
+ public boolean seekToLastRow() throws IOException {
+ return this.delegate.seekToLastRow();
+ }
+
+ @Override
+ public boolean seekToPreviousRow(KeyValue arg0) throws IOException {
+ return this.delegate.seekToPreviousRow(arg0);
+ }
- */
+ }
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/b3a330ca/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/table/CoprocessorHTableFactory.java
----------------------------------------------------------------------
diff --cc phoenix-core/src/main/java/org/apache/phoenix/hbase/index/table/CoprocessorHTableFactory.java
index 0000000,33559da..8ef3e4f
mode 000000,100644..100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/table/CoprocessorHTableFactory.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/table/CoprocessorHTableFactory.java
@@@ -1,0 -1,68 +1,69 @@@
+ /*
+ * 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.phoenix.hbase.index.table;
+
+ import java.io.IOException;
+
+ import org.apache.commons.logging.Log;
+ import org.apache.commons.logging.LogFactory;
+ import org.apache.hadoop.conf.Configuration;
+ import org.apache.hadoop.hbase.CoprocessorEnvironment;
+ import org.apache.hadoop.hbase.HConstants;
++import org.apache.hadoop.hbase.TableName;
+ import org.apache.hadoop.hbase.client.HTableInterface;
+ import org.apache.hadoop.hbase.util.Bytes;
+
+ import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
+ import org.apache.phoenix.hbase.index.util.IndexManagementUtil;
+
+ public class CoprocessorHTableFactory implements HTableFactory {
+
+ /** Number of milliseconds per-interval to retry zookeeper */
+ private static final String ZOOKEEPER_RECOVERY_RETRY_INTERVALMILL = "zookeeper.recovery.retry.intervalmill";
+ /** Number of retries for zookeeper */
+ private static final String ZOOKEEPER_RECOVERY_RETRY_KEY = "zookeeper.recovery.retry";
+ private static final Log LOG = LogFactory.getLog(CoprocessorHTableFactory.class);
+ private CoprocessorEnvironment e;
+
+ public CoprocessorHTableFactory(CoprocessorEnvironment e) {
+ this.e = e;
+ }
+
+ @Override
+ public HTableInterface getTable(ImmutableBytesPtr tablename) throws IOException {
+ Configuration conf = e.getConfiguration();
+ // make sure writers fail fast
+ IndexManagementUtil.setIfNotSet(conf, HConstants.HBASE_CLIENT_RETRIES_NUMBER, 3);
+ IndexManagementUtil.setIfNotSet(conf, HConstants.HBASE_CLIENT_PAUSE, 1000);
+ IndexManagementUtil.setIfNotSet(conf, ZOOKEEPER_RECOVERY_RETRY_KEY, 3);
+ IndexManagementUtil.setIfNotSet(conf, ZOOKEEPER_RECOVERY_RETRY_INTERVALMILL, 100);
+ IndexManagementUtil.setIfNotSet(conf, HConstants.ZK_SESSION_TIMEOUT, 30000);
+ IndexManagementUtil.setIfNotSet(conf, HConstants.HBASE_RPC_TIMEOUT_KEY, 5000);
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Creating new HTable: " + Bytes.toString(tablename.copyBytesIfNecessary()));
+ }
- return this.e.getTable(tablename.copyBytesIfNecessary());
++ return this.e.getTable(TableName.valueOf(tablename.copyBytesIfNecessary()));
+ }
+
+ @Override
+ public void shutdown() {
+ // noop
+ }
+ }
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/b3a330ca/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/util/IndexManagementUtil.java
----------------------------------------------------------------------
diff --cc phoenix-core/src/main/java/org/apache/phoenix/hbase/index/util/IndexManagementUtil.java
index 0000000,76ec9ce..2199b4f
mode 000000,100644..100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/util/IndexManagementUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/util/IndexManagementUtil.java
@@@ -1,0 -1,244 +1,247 @@@
+ /*
+ * 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.phoenix.hbase.index.util;
+
+ import java.io.IOException;
+ import java.util.Collection;
+ import java.util.List;
+ import java.util.Map;
+
+ import org.apache.commons.logging.Log;
+ import org.apache.commons.logging.LogFactory;
+ import org.apache.hadoop.conf.Configuration;
+ import org.apache.hadoop.hbase.HConstants;
+ import org.apache.hadoop.hbase.KeyValue;
+ import org.apache.hadoop.hbase.client.Scan;
++import org.apache.hadoop.hbase.regionserver.wal.WALCellCodec;
+
+ import com.google.common.collect.Maps;
+ import org.apache.phoenix.hbase.index.ValueGetter;
+ import org.apache.phoenix.hbase.index.builder.IndexBuildingFailureException;
+ import org.apache.phoenix.hbase.index.covered.data.LazyValueGetter;
+ import org.apache.phoenix.hbase.index.covered.update.ColumnReference;
+ import org.apache.phoenix.hbase.index.scanner.Scanner;
+
+ /**
+ * Utility class to help manage indexes
+ */
+ public class IndexManagementUtil {
+
+ private IndexManagementUtil() {
+ // private ctor for util classes
+ }
+
+ // Don't rely on statically defined classes constants from classes that may not exist
+ // in earlier HBase versions
+ public static final String INDEX_WAL_EDIT_CODEC_CLASS_NAME = "org.apache.hadoop.hbase.regionserver.wal.IndexedWALEditCodec";
+ public static final String HLOG_READER_IMPL_KEY = "hbase.regionserver.hlog.reader.impl";
+ public static final String WAL_EDIT_CODEC_CLASS_KEY = "hbase.regionserver.wal.codec";
+
+ private static final String INDEX_HLOG_READER_CLASS_NAME = "org.apache.hadoop.hbase.regionserver.wal.IndexedHLogReader";
+ private static final Log LOG = LogFactory.getLog(IndexManagementUtil.class);
+
+ public static boolean isWALEditCodecSet(Configuration conf) {
+ // check to see if the WALEditCodec is installed
+ try {
+ // Use reflection to load the IndexedWALEditCodec, since it may not load with an older version
+ // of HBase
+ Class.forName(INDEX_WAL_EDIT_CODEC_CLASS_NAME);
+ } catch (Throwable t) {
+ return false;
+ }
- if (INDEX_WAL_EDIT_CODEC_CLASS_NAME.equals(conf.get(WAL_EDIT_CODEC_CLASS_KEY, null))) {
++ if (INDEX_WAL_EDIT_CODEC_CLASS_NAME.equals(conf
++ .get(WALCellCodec.WAL_CELL_CODEC_CLASS_KEY, null))) {
+ // its installed, and it can handle compression and non-compression cases
+ return true;
+ }
+ return false;
+ }
+
+ public static void ensureMutableIndexingCorrectlyConfigured(Configuration conf) throws IllegalStateException {
+
+ // check to see if the WALEditCodec is installed
+ if (isWALEditCodecSet(conf)) { return; }
+
+ // otherwise, we have to install the indexedhlogreader, but it cannot have compression
+ String codecClass = INDEX_WAL_EDIT_CODEC_CLASS_NAME;
+ String indexLogReaderName = INDEX_HLOG_READER_CLASS_NAME;
+ try {
+ // Use reflection to load the IndexedHLogReader, since it may not load with an older version
+ // of HBase
+ Class.forName(indexLogReaderName);
+ } catch (ClassNotFoundException e) {
+ throw new IllegalStateException(codecClass + " is not installed, but "
+ + indexLogReaderName + " hasn't been installed in hbase-site.xml under " + HLOG_READER_IMPL_KEY);
+ }
+ if (indexLogReaderName.equals(conf.get(HLOG_READER_IMPL_KEY, indexLogReaderName))) {
+ if (conf.getBoolean(HConstants.ENABLE_WAL_COMPRESSION, false)) { throw new IllegalStateException(
+ "WAL Compression is only supported with " + codecClass
- + ". You can install in hbase-site.xml, under " + WAL_EDIT_CODEC_CLASS_KEY); }
++ + ". You can install in hbase-site.xml, under " + WALCellCodec.WAL_CELL_CODEC_CLASS_KEY);
++ }
+ } else {
+ throw new IllegalStateException(codecClass + " is not installed, but "
+ + indexLogReaderName + " hasn't been installed in hbase-site.xml under " + HLOG_READER_IMPL_KEY);
+ }
+
+ }
+
+ public static ValueGetter createGetterFromKeyValues(Collection<KeyValue> pendingUpdates) {
+ final Map<ReferencingColumn, ImmutableBytesPtr> valueMap = Maps.newHashMapWithExpectedSize(pendingUpdates
+ .size());
+ for (KeyValue kv : pendingUpdates) {
+ // create new pointers to each part of the kv
+ ImmutableBytesPtr family = new ImmutableBytesPtr(kv.getBuffer(), kv.getFamilyOffset(), kv.getFamilyLength());
+ ImmutableBytesPtr qual = new ImmutableBytesPtr(kv.getBuffer(), kv.getQualifierOffset(),
+ kv.getQualifierLength());
+ ImmutableBytesPtr value = new ImmutableBytesPtr(kv.getBuffer(), kv.getValueOffset(), kv.getValueLength());
+ valueMap.put(new ReferencingColumn(family, qual), value);
+ }
+ return new ValueGetter() {
+ @Override
+ public ImmutableBytesPtr getLatestValue(ColumnReference ref) throws IOException {
+ return valueMap.get(ReferencingColumn.wrap(ref));
+ }
+ };
+ }
+
+ private static class ReferencingColumn {
+ ImmutableBytesPtr family;
+ ImmutableBytesPtr qual;
+
+ static ReferencingColumn wrap(ColumnReference ref) {
+ ImmutableBytesPtr family = new ImmutableBytesPtr(ref.getFamily());
+ ImmutableBytesPtr qual = new ImmutableBytesPtr(ref.getQualifier());
+ return new ReferencingColumn(family, qual);
+ }
+
+ public ReferencingColumn(ImmutableBytesPtr family, ImmutableBytesPtr qual) {
+ this.family = family;
+ this.qual = qual;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((family == null) ? 0 : family.hashCode());
+ result = prime * result + ((qual == null) ? 0 : qual.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (getClass() != obj.getClass()) return false;
+ ReferencingColumn other = (ReferencingColumn)obj;
+ if (family == null) {
+ if (other.family != null) return false;
+ } else if (!family.equals(other.family)) return false;
+ if (qual == null) {
+ if (other.qual != null) return false;
+ } else if (!qual.equals(other.qual)) return false;
+ return true;
+ }
+ }
+
+ public static ValueGetter createGetterFromScanner(Scanner scanner, byte[] currentRow) {
+ return new LazyValueGetter(scanner, currentRow);
+ }
+
+ /**
+ * check to see if the kvs in the update match any of the passed columns. Generally, this is useful to for an index
+ * codec to determine if a given update should even be indexed. This assumes that for any index, there are going to
+ * small number of columns, versus the number of kvs in any one batch.
+ */
+ public static boolean updateMatchesColumns(Collection<KeyValue> update, List<ColumnReference> columns) {
+ // check to see if the kvs in the new update even match any of the columns requested
+ // assuming that for any index, there are going to small number of columns, versus the number of
+ // kvs in any one batch.
+ boolean matches = false;
+ outer: for (KeyValue kv : update) {
+ for (ColumnReference ref : columns) {
+ if (ref.matchesFamily(kv.getFamily()) && ref.matchesQualifier(kv.getQualifier())) {
+ matches = true;
+ // if a single column matches a single kv, we need to build a whole scanner
+ break outer;
+ }
+ }
+ }
+ return matches;
+ }
+
+ /**
+ * Check to see if the kvs in the update match any of the passed columns. Generally, this is useful to for an index
+ * codec to determine if a given update should even be indexed. This assumes that for any index, there are going to
+ * small number of kvs, versus the number of columns in any one batch.
+ * <p>
+ * This employs the same logic as {@link #updateMatchesColumns(Collection, List)}, but is flips the iteration logic
+ * to search columns before kvs.
+ */
+ public static boolean columnMatchesUpdate(List<ColumnReference> columns, Collection<KeyValue> update) {
+ boolean matches = false;
+ outer: for (ColumnReference ref : columns) {
+ for (KeyValue kv : update) {
+ if (ref.matchesFamily(kv.getFamily()) && ref.matchesQualifier(kv.getQualifier())) {
+ matches = true;
+ // if a single column matches a single kv, we need to build a whole scanner
+ break outer;
+ }
+ }
+ }
+ return matches;
+ }
+
+ public static Scan newLocalStateScan(List<? extends Iterable<? extends ColumnReference>> refsArray) {
+ Scan s = new Scan();
+ s.setRaw(true);
+ // add the necessary columns to the scan
+ for (Iterable<? extends ColumnReference> refs : refsArray) {
+ for (ColumnReference ref : refs) {
+ s.addFamily(ref.getFamily());
+ }
+ }
+ s.setMaxVersions();
+ return s;
+ }
+
+ /**
+ * Propagate the given failure as a generic {@link IOException}, if it isn't already
+ *
+ * @param e
+ * reason indexing failed. If ,tt>null</tt>, throws a {@link NullPointerException}, which should unload
+ * the coprocessor.
+ */
+ public static void rethrowIndexingException(Throwable e) throws IOException {
+ try {
+ throw e;
+ } catch (IOException e1) {
+ LOG.info("Rethrowing " + e);
+ throw e1;
+ } catch (Throwable e1) {
+ LOG.info("Rethrowing " + e1 + " as a " + IndexBuildingFailureException.class.getSimpleName());
+ throw new IndexBuildingFailureException("Failed to build index for unexpected reason!", e1);
+ }
+ }
+
+ public static void setIfNotSet(Configuration conf, String key, int value) {
+ if (conf.get(key) == null) {
+ conf.setInt(key, value);
+ }
+ }
+ }
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/b3a330ca/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/wal/IndexedKeyValue.java
----------------------------------------------------------------------
diff --cc phoenix-core/src/main/java/org/apache/phoenix/hbase/index/wal/IndexedKeyValue.java
index 0000000,253fd0d..0be1a6b
mode 000000,100644..100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/wal/IndexedKeyValue.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/wal/IndexedKeyValue.java
@@@ -1,0 -1,173 +1,180 @@@
+ /*
+ * 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.phoenix.hbase.index.wal;
+
-import java.io.ByteArrayOutputStream;
+ import java.io.DataInput;
+ import java.io.DataOutput;
-import java.io.DataOutputStream;
+ import java.io.IOException;
+ import java.util.Arrays;
+
+ import org.apache.hadoop.hbase.KeyValue;
++import org.apache.hadoop.hbase.client.Delete;
+ import org.apache.hadoop.hbase.client.Mutation;
-import org.apache.hadoop.hbase.regionserver.wal.HLog;
++import org.apache.hadoop.hbase.client.Put;
++import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto;
++import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto.MutationType;
++import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
+ import org.apache.hadoop.hbase.util.Bytes;
-
+ import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
+
+ public class IndexedKeyValue extends KeyValue {
++ public static final byte [] COLUMN_FAMILY = Bytes.toBytes("INDEXEDKEYVALUE_FAKED_FAMILY");
++
+ private static int calcHashCode(ImmutableBytesPtr indexTableName, Mutation mutation) {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + indexTableName.hashCode();
+ result = prime * result + Arrays.hashCode(mutation.getRow());
+ return result;
+ }
+
+ private ImmutableBytesPtr indexTableName;
+ private Mutation mutation;
+ // optimization check to ensure that batches don't get replayed to the index more than once
+ private boolean batchFinished = false;
+ private int hashCode;
+
+ public IndexedKeyValue() {}
+
+ public IndexedKeyValue(byte[] bs, Mutation mutation) {
+ this.indexTableName = new ImmutableBytesPtr(bs);
+ this.mutation = mutation;
+ this.hashCode = calcHashCode(indexTableName, mutation);
+ }
+
+ public byte[] getIndexTable() {
+ return this.indexTableName.get();
+ }
+
+ public Mutation getMutation() {
+ return mutation;
+ }
+
++ /*
++ * Returns a faked column family for an IndexedKeyValue instance
++ */
++ @Override
++ public byte [] getFamily() {
++ return COLUMN_FAMILY;
++ }
++
+ /**
- * This is a KeyValue that shouldn't actually be replayed, so we always mark it as an {@link HLog#METAFAMILY} so it
- * isn't replayed via the normal replay mechanism
++ * This is a KeyValue that shouldn't actually be replayed/replicated, so we always mark it as
++ * an {@link WALEdit#METAFAMILY} so it isn't replayed/replicated via the normal replay mechanism
+ */
+ @Override
+ public boolean matchingFamily(final byte[] family) {
- return Bytes.equals(family, HLog.METAFAMILY);
++ return Bytes.equals(family, WALEdit.METAFAMILY);
++ }
++
++ /**
++ * Not a real KeyValue
++ */
++ @Override
++ public boolean matchingRow(final byte [] row) {
++ return false;
+ }
+
+ @Override
+ public String toString() {
+ return "IndexWrite:\n\ttable: " + indexTableName + "\n\tmutation:" + mutation;
+ }
+
+ /**
+ * This is a very heavy-weight operation and should only be done when absolutely necessary - it does a full
+ * serialization of the underyling mutation to compare the underlying data.
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if(obj == null) return false;
+ if (this == obj) return true;
+ if (getClass() != obj.getClass()) return false;
+ IndexedKeyValue other = (IndexedKeyValue)obj;
+ if (hashCode() != other.hashCode()) return false;
+ if (!other.indexTableName.equals(this.indexTableName)) return false;
+ byte[] current = this.getMutationBytes();
+ byte[] otherMutation = other.getMutationBytes();
+ return Bytes.equals(current, otherMutation);
+ }
+
+ private byte[] getMutationBytes() {
- ByteArrayOutputStream bos = null;
+ try {
- bos = new ByteArrayOutputStream();
- this.mutation.write(new DataOutputStream(bos));
- bos.flush();
- return bos.toByteArray();
++ MutationProto m = toMutationProto(this.mutation);
++ return m.toByteArray();
+ } catch (IOException e) {
+ throw new IllegalArgumentException("Failed to get bytes for mutation!", e);
- } finally {
- if (bos != null) {
- try {
- bos.close();
- } catch (IOException e) {
- throw new IllegalArgumentException("Failed to get bytes for mutation!", e);
- }
- }
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ return hashCode;
+ }
+
- @Override
- public void write(DataOutput out) throws IOException {
- KeyValueCodec.write(out, this);
- }
-
+ /**
+ * Internal write the underlying data for the entry - this does not do any special prefixing. Writing should be done
+ * via {@link KeyValueCodec#write(DataOutput, KeyValue)} to ensure consistent reading/writing of
+ * {@link IndexedKeyValue}s.
+ *
+ * @param out
+ * to write data to. Does not close or flush the passed object.
+ * @throws IOException
+ * if there is a problem writing the underlying data
+ */
+ void writeData(DataOutput out) throws IOException {
+ Bytes.writeByteArray(out, this.indexTableName.get());
- out.writeUTF(this.mutation.getClass().getName());
- this.mutation.write(out);
++ MutationProto m = toMutationProto(this.mutation);
++ Bytes.writeByteArray(out, m.toByteArray());
+ }
+
+ /**
+ * This method shouldn't be used - you should use {@link KeyValueCodec#readKeyValue(DataInput)} instead. Its the
+ * complement to {@link #writeData(DataOutput)}.
+ */
+ @SuppressWarnings("javadoc")
- @Override
+ public void readFields(DataInput in) throws IOException {
+ this.indexTableName = new ImmutableBytesPtr(Bytes.readByteArray(in));
- Class<? extends Mutation> clazz;
- try {
- clazz = Class.forName(in.readUTF()).asSubclass(Mutation.class);
- this.mutation = clazz.newInstance();
- this.mutation.readFields(in);
- this.hashCode = calcHashCode(indexTableName, mutation);
- } catch (ClassNotFoundException e) {
- throw new IOException(e);
- } catch (InstantiationException e) {
- throw new IOException(e);
- } catch (IllegalAccessException e) {
- throw new IOException(e);
- }
++ byte[] mutationData = Bytes.readByteArray(in);
++ MutationProto mProto = MutationProto.parseFrom(mutationData);
++ this.mutation = org.apache.hadoop.hbase.protobuf.ProtobufUtil.toMutation(mProto);
++ this.hashCode = calcHashCode(indexTableName, mutation);
+ }
+
+ public boolean getBatchFinished() {
+ return this.batchFinished;
+ }
+
+ public void markBatchFinished() {
+ this.batchFinished = true;
+ }
++
++ protected MutationProto toMutationProto(Mutation mutation) throws IOException {
++ MutationProto m = null;
++ if(mutation instanceof Put){
++ m = org.apache.hadoop.hbase.protobuf.ProtobufUtil.toMutation(MutationType.PUT,
++ mutation);
++ } else if(mutation instanceof Delete) {
++ m = org.apache.hadoop.hbase.protobuf.ProtobufUtil.toMutation(MutationType.DELETE,
++ mutation);
++ } else {
++ throw new IOException("Put/Delete mutations only supported");
++ }
++ return m;
++ }
+ }
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/b3a330ca/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/wal/KeyValueCodec.java
----------------------------------------------------------------------
diff --cc phoenix-core/src/main/java/org/apache/phoenix/hbase/index/wal/KeyValueCodec.java
index 0000000,3815937..682a504
mode 000000,100644..100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/wal/KeyValueCodec.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/wal/KeyValueCodec.java
@@@ -1,0 -1,97 +1,96 @@@
+ /*
+ * 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.phoenix.hbase.index.wal;
+
+ import java.io.DataInput;
+ import java.io.DataOutput;
+ import java.io.IOException;
+ import java.util.ArrayList;
+ import java.util.Collections;
+ import java.util.List;
+
++import org.apache.hadoop.hbase.Cell;
+ import org.apache.hadoop.hbase.KeyValue;
+ import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
+
+ /**
+ * Codec to encode/decode {@link KeyValue}s and {@link IndexedKeyValue}s within a {@link WALEdit}
+ */
+ public class KeyValueCodec {
+
+ /**
+ * KeyValue length marker specifying that its actually an {@link IndexedKeyValue} rather than a
+ * regular {@link KeyValue}.
+ */
+ public static final int INDEX_TYPE_LENGTH_MARKER = -1;
+
+ /**
+ * Read a {@link List} of {@link KeyValue} from the input stream - may contain regular
+ * {@link KeyValue}s or {@link IndexedKeyValue}s.
+ * @param in to read from
+ * @return the next {@link KeyValue}s
+ * @throws IOException if the next {@link KeyValue} cannot be read
+ */
+ public static List<KeyValue> readKeyValues(DataInput in) throws IOException {
+ int size = in.readInt();
+ if (size == 0) {
+ return Collections.<KeyValue>emptyList();
+ }
+ List<KeyValue> kvs = new ArrayList<KeyValue>(size);
+ for (int i = 0; i < size; i++) {
+ kvs.add(readKeyValue(in));
+ }
+ return kvs;
+ }
+
+ /**
+ * Read a single {@link KeyValue} from the input stream - may either be a regular {@link KeyValue}
+ * or an {@link IndexedKeyValue}.
+ * @param in to read from
+ * @return the next {@link KeyValue}, if one is available
+ * @throws IOException if the next {@link KeyValue} cannot be read
+ */
+ public static KeyValue readKeyValue(DataInput in) throws IOException {
+ int length = in.readInt();
- KeyValue kv;
+ // its a special IndexedKeyValue
+ if (length == INDEX_TYPE_LENGTH_MARKER) {
- kv = new IndexedKeyValue();
++ IndexedKeyValue kv = new IndexedKeyValue();
+ kv.readFields(in);
++ return kv;
+ } else {
- kv = new KeyValue();
- kv.readFields(length, in);
++ return KeyValue.create(length, in);
+ }
- return kv;
+ }
+
+ /**
+ * Write a {@link KeyValue} or an {@link IndexedKeyValue} to the output stream. These can be read
+ * back via {@link #readKeyValue(DataInput)} or {@link #readKeyValues(DataInput)}.
+ * @param out to write to
+ * @param kv {@link KeyValue} to which to write
+ * @throws IOException if there is an error writing
+ */
+ public static void write(DataOutput out, KeyValue kv) throws IOException {
+ if (kv instanceof IndexedKeyValue) {
+ out.writeInt(INDEX_TYPE_LENGTH_MARKER);
+ ((IndexedKeyValue) kv).writeData(out);
+ } else {
- kv.write(out);
++ KeyValue.write(kv, out);
+ }
+ }
+ }
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/b3a330ca/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
----------------------------------------------------------------------
diff --cc phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
index 69611a2,fcd3c94..775c897
--- a/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
@@@ -37,11 -34,7 +35,8 @@@ import org.apache.hadoop.hbase.CellUtil
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.Delete;
+import org.apache.hadoop.hbase.client.Durability;
import org.apache.hadoop.hbase.client.Put;
- import org.apache.hadoop.hbase.index.ValueGetter;
- import org.apache.hadoop.hbase.index.covered.update.ColumnReference;
- import org.apache.hadoop.hbase.index.util.ImmutableBytesPtr;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.Writable;
@@@ -353,7 -364,7 +366,6 @@@ public class IndexMaintainer implement
}
}
-- @SuppressWarnings("deprecation")
public Put buildUpdateMutation(ValueGetter valueGetter, ImmutableBytesWritable dataRowKeyPtr, long ts) throws IOException {
Put put = null;
// New row being inserted: add the empty key value
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/b3a330ca/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexBuilder.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/b3a330ca/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexFailurePolicy.java
----------------------------------------------------------------------
diff --cc phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexFailurePolicy.java
index 197bc06,5943e04..9e2cc7a
--- a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexFailurePolicy.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexFailurePolicy.java
@@@ -33,24 -29,15 +31,22 @@@ import org.apache.hadoop.hbase.TableNam
import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.Mutation;
import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.coprocessor.Batch;
import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
+import org.apache.hadoop.hbase.ipc.BlockingRpcCallback;
+import org.apache.hadoop.hbase.ipc.ServerRpcController;
+import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto;
import com.google.common.collect.Multimap;
- import org.apache.hadoop.hbase.index.table.HTableInterfaceReference;
- import org.apache.hadoop.hbase.index.write.KillServerOnFailurePolicy;
--import org.apache.phoenix.coprocessor.MetaDataProtocol;
import org.apache.phoenix.coprocessor.MetaDataProtocol.MetaDataMutationResult;
import org.apache.phoenix.coprocessor.MetaDataProtocol.MutationCode;
- import org.apache.phoenix.coprocessor.generated.MetaDataProtos.DropColumnRequest;
+ import org.apache.phoenix.hbase.index.table.HTableInterfaceReference;
+ import org.apache.phoenix.hbase.index.write.KillServerOnFailurePolicy;
+import org.apache.phoenix.coprocessor.generated.MetaDataProtos.MetaDataResponse;
+import org.apache.phoenix.coprocessor.generated.MetaDataProtos.MetaDataService;
+import org.apache.phoenix.coprocessor.generated.MetaDataProtos.UpdateIndexStateRequest;
import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
+import org.apache.phoenix.protobuf.ProtobufUtil;
import org.apache.phoenix.schema.PIndexState;
import org.apache.phoenix.util.SchemaUtil;
@@@ -87,7 -74,8 +83,7 @@@ public class PhoenixIndexFailurePolicy
// Disable the index by using the updateIndexState method of MetaDataProtocol end point coprocessor.
String indexTableName = ref.getTableName();
byte[] indexTableKey = SchemaUtil.getTableKeyFromFullName(indexTableName);
- HTableInterface systemTable = env.getTable(TableName.valueOf(PhoenixDatabaseMetaData.TYPE_TABLE_NAME_BYTES));
- HTableInterface systemTable = env.getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES);
- MetaDataProtocol mdProxy = systemTable.coprocessorProxy(MetaDataProtocol.class, indexTableKey);
++ HTableInterface systemTable = env.getTable(TableName.valueOf(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES));
// Mimic the Put that gets generated by the client on an update of the index state
Put put = new Put(indexTableKey);
put.add(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES, PhoenixDatabaseMetaData.INDEX_STATE_BYTES, PIndexState.DISABLE.getSerializedBytes());
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/b3a330ca/phoenix-core/src/main/java/org/apache/phoenix/iterate/MappedByteBufferSortedQueue.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/b3a330ca/phoenix-core/src/main/java/org/apache/phoenix/iterate/RegionScannerResultIterator.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/b3a330ca/phoenix-core/src/main/java/org/apache/phoenix/iterate/SpoolingResultIterator.java
----------------------------------------------------------------------
diff --cc phoenix-core/src/main/java/org/apache/phoenix/iterate/SpoolingResultIterator.java
index 7635b6e,49b1468..1a256de
--- a/phoenix-core/src/main/java/org/apache/phoenix/iterate/SpoolingResultIterator.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/iterate/SpoolingResultIterator.java
@@@ -24,10 -28,10 +28,9 @@@ import java.sql.SQLException
import java.util.List;
import org.apache.commons.io.output.DeferredFileOutputStream;
--import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.io.WritableUtils;
-
+ import org.apache.phoenix.compile.StatementContext;
import org.apache.phoenix.iterate.ParallelIterators.ParallelIteratorFactory;
import org.apache.phoenix.memory.MemoryManager;
import org.apache.phoenix.memory.MemoryManager.MemoryChunk;
@@@ -35,7 -39,9 +38,10 @@@ import org.apache.phoenix.query.QuerySe
import org.apache.phoenix.query.QueryServicesOptions;
import org.apache.phoenix.schema.tuple.ResultTuple;
import org.apache.phoenix.schema.tuple.Tuple;
- import org.apache.phoenix.util.*;
+ import org.apache.phoenix.util.ByteUtil;
++import org.apache.phoenix.util.ResultUtil;
+ import org.apache.phoenix.util.ServerUtil;
+ import org.apache.phoenix.util.TupleUtil;
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/b3a330ca/phoenix-core/src/main/java/org/apache/phoenix/job/JobManager.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/b3a330ca/phoenix-core/src/main/java/org/apache/phoenix/join/HashCacheFactory.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/b3a330ca/phoenix-core/src/main/java/org/apache/phoenix/join/ScanProjector.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/b3a330ca/phoenix-core/src/main/java/org/apache/phoenix/map/reduce/CSVBulkLoader.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/b3a330ca/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
----------------------------------------------------------------------
diff --cc phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
index f82dc59,139a1e0..ff87278
--- a/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
@@@ -180,12 -222,12 +222,12 @@@ public class QueryOptimizer
* b) the plan that preserves ordering for a group by.
* c) the data table plan
* @param plans the list of candidate plans
- * @return
+ * @return QueryPlan
*/
private QueryPlan chooseBestPlan(SelectStatement select, List<QueryPlan> plans) {
- QueryPlan firstPlan = plans.get(0);
+ final QueryPlan dataPlan = plans.get(0);
if (plans.size() == 1) {
- return firstPlan;
+ return dataPlan;
}
/**