Skip to content
Closed
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 @@ -665,4 +665,16 @@ private ConfigNodeMessages() {}
public static final String
EXCEPTION_FAILED_TO_CREATE_OR_ALTER_TOPIC_MODE_CONSENSUS_DOES_NOT_SUPPORT_TOPIC_ATTRIBUTES_ARG_3C2D0BDA =
"Failed to create or alter topic, mode=consensus does not support topic attributes %s";
public static final String
LOG_REJECT_CREATEREGIONGROUPSPLAN_BECAUSE_DATABASE_ARG_DOES_NOT_EXIST_616E0CDE =
"Reject CreateRegionGroupsPlan because database {} does not exist";
public static final String
LOG_REJECT_CREATEREGIONGROUPSPLAN_BECAUSE_DATABASE_ARG_IS_BEING_DELETED_C085AC01 =
"Reject CreateRegionGroupsPlan because database {} is being deleted";
public static final String
MESSAGE_CREATE_REGIONGROUPS_FAILED_BECAUSE_DATABASE_ARG_DOES_NOT_EXIST_AF0F2440 =
"Create RegionGroups failed because database %s does not exist";
public static final String
MESSAGE_CREATE_REGIONGROUPS_FAILED_BECAUSE_DATABASE_ARG_IS_BEING_DELETED_651DB780 =
"Create RegionGroups failed because database %s is being deleted";
}
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,11 @@ private ManagerMessages() {}
public static final String MESSAGE_SCHEMA_ENGINE_MODE_E37ED98C = "schema_engine_mode";
public static final String MESSAGE_TAG_ATTRIBUTE_TOTAL_SIZE_AF658CFE = "tag_attribute_total_size";
public static final String MESSAGE_DATABASE_LIMIT_THRESHOLD_45C23274 = "database_limit_threshold";
public static final String
MESSAGE_DATABASE_ARG_STILL_HAS_UNFINISHED_LIFECYCLE_PROCEDURES_67573924 =
"Database %s still has unfinished lifecycle procedures";
public static final String MESSAGE_SOME_OTHER_TASK_IS_DELETING_DATABASE_ARG_7BDB2C0F =
"Some other task is deleting database %s";
public static final String LOG_UNEXPECTED_ERROR_HAPPENED_SETTING_SPACE_QUOTA_DATABASE_ARG_F6ED7586 = "Unexpected error happened while setting space quota on database: %s ";
public static final String LOG_UNEXPECTED_ERROR_HAPPENED_SETTING_THROTTLE_QUOTA_USER_ARG_C111BE81 = "Unexpected error happened while setting throttle quota on user: %s ";
public static final String LOG_SCHEMA_TEMPLATE_NEED_TWO_FILES_1E57542A = "schema_template need two files";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -710,4 +710,16 @@ private ConfigNodeMessages() {}
public static final String
EXCEPTION_FAILED_TO_CREATE_OR_ALTER_TOPIC_MODE_CONSENSUS_DOES_NOT_SUPPORT_TOPIC_ATTRIBUTES_ARG_3C2D0BDA =
"创建或修改 topic 失败,mode=consensus 不支持 topic 属性 %s";
public static final String
LOG_REJECT_CREATEREGIONGROUPSPLAN_BECAUSE_DATABASE_ARG_DOES_NOT_EXIST_616E0CDE =
"拒绝 CreateRegionGroupsPlan,因为数据库 {} 不存在";
public static final String
LOG_REJECT_CREATEREGIONGROUPSPLAN_BECAUSE_DATABASE_ARG_IS_BEING_DELETED_C085AC01 =
"拒绝 CreateRegionGroupsPlan,因为数据库 {} 正在删除";
public static final String
MESSAGE_CREATE_REGIONGROUPS_FAILED_BECAUSE_DATABASE_ARG_DOES_NOT_EXIST_AF0F2440 =
"创建 RegionGroups 失败,因为数据库 %s 不存在";
public static final String
MESSAGE_CREATE_REGIONGROUPS_FAILED_BECAUSE_DATABASE_ARG_IS_BEING_DELETED_651DB780 =
"创建 RegionGroups 失败,因为数据库 %s 正在删除";
}
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,11 @@ private ManagerMessages() {}
public static final String MESSAGE_SCHEMA_ENGINE_MODE_E37ED98C = "schema_engine_mode";
public static final String MESSAGE_TAG_ATTRIBUTE_TOTAL_SIZE_AF658CFE = "tag_attribute_total_size";
public static final String MESSAGE_DATABASE_LIMIT_THRESHOLD_45C23274 = "database_limit_threshold";
public static final String
MESSAGE_DATABASE_ARG_STILL_HAS_UNFINISHED_LIFECYCLE_PROCEDURES_67573924 =
"数据库 %s 仍有未完成的生命周期流程";
public static final String MESSAGE_SOME_OTHER_TASK_IS_DELETING_DATABASE_ARG_7BDB2C0F =
"其他任务正在删除数据库 %s";
public static final String LOG_UNEXPECTED_ERROR_HAPPENED_SETTING_SPACE_QUOTA_DATABASE_ARG_F6ED7586 = "设置数据库 %s 的空间配额时发生意外错误 ";
public static final String LOG_UNEXPECTED_ERROR_HAPPENED_SETTING_THROTTLE_QUOTA_USER_ARG_C111BE81 = "设置用户 %s 的限流配额时发生意外错误 ";
public static final String LOG_SCHEMA_TEMPLATE_NEED_TWO_FILES_1E57542A = "schema_template 需要两个文件";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import org.apache.iotdb.confignode.consensus.request.write.procedure.UpdateProcedurePlan;
import org.apache.iotdb.confignode.consensus.request.write.quota.SetSpaceQuotaPlan;
import org.apache.iotdb.confignode.consensus.request.write.quota.SetThrottleQuotaPlan;
import org.apache.iotdb.confignode.consensus.request.write.region.BatchRemoveRegionCreateTasksPlan;
import org.apache.iotdb.confignode.consensus.request.write.region.CreateRegionGroupsPlan;
import org.apache.iotdb.confignode.consensus.request.write.region.OfferRegionMaintainTasksPlan;
import org.apache.iotdb.confignode.consensus.request.write.region.PollRegionMaintainTaskPlan;
Expand Down Expand Up @@ -266,6 +267,9 @@ public static ConfigPhysicalPlan create(final ByteBuffer buffer) throws IOExcept
case PollSpecificRegionMaintainTask:
plan = new PollSpecificRegionMaintainTaskPlan();
break;
case BatchRemoveRegionCreateTasks:
plan = new BatchRemoveRegionCreateTasksPlan();
break;
case CreateSchemaPartition:
plan = new CreateSchemaPartitionPlan();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public enum ConfigPhysicalPlanType {
AddRegionLocation((short) 311),
RemoveRegionLocation((short) 312),
GetRegionGroupsByTime((short) 313),
BatchRemoveRegionCreateTasks((short) 314),

/** Partition. */
GetSchemaPartition((short) 400),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* 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.
*/

package org.apache.iotdb.confignode.consensus.request.write.region;

import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlan;
import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlanType;

import org.apache.tsfile.utils.ReadWriteIOUtils;

import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Objects;

/**
* Removes every queued RegionCreateTask that belongs to the specified pre-deleted database.
*
* <p>The state machine ignores this plan when the database is missing or active, so replaying a
* cancellation cannot affect a later database incarnation that reuses the same name.
*/
public class BatchRemoveRegionCreateTasksPlan extends ConfigPhysicalPlan {

private String database;

public BatchRemoveRegionCreateTasksPlan() {
super(ConfigPhysicalPlanType.BatchRemoveRegionCreateTasks);
}

public BatchRemoveRegionCreateTasksPlan(final String database) {
super(ConfigPhysicalPlanType.BatchRemoveRegionCreateTasks);
this.database = database;
}

public String getDatabase() {
return database;
}

@Override
protected void serializeImpl(DataOutputStream stream) throws IOException {
stream.writeShort(getType().getPlanType());
ReadWriteIOUtils.write(database, stream);
}

@Override
protected void deserializeImpl(ByteBuffer buffer) throws IOException {
database = ReadWriteIOUtils.readString(buffer);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof BatchRemoveRegionCreateTasksPlan)) {
return false;
}
final BatchRemoveRegionCreateTasksPlan that = (BatchRemoveRegionCreateTasksPlan) o;
return Objects.equals(database, that.database);
}

@Override
public int hashCode() {
return Objects.hash(database);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ public class ProcedureManager {
private final PartitionTableAutoCleaner partitionTableCleaner;

private final ReentrantLock tableLock = new ReentrantLock();
private final ReentrantLock databaseLifecycleAdmissionLock = new ReentrantLock();

public ProcedureManager(ConfigManager configManager, ProcedureInfo procedureInfo) {
this.configManager = configManager;
Expand Down Expand Up @@ -1501,18 +1502,27 @@ private static TDataNodeLocation buildFakeDataNodeLocation(int dataNodeId, Strin

// endregion

public CreateRegionGroupsProcedure submitCreateRegionGroups(
final TConsensusGroupType consensusGroupType,
final CreateRegionGroupsPlan createRegionGroupsPlan) {
final CreateRegionGroupsProcedure procedure =
new CreateRegionGroupsProcedure(consensusGroupType, createRegionGroupsPlan);
// Reentrant for PartitionManager, which holds the same admission lock while allocating the
// plan. Keeping this guard here also makes a future direct submission visible atomically to
// same-name database creation.
try (final AutoCloseableLock ignored = acquireDatabaseLifecycleAdmissionLock()) {
executor.submitProcedure(procedure);
}
return procedure;
}

/**
* Generate {@link CreateRegionGroupsProcedure} and wait until it finished.
* Wait until a {@link CreateRegionGroupsProcedure} finishes.
*
* @return {@link TSStatusCode#SUCCESS_STATUS} if all RegionGroups have been created successfully,
* {@link TSStatusCode#CREATE_REGION_ERROR} otherwise
*/
public TSStatus createRegionGroups(
final TConsensusGroupType consensusGroupType,
final CreateRegionGroupsPlan createRegionGroupsPlan) {
final CreateRegionGroupsProcedure procedure =
new CreateRegionGroupsProcedure(consensusGroupType, createRegionGroupsPlan);
executor.submitProcedure(procedure);
public TSStatus waitCreateRegionGroups(final CreateRegionGroupsProcedure procedure) {
final TSStatus status = waitingProcedureFinished(procedure);
if (status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
return status;
Expand All @@ -1522,6 +1532,21 @@ public TSStatus createRegionGroups(
}
}

public AutoCloseableLock acquireDatabaseLifecycleAdmissionLock() {
return AutoCloseableLock.acquire(databaseLifecycleAdmissionLock);
}

public boolean hasUnfinishedDatabaseLifecycleProcedure(final String database) {
return executor.getProcedures().values().stream()
.filter(procedure -> !procedure.isFinished())
.anyMatch(
procedure ->
(procedure instanceof DeleteDatabaseProcedure
&& database.equals(((DeleteDatabaseProcedure) procedure).getDatabase()))
|| (procedure instanceof CreateRegionGroupsProcedure
&& ((CreateRegionGroupsProcedure) procedure).containsDatabase(database)));
}

/**
* Generate {@link CreateTriggerProcedure} and wait until it finished.
*
Expand Down
Loading
Loading