apurtell commented on code in PR #2718:
URL: https://github.com/apache/phoenix/pull/2718#discussion_r4794845459


##########
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:
   Done in 76529c2ee9. The fallback now catches the I/O, SQL and runtime 
exceptions by name. The build from mutations declares only the first two, so 
the set of exceptions it handles is the same as before. An interrupt cannot 
reach this catch as a checked InterruptedException. Returning success is the 
intent here, because the catalog rows are already committed.
   
   (Claude Code)



##########
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:
   I would keep WARN here. This path runs only when the read of a table that 
was just committed fails in the same RPC. That is rare and unexpected, and an 
operator should see it. A balancer that moves regions often does not cause it 
on its own. The message is one line per affected create, not per request.
   
   (Claude Code)



##########
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:
   Added in 76529c2ee9. A fail-once test hook in the endpoint makes the read 
after a create fail, and optionally the build from mutations too. Two new tests 
in MetaDataEndpointImplIT check both cases. Each create succeeds, and queries 
and upserts work afterwards. When the table comes from the mutations, the 
client keeps the DDL timestamp stored in SYSTEM.CATALOG. When it does not, the 
client builds the table itself and has no server timestamp.
   
   (Claude Code)



##########
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:
   This class spells it clientTimeStamp almost everywhere (about 160 uses). The 
two clientTimestamp uses are in the existing exportSchema method, so the new 
helper follows the class-wide spelling. I left exportSchema unchanged to keep 
this change small.
   
   (Claude Code)



-- 
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]

Reply via email to