Skip to content
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 @@ -665,4 +665,22 @@ 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
LOG_REJECT_CREATEREGIONGROUPSPLAN_BECAUSE_DATABASE_ARG_LIFECYCLE_GENERATION_CHANGED_FROM_ARG_TO_ARG_4306DEC3 =
"Reject CreateRegionGroupsPlan because database {} lifecycle generation changed from {} to {}";
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";
public static final String
MESSAGE_CREATE_REGIONGROUPS_FAILED_BECAUSE_DATABASE_ARG_LIFECYCLE_GENERATION_CHANGED_FROM_ARG_TO_ARG_CCDAF444 =
"Create RegionGroups failed because database %s lifecycle generation changed from %d to %d";
}
Original file line number Diff line number Diff line change
Expand Up @@ -710,4 +710,22 @@ 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
LOG_REJECT_CREATEREGIONGROUPSPLAN_BECAUSE_DATABASE_ARG_LIFECYCLE_GENERATION_CHANGED_FROM_ARG_TO_ARG_4306DEC3 =
"拒绝 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 正在删除";
public static final String
MESSAGE_CREATE_REGIONGROUPS_FAILED_BECAUSE_DATABASE_ARG_LIFECYCLE_GENERATION_CHANGED_FROM_ARG_TO_ARG_CCDAF444 =
"创建 RegionGroups 失败,因为数据库 %s 的生命周期代次已从 %d 变为 %d";
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,47 @@
/** Create regions for specified Databases. */
public class CreateRegionGroupsPlan extends ConfigPhysicalPlan {

public static final long DATABASE_GENERATION_NOT_SET = -1;

// Map<Database, List<TRegionReplicaSet>>
protected final Map<String, List<TRegionReplicaSet>> regionGroupMap;

// Map<Database, lifecycle generation>. It fences a RegionGroup allocation from a later database
// that reuses the same name.
protected final Map<String, Long> databaseGenerationMap;

public CreateRegionGroupsPlan() {
super(ConfigPhysicalPlanType.CreateRegionGroups);
this.regionGroupMap = new HashMap<>();
this.databaseGenerationMap = new HashMap<>();
}

public CreateRegionGroupsPlan(final ConfigPhysicalPlanType type) {
super(type);
this.regionGroupMap = new HashMap<>();
this.databaseGenerationMap = new HashMap<>();
}

public Map<String, List<TRegionReplicaSet>> getRegionGroupMap() {
return regionGroupMap;
}

public Map<String, Long> getDatabaseGenerationMap() {
return databaseGenerationMap;
}

public long getDatabaseGeneration(final String database) {
return databaseGenerationMap.getOrDefault(database, DATABASE_GENERATION_NOT_SET);
}

public boolean isDatabaseGenerationSet(final String database) {
return databaseGenerationMap.containsKey(database);
}

public void setDatabaseGeneration(final String database, final long databaseGeneration) {
databaseGenerationMap.put(database, databaseGeneration);
}

public void addRegionGroup(final String database, final TRegionReplicaSet regionReplicaSet) {
regionGroupMap
.computeIfAbsent(database, regionReplicaSets -> new ArrayList<>())
Expand All @@ -84,17 +108,22 @@ public void planLog(final Logger logger) {
}

public void serializeForProcedure(final DataOutputStream stream) throws IOException {
this.serializeImpl(stream);
serializeRegionGroupMap(stream);
}

public void deserializeForProcedure(final ByteBuffer buffer) throws IOException {
// to remove the planType of ConfigPhysicalPlanType
buffer.getShort();
this.deserializeImpl(buffer);
deserializeRegionGroupMap(buffer);
}

@Override
protected void serializeImpl(final DataOutputStream stream) throws IOException {
serializeRegionGroupMap(stream);
serializeDatabaseGenerationMap(stream);
}

private void serializeRegionGroupMap(final DataOutputStream stream) throws IOException {
stream.writeShort(getType().getPlanType());

stream.writeInt(regionGroupMap.size());
Expand All @@ -111,6 +140,13 @@ protected void serializeImpl(final DataOutputStream stream) throws IOException {

@Override
protected void deserializeImpl(final ByteBuffer buffer) throws IOException {
deserializeRegionGroupMap(buffer);
if (buffer.hasRemaining()) {
deserializeDatabaseGenerationMap(buffer);
}
}

private void deserializeRegionGroupMap(final ByteBuffer buffer) throws IOException {
final int databaseNum = buffer.getInt();
for (int i = 0; i < databaseNum; i++) {
final String database = BasicStructureSerDeUtil.readString(buffer);
Expand All @@ -125,6 +161,21 @@ protected void deserializeImpl(final ByteBuffer buffer) throws IOException {
}
}

public void serializeDatabaseGenerationMap(final DataOutputStream stream) throws IOException {
stream.writeInt(databaseGenerationMap.size());
for (final Entry<String, Long> entry : databaseGenerationMap.entrySet()) {
BasicStructureSerDeUtil.write(entry.getKey(), stream);
stream.writeLong(entry.getValue());
}
}

public void deserializeDatabaseGenerationMap(final ByteBuffer buffer) {
final int databaseNum = buffer.getInt();
for (int i = 0; i < databaseNum; i++) {
databaseGenerationMap.put(BasicStructureSerDeUtil.readString(buffer), buffer.getLong());
}
}

@Override
public boolean equals(final Object o) {
if (this == o) {
Expand All @@ -137,11 +188,12 @@ public boolean equals(final Object o) {
return false;
}
final CreateRegionGroupsPlan that = (CreateRegionGroupsPlan) o;
return Objects.equals(regionGroupMap, that.regionGroupMap);
return Objects.equals(regionGroupMap, that.regionGroupMap)
&& Objects.equals(databaseGenerationMap, that.databaseGenerationMap);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), regionGroupMap);
return Objects.hash(super.hashCode(), regionGroupMap, databaseGenerationMap);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public CreateRegionGroupsPlan genRegionGroupsAllocationPlan(
for (final Map.Entry<String, Integer> entry : allotmentMap.entrySet()) {
final String database = entry.getKey();
final int allotment = entry.getValue();
createRegionGroupsPlan.setDatabaseGeneration(
database, getPartitionManager().getDatabaseGeneration(database));
final int replicationFactor =
getClusterSchemaManager().getReplicationFactor(database, consensusGroupType);
// Only considering the specified Database when doing allocation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,14 @@ public boolean isDatabasePreDeleted(final String database) {
return partitionInfo.isDatabasePreDeleted(database);
}

public long getDatabaseGeneration(final String database) {
return partitionInfo.getDatabaseGeneration(database);
}

public TSStatus validateCreateRegionGroups(final CreateRegionGroupsPlan plan) {
return partitionInfo.validateCreateRegionGroups(plan);
}

/**
* Get TSeriesPartitionSlot.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.iotdb.commons.partition.SchemaPartitionTable;
import org.apache.iotdb.commons.utils.CommonDateTimeUtils;
import org.apache.iotdb.confignode.consensus.request.read.region.GetRegionInfoListPlan;
import org.apache.iotdb.confignode.consensus.request.write.region.CreateRegionGroupsPlan;
import org.apache.iotdb.confignode.i18n.ConfigNodeMessages;
import org.apache.iotdb.confignode.rpc.thrift.TRegionInfo;
import org.apache.iotdb.confignode.rpc.thrift.TShowRegionReq;
Expand Down Expand Up @@ -66,6 +67,8 @@ public class DatabasePartitionTable {
private volatile boolean preDeleted = false;
// The name of database
private String databaseName;
// The incarnation of databaseName. A new value is assigned whenever the name is recreated.
private final long databaseGeneration;

// RegionGroup
private final Map<TConsensusGroupId, RegionGroup> regionGroupMap;
Expand All @@ -75,7 +78,12 @@ public class DatabasePartitionTable {
private final DataPartitionTable dataPartitionTable;

public DatabasePartitionTable(String databaseName) {
this(databaseName, CreateRegionGroupsPlan.DATABASE_GENERATION_NOT_SET);
}

public DatabasePartitionTable(String databaseName, long databaseGeneration) {
this.databaseName = databaseName;
this.databaseGeneration = databaseGeneration;

this.regionGroupMap = new ConcurrentHashMap<>();

Expand All @@ -91,6 +99,10 @@ public void setPreDeleted(boolean preDeleted) {
this.preDeleted = preDeleted;
}

public long getDatabaseGeneration() {
return databaseGeneration;
}

/**
* Update the DataNodeLocation in cached RegionGroups.
*
Expand Down Expand Up @@ -655,14 +667,16 @@ public boolean equals(Object o) {
return false;
}
DatabasePartitionTable that = (DatabasePartitionTable) o;
return databaseName.equals(that.databaseName)
return databaseGeneration == that.databaseGeneration
&& databaseName.equals(that.databaseName)
&& regionGroupMap.equals(that.regionGroupMap)
&& schemaPartitionTable.equals(that.schemaPartitionTable)
&& dataPartitionTable.equals(that.dataPartitionTable);
}

@Override
public int hashCode() {
return Objects.hash(databaseName, regionGroupMap, schemaPartitionTable, dataPartitionTable);
return Objects.hash(
databaseName, databaseGeneration, regionGroupMap, schemaPartitionTable, dataPartitionTable);
}
}
Loading
Loading