Copilot commented on code in PR #2718:
URL: https://github.com/apache/phoenix/pull/2718#discussion_r4794604201
##########
phoenix-core-server/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java:
##########
@@ -2981,7 +2981,27 @@ Collections.<byte[]> emptySet(), HConstants.NO_NONCE,
HConstants.NO_NONCE,
// used by buildTable does not include 't' due to how SCN is
implemented.
clientTimeStamp += 1;
}
- PTable newTable = buildTable(tableKey, cacheKey, region,
clientTimeStamp, clientVersion);
+ // The catalog rows are already committed here, so a failed read must
not report a
+ // failure. If the read fails, for example because the region moves,
build the table from
+ // the committed mutations. These mutations carry the server-side
values that the client
+ // needs, such as the last DDL timestamp and the external schema id.
If that build also
+ // fails, return success without the table. The client then builds the
table from its own
+ // metadata.
+ PTable newTable = null;
+ try {
+ newTable = buildTable(tableKey, cacheKey, region, clientTimeStamp,
clientVersion);
+ } catch (IOException | SQLException e) {
+ LOGGER.warn("Could not read {} {} after create, key {}; building it
from mutations",
+ tableType, fullTableName, Bytes.toStringBinary(tableKey), e);
+ try {
+ newTable =
getTableFromMutations(getTableRowMutations(tableMetadata, tableKey),
+ clientTimeStamp, clientVersion, null);
+ } catch (Exception buildException) {
+ LOGGER.warn(
+ "Could not build {} {} from mutations, key {}; returning success
without it",
+ tableType, fullTableName, Bytes.toStringBinary(tableKey),
buildException);
Review Comment:
Catching `Exception` here is overly broad and can accidentally swallow
interrupt signals (e.g., `InterruptedException`) or other unexpected checked
exceptions, making operational behavior harder to reason about. Prefer catching
the concrete expected exceptions (`IOException`, `SQLException`, and optionally
`RuntimeException`). If an interrupt is caught, restore the interrupt flag via
`Thread.currentThread().interrupt()` before returning.
##########
phoenix-core-server/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java:
##########
@@ -2981,7 +2981,27 @@ Collections.<byte[]> emptySet(), HConstants.NO_NONCE,
HConstants.NO_NONCE,
// used by buildTable does not include 't' due to how SCN is
implemented.
clientTimeStamp += 1;
}
- PTable newTable = buildTable(tableKey, cacheKey, region,
clientTimeStamp, clientVersion);
+ // The catalog rows are already committed here, so a failed read must
not report a
+ // failure. If the read fails, for example because the region moves,
build the table from
+ // the committed mutations. These mutations carry the server-side
values that the client
+ // needs, such as the last DDL timestamp and the external schema id.
If that build also
+ // fails, return success without the table. The client then builds the
table from its own
+ // metadata.
+ PTable newTable = null;
+ try {
+ newTable = buildTable(tableKey, cacheKey, region, clientTimeStamp,
clientVersion);
+ } catch (IOException | SQLException e) {
+ LOGGER.warn("Could not read {} {} after create, key {}; building it
from mutations",
+ tableType, fullTableName, Bytes.toStringBinary(tableKey), e);
+ try {
+ newTable =
getTableFromMutations(getTableRowMutations(tableMetadata, tableKey),
+ clientTimeStamp, clientVersion, null);
+ } catch (Exception buildException) {
+ LOGGER.warn(
+ "Could not build {} {} from mutations, key {}; returning success
without it",
+ tableType, fullTableName, Bytes.toStringBinary(tableKey),
buildException);
Review Comment:
This path can be triggered by transient/expected conditions (e.g., region
movement) and may happen in clusters with frequent balancing. Logging at WARN
can create alert fatigue and noisy logs even though the operation ultimately
returns success. Consider lowering to INFO/DEBUG and/or
rate-limiting/throttling this log message while preserving the exception for
diagnostics.
##########
phoenix-core-server/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java:
##########
@@ -3010,8 +3030,11 @@ private void
updateCreateTableDdlSuccessMetrics(PTableType tableType) {
}
}
- private void exportSchema(List<Mutation> tableMetadata, byte[] tableKey,
long clientTimestamp,
- int clientVersion, PTable oldTable) throws SQLException, IOException {
+ /**
+ * Builds a PTable from the catalog mutations of a DDL operation, without a
read from the region.
+ */
+ private PTable getTableFromMutations(List<Mutation> tableMetadata, long
clientTimeStamp,
+ int clientVersion, PTable oldTable) throws IOException, SQLException {
Review Comment:
The new parameter name `clientTimeStamp` is inconsistent with the existing
`clientTimestamp` naming used elsewhere in this class (including
`exportSchema(...)`). Standardizing on one spelling improves readability and
reduces the chance of confusion during future refactors.
##########
phoenix-core-server/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java:
##########
@@ -2981,7 +2981,27 @@ Collections.<byte[]> emptySet(), HConstants.NO_NONCE,
HConstants.NO_NONCE,
// used by buildTable does not include 't' due to how SCN is
implemented.
clientTimeStamp += 1;
}
- PTable newTable = buildTable(tableKey, cacheKey, region,
clientTimeStamp, clientVersion);
+ // The catalog rows are already committed here, so a failed read must
not report a
+ // failure. If the read fails, for example because the region moves,
build the table from
+ // the committed mutations. These mutations carry the server-side
values that the client
+ // needs, such as the last DDL timestamp and the external schema id.
If that build also
+ // fails, return success without the table. The client then builds the
table from its own
+ // metadata.
+ PTable newTable = null;
+ try {
+ newTable = buildTable(tableKey, cacheKey, region, clientTimeStamp,
clientVersion);
+ } catch (IOException | SQLException e) {
+ LOGGER.warn("Could not read {} {} after create, key {}; building it
from mutations",
+ tableType, fullTableName, Bytes.toStringBinary(tableKey), e);
+ try {
+ newTable =
getTableFromMutations(getTableRowMutations(tableMetadata, tableKey),
+ clientTimeStamp, clientVersion, null);
+ } catch (Exception buildException) {
+ LOGGER.warn(
+ "Could not build {} {} from mutations, key {}; returning success
without it",
+ tableType, fullTableName, Bytes.toStringBinary(tableKey),
buildException);
+ }
+ }
Review Comment:
This introduces new correctness-critical behavior (returning success and
optionally reconstructing `PTable` from committed mutations when the
post-commit read fails). Add test coverage that simulates (or injects) a
post-commit `buildTable(...)` failure and asserts: (1) the RPC returns success,
and (2) the returned table is built from mutations when possible, otherwise
success with no table.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]