Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] cloud table supports property replication_num #52292

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public AlterJobV2 build() throws UserException {
long partitionId = partition.getParentId();
long physicalPartitionId = partition.getId();
long shardGroupId = partition.getShardGroupId();
short replicationNum = table.getPartitionInfo().getReplicationNum(partitionId);
List<Tablet> originTablets = partition.getIndex(originIndexId).getTablets();
// TODO: It is not good enough to create shards into the same group id, schema change PR needs to
// revise the code again.
Expand All @@ -86,7 +87,7 @@ public AlterJobV2 build() throws UserException {
List<Long> shadowTabletIds =
createShards(originTablets.size(), table.getPartitionFilePathInfo(partitionId),
table.getPartitionFileCacheInfo(partitionId), shardGroupId,
originTabletIds, properties, warehouseId);
originTabletIds, properties, warehouseId, replicationNum);
Preconditions.checkState(originTablets.size() == shadowTabletIds.size());

TStorageMedium medium = table.getPartitionInfo().getDataProperty(partitionId).getStorageMedium();
Expand All @@ -112,12 +113,12 @@ public AlterJobV2 build() throws UserException {
@VisibleForTesting
public static List<Long> createShards(int shardCount, FilePathInfo pathInfo, FileCacheInfo cacheInfo,
long groupId, List<Long> matchShardIds, Map<String, String> properties,
long warehouseId)
long warehouseId, short replicationNum)
throws DdlException {
WarehouseManager warehouseManager = GlobalStateMgr.getCurrentState().getWarehouseMgr();
return GlobalStateMgr.getCurrentState().getStarOSAgent()
.createShards(shardCount, pathInfo, cacheInfo, groupId, matchShardIds, properties,
warehouseManager.selectWorkerGroupByWarehouseId(warehouseId)
.orElse(StarOSAgent.DEFAULT_WORKER_GROUP_ID));
.orElse(StarOSAgent.DEFAULT_WORKER_GROUP_ID), replicationNum);
}
}
3 changes: 3 additions & 0 deletions fe/fe-core/src/main/java/com/starrocks/common/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -3280,4 +3280,7 @@ public class Config extends ConfigBase {

@ConfField(mutable = false)
public static int lake_remove_table_thread_num = 4;

@ConfField(mutable = true)
public static int lake_table_max_replication_num = 3;
}
Original file line number Diff line number Diff line change
Expand Up @@ -587,9 +587,12 @@ private static void checkReplicationNum(short replicationNum) {
List<Long> backendIds = GlobalStateMgr.getCurrentState().getNodeMgr().getClusterInfo().getAvailableBackendIds();
if (RunMode.isSharedDataMode()) {
backendIds.addAll(GlobalStateMgr.getCurrentState().getNodeMgr().getClusterInfo().getAvailableComputeNodeIds());
if (RunMode.defaultReplicationNum() > backendIds.size()) {
throw new SemanticException("Number of available CN nodes is " + backendIds.size()
+ ", less than " + RunMode.defaultReplicationNum());
if (backendIds.isEmpty()) {
throw new SemanticException("No alive Backend or Compute Node.");
}
if (replicationNum > Config.lake_table_max_replication_num) {
throw new SemanticException(String.format("Property replication_num should not be bigger than " +
"%d[lake_table_max_replication_num]", Config.lake_table_max_replication_num));
}
} else {
if (replicationNum > backendIds.size()) {
Expand Down
3 changes: 1 addition & 2 deletions fe/fe-core/src/main/java/com/starrocks/lake/LakeTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,8 @@ public Status createTabletsForRestore(int tabletNum, MaterializedIndex index, Gl
properties.put(LakeTablet.PROPERTY_KEY_INDEX_ID, Long.toString(index.getId()));
List<Long> shardIds = null;
try {
// Ignore the parameter replicationNum
shardIds = globalStateMgr.getStarOSAgent().createShards(tabletNum, fsInfo, cacheInfo, shardGroupId, null, properties,
StarOSAgent.DEFAULT_WORKER_GROUP_ID);
StarOSAgent.DEFAULT_WORKER_GROUP_ID, replicationNum);
} catch (DdlException e) {
LOG.error(e.getMessage(), e);
return new Status(Status.ErrCode.COMMON_ERROR, e.getMessage());
Expand Down
4 changes: 2 additions & 2 deletions fe/fe-core/src/main/java/com/starrocks/lake/StarOSAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ public List<ShardGroupInfo> listShardGroup() {

public List<Long> createShards(int numShards, FilePathInfo pathInfo, FileCacheInfo cacheInfo, long groupId,
@Nullable List<Long> matchShardIds, @NotNull Map<String, String> properties,
long workerGroupId)
long workerGroupId, int replicationNum)
throws DdlException {
if (matchShardIds != null) {
Preconditions.checkState(numShards == matchShardIds.size());
Expand All @@ -468,7 +468,7 @@ public List<Long> createShards(int numShards, FilePathInfo pathInfo, FileCacheIn
List<CreateShardInfo> createShardInfoList = new ArrayList<>(numShards);

CreateShardInfo.Builder builder = CreateShardInfo.newBuilder();
builder.setReplicaCount(1)
builder.setReplicaCount(replicationNum)
.addGroupIds(groupId)
.setPathInfo(pathInfo)
.setCacheInfo(cacheInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1600,7 +1600,7 @@ private PhysicalPartition createPhysicalPartition(String name, Database db, Olap
storageMedium, olapTable.isCloudNativeTableOrMaterializedView());

if (olapTable.isCloudNativeTableOrMaterializedView()) {
createLakeTablets(olapTable, id, shardGroupId, index, distributionInfo,
createLakeTablets(olapTable, id, shardGroupId, index, distributionInfo, replicationNum,
tabletMeta, tabletIdSet, warehouseId);
} else {
createOlapTablets(olapTable, index, Replica.ReplicaState.NORMAL, distributionInfo,
Expand Down Expand Up @@ -1766,7 +1766,7 @@ Partition createPartition(Database db, OlapTable table, long partitionId, String
storageMedium, table.isCloudNativeTableOrMaterializedView());

if (table.isCloudNativeTableOrMaterializedView()) {
createLakeTablets(table, partitionId, shardGroupId, index, distributionInfo,
createLakeTablets(table, partitionId, shardGroupId, index, distributionInfo, replicationNum,
tabletMeta, tabletIdSet, warehouseId);
} else {
createOlapTablets(table, index, Replica.ReplicaState.NORMAL, distributionInfo,
Expand Down Expand Up @@ -2006,7 +2006,7 @@ public void replayCreateTable(CreateTableInfo info) {
}

private void createLakeTablets(OlapTable table, long partitionId, long shardGroupId, MaterializedIndex index,
DistributionInfo distributionInfo, TabletMeta tabletMeta,
DistributionInfo distributionInfo, short replicationNum, TabletMeta tabletMeta,
Set<Long> tabletIdSet, long warehouseId)
throws DdlException {
Preconditions.checkArgument(table.isCloudNativeTableOrMaterializedView());
Expand All @@ -2030,7 +2030,7 @@ private void createLakeTablets(OlapTable table, long partitionId, long shardGrou
}
List<Long> shardIds = stateMgr.getStarOSAgent().createShards(bucketNum,
table.getPartitionFilePathInfo(partitionId), table.getPartitionFileCacheInfo(partitionId), shardGroupId,
null, properties, workerGroupId.get());
null, properties, workerGroupId.get(), replicationNum);
for (long shardId : shardIds) {
Tablet tablet = new LakeTablet(shardId);
index.addTablet(tablet, tabletMeta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ public List<ShardGroupInfo> listShardGroup(String serviceId) throws StarClientEx
FileCacheInfo cacheInfo = FileCacheInfo.newBuilder().build();
Assert.assertEquals(Lists.newArrayList(10L, 11L),
starosAgent.createShards(2, pathInfo, cacheInfo, 333, null,
Collections.EMPTY_MAP, StarOSAgent.DEFAULT_WORKER_GROUP_ID));
Collections.EMPTY_MAP, StarOSAgent.DEFAULT_WORKER_GROUP_ID, 1));

// list shard group
List<ShardGroupInfo> realGroupIds = starosAgent.listShardGroup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ public long createShardGroup(long dbId, long tableId, long partitionId) throws D

@Override
public List<Long> createShards(int numShards, FilePathInfo pathInfo, FileCacheInfo cacheInfo,
long groupId, List<Long> matchShardIds, Map<String, String> properties, long workerGroupId)
long groupId, List<Long> matchShardIds, Map<String, String> properties,
long workerGroupId, int replicationNum)
throws DdlException {
List<Long> shardIds = new ArrayList<>();
for (int i = 0; i < numShards; i++) {
Expand Down
Loading