Skip to content

Commit

Permalink
fix ut p0
Browse files Browse the repository at this point in the history
  • Loading branch information
deardeng committed Sep 12, 2024
1 parent fbfd1f0 commit cfc7618
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1630,7 +1630,7 @@ private static Map<String, String> rewriteReplicaAllocationProperties(

private static Map<String, String> rewriteReplicaAllocationPropertiesByDatabase(
String ctl, String database, Map<String, String> properties) {
// if table contain `replication_allocation` or `replication_allocation`,not need rewrite by db
// if table contain `replication_allocation` or `replication_num`,not need rewrite by db
if (properties != null && (properties.containsKey(PropertyAnalyzer.PROPERTIES_REPLICATION_ALLOCATION)
|| properties.containsKey(PropertyAnalyzer.PROPERTIES_REPLICATION_NUM))) {
return properties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,19 @@ public Backend selectBackendForGroupCommit(long tableId, ConnectContext context)
throws LoadException, DdlException {
// If a group commit request is sent to the follower FE, we will send this request to the master FE. master FE
// can select a BE and return this BE id to follower FE.
String clusterName = "";
if (Config.isCloudMode()) {
try {
clusterName = context.getCloudCluster();
} catch (Exception e) {
LOG.warn("failed to get cluster name", e);
throw new LoadException(e.getMessage());
}
}
if (!Env.getCurrentEnv().isMaster()) {
try {
long backendId = new MasterOpExecutor(context)
.getGroupCommitLoadBeId(tableId, context.getCloudCluster());
.getGroupCommitLoadBeId(tableId, clusterName);
return Env.getCurrentSystemInfo().getBackend(backendId);
} catch (Exception e) {
throw new LoadException(e.getMessage());
Expand All @@ -202,7 +211,7 @@ public Backend selectBackendForGroupCommit(long tableId, ConnectContext context)
try {
// Master FE will select BE by itself.
return Env.getCurrentSystemInfo()
.getBackend(selectBackendForGroupCommitInternal(tableId, context.getCloudCluster()));
.getBackend(selectBackendForGroupCommitInternal(tableId, clusterName));
} catch (Exception e) {
LOG.warn("get backend failed, tableId: {}, exception", tableId, e);
throw new LoadException(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ private static void logAuditLogImpl(ConnectContext ctx, String origStmt, Stateme
CatalogIf catalog = ctx.getCurrentCatalog();
String cloudCluster = "";
try {
cloudCluster = ctx.getCloudCluster();
if (Config.isCloudMode()) {
cloudCluster = ctx.getCloudCluster();
}
} catch (ClusterException e) {
LOG.warn("Failed to get cloud cluster", e);
}
Expand Down Expand Up @@ -212,7 +214,9 @@ private static void logAuditLogImpl(ConnectContext ctx, String origStmt, Stateme
MetricRepo.COUNTER_QUERY_ALL.increase(1L);
MetricRepo.USER_COUNTER_QUERY_ALL.getOrAdd(ctx.getQualifiedUser()).increase(1L);
try {
cloudCluster = ctx.getCloudCluster(false);
if (Config.isCloudMode()) {
cloudCluster = ctx.getCloudCluster(false);
}
} catch (ClusterException e) {
LOG.warn("Failed to get cloud cluster", e);
return;
Expand Down
71 changes: 0 additions & 71 deletions fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.apache.doris.catalog.FunctionRegistry;
import org.apache.doris.catalog.TableIf;
import org.apache.doris.catalog.Type;
import org.apache.doris.cloud.proto.Cloud;
import org.apache.doris.cloud.qe.ClusterException;
import org.apache.doris.cloud.system.CloudSystemInfoService;
import org.apache.doris.cluster.ClusterNamespace;
Expand Down Expand Up @@ -1154,30 +1153,6 @@ public String toString() {
}
}

public static String cloudNoBackendsReason() throws ClusterException {
StringBuilder sb = new StringBuilder();
if (ConnectContext.get() != null) {
String clusterName = ConnectContext.get().getCloudCluster();
String hits = "or you may not have permission to access the current cluster = ";
sb.append(" ");
if (Strings.isNullOrEmpty(clusterName)) {
return sb.append(hits).append("cluster name empty").toString();
}
String clusterStatus = ((CloudSystemInfoService) Env.getCurrentSystemInfo())
.getCloudStatusByName(clusterName);
if (!Strings.isNullOrEmpty(clusterStatus)
&& Cloud.ClusterStatus.valueOf(clusterStatus)
== Cloud.ClusterStatus.MANUAL_SHUTDOWN) {
LOG.warn("auto start cluster {} in manual shutdown status", clusterName);
sb.append("cluster ").append(clusterName)
.append(" is shutdown manually, please start it first");
} else {
sb.append(hits).append(clusterName);
}
}
return sb.toString();
}

// can't get cluster from context, use the following strategy to obtain the cluster name
// 当用户有多个集群的权限时,会按照如下策略进行拉取:
// 如果当前mysql用户没有指定cluster(没有default 或者 use), 选择有权限的cluster。
Expand Down Expand Up @@ -1302,52 +1277,6 @@ public String getDefaultCloudCluster() {
return null;
}

public String getAuthorizedCloudCluster() throws ClusterException {
List<String> cloudClusterNames = ((CloudSystemInfoService) Env.getCurrentSystemInfo()).getCloudClusterNames();
// get all available cluster of the user
boolean hasAuthCluster = false;
AtomicBoolean selectedClusterHasAliveBe = new AtomicBoolean(false);
String selectedCluster = null;
for (String cloudClusterName : cloudClusterNames) {
if (!Env.getCurrentEnv().getAuth().checkCloudPriv(getCurrentUserIdentity(),
cloudClusterName, PrivPredicate.USAGE, ResourceTypeEnum.CLUSTER)) {
continue;
}
hasAuthCluster = true;
// find a cluster has more than one alive be
selectedCluster = cloudClusterName;
List<Backend> bes = ((CloudSystemInfoService) Env.getCurrentSystemInfo())
.getBackendsByClusterName(cloudClusterName);

bes.stream().filter(Backend::isAlive).findAny().ifPresent(backend -> {
if (LOG.isDebugEnabled()) {
LOG.debug("get a clusterName {}, it's has more than one alive be {}", cloudClusterName, backend);
}
selectedClusterHasAliveBe.set(true);
});
if (selectedClusterHasAliveBe.get()) {
if (LOG.isDebugEnabled()) {
LOG.debug("set context cluster name {}", cloudClusterName);
}
return cloudClusterName;
}
}
if (!hasAuthCluster) {
throw new ClusterException("the user is not granted permission to the cluster",
ClusterException.FailedTypeEnum.CURRENT_USER_NO_AUTH_TO_USE_ANY_CLUSTER);
}

if (!selectedClusterHasAliveBe.get()) {
throw new ClusterException(
String.format("All the Backend nodes in the current cluster %s are in an abnormal state",
selectedCluster),
ClusterException.FailedTypeEnum.CLUSTERS_NO_ALIVE_BE);
}

throw new ClusterException("There are no clusters registered in the current system",
ClusterException.FailedTypeEnum.SYSTEM_NOT_HAVE_CLUSTER);
}

public StatsErrorEstimator getStatsErrorEstimator() {
return statsErrorEstimator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ public void testCreateAndDropWithSql() throws Exception {
+ "PROPERTIES (\n"
+ " 'location'='hdfs://loc/db/tbl',\n"
+ " 'file_format'='orc')";
ExceptionChecker.expectThrowsWithMsg(org.apache.doris.common.UserException.class,
"errCode = 2, detailMessage = errCode = 2,"
ExceptionChecker.expectThrowsWithMsg(org.apache.doris.nereids.exceptions.AnalysisException.class,
"errCode = 2,"
+ " detailMessage = Create hive bucket table need set enable_create_hive_bucket_table to true",
() -> createTable(createBucketedTableErr, true));

Expand Down

0 comments on commit cfc7618

Please sign in to comment.