You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2015/05/09 19:16:45 UTC
phoenix git commit: PHOENIX-1958 Minimize memory allocation on new
connection
Repository: phoenix
Updated Branches:
refs/heads/4.x-HBase-0.98 1299c7795 -> 0f15700f2
PHOENIX-1958 Minimize memory allocation on new connection
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/0f15700f
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/0f15700f
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/0f15700f
Branch: refs/heads/4.x-HBase-0.98
Commit: 0f15700f21db454a81cb1dcb30ff3016e5321b38
Parents: 1299c77
Author: James Taylor <jt...@salesforce.com>
Authored: Sat May 9 10:16:19 2015 -0700
Committer: James Taylor <jt...@salesforce.com>
Committed: Sat May 9 10:16:19 2015 -0700
----------------------------------------------------------------------
.../apache/phoenix/jdbc/PhoenixConnection.java | 37 +++++++++++---------
.../org/apache/phoenix/util/ReadOnlyProps.java | 32 +++++++++++++++++
2 files changed, 52 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/0f15700f/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
index 23add8f..e33e8ee 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
@@ -48,7 +48,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Properties;
import java.util.concurrent.Executor;
@@ -102,7 +101,6 @@ import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
/**
@@ -183,21 +181,9 @@ public class PhoenixConnection implements Connection, org.apache.phoenix.jdbc.Jd
if (tenantId != null) {
services = services.getChildQueryServices(tenantId.getBytesPtr());
}
- // TODO: we could avoid creating another wrapper if the only property
- // specified was for the tenant ID
- Map<String, String> existingProps = services.getProps().asMap();
- final Map<String, String> tmpAugmentedProps = Maps.newHashMapWithExpectedSize(existingProps.size() + info.size());
- tmpAugmentedProps.putAll(existingProps);
- boolean needsDelegate = false;
- for (Entry<Object, Object> entry : this.info.entrySet()) {
- String key = entry.getKey().toString();
- String value = entry.getValue().toString();
- String oldValue = tmpAugmentedProps.put(key, value);
- needsDelegate |= !Objects.equal(oldValue, value);
- }
- this.services = !needsDelegate ? services : new DelegateConnectionQueryServices(services) {
- final ReadOnlyProps augmentedProps = new ReadOnlyProps(tmpAugmentedProps);
-
+ ReadOnlyProps currentProps = services.getProps();
+ final ReadOnlyProps augmentedProps = currentProps.addAll(filterKnownNonProperties(this.info));
+ this.services = augmentedProps == currentProps ? services : new DelegateConnectionQueryServices(services) {
@Override
public ReadOnlyProps getProps() {
return augmentedProps;
@@ -256,6 +242,23 @@ public class PhoenixConnection implements Connection, org.apache.phoenix.jdbc.Jd
this.customTracingAnnotations = getImmutableCustomTracingAnnotations();
}
+ private static Properties filterKnownNonProperties(Properties info) {
+ Properties prunedProperties = info;
+ if (info.contains(PhoenixRuntime.CURRENT_SCN_ATTRIB)) {
+ if (prunedProperties == info) {
+ prunedProperties = PropertiesUtil.deepCopy(info);
+ }
+ prunedProperties.remove(PhoenixRuntime.CURRENT_SCN_ATTRIB);
+ }
+ if (info.contains(PhoenixRuntime.TENANT_ID_ATTRIB)) {
+ if (prunedProperties == info) {
+ prunedProperties = PropertiesUtil.deepCopy(info);
+ }
+ prunedProperties.remove(PhoenixRuntime.TENANT_ID_ATTRIB);
+ }
+ return prunedProperties;
+ }
+
private ImmutableMap<String, String> getImmutableCustomTracingAnnotations() {
Builder<String, String> result = ImmutableMap.builder();
result.putAll(JDBCUtil.getAnnotations(url, info));
http://git-wip-us.apache.org/repos/asf/phoenix/blob/0f15700f/phoenix-core/src/main/java/org/apache/phoenix/util/ReadOnlyProps.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/ReadOnlyProps.java b/phoenix-core/src/main/java/org/apache/phoenix/util/ReadOnlyProps.java
index 68b0879..47137ef 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/ReadOnlyProps.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/ReadOnlyProps.java
@@ -23,10 +23,13 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import com.google.common.base.Objects;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
/**
*
@@ -61,6 +64,17 @@ public class ReadOnlyProps implements Iterable<Entry<String, String>> {
this.props = ImmutableMap.copyOf(props);
}
+ private ReadOnlyProps(ReadOnlyProps defaultProps, Properties overrides) {
+ Map<String,String> combinedProps = Maps.newHashMapWithExpectedSize(defaultProps.props.size() + overrides.size());
+ combinedProps.putAll(defaultProps.props);
+ for (Entry<Object, Object> entry : overrides.entrySet()) {
+ String key = entry.getKey().toString();
+ String value = entry.getValue().toString();
+ combinedProps.put(key, value);
+ }
+ this.props = ImmutableMap.copyOf(combinedProps);
+ }
+
private static Pattern varPat = Pattern.compile("\\$\\{[^\\}\\$\u0020]+\\}");
private static int MAX_SUBST = 20;
@@ -269,4 +283,22 @@ public class ReadOnlyProps implements Iterable<Entry<String, String>> {
public boolean isEmpty() {
return props.isEmpty();
}
+
+ /**
+ * Constructs new map only if necessary for adding the override properties.
+ * @param overrides Map of properties to override current properties.
+ * @return new ReadOnlyProps if in applying the overrides there are
+ * modifications to the current underlying Map, otherwise returns this.
+ */
+ public ReadOnlyProps addAll(Properties overrides) {
+ for (Entry<Object, Object> entry : overrides.entrySet()) {
+ String key = entry.getKey().toString();
+ String value = entry.getValue().toString();
+ String oldValue = props.get(key);
+ if (!Objects.equal(oldValue, value)) {
+ return new ReadOnlyProps(this, overrides);
+ }
+ }
+ return this;
+ }
}