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 2014/10/10 08:58:22 UTC
[2/2] git commit: PHOENIX-1309 Remove getGuidePosts() methods and
access through PTableStats instead
PHOENIX-1309 Remove getGuidePosts() methods and access through PTableStats instead
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/71d6d1a1
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/71d6d1a1
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/71d6d1a1
Branch: refs/heads/4.0
Commit: 71d6d1a1e657c45b525eec10867bc04c686505bf
Parents: b1d1995
Author: James Taylor <jt...@salesforce.com>
Authored: Fri Oct 10 00:02:06 2014 -0700
Committer: James Taylor <jt...@salesforce.com>
Committed: Fri Oct 10 00:02:06 2014 -0700
----------------------------------------------------------------------
.../org/apache/phoenix/end2end/QueryIT.java | 20 +--
.../coprocessor/generated/PTableProtos.java | 122 ++++---------------
.../query/ConnectionQueryServicesImpl.java | 1 +
.../apache/phoenix/schema/PColumnFamily.java | 3 -
.../phoenix/schema/PColumnFamilyImpl.java | 19 ---
.../java/org/apache/phoenix/schema/PTable.java | 7 --
.../org/apache/phoenix/schema/PTableImpl.java | 53 ++------
.../phoenix/schema/stats/PTableStats.java | 7 ++
.../phoenix/schema/stats/PTableStatsImpl.java | 18 +++
.../phoenix/schema/stats/StatisticsScanner.java | 2 -
.../java/org/apache/phoenix/util/SizedUtil.java | 5 +
phoenix-protocol/src/main/PTable.proto | 2 +-
12 files changed, 79 insertions(+), 180 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/71d6d1a1/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java
index 07cb624..083c220 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java
@@ -204,7 +204,7 @@ public class QueryIT extends BaseQueryIT {
}
private void testNoStringValue(String value) throws Exception {
- String url = getUrl() + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 1);
+ String url = getUrl() + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 10);
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection upsertConn = DriverManager.getConnection(url, props);
upsertConn.setAutoCommit(true); // Test auto commit
@@ -215,13 +215,15 @@ public class QueryIT extends BaseQueryIT {
stmt.setString(2, ROW5);
stmt.setString(3, value);
stmt.execute(); // should commit too
+ upsertConn.close();
+
+ props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 20));
Connection conn1 = DriverManager.getConnection(getUrl(), props);
analyzeTable(conn1, "ATABLE");
conn1.close();
- upsertConn.close();
String query = "SELECT a_string, b_string FROM aTable WHERE organization_id=? and a_integer = 5";
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2));
+ props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
PreparedStatement statement = conn.prepareStatement(query);
@@ -813,15 +815,15 @@ public class QueryIT extends BaseQueryIT {
public void testSumOverNullIntegerColumn() throws Exception {
String query = "SELECT sum(a_integer) FROM aTable a";
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2));
+ props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 20));
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.setAutoCommit(true);
conn.createStatement().execute("UPSERT INTO atable(organization_id,entity_id,a_integer) VALUES('" + getOrganizationId() + "','" + ROW3 + "',NULL)");
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 6));
+ props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
Connection conn1 = DriverManager.getConnection(getUrl(), props);
analyzeTable(conn1, "ATABLE");
conn1.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 5));
+ props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 50));
conn = DriverManager.getConnection(getUrl(), props);
try {
PreparedStatement statement = conn.prepareStatement(query);
@@ -832,15 +834,15 @@ public class QueryIT extends BaseQueryIT {
} finally {
conn.close();
}
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 7));
+ props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 70));
conn = DriverManager.getConnection(getUrl(), props);
conn.setAutoCommit(true);
conn.createStatement().execute("UPSERT INTO atable(organization_id,entity_id,a_integer) SELECT organization_id, entity_id, null FROM atable");
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 6));
+ props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 60));
conn1 = DriverManager.getConnection(getUrl(), props);
analyzeTable(conn1, "ATABLE");
conn1.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 9));
+ props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 90));
conn = DriverManager.getConnection(getUrl(), props);
try {
PreparedStatement statement = conn.prepareStatement(query);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/71d6d1a1/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/generated/PTableProtos.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/generated/PTableProtos.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/generated/PTableProtos.java
index ef0ece2..866870f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/generated/PTableProtos.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/generated/PTableProtos.java
@@ -1578,20 +1578,15 @@ public final class PTableProtos {
public interface PTableStatsOrBuilder
extends com.google.protobuf.MessageOrBuilder {
- // required string key = 1;
+ // required bytes key = 1;
/**
- * <code>required string key = 1;</code>
+ * <code>required bytes key = 1;</code>
*/
boolean hasKey();
/**
- * <code>required string key = 1;</code>
+ * <code>required bytes key = 1;</code>
*/
- java.lang.String getKey();
- /**
- * <code>required string key = 1;</code>
- */
- com.google.protobuf.ByteString
- getKeyBytes();
+ com.google.protobuf.ByteString getKey();
// repeated bytes values = 2;
/**
@@ -1714,47 +1709,20 @@ public final class PTableProtos {
}
private int bitField0_;
- // required string key = 1;
+ // required bytes key = 1;
public static final int KEY_FIELD_NUMBER = 1;
- private java.lang.Object key_;
+ private com.google.protobuf.ByteString key_;
/**
- * <code>required string key = 1;</code>
+ * <code>required bytes key = 1;</code>
*/
public boolean hasKey() {
return ((bitField0_ & 0x00000001) == 0x00000001);
}
/**
- * <code>required string key = 1;</code>
+ * <code>required bytes key = 1;</code>
*/
- public java.lang.String getKey() {
- java.lang.Object ref = key_;
- if (ref instanceof java.lang.String) {
- return (java.lang.String) ref;
- } else {
- com.google.protobuf.ByteString bs =
- (com.google.protobuf.ByteString) ref;
- java.lang.String s = bs.toStringUtf8();
- if (bs.isValidUtf8()) {
- key_ = s;
- }
- return s;
- }
- }
- /**
- * <code>required string key = 1;</code>
- */
- public com.google.protobuf.ByteString
- getKeyBytes() {
- java.lang.Object ref = key_;
- if (ref instanceof java.lang.String) {
- com.google.protobuf.ByteString b =
- com.google.protobuf.ByteString.copyFromUtf8(
- (java.lang.String) ref);
- key_ = b;
- return b;
- } else {
- return (com.google.protobuf.ByteString) ref;
- }
+ public com.google.protobuf.ByteString getKey() {
+ return key_;
}
// repeated bytes values = 2;
@@ -1781,7 +1749,7 @@ public final class PTableProtos {
}
private void initFields() {
- key_ = "";
+ key_ = com.google.protobuf.ByteString.EMPTY;
values_ = java.util.Collections.emptyList();
}
private byte memoizedIsInitialized = -1;
@@ -1801,7 +1769,7 @@ public final class PTableProtos {
throws java.io.IOException {
getSerializedSize();
if (((bitField0_ & 0x00000001) == 0x00000001)) {
- output.writeBytes(1, getKeyBytes());
+ output.writeBytes(1, key_);
}
for (int i = 0; i < values_.size(); i++) {
output.writeBytes(2, values_.get(i));
@@ -1817,7 +1785,7 @@ public final class PTableProtos {
size = 0;
if (((bitField0_ & 0x00000001) == 0x00000001)) {
size += com.google.protobuf.CodedOutputStream
- .computeBytesSize(1, getKeyBytes());
+ .computeBytesSize(1, key_);
}
{
int dataSize = 0;
@@ -1988,7 +1956,7 @@ public final class PTableProtos {
public Builder clear() {
super.clear();
- key_ = "";
+ key_ = com.google.protobuf.ByteString.EMPTY;
bitField0_ = (bitField0_ & ~0x00000001);
values_ = java.util.Collections.emptyList();
bitField0_ = (bitField0_ & ~0x00000002);
@@ -2046,9 +2014,7 @@ public final class PTableProtos {
public Builder mergeFrom(org.apache.phoenix.coprocessor.generated.PTableProtos.PTableStats other) {
if (other == org.apache.phoenix.coprocessor.generated.PTableProtos.PTableStats.getDefaultInstance()) return this;
if (other.hasKey()) {
- bitField0_ |= 0x00000001;
- key_ = other.key_;
- onChanged();
+ setKey(other.getKey());
}
if (!other.values_.isEmpty()) {
if (values_.isEmpty()) {
@@ -2091,49 +2057,24 @@ public final class PTableProtos {
}
private int bitField0_;
- // required string key = 1;
- private java.lang.Object key_ = "";
+ // required bytes key = 1;
+ private com.google.protobuf.ByteString key_ = com.google.protobuf.ByteString.EMPTY;
/**
- * <code>required string key = 1;</code>
+ * <code>required bytes key = 1;</code>
*/
public boolean hasKey() {
return ((bitField0_ & 0x00000001) == 0x00000001);
}
/**
- * <code>required string key = 1;</code>
+ * <code>required bytes key = 1;</code>
*/
- public java.lang.String getKey() {
- java.lang.Object ref = key_;
- if (!(ref instanceof java.lang.String)) {
- java.lang.String s = ((com.google.protobuf.ByteString) ref)
- .toStringUtf8();
- key_ = s;
- return s;
- } else {
- return (java.lang.String) ref;
- }
- }
- /**
- * <code>required string key = 1;</code>
- */
- public com.google.protobuf.ByteString
- getKeyBytes() {
- java.lang.Object ref = key_;
- if (ref instanceof String) {
- com.google.protobuf.ByteString b =
- com.google.protobuf.ByteString.copyFromUtf8(
- (java.lang.String) ref);
- key_ = b;
- return b;
- } else {
- return (com.google.protobuf.ByteString) ref;
- }
+ public com.google.protobuf.ByteString getKey() {
+ return key_;
}
/**
- * <code>required string key = 1;</code>
+ * <code>required bytes key = 1;</code>
*/
- public Builder setKey(
- java.lang.String value) {
+ public Builder setKey(com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
@@ -2143,7 +2084,7 @@ public final class PTableProtos {
return this;
}
/**
- * <code>required string key = 1;</code>
+ * <code>required bytes key = 1;</code>
*/
public Builder clearKey() {
bitField0_ = (bitField0_ & ~0x00000001);
@@ -2151,19 +2092,6 @@ public final class PTableProtos {
onChanged();
return this;
}
- /**
- * <code>required string key = 1;</code>
- */
- public Builder setKeyBytes(
- com.google.protobuf.ByteString value) {
- if (value == null) {
- throw new NullPointerException();
- }
- bitField0_ |= 0x00000001;
- key_ = value;
- onChanged();
- return this;
- }
// repeated bytes values = 2;
private java.util.List<com.google.protobuf.ByteString> values_ = java.util.Collections.emptyList();
@@ -5721,7 +5649,7 @@ public final class PTableProtos {
"le\030\005 \001(\005\022\020\n\010nullable\030\006 \002(\010\022\020\n\010position\030\007" +
" \002(\005\022\021\n\tsortOrder\030\010 \002(\005\022\021\n\tarraySize\030\t \001" +
"(\005\022\024\n\014viewConstant\030\n \001(\014\022\026\n\016viewReferenc" +
- "ed\030\013 \001(\010\"*\n\013PTableStats\022\013\n\003key\030\001 \002(\t\022\016\n\006" +
+ "ed\030\013 \001(\010\"*\n\013PTableStats\022\013\n\003key\030\001 \002(\014\022\016\n\006" +
"values\030\002 \003(\014\"\212\004\n\006PTable\022\027\n\017schemaNameByt" +
"es\030\001 \002(\014\022\026\n\016tableNameBytes\030\002 \002(\014\022\036\n\ttabl" +
"eType\030\003 \002(\0162\013.PTableType\022\022\n\nindexState\030\004",
http://git-wip-us.apache.org/repos/asf/phoenix/blob/71d6d1a1/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
index 40b6bc4..9223b0b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
@@ -1901,6 +1901,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
sqlE = new SQLException(e);
} finally {
try {
+ if (tenantId.length == 0) tableStatsCache.invalidate(SchemaUtil.getTableName(schemaName, tableName));
htable.close();
} catch (IOException e) {
if (sqlE == null) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/71d6d1a1/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnFamily.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnFamily.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnFamily.java
index 01c236f..24da14d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnFamily.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnFamily.java
@@ -18,7 +18,6 @@
package org.apache.phoenix.schema;
import java.util.Collection;
-import java.util.List;
/**
*
@@ -52,6 +51,4 @@ public interface PColumnFamily {
PColumn getColumn(String name) throws ColumnNotFoundException;
int getEstimatedSize();
-
- List<byte[]> getGuidePosts();
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/phoenix/blob/71d6d1a1/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnFamilyImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnFamilyImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnFamilyImpl.java
index 9841233..2e29656 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnFamilyImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PColumnFamilyImpl.java
@@ -17,7 +17,6 @@
*/
package org.apache.phoenix.schema;
-import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -35,7 +34,6 @@ public class PColumnFamilyImpl implements PColumnFamily {
private final Map<String, PColumn> columnByString;
private final Map<byte[], PColumn> columnByBytes;
private final int estimatedSize;
- private List<byte[]> guidePosts = Collections.emptyList();
@Override
public int getEstimatedSize() {
@@ -43,22 +41,10 @@ public class PColumnFamilyImpl implements PColumnFamily {
}
public PColumnFamilyImpl(PName name, List<PColumn> columns) {
- this(name, columns, null);
- }
-
- public PColumnFamilyImpl(PName name, List<PColumn> columns, List<byte[]> guidePosts) {
Preconditions.checkNotNull(name);
// Include guidePosts also in estimating the size
long estimatedSize = SizedUtil.OBJECT_SIZE + SizedUtil.POINTER_SIZE * 5 + SizedUtil.INT_SIZE + name.getEstimatedSize() +
SizedUtil.sizeOfMap(columns.size()) * 2 + SizedUtil.sizeOfArrayList(columns.size());
- if(guidePosts != null) {
- int guidePostsSize = guidePosts.size();
- estimatedSize += SizedUtil.sizeOfArrayList(guidePostsSize);
- for(byte[] gps : guidePosts) {
- estimatedSize += gps.length;
- }
- this.guidePosts = guidePosts;
- }
this.name = name;
this.columns = ImmutableList.copyOf(columns);
ImmutableMap.Builder<String, PColumn> columnByStringBuilder = ImmutableMap.builder();
@@ -100,9 +86,4 @@ public class PColumnFamilyImpl implements PColumnFamily {
}
return column;
}
-
- @Override
- public List<byte[]> getGuidePosts() {
- return guidePosts;
- }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/71d6d1a1/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
index 3ea08e1..4193200 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
@@ -252,13 +252,6 @@ public interface PTable {
*/
int newKey(ImmutableBytesWritable key, byte[][] values);
- /**
- * Return the statistics table associated with this PTable. A list of
- * guide posts are return
- * @return the statistics table.
- */
- List<byte[]> getGuidePosts();
-
RowKeySchema getRowKeySchema();
/**
http://git-wip-us.apache.org/repos/asf/phoenix/blob/71d6d1a1/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
index d883259..fdafc59 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
@@ -115,7 +115,6 @@ public class PTableImpl implements PTable {
private Short viewIndexId;
private int estimatedSize;
private IndexType indexType;
- private List<byte[]> guidePosts = Collections.emptyList();
private PTableStats tableStats = PTableStats.EMPTY_STATS;
public PTableImpl() {
@@ -357,24 +356,13 @@ public class PTableImpl implements PTable {
estimatedSize += rowKeySchema.getEstimatedSize();
Iterator<Map.Entry<PName,List<PColumn>>> iterator = familyMap.entrySet().iterator();
PColumnFamily[] families = new PColumnFamily[familyMap.size()];
- if (families.length == 0) {
- byte[] defaultFamilyNameBytes = (defaultFamilyName == null) ? QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES : defaultFamilyName.getBytes();
- List<byte[]> guidePosts = stats.getGuidePosts().get(defaultFamilyNameBytes);
- if (guidePosts != null) {
- this.guidePosts = guidePosts;
- estimatedSize += SizedUtil.sizeOfArrayList(guidePosts.size());
- for (byte[] gps : guidePosts) {
- estimatedSize += gps.length;
- }
- }
- }
+ estimatedSize += this.tableStats.getEstimatedSize();
ImmutableMap.Builder<String, PColumnFamily> familyByString = ImmutableMap.builder();
ImmutableSortedMap.Builder<byte[], PColumnFamily> familyByBytes = ImmutableSortedMap
.orderedBy(Bytes.BYTES_COMPARATOR);
for (int i = 0; i < families.length; i++) {
Map.Entry<PName,List<PColumn>> entry = iterator.next();
- List<byte[]> famGuidePosts = stats.getGuidePosts().get(entry.getKey().getBytes());
- PColumnFamily family = new PColumnFamilyImpl(entry.getKey(), entry.getValue(), famGuidePosts);
+ PColumnFamily family = new PColumnFamilyImpl(entry.getKey(), entry.getValue());
families[i] = family;
familyByString.put(family.getName().getString(), family);
familyByBytes.put(family.getName().getBytes(), family);
@@ -726,11 +714,6 @@ public class PTableImpl implements PTable {
}
@Override
- public List<byte[]> getGuidePosts() {
- return guidePosts;
- }
-
- @Override
public PColumn getPKColumn(String name) throws ColumnNotFoundException {
List<PColumn> columns = columnsByName.get(name);
int size = columns.size();
@@ -892,8 +875,10 @@ public class PTableImpl implements PTable {
for (int j = 0; j < pTableStatsProto.getValuesCount(); j++) {
value.add(pTableStatsProto.getValues(j).toByteArray());
}
- tableGuidePosts.put(pTableStatsProto.getKeyBytes().toByteArray(), value);
+ tableGuidePosts.put(pTableStatsProto.getKey().toByteArray(), value);
}
+ PTableStats stats = new PTableStatsImpl(tableGuidePosts);
+
PName dataTableName = null;
if (table.hasDataTableNameBytes()) {
dataTableName = PNameFactory.newName(table.getDataTableNameBytes().toByteArray());
@@ -920,7 +905,6 @@ public class PTableImpl implements PTable {
}
}
- PTableStats stats = new PTableStatsImpl(tableGuidePosts);
try {
PTableImpl result = new PTableImpl();
result.init(tenantId, schemaName, tableName, tableType, indexState, timeStamp, sequenceNumber, pkName,
@@ -978,28 +962,13 @@ public class PTableImpl implements PTable {
}
builder.setIsImmutableRows(table.isImmutableRows());
- // build stats for the table
- if (table.getColumnFamilies().isEmpty() && !table.getGuidePosts().isEmpty()) {
- List<byte[]> stats = table.getGuidePosts();
- if (stats != null) {
- PTableProtos.PTableStats.Builder statsBuilder = PTableProtos.PTableStats.newBuilder();
- statsBuilder.setKey(Bytes.toString(SchemaUtil.getEmptyColumnFamily(table)));
- for (byte[] stat : stats) {
- statsBuilder.addValues(HBaseZeroCopyByteString.wrap(stat));
- }
- builder.addGuidePosts(statsBuilder.build());
+ for (Map.Entry<byte[], List<byte[]>> entry : table.getTableStats().getGuidePosts().entrySet()) {
+ PTableProtos.PTableStats.Builder statsBuilder = PTableProtos.PTableStats.newBuilder();
+ statsBuilder.setKey(HBaseZeroCopyByteString.wrap(entry.getKey()));
+ for (byte[] stat : entry.getValue()) {
+ statsBuilder.addValues(HBaseZeroCopyByteString.wrap(stat));
}
- } else {
- for (PColumnFamily fam : table.getColumnFamilies()) {
- PTableProtos.PTableStats.Builder statsBuilder = PTableProtos.PTableStats.newBuilder();
- if (fam.getGuidePosts() != null) {
- statsBuilder.setKey(fam.getName().getString());
- for (byte[] stat : fam.getGuidePosts()) {
- statsBuilder.addValues(HBaseZeroCopyByteString.wrap(stat));
- }
- builder.addGuidePosts(statsBuilder.build());
- }
- }
+ builder.addGuidePosts(statsBuilder.build());
}
if (table.getParentName() != null) {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/71d6d1a1/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/PTableStats.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/PTableStats.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/PTableStats.java
index 40309e4..0782a2b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/PTableStats.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/PTableStats.java
@@ -33,6 +33,11 @@ public interface PTableStats {
public SortedMap<byte[], List<byte[]>> getGuidePosts() {
return ImmutableSortedMap.of();
}
+
+ @Override
+ public int getEstimatedSize() {
+ return 0;
+ }
};
/**
@@ -41,4 +46,6 @@ public interface PTableStats {
* @return
*/
SortedMap<byte[], List<byte[]>> getGuidePosts();
+
+ int getEstimatedSize();
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/71d6d1a1/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/PTableStatsImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/PTableStatsImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/PTableStatsImpl.java
index 02ecb20..5d7d2ac 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/PTableStatsImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/PTableStatsImpl.java
@@ -23,6 +23,7 @@ import java.util.SortedMap;
import java.util.TreeMap;
import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.util.SizedUtil;
import com.sun.istack.NotNull;
@@ -31,6 +32,7 @@ import com.sun.istack.NotNull;
*/
public class PTableStatsImpl implements PTableStats {
private final SortedMap<byte[], List<byte[]>> guidePosts;
+ private final int estimatedSize;
public PTableStatsImpl() {
this(new TreeMap<byte[], List<byte[]>>(Bytes.BYTES_COMPARATOR));
@@ -38,6 +40,17 @@ public class PTableStatsImpl implements PTableStats {
public PTableStatsImpl(@NotNull SortedMap<byte[], List<byte[]>> guidePosts) {
this.guidePosts = guidePosts;
+ int estimatedSize = SizedUtil.OBJECT_SIZE + SizedUtil.INT_SIZE + SizedUtil.sizeOfTreeMap(guidePosts.size());
+ for (Map.Entry<byte[], List<byte[]>> entry : guidePosts.entrySet()) {
+ byte[] cf = entry.getKey();
+ estimatedSize += SizedUtil.ARRAY_SIZE + cf.length;
+ List<byte[]> keys = entry.getValue();
+ estimatedSize += SizedUtil.sizeOfArrayList(keys.size());
+ for (byte[] key : keys) {
+ estimatedSize += SizedUtil.ARRAY_SIZE + key.length;
+ }
+ }
+ this.estimatedSize = estimatedSize;
}
@Override
@@ -65,5 +78,10 @@ public class PTableStatsImpl implements PTableStats {
buf.append("]");
return buf.toString();
}
+
+ @Override
+ public int getEstimatedSize() {
+ return estimatedSize;
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/71d6d1a1/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/StatisticsScanner.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/StatisticsScanner.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/StatisticsScanner.java
index 598f0d2..60b9601 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/StatisticsScanner.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/stats/StatisticsScanner.java
@@ -21,7 +21,6 @@ import org.apache.hadoop.hbase.client.Mutation;
import org.apache.hadoop.hbase.regionserver.HRegion;
import org.apache.hadoop.hbase.regionserver.InternalScanner;
import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.phoenix.util.TimeKeeper;
/**
* The scanner that does the scanning to collect the stats during major compaction.{@link StatisticsCollector}
@@ -81,7 +80,6 @@ public class StatisticsScanner implements InternalScanner {
// update the statistics table
// Just verify if this if fine
ArrayList<Mutation> mutations = new ArrayList<Mutation>();
- long currentTime = TimeKeeper.SYSTEM.getCurrentTime();
if (LOG.isDebugEnabled()) {
LOG.debug("Deleting the stats for the region " + region.getRegionNameAsString()
+ " as part of major compaction");
http://git-wip-us.apache.org/repos/asf/phoenix/blob/71d6d1a1/phoenix-core/src/main/java/org/apache/phoenix/util/SizedUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/SizedUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/SizedUtil.java
index c49b0e7..f82c1b8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/SizedUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/SizedUtil.java
@@ -38,6 +38,7 @@ public class SizedUtil {
public static final int INT_SIZE = 4;
public static final int LONG_SIZE = 8;
+ public static final int TREE_MAP_SIZE = OBJECT_SIZE + INT_SIZE * 2 + POINTER_SIZE * 2;
public static final int MAP_ENTRY_SIZE = OBJECT_SIZE + 3 * POINTER_SIZE + INT_SIZE;
public static final int IMMUTABLE_BYTES_WRITABLE_SIZE = OBJECT_SIZE + INT_SIZE * 2 + ARRAY_SIZE;
public static final int IMMUTABLE_BYTES_PTR_SIZE = IMMUTABLE_BYTES_WRITABLE_SIZE + INT_SIZE;// Extra is an int field which caches hashcode.
@@ -52,6 +53,10 @@ public class SizedUtil {
private SizedUtil() {
}
+ public static int sizeOfTreeMap(int size) {
+ return TREE_MAP_SIZE + (OBJECT_SIZE + INT_SIZE + POINTER_SIZE * 5) * size;
+ }
+
public static int sizeOfArrayList(int capacity) {
return SizedUtil.OBJECT_SIZE + SizedUtil.POINTER_SIZE + SizedUtil.INT_SIZE + SizedUtil.ARRAY_SIZE + SizedUtil.POINTER_SIZE * capacity;
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/71d6d1a1/phoenix-protocol/src/main/PTable.proto
----------------------------------------------------------------------
diff --git a/phoenix-protocol/src/main/PTable.proto b/phoenix-protocol/src/main/PTable.proto
index 3b5f5cf..0edc046 100644
--- a/phoenix-protocol/src/main/PTable.proto
+++ b/phoenix-protocol/src/main/PTable.proto
@@ -47,7 +47,7 @@ message PColumn {
}
message PTableStats {
- required string key = 1;
+ required bytes key = 1;
repeated bytes values = 2;
}