Skip to content

Commit

Permalink
[Enhancement] optimize storage medium infer when having mixed types (#…
Browse files Browse the repository at this point in the history
…18649)

Signed-off-by: Dejun Xia <xiadejun@starrocks.com>
(cherry picked from commit 9acb8df)
  • Loading branch information
nshangyiming authored and mergify[bot] committed Mar 1, 2023
1 parent 3062b68 commit 000c5e1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
14 changes: 10 additions & 4 deletions fe/fe-core/src/main/java/com/starrocks/catalog/DataProperty.java
Expand Up @@ -24,6 +24,7 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.Sets;
import com.google.gson.annotations.SerializedName;
import com.starrocks.common.Config;
import com.starrocks.common.io.Text;
import com.starrocks.common.io.Writable;
import com.starrocks.common.util.TimeUtils;
Expand Down Expand Up @@ -83,11 +84,16 @@ public static DataProperty getInferredDefaultDataProperty() {

Preconditions.checkState(mediumSet.size() <= 2, "current medium set: " + mediumSet);
TStorageMedium m = TStorageMedium.SSD;
// If the storage paths reported by all the backends all have storage medium type HDD,
// we infer that user wants to create a table or partition with storage_medium=HDD when not explicitly
// specify the storage_medium property, otherwise it's SSD
// When storage_medium property is not explicitly specified on creating table, we infer the storage medium type
// based on the types of storage paths reported by backends. Here is the rules,
// 1. If the storage paths reported by all the backends all have storage medium type HDD,
// we infer that user wants to create a table or partition with storage_medium=HDD.
// 2. If the reported storage paths have both SSD type and HDD type, and storage cool down feature is
// not used, we also infer with HDD type.
// 3. In other cases, it's SSD type.
if (mediumSet.size() == 0 ||
(mediumSet.size() == 1 && mediumSet.iterator().next() == TStorageMedium.HDD)) {
(mediumSet.size() == 1 && mediumSet.iterator().next() == TStorageMedium.HDD) ||
(mediumSet.size() == 2 && Config.tablet_sched_storage_cooldown_second < 0)) {
m = TStorageMedium.HDD;
}

Expand Down
Expand Up @@ -37,7 +37,7 @@

import java.util.List;

public class StorageMediumInfoTest {
public class StorageMediumInferTest {
private static ConnectContext connectContext;
private static Backend be1;
private static Backend be2;
Expand Down Expand Up @@ -99,6 +99,7 @@ public void testCreateTable() throws Exception {

be1.setStorageMediumForAllDisks(TStorageMedium.SSD);
be2.setStorageMediumForAllDisks(TStorageMedium.HDD);
Config.tablet_sched_storage_cooldown_second = 123123213L;
createTable("create table test.tbl3(key1 int, key2 varchar(10)) \n" +
"distributed by hash(key1) buckets 10 properties('replication_num' = '1');");
OlapTable tbl3 = (OlapTable) db.getTable("tbl3");
Expand All @@ -107,6 +108,16 @@ public void testCreateTable() throws Exception {
globalStateMgr.getDataPropertyIncludeRecycleBin(tbl3.getPartitionInfo(),
partitionList3.get(0).getId());
Assert.assertEquals(TStorageMedium.SSD, dataProperty3.getStorageMedium());

Config.tablet_sched_storage_cooldown_second = -1L; // default value, no storage cool down
createTable("create table test.tbl4(key1 int, key2 varchar(10)) \n" +
"distributed by hash(key1) buckets 10 properties('replication_num' = '1');");
OlapTable tbl4 = (OlapTable) db.getTable("tbl4");
List<Partition> partitionList4 = Lists.newArrayList(tbl4.getPartitions());
DataProperty dataProperty4 =
globalStateMgr.getDataPropertyIncludeRecycleBin(tbl4.getPartitionInfo(),
partitionList4.get(0).getId());
Assert.assertEquals(TStorageMedium.HDD, dataProperty4.getStorageMedium());
}

@Test
Expand Down

0 comments on commit 000c5e1

Please sign in to comment.