morrySnow commented on code in PR #53334:
URL: https://github.com/apache/doris/pull/53334#discussion_r2284205356
##########
fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java:
##########
@@ -3285,6 +3285,8 @@ private boolean createOlapTable(Database db,
CreateTableStmt stmt) throws UserEx
if (replicaAlloc.isNotSet()) {
replicaAlloc = ReplicaAllocation.DEFAULT_ALLOCATION;
}
+ LOG.info("rewriteReplicaAllocationProperties, properties={},
replicaAlloc={}, num={}",
+ stmt.getProperties(), replicaAlloc,
replicaAlloc.getTotalReplicaNum());
Review Comment:
debug level?
##########
regression-test/suites/session_var/table_replica_count_override.groovy:
##########
@@ -0,0 +1,64 @@
+// 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("table_replica_count_override", "p0") {
+ sql """ set table_replica_count_override = 3; """
+ def result = sql """ show variables like "%table_replica_count_override%";
"""
+ assertEquals(result.size(), 1)
+
+ result = """ show backends; """
+ if (result.size() <= 1) {
+ try {
+ sql """
+ CREATE TABLE IF NOT EXISTS test_replica_count (
+ id int,
+ name varchar(255)
+ )
+ DISTRIBUTED BY HASH(id) BUCKETS 1
+ PROPERTIES (
+ "replication_num" = "1"
+ )
+ """
+ } catch (Exception e) {
+ logger.info("result, ${e.getMessage()}")
+ }
Review Comment:
use
```
test {
sql "..."
exception "..."
}
```
##########
fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java:
##########
@@ -703,10 +703,13 @@ public class SessionVariable implements Serializable,
Writable {
public static final String DISABLE_INVERTED_INDEX_V1_FOR_VARIANT =
"disable_inverted_index_v1_for_variant";
+ public static final String TABLE_REPLICA_COUNT_OVERRIDE =
"table_replica_count_override";
+
// enable variant flatten nested as session variable, default is false,
// which means do not flatten nested when create table
public static final String ENABLE_VARIANT_FLATTEN_NESTED =
"enable_variant_flatten_nested";
+
Review Comment:
more than one blank line
##########
fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java:
##########
@@ -1392,6 +1395,23 @@ public enum IgnoreSplitType {
@VariableMgr.VarAttr(name = DISABLE_INVERTED_INDEX_V1_FOR_VARIANT,
needForward = true)
private boolean disableInvertedIndexV1ForVaraint = true;
+ @VariableMgr.VarAttr(name = TABLE_REPLICA_COUNT_OVERRIDE, needForward =
true,
+ description = {"The variable tableReplicaCountOverrideis used to
enable test programs "
+ + "to run successfully in both single-BE (Backend) and
multi-BE environments."
+ + "\nIt ensures that:"
+ + "\nIn single-BE environments, tables are created with
1 replica by default"
+ + "\nIn multi-BE environments, tables are created with
multiple replicas by default"
+ + "\nWhile still allowing creation of single-replica
tables in multi-BE environments when needed"})
Review Comment:
add chinese desc?
##########
fe/fe-core/src/main/java/org/apache/doris/common/util/PropertyAnalyzer.java:
##########
@@ -1749,32 +1749,38 @@ public ImmutableList<RewriteProperty>
getForceProperties() {
return forceProperties;
}
+ /**
+ * tableReplicaCountOverrideForTest: force override table's replica count.
+ * 0: not override.
+ * 1~n: override replica numbers to tableReplicaCountOverrideForTest
+ */
private static Map<String, String> rewriteReplicaAllocationProperties(
- String ctl, String db, Map<String, String> properties) {
- if (Config.force_olap_table_replication_num <= 0) {
+ String ctl, String db, Map<String, String> properties, int
tableReplicaCountOverrideForTest) {
+ LOG.info("rewriteReplicaAllocationProperties={}",
tableReplicaCountOverrideForTest);
+ if (tableReplicaCountOverrideForTest <= 0) {
return rewriteReplicaAllocationPropertiesByDatabase(ctl, db,
properties);
}
- // if force_olap_table_replication_num is set, use this value to
rewrite the replication_num or
- // replication_allocation properties
Map<String, String> newProperties = properties;
if (newProperties == null) {
newProperties = Maps.newHashMap();
}
boolean rewrite = false;
if
(newProperties.containsKey(PropertyAnalyzer.PROPERTIES_REPLICATION_NUM)) {
newProperties.put(PropertyAnalyzer.PROPERTIES_REPLICATION_NUM,
- String.valueOf(Config.force_olap_table_replication_num));
+ String.valueOf(tableReplicaCountOverrideForTest));
rewrite = true;
}
if
(newProperties.containsKey(PropertyAnalyzer.PROPERTIES_REPLICATION_ALLOCATION))
{
newProperties.put(PropertyAnalyzer.PROPERTIES_REPLICATION_ALLOCATION,
- new ReplicaAllocation((short)
Config.force_olap_table_replication_num).toCreateStmt());
+ new ReplicaAllocation((short)
tableReplicaCountOverrideForTest).toCreateStmt());
rewrite = true;
}
if (!rewrite) {
newProperties.put(PropertyAnalyzer.PROPERTIES_REPLICATION_NUM,
- String.valueOf(Config.force_olap_table_replication_num));
+ String.valueOf(tableReplicaCountOverrideForTest));
}
+
+ LOG.info("rewriteReplicaAllocationProperties properties={}",
newProperties);
Review Comment:
debug level?
--
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]