PHOENIX-3806 Reduce IndexUpdateManager sorting overhead during Index rebuild
Signed-off-by: Lars Hofhansl <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/a1d3c169 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/a1d3c169 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/a1d3c169 Branch: refs/heads/omid Commit: a1d3c1697eb478a04c7f94e37cdfc2334f94b4f5 Parents: f51c0db Author: Vincent Poon <[email protected]> Authored: Mon May 8 16:58:01 2017 -0700 Committer: Lars Hofhansl <[email protected]> Committed: Mon May 8 16:58:01 2017 -0700 ---------------------------------------------------------------------- .../covered/update/IndexUpdateManager.java | 12 +- .../index/covered/update/SortedCollection.java | 128 ------------------- 2 files changed, 8 insertions(+), 132 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/a1d3c169/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/update/IndexUpdateManager.java ---------------------------------------------------------------------- diff --git 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 index a183186..5f6020a 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 @@ -23,6 +23,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.TreeSet; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.client.Delete; @@ -109,7 +110,7 @@ public class IndexUpdateManager { ImmutableBytesPtr key = new ImmutableBytesPtr(tableName); Collection<Mutation> updates = map.get(key); if (updates == null) { - updates = new SortedCollection<Mutation>(COMPARATOR); + updates = new TreeSet<Mutation>(COMPARATOR); map.put(key, updates); } fixUpCurrentUpdates(updates, m); @@ -167,9 +168,12 @@ public class IndexUpdateManager { break; } } - - updates.remove(toRemove); - updates.add(pendingMutation); + if (toRemove != null) { + updates.remove(toRemove); + } + if (pendingMutation != null) { + updates.add(pendingMutation); + } } private void markMutationForRemoval(Mutation m) { http://git-wip-us.apache.org/repos/asf/phoenix/blob/a1d3c169/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/update/SortedCollection.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/update/SortedCollection.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/update/SortedCollection.java deleted file mode 100644 index ee8b453..0000000 --- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/update/SortedCollection.java +++ /dev/null @@ -1,128 +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.phoenix.hbase.index.covered.update; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Comparator; -import java.util.Iterator; -import java.util.PriorityQueue; - -import com.google.common.collect.Iterators; - -/** - * A collection whose elements are stored and returned sorted. - * <p> - * We can't just use something like a {@link PriorityQueue} because it doesn't return the - * underlying values in sorted order. - * @param <T> - */ -class SortedCollection<T> implements Collection<T>, Iterable<T> { - - private PriorityQueue<T> queue; - private Comparator<T> comparator; - - /** - * Use the given comparator to compare all keys for sorting - * @param comparator - */ - public SortedCollection(Comparator<T> comparator) { - this.queue = new PriorityQueue<T>(1, comparator); - this.comparator = comparator; - } - - /** - * All passed elements are expected to be {@link Comparable} - */ - public SortedCollection() { - this.queue = new PriorityQueue<T>(); - } - - @Override - public int size() { - return this.queue.size(); - } - - @Override - public boolean isEmpty() { - return this.queue.isEmpty(); - } - - @Override - public boolean contains(Object o) { - return this.queue.contains(o); - } - - @Override - public Iterator<T> iterator() { - @SuppressWarnings("unchecked") - T[] array = (T[]) this.queue.toArray(); - if (this.comparator == null) { - Arrays.sort(array); - } else { - Arrays.sort( - array, this.comparator);} - return Iterators.forArray(array); - } - - @Override - public Object[] toArray() { - return this.queue.toArray(); - } - - @SuppressWarnings("hiding") - @Override - public <T> T[] toArray(T[] a) { - return this.queue.toArray(a); - } - - @Override - public boolean add(T e) { - return this.queue.add(e); - } - - @Override - public boolean remove(Object o) { - return this.queue.remove(o); - } - - @Override - public boolean containsAll(Collection<?> c) { - return this.queue.containsAll(c); - } - - @Override - public boolean addAll(Collection<? extends T> c) { - return this.queue.addAll(c); - } - - @Override - public boolean removeAll(Collection<?> c) { - return queue.removeAll(c); - } - - @Override - public boolean retainAll(Collection<?> c) { - return this.queue.retainAll(c); - } - - @Override - public void clear() { - this.queue.clear(); - } -} \ No newline at end of file
