Skip to content

Commit

Permalink
[Fix](group commit) Fix table not found fault when disable group comm…
Browse files Browse the repository at this point in the history
…it (apache#39731)

<!--Describe your changes.-->

selectRedirectBackend param table id is only needed by group commit. In
non group commit mode, if table id is null, we need to ignore it.
  • Loading branch information
Yukang-Lian committed Sep 3, 2024
1 parent 0e9fa3d commit 7108b23
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,20 @@ private Object executeWithoutPassword(HttpServletRequest request,
return new RestBaseResult(e.getMessage());
}
} else {
long tableId = ((OlapTable) ((Database) Env.getCurrentEnv().getCurrentCatalog().getDb(dbName)
.get()).getTable(tableName).get()).getId();
long tableId = -1;
if (groupCommit) {
Optional<?> database = Env.getCurrentEnv().getCurrentCatalog().getDb(dbName);
if (!database.isPresent()) {
return new RestBaseResult("Database not found.");
}

Optional<?> olapTable = ((Database) database.get()).getTable(tableName);
if (!olapTable.isPresent()) {
return new RestBaseResult("OlapTable not found.");
}

tableId = ((OlapTable) olapTable.get()).getId();
}
redirectAddr = selectRedirectBackend(request, groupCommit, tableId);
}

Expand Down Expand Up @@ -337,7 +349,18 @@ private TNetworkAddress selectRedirectBackend(HttpServletRequest request, boolea
Backend backend = Env.getCurrentSystemInfo().getBackend(debugBackendId);
return new TNetworkAddress(backend.getHost(), backend.getHttpPort());
}
return selectLocalRedirectBackend(groupCommit, request, tableId);
if (Config.isCloudMode()) {
String cloudClusterName = getCloudClusterName(request);
if (Strings.isNullOrEmpty(cloudClusterName)) {
throw new LoadException("No cloud cluster name selected.");
}
return selectCloudRedirectBackend(cloudClusterName, request, groupCommit, tableId);
} else {
if (groupCommit && tableId == -1) {
throw new LoadException("Group commit table id wrong.");
}
return selectLocalRedirectBackend(groupCommit, request, tableId);
}
}

private TNetworkAddress selectLocalRedirectBackend(boolean groupCommit, HttpServletRequest request, long tableId)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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.

suite("test_group_commit_stream_load_with_nonexist_db_and_table") {
def tableName = "test_group_commit_stream_load_with_nonexist_db_and_table"
sql "create database if not exists ${tableName}"

try {
def command = "curl --location-trusted -u ${context.config.feHttpUser}:${context.config.feHttpPassword}" +
" -H group_commit:sync_mode" +
" -H column_separator:," +
" -T ${context.config.dataPath}/load_p0/stream_load/test_stream_load1.csv" +
" http://${context.config.feHttpAddress}/api/${tableName}/${tableName}/_stream_load"
log.info("stream load command: ${command}")

def process = command.execute()
code = process.waitFor()
out = process.text
log.info("stream lad result: ${out}".toString())
assertTrue(out.toString().contains("table not found"))
} catch (Exception e) {
logger.info("failed: " + e.getMessage())
assertTrue(false)
} finally {

}
}

0 comments on commit 7108b23

Please sign in to comment.