github-actions[bot] commented on code in PR #62578:
URL: https://github.com/apache/doris/pull/62578#discussion_r3115698372


##########
fe/be-java-extensions/max-compute-connector/src/main/java/org/apache/doris/maxcompute/MaxComputeJniScanner.java:
##########
@@ -253,166 +234,55 @@ protected int getNext() throws IOException {
         return readVectors(expectedRows);
     }
 
-    private VectorSchemaRoot getNextBatch() throws IOException {
-        try {
-            if (!currentSplitReader.hasNext()) {
-                currentSplitReader.close();
-                currentSplitReader = null;
-                return null;
-            }
-            return currentSplitReader.get();
-        } catch (Exception e) {
-            String errorMsg = "MaxComputeJniScanner readVectors get batch 
fail";
-            LOG.warn(errorMsg, e);
-            throw new IOException(e.getMessage(), e);
-        }
-    }
-
     private int readVectors(int expectedRows) throws IOException {
         int curReadRows = 0;
-        long accumulatedBytes = 0;
         while (curReadRows < expectedRows) {
-            // Stop early if accumulated variable-width bytes approach int32 
limit
-            if (accumulatedBytes >= MAX_BATCH_BYTES) {
-                break;
-            }
-            if (currentBatch == null) {
-                currentBatch = getNextBatch();
-                if (currentBatch == null || currentBatch.getRowCount() == 0) {
-                    currentBatch = null;
+            try {
+                if (!currentSplitReader.hasNext()) {
+                    currentSplitReader.close();
+                    currentSplitReader = null;
                     break;
                 }
-                currentBatchRowOffset = 0;
+            } catch (Exception e) {
+                String errorMsg = "MaxComputeJniScanner readVectors hasNext 
fail";
+                LOG.warn(errorMsg, e);
+                throw new IOException(e.getMessage(), e);
             }
+
             try {
-                int rowsToAppend = Math.min(expectedRows - curReadRows,
-                        currentBatch.getRowCount() - currentBatchRowOffset);
-                List<FieldVector> fieldVectors = 
currentBatch.getFieldVectors();
-
-                // Limit rows to avoid int32 overflow in VectorColumn's String 
byte buffer
-                rowsToAppend = limitRowsByVarWidthBytes(
-                        fieldVectors, currentBatchRowOffset, rowsToAppend,
-                        MAX_BATCH_BYTES - accumulatedBytes);
-                if (rowsToAppend <= 0) {
+                VectorSchemaRoot data = currentSplitReader.get();
+                if (data.getRowCount() == 0) {

Review Comment:
   The old implementation intentionally kept 
`currentBatch/currentBatchRowOffset` plus a 256 MB var-width byte cap so one 
large MaxCompute Arrow batch could be drained across multiple Doris batches. 
After this rewrite we always append the full `currentSplitReader.get()` batch 
here, ignoring both `expectedRows` and the previous byte budget. Since 
`VectorColumn.reserve()` will happily grow beyond the initial `batchSize`, a 
single large MaxCompute batch can again materialize multi-GB off-heap columns 
and huge BE blocks. Please keep a carry-over buffer or otherwise split 
oversized Arrow batches before appending them to `VectorTable`.



##########
be/src/util/jni_native_method.cpp:
##########
@@ -17,16 +17,100 @@
 
 #include "util/jni_native_method.h"
 
+#include <gen_cpp/FrontendService.h>
 #include <glog/logging.h>
 
+#include <chrono>
 #include <cstdlib>
+#include <thread>
 #include <vector>
 
+#include "common/status.h"
 #include "jni.h"
+#include "runtime/exec_env.h"
+#include "util/client_cache.h"
 #include "util/defer_op.h"
+#include "util/thrift_rpc_helper.h"
 
 namespace doris {
 
+namespace {
+
+void throw_java_runtime_exception(JNIEnv* env, const std::string& message) {
+    jclass exception_cl = env->FindClass("java/lang/IllegalStateException");
+    if (exception_cl != nullptr) {
+        env->ThrowNew(exception_cl, message.c_str());
+        env->DeleteLocalRef(exception_cl);
+    }
+}
+
+Result<int64_t> request_maxcompute_block_id_from_fe(int64_t txn_id,
+                                                    const std::string& 
write_session_id) {
+    if (txn_id <= 0) {
+        return ResultError(Status::InvalidArgument(
+                "invalid MaxCompute txn_id for block_id allocation: {}", 
txn_id));
+    }
+    if (write_session_id.empty()) {
+        return ResultError(Status::InvalidArgument(
+                "empty MaxCompute write_session_id for block_id allocation"));
+    }
+
+    constexpr uint32_t FETCH_BLOCK_ID_MAX_RETRY_TIMES = 3;
+    TNetworkAddress master_addr = 
ExecEnv::GetInstance()->cluster_info()->master_fe_addr;
+    for (uint32_t retry_times = 0; retry_times < 
FETCH_BLOCK_ID_MAX_RETRY_TIMES; retry_times++) {
+        TMaxComputeBlockIdRequest request;
+        TMaxComputeBlockIdResult result;
+        request.__set_txn_id(txn_id);
+        request.__set_write_session_id(write_session_id);
+        request.__set_length(1);
+
+        Status rpc_status = ThriftRpcHelper::rpc<FrontendServiceClient>(
+                master_addr.hostname, master_addr.port,
+                [&request, &result](FrontendServiceConnection& client) {
+                    client->getMaxComputeBlockIdRange(result, request);
+                });
+
+        if (rpc_status.is<ErrorCode::NOT_MASTER>()) {
+            LOG(WARNING) << "Failed to allocate MaxCompute block_id, requested 
non-master FE@"

Review Comment:
   `FrontendServiceImpl.getMaxComputeBlockIdRange()` reports follower/error 
cases through `result.status`, not through the transport status. When this RPC 
hits a follower FE, `rpc_status` is still OK, so this branch never runs; we 
fall through to `result.length != 1`, retry the same follower, and finally 
return a generic RPC error. The same also swallows real FE-side errors such as 
session mismatch or block-id exhaustion, because their `ANALYSIS_ERROR` never 
gets surfaced back to Java. Please inspect `result.status` first (handle 
`NOT_MASTER` by switching to `result.master_address`, and return the FE error 
message for other non-OK statuses) before trusting `start/length`.



##########
fe/be-java-extensions/max-compute-connector/src/main/java/org/apache/doris/maxcompute/MaxComputeJniScanner.java:
##########
@@ -225,17 +215,8 @@ public void open() throws IOException {
 
     @Override
     public void close() throws IOException {
-        if (currentSplitReader != null) {
-            try {
-                currentSplitReader.close();
-            } catch (Exception e) {
-                LOG.warn("Failed to close MaxCompute split reader for table " 
+ project + "." + table, e);
-            }
-        }
         startOffset = -1;
         splitSize = -1;
-        currentBatch = null;
-        currentBatchRowOffset = 0;
         currentSplitReader = null;
         settings = null;

Review Comment:
   `close()` no longer closes `currentSplitReader`. The EOF path in 
`readVectors()` still closes it, but cancellation/error paths now leak the 
underlying MaxCompute reader because `JniReader::close()` always ends up here 
even when the scan stops before EOF. Please keep the previous best-effort 
`currentSplitReader.close()` in `close()`.



##########
fe/be-java-extensions/max-compute-connector/src/main/java/org/apache/doris/maxcompute/MaxComputeJniWriter.java:
##########
@@ -150,15 +138,19 @@ public MaxComputeJniWriter(int batchSize, Map<String, 
String> params) {
         this.project = Objects.requireNonNull(params.get(PROJECT), "required 
property '" + PROJECT + "'.");
         this.tableName = Objects.requireNonNull(params.get(TABLE), "required 
property '" + TABLE + "'.");
         this.quota = params.getOrDefault(QUOTA, "");
+        this.txnId = Long.parseLong(Objects.requireNonNull(params.get(TXN_ID),
+                "required property '" + TXN_ID + "'."));

Review Comment:
   `txn_id` was added as an optional thrift field, but the new writer now makes 
it mandatory. During a rolling upgrade, a new BE/Java extension can still 
receive `TMaxComputeTableSink` from an old FE that does not populate field 18; 
in that case `params.get(TXN_ID)` is null and every MaxCompute insert fails 
before the old local block-id path can run. We need a compatibility fallback 
here (for example, keep the old `block_id`-based allocator when `txn_id` is 
absent) instead of treating the new field as required.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to