Copilot commented on code in PR #10854:
URL: https://github.com/apache/gravitino/pull/10854#discussion_r3129374650


##########
dev/ci/hive_catalog_oom_repro.sh:
##########
@@ -0,0 +1,214 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+set -euo pipefail
+
+SERVER="${SERVER:-http://localhost:8090}";
+METALAKE="${METALAKE:-metalake}"
+METASTORE_URIS="${METASTORE_URIS:-}"
+ITERATIONS="${ITERATIONS:-1000}"
+CATALOG_PREFIX="${CATALOG_PREFIX:-hive_oom}"
+SLEEP_MS="${SLEEP_MS:-0}"
+AUTH_HEADER="${AUTH_HEADER:-}"
+CONTINUE_ON_ERROR="${CONTINUE_ON_ERROR:-false}"
+
+usage() {
+  cat <<EOF
+Usage: $0 --metastore-uris <thrift://host:9083> [options]
+
+Required:
+  --metastore-uris <uri>           Hive metastore URI, e.g. 
thrift://localhost:9083
+
+Options:
+  --server <url>                   Gravitino server URL (default: ${SERVER})
+  --metalake <name>                Metalake name (default: ${METALAKE})
+  --iterations <n>                 Loop iterations (default: ${ITERATIONS})
+  --catalog-prefix <prefix>        Catalog prefix (default: ${CATALOG_PREFIX})
+  --sleep-ms <ms>                  Sleep between iterations (default: 
${SLEEP_MS})
+  --auth-header <header>           Extra HTTP header, e.g. "Authorization: 
Bearer xxx"
+  --continue-on-error <true|false> Continue after failures (default: 
${CONTINUE_ON_ERROR})
+  -h, --help                       Show this help
+
+Examples:
+  $0 --metastore-uris thrift://localhost:9083 --iterations 20000
+  $0 --metastore-uris thrift://hive:9083 --auth-header "Authorization: Bearer 
<token>"
+EOF
+}
+
+while [[ $# -gt 0 ]]; do
+  case "$1" in
+    --server)
+      SERVER="$2"
+      shift 2
+      ;;
+    --metalake)
+      METALAKE="$2"
+      shift 2
+      ;;
+    --metastore-uris)
+      METASTORE_URIS="$2"
+      shift 2
+      ;;
+    --iterations)
+      ITERATIONS="$2"
+      shift 2
+      ;;
+    --catalog-prefix)
+      CATALOG_PREFIX="$2"
+      shift 2
+      ;;
+    --sleep-ms)
+      SLEEP_MS="$2"
+      shift 2
+      ;;
+    --auth-header)
+      AUTH_HEADER="$2"
+      shift 2
+      ;;
+    --continue-on-error)
+      CONTINUE_ON_ERROR="$2"
+      shift 2
+      ;;
+    -h|--help)
+      usage
+      exit 0
+      ;;
+    *)
+      echo "Unknown argument: $1" >&2
+      usage
+      exit 1
+      ;;
+  esac
+done
+
+if [[ -z "${METASTORE_URIS}" ]]; then
+  echo "--metastore-uris is required" >&2
+  usage
+  exit 1
+fi
+
+if ! [[ "${ITERATIONS}" =~ ^[0-9]+$ && "${ITERATIONS}" -gt 0 ]]; then
+  echo "--iterations must be a positive integer" >&2
+  exit 1
+fi
+
+if ! [[ "${SLEEP_MS}" =~ ^[0-9]+$ ]]; then
+  echo "--sleep-ms must be a non-negative integer" >&2
+  exit 1
+fi
+
+if [[ "${CONTINUE_ON_ERROR}" != "true" && "${CONTINUE_ON_ERROR}" != "false" 
]]; then
+  echo "--continue-on-error must be true or false" >&2
+  exit 1
+fi
+
+HEADERS=(
+  -H "Accept: application/vnd.gravitino.v1+json"
+  -H "Content-Type: application/json"
+)
+if [[ -n "${AUTH_HEADER}" ]]; then
+  HEADERS+=(-H "${AUTH_HEADER}")
+fi
+
+request() {
+  local method="$1"
+  local path="$2"
+  local body="${3:-}"
+  if [[ -n "${body}" ]]; then
+    curl -sS --fail-with-body -X "${method}" "${HEADERS[@]}" --data "${body}" \
+      "${SERVER}/api${path}" >/dev/null
+  else
+    curl -sS --fail-with-body -X "${method}" "${HEADERS[@]}" \
+      "${SERVER}/api${path}" >/dev/null
+  fi
+}
+
+drop_catalog_force() {
+  local catalog="$1"
+  curl -sS --fail-with-body -X DELETE "${HEADERS[@]}" \
+    "${SERVER}/api/metalakes/${METALAKE}/catalogs/${catalog}?force=true" 
>/dev/null || true

Review Comment:
   `curl --fail-with-body` is intended to keep the response body available on 
HTTP errors, but the function redirects stdout to `/dev/null`, which discards 
the body and defeats the purpose. Consider capturing the response (or sending 
it to stderr) and only silencing output on success, so failures include the 
server-provided body for debugging.
   ```suggestion
     local response=""
     local status=0
   
     if [[ -n "${body}" ]]; then
       response="$(
         curl -sS --fail-with-body -X "${method}" "${HEADERS[@]}" --data 
"${body}" \
           "${SERVER}/api${path}"
       )" || status=$?
     else
       response="$(
         curl -sS --fail-with-body -X "${method}" "${HEADERS[@]}" \
           "${SERVER}/api${path}"
       )" || status=$?
     fi
   
     if [[ ${status} -ne 0 ]]; then
       if [[ -n "${response}" ]]; then
         printf '%s\n' "${response}" >&2
       fi
       return "${status}"
     fi
   }
   
   drop_catalog_force() {
     local catalog="$1"
     request "DELETE" "/metalakes/${METALAKE}/catalogs/${catalog}?force=true" 
|| true
   ```



##########
dev/ci/hive_catalog_oom_repro.sh:
##########
@@ -0,0 +1,214 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+set -euo pipefail
+
+SERVER="${SERVER:-http://localhost:8090}";
+METALAKE="${METALAKE:-metalake}"
+METASTORE_URIS="${METASTORE_URIS:-}"
+ITERATIONS="${ITERATIONS:-1000}"
+CATALOG_PREFIX="${CATALOG_PREFIX:-hive_oom}"
+SLEEP_MS="${SLEEP_MS:-0}"
+AUTH_HEADER="${AUTH_HEADER:-}"
+CONTINUE_ON_ERROR="${CONTINUE_ON_ERROR:-false}"
+
+usage() {
+  cat <<EOF
+Usage: $0 --metastore-uris <thrift://host:9083> [options]
+
+Required:
+  --metastore-uris <uri>           Hive metastore URI, e.g. 
thrift://localhost:9083
+
+Options:
+  --server <url>                   Gravitino server URL (default: ${SERVER})
+  --metalake <name>                Metalake name (default: ${METALAKE})
+  --iterations <n>                 Loop iterations (default: ${ITERATIONS})
+  --catalog-prefix <prefix>        Catalog prefix (default: ${CATALOG_PREFIX})
+  --sleep-ms <ms>                  Sleep between iterations (default: 
${SLEEP_MS})
+  --auth-header <header>           Extra HTTP header, e.g. "Authorization: 
Bearer xxx"
+  --continue-on-error <true|false> Continue after failures (default: 
${CONTINUE_ON_ERROR})
+  -h, --help                       Show this help
+
+Examples:
+  $0 --metastore-uris thrift://localhost:9083 --iterations 20000
+  $0 --metastore-uris thrift://hive:9083 --auth-header "Authorization: Bearer 
<token>"
+EOF
+}
+
+while [[ $# -gt 0 ]]; do
+  case "$1" in
+    --server)
+      SERVER="$2"
+      shift 2
+      ;;
+    --metalake)
+      METALAKE="$2"
+      shift 2
+      ;;
+    --metastore-uris)
+      METASTORE_URIS="$2"
+      shift 2
+      ;;
+    --iterations)
+      ITERATIONS="$2"
+      shift 2
+      ;;
+    --catalog-prefix)
+      CATALOG_PREFIX="$2"
+      shift 2
+      ;;
+    --sleep-ms)
+      SLEEP_MS="$2"
+      shift 2
+      ;;
+    --auth-header)
+      AUTH_HEADER="$2"
+      shift 2
+      ;;
+    --continue-on-error)
+      CONTINUE_ON_ERROR="$2"
+      shift 2
+      ;;
+    -h|--help)
+      usage
+      exit 0
+      ;;
+    *)
+      echo "Unknown argument: $1" >&2
+      usage
+      exit 1
+      ;;
+  esac
+done
+
+if [[ -z "${METASTORE_URIS}" ]]; then
+  echo "--metastore-uris is required" >&2
+  usage
+  exit 1
+fi
+
+if ! [[ "${ITERATIONS}" =~ ^[0-9]+$ && "${ITERATIONS}" -gt 0 ]]; then
+  echo "--iterations must be a positive integer" >&2
+  exit 1
+fi
+
+if ! [[ "${SLEEP_MS}" =~ ^[0-9]+$ ]]; then
+  echo "--sleep-ms must be a non-negative integer" >&2
+  exit 1
+fi
+
+if [[ "${CONTINUE_ON_ERROR}" != "true" && "${CONTINUE_ON_ERROR}" != "false" 
]]; then
+  echo "--continue-on-error must be true or false" >&2
+  exit 1
+fi
+
+HEADERS=(
+  -H "Accept: application/vnd.gravitino.v1+json"
+  -H "Content-Type: application/json"
+)
+if [[ -n "${AUTH_HEADER}" ]]; then
+  HEADERS+=(-H "${AUTH_HEADER}")
+fi
+
+request() {
+  local method="$1"
+  local path="$2"
+  local body="${3:-}"
+  if [[ -n "${body}" ]]; then
+    curl -sS --fail-with-body -X "${method}" "${HEADERS[@]}" --data "${body}" \
+      "${SERVER}/api${path}" >/dev/null
+  else
+    curl -sS --fail-with-body -X "${method}" "${HEADERS[@]}" \
+      "${SERVER}/api${path}" >/dev/null
+  fi
+}
+
+drop_catalog_force() {
+  local catalog="$1"
+  curl -sS --fail-with-body -X DELETE "${HEADERS[@]}" \
+    "${SERVER}/api/metalakes/${METALAKE}/catalogs/${catalog}?force=true" 
>/dev/null || true
+}
+
+run_id="$(date +%s)"

Review Comment:
   `run_id` uses `date +%s` (1-second resolution). If this script is started 
twice within the same second (common in parallel stress runs/CI), catalog names 
can collide and cause false failures. Use a higher-entropy suffix (e.g., 
nanoseconds or a random component) to ensure uniqueness across concurrent runs.
   ```suggestion
   run_id="$(printf '%s_%s_%s%s' "$(date +%s)" "${BASHPID}" "${RANDOM}" 
"${RANDOM}")"
   ```



##########
catalogs/hive-metastore-common/src/main/java/org/apache/gravitino/hive/HiveClientPool.java:
##########
@@ -69,6 +69,23 @@ protected boolean isConnectionException(Exception e) {
     return false;
   }
 
+  @Override
+  public void close() {
+    if (isClosed()) {
+      return;
+    }
+
+    try {
+      super.close();
+    } finally {
+      closeClientFactory();
+    }
+  }
+
+  void closeClientFactory() {
+    clientFactory.close();
+  }
+

Review Comment:
   `closeClientFactory()` appears to be introduced primarily for test 
verification, but leaving it as an unannotated package-private method adds 
production API surface within the package. Consider marking it 
`@VisibleForTesting` (consistent with patterns like `CachedClientPool`), or 
otherwise structuring the test to verify `HiveClientFactory#close()` without 
adding a new callable method on the pool.
   ```suggestion
         clientFactory.close();
       }
     }
   ```



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