Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHOENIX-6883 : Phoenix Metadata Caching Redesign #1883

Merged
merged 10 commits into from
Jun 27, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ public long getLastDDLTimestampForTable(byte[] tenantID, byte[] schemaName, byte
properties.setProperty(TENANT_ID_ATTRIB, tenantIDStr);
}
try (Connection connection = getConnection(properties)) {
// Using PhoenixRuntime#getTableNoCache since se don't want to read cached value.
table = PhoenixRuntime.getTableNoCache(connection, fullTableNameStr);
// Using PhoenixRuntime#getTableFromServerNoCache to completely bypass CQSI cache.
table = PhoenixRuntime.getTableFromServerNoCache(connection, schemaName, tableName);
// TODO PhoenixRuntime#getTableNoCache can throw TableNotFoundException.
// In that case, do we want to throw non retryable exception back to the client?
// Update cache with the latest DDL timestamp from SYSCAT server.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
import org.apache.phoenix.thirdparty.com.google.common.collect.ImmutableMap.Builder;
import org.apache.phoenix.trace.util.Tracing;
import org.apache.phoenix.transaction.PhoenixTransactionContext;
import org.apache.phoenix.util.ByteUtil;
import org.apache.phoenix.util.DateUtil;
import org.apache.phoenix.util.EnvironmentEdgeManager;
import org.apache.phoenix.util.JDBCUtil;
Expand Down Expand Up @@ -726,6 +727,20 @@ public PTable getTableNoCache(String name) throws SQLException {
return getTableNoCache(getTenantId(), name);
}

/**
* Returns the most recent PTable fetched from the server without updating the CQSI cache.
*/
public PTable getTableFromServerNoCache(byte[] schemaName, byte[] tableName)
throws SQLException {
MetaDataProtocol.MetaDataMutationResult result =
getQueryServices().getTable(getTenantId(), schemaName,
tableName, HConstants.LATEST_TIMESTAMP, HConstants.LATEST_TIMESTAMP);
if (result.getMutationCode() != MetaDataProtocol.MutationCode.TABLE_ALREADY_EXISTS) {
throw new TableNotFoundException(new String(schemaName), new String(tableName));
}
return result.getTable();
}

/**
* Returns the table if it is found in the client metadata cache. If the metadata of this
* table has changed since it was put in the cache these changes will not necessarily be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.apache.hadoop.hbase.util.Pair;
import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting;
import org.apache.phoenix.compile.QueryPlan;
import org.apache.phoenix.coprocessorclient.MetaDataProtocol;
import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.LiteralExpression;
import org.apache.phoenix.expression.OrderByExpression;
Expand All @@ -71,6 +72,7 @@
import org.apache.phoenix.monitoring.PhoenixTableMetric;
import org.apache.phoenix.monitoring.TableMetricsManager;
import org.apache.phoenix.monitoring.connectionqueryservice.ConnectionQueryServicesMetricsManager;
import org.apache.phoenix.query.ConnectionQueryServices;
import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.schema.AmbiguousColumnException;
Expand Down Expand Up @@ -539,6 +541,18 @@ public static PTable getTable(Connection conn, @Nullable String tenantId, String
return pconn.getTable(tenantId, fullTableName, timestamp);
}

/**
* Returns the most recent PTable fetched from the server without updating the CQSI cache.
*/
public static PTable getTableFromServerNoCache(Connection conn, byte[] schemaName,
palashc marked this conversation as resolved.
Show resolved Hide resolved
byte[] tableName) throws SQLException {
if (schemaName == null) {
schemaName = ByteUtil.EMPTY_BYTE_ARRAY;
}
PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class);
return pconn.getTableFromServerNoCache(schemaName, tableName);
}

/**
* Get list of ColumnInfos that contain Column Name and its associated PDataType for an import.
* The supplied list of columns can be null -- if it is non-null, it represents a user-supplied
Expand Down