deniskuzZ commented on a change in pull request #1087:
URL: https://github.com/apache/hive/pull/1087#discussion_r447478910



##########
File path: 
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java
##########
@@ -2015,8 +2019,49 @@ public AllocateTableWriteIdsResponse 
allocateTableWriteIds(AllocateTableWriteIds
       return allocateTableWriteIds(rqst);
     }
   }
+
+  @Override
+  public MaxAllocatedTableWriteIdResponse 
getMaxAllocatedTableWrited(MaxAllocatedTableWriteIdRequest rqst) throws 
MetaException {
+    String dbName = rqst.getDbName();
+    String tableName = rqst.getTableName();
+    try {
+      Connection dbConn = null;
+      PreparedStatement pStmt = null;
+      ResultSet rs = null;
+      try {
+        lockInternal();
+        dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED);
+        List<String> params = Arrays.asList(dbName, tableName);
+        String query = "SELECT \"NWI_NEXT\" FROM \"NEXT_WRITE_ID\" WHERE 
\"NWI_DATABASE\" = ? AND \"NWI_TABLE\" = ?";
+        pStmt = sqlGenerator.prepareStmtWithParameters(dbConn, query, params);
+        LOG.debug("Going to execute query <" + query.replaceAll("\\?", "{}") + 
">", quoteString(dbName),
+            quoteString(tableName));
+        rs = pStmt.executeQuery();
+        // If there is no record, we never allocated anything
+        long maxWriteId = 0l;
+        if (rs.next()) {
+          // The row contains the nextId not the previously allocated
+          maxWriteId = rs.getLong(1) - 1;
+        }
+        return new MaxAllocatedTableWriteIdResponse(maxWriteId);
+      } catch (SQLException e) {
+        LOG.error(
+            "Exception during reading the max allocated writeId for dbName={}, 
tableName={}. Will retry if possible.",
+            dbName, tableName, e);
+        rollbackDBConn(dbConn);

Review comment:
       what to rollback, you have select here?




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org
For additional commands, e-mail: gitbox-h...@hive.apache.org

Reply via email to