Github user JamesRTaylor commented on a diff in the pull request:
https://github.com/apache/phoenix/pull/8#discussion_r16699418
--- Diff:
phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
---
@@ -664,14 +698,161 @@ private PTable getTable(RegionScanner scanner, long
clientTimeStamp, long tableT
} else {
addColumnToTable(results, colName, famName, colKeyValues,
columns, saltBucketNum != null);
}
+ }
+ byte[] tenIdBytes = QueryConstants.EMPTY_BYTE_ARRAY;
+ if (tenantId != null) {
+ tenIdBytes = tenantId.getBytes();
}
-
+ byte[] schNameInBytes = QueryConstants.EMPTY_BYTE_ARRAY;
+ if (schemaName != null) {
+ schNameInBytes = Bytes.toBytes(schemaName.getString());
+ }
+ PTableStats stats = updateStats(SchemaUtil.getTableKey(tenIdBytes,
schNameInBytes, tableNameBytes));
return PTableImpl.makePTable(tenantId, schemaName, tableName,
tableType, indexState, timeStamp,
tableSeqNum, pkName, saltBucketNum, columns, tableType ==
INDEX ? dataTableName : null,
indexes, isImmutableRows, physicalTables, defaultFamilyName,
viewStatement, disableWAL,
- multiTenant, viewType, viewIndexId, indexType);
+ multiTenant, viewType, viewIndexId, indexType, stats);
}
+ private PTableStats updateStats(final byte[] tableNameBytes) {
+ lock.readLock().lock();
+ try {
+ PTableStats stats =
tableStatsMap.get(Bytes.toString(tableNameBytes));
+ return stats;
+ } finally {
+ lock.readLock().unlock();
+ }
+ }
+
+ private void updateStatsInternal(byte[] tableNameBytes,
RegionCoprocessorEnvironment env)
--- End diff --
Yes, the latter, but with the above caveat (to age-out a cache entry - it's
an option on the guava-based Cache): The invalidation is done only when the
schema changes or index is removed/added which also means there is no need for
periodic scanning of stats table.
This will be much simpler and we only have to manage a single cache. Perf
should be fine - it's just an extra Scan and if it was done recently will be in
the block cache anyway.
Make sure you update the size of PTableImpl by taking into account the size
of a PTableStatsImpl so the cache is sized correctly.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---