You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ta...@apache.org on 2023/07/10 07:37:50 UTC
[iotdb] branch jira5993_cp created (now 3ae94673309)
This is an automated email from the ASF dual-hosted git repository.
tanxinyu pushed a change to branch jira5993_cp
in repository https://gitbox.apache.org/repos/asf/iotdb.git
at 3ae94673309 [IOTDB-5993] ConfigNode leader changing causes lacking some DataPartition allocation result in the response of getOrCreateDataPartition method (#10211)
This branch includes the following new commits:
new 3ae94673309 [IOTDB-5993] ConfigNode leader changing causes lacking some DataPartition allocation result in the response of getOrCreateDataPartition method (#10211)
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[iotdb] 01/01: [IOTDB-5993] ConfigNode leader changing causes lacking some DataPartition allocation result in the response of getOrCreateDataPartition method (#10211)
Posted by ta...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tanxinyu pushed a commit to branch jira5993_cp
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 3ae94673309441dbff7de59d2558ac11f9da777c
Author: YongzaoDan <33...@users.noreply.github.com>
AuthorDate: Mon Jun 19 17:59:59 2023 +0800
[IOTDB-5993] ConfigNode leader changing causes lacking some DataPartition allocation result in the response of getOrCreateDataPartition method (#10211)
---
.../manager/partition/PartitionManager.java | 134 ++++++++++++++-------
1 file changed, 88 insertions(+), 46 deletions(-)
diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/manager/partition/PartitionManager.java b/confignode/src/main/java/org/apache/iotdb/confignode/manager/partition/PartitionManager.java
index 85d9fed6b22..b8d1c0e93d8 100644
--- a/confignode/src/main/java/org/apache/iotdb/confignode/manager/partition/PartitionManager.java
+++ b/confignode/src/main/java/org/apache/iotdb/confignode/manager/partition/PartitionManager.java
@@ -237,41 +237,59 @@ public class PartitionManager {
return resp;
}
+ Map<String, SchemaPartitionTable> assignedSchemaPartition;
+ try {
+ assignedSchemaPartition =
+ getLoadManager().allocateSchemaPartition(unassignedSchemaPartitionSlotsMap);
+ } catch (NoAvailableRegionGroupException e) {
+ status = getConsensusManager().confirmLeader();
+ if (status.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+ // The allocation might fail due to leadership change
+ resp.setStatus(status);
+ return resp;
+ }
+
+ LOGGER.error("Create SchemaPartition failed because: ", e);
+ resp.setStatus(
+ new TSStatus(TSStatusCode.NO_AVAILABLE_REGION_GROUP.getStatusCode())
+ .setMessage(e.getMessage()));
+ return resp;
+ }
+
+ // Cache allocating result only if the current ConfigNode still holds its leadership
+ CreateSchemaPartitionPlan createPlan = new CreateSchemaPartitionPlan();
+ createPlan.setAssignedSchemaPartition(assignedSchemaPartition);
status = getConsensusManager().confirmLeader();
if (status.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
// Here we check the leadership second time
// since the RegionGroup creating process might take some time
resp.setStatus(status);
return resp;
- } else {
- // Allocate SchemaPartitions only if
- // the current ConfigNode still holds its leadership
- Map<String, SchemaPartitionTable> assignedSchemaPartition;
- try {
- assignedSchemaPartition =
- getLoadManager().allocateSchemaPartition(unassignedSchemaPartitionSlotsMap);
- } catch (NoAvailableRegionGroupException e) {
- LOGGER.error("Create SchemaPartition failed because: ", e);
- resp.setStatus(
- new TSStatus(TSStatusCode.NO_AVAILABLE_REGION_GROUP.getStatusCode())
- .setMessage(e.getMessage()));
- return resp;
- }
-
- // Cache allocating result
- CreateSchemaPartitionPlan createPlan = new CreateSchemaPartitionPlan();
- createPlan.setAssignedSchemaPartition(assignedSchemaPartition);
- getConsensusManager().write(createPlan);
}
+ getConsensusManager().write(createPlan);
}
resp = (SchemaPartitionResp) getSchemaPartition(req);
if (!resp.isAllPartitionsExist()) {
- LOGGER.error(
- "Lacked some SchemaPartition allocation result in the response of getOrCreateSchemaPartition method");
+ // Count the fail rate
+ AtomicInteger totalSlotNum = new AtomicInteger();
+ req.getPartitionSlotsMap()
+ .forEach((database, partitionSlots) -> totalSlotNum.addAndGet(partitionSlots.size()));
+
+ AtomicInteger unassignedSlotNum = new AtomicInteger();
+ Map<String, List<TSeriesPartitionSlot>> unassignedSchemaPartitionSlotsMap =
+ partitionInfo.filterUnassignedSchemaPartitionSlots(req.getPartitionSlotsMap());
+ unassignedSchemaPartitionSlotsMap.forEach(
+ (database, unassignedSchemaPartitionSlots) ->
+ unassignedSlotNum.addAndGet(unassignedSchemaPartitionSlots.size()));
+
+ String errMsg =
+ String.format(
+ "Lacked %d/%d SchemaPartition allocation result in the response of getOrCreateSchemaPartition method",
+ unassignedSlotNum.get(), totalSlotNum.get());
+ LOGGER.error(errMsg);
resp.setStatus(
- new TSStatus(TSStatusCode.LACK_PARTITION_ALLOCATION.getStatusCode())
- .setMessage("Lacked some SchemaPartition allocation result in the response"));
+ new TSStatus(TSStatusCode.LACK_PARTITION_ALLOCATION.getStatusCode()).setMessage(errMsg));
return resp;
}
return resp;
@@ -343,41 +361,65 @@ public class PartitionManager {
return resp;
}
+ Map<String, DataPartitionTable> assignedDataPartition;
+ try {
+ assignedDataPartition =
+ getLoadManager().allocateDataPartition(unassignedDataPartitionSlotsMap);
+ } catch (NoAvailableRegionGroupException e) {
+ status = getConsensusManager().confirmLeader();
+ if (status.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+ // The allocation might fail due to leadership change
+ resp.setStatus(status);
+ return resp;
+ }
+
+ LOGGER.error("Create DataPartition failed because: ", e);
+ resp.setStatus(
+ new TSStatus(TSStatusCode.NO_AVAILABLE_REGION_GROUP.getStatusCode())
+ .setMessage(e.getMessage()));
+ return resp;
+ }
+
+ // Cache allocating result only if the current ConfigNode still holds its leadership
+ CreateDataPartitionPlan createPlan = new CreateDataPartitionPlan();
+ createPlan.setAssignedDataPartition(assignedDataPartition);
status = getConsensusManager().confirmLeader();
if (status.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
// Here we check the leadership second time
// since the RegionGroup creating process might take some time
resp.setStatus(status);
return resp;
- } else {
- // Allocate DataPartitions only if
- // the current ConfigNode still holds its leadership
- Map<String, DataPartitionTable> assignedDataPartition;
- try {
- assignedDataPartition =
- getLoadManager().allocateDataPartition(unassignedDataPartitionSlotsMap);
- } catch (NoAvailableRegionGroupException e) {
- LOGGER.error("Create DataPartition failed because: ", e);
- resp.setStatus(
- new TSStatus(TSStatusCode.NO_AVAILABLE_REGION_GROUP.getStatusCode())
- .setMessage(e.getMessage()));
- return resp;
- }
-
- // Cache allocating result
- CreateDataPartitionPlan createPlan = new CreateDataPartitionPlan();
- createPlan.setAssignedDataPartition(assignedDataPartition);
- getConsensusManager().write(createPlan);
}
+ getConsensusManager().write(createPlan);
}
resp = (DataPartitionResp) getDataPartition(req);
if (!resp.isAllPartitionsExist()) {
- LOGGER.error(
- "Lacked some DataPartition allocation result in the response of getOrCreateDataPartition method");
+ // Count the fail rate
+ AtomicInteger totalSlotNum = new AtomicInteger();
+ req.getPartitionSlotsMap()
+ .forEach(
+ (database, partitionSlots) ->
+ partitionSlots.forEach(
+ (seriesPartitionSlot, timeSlotList) ->
+ totalSlotNum.addAndGet(timeSlotList.getTimePartitionSlots().size())));
+
+ AtomicInteger unassignedSlotNum = new AtomicInteger();
+ Map<String, Map<TSeriesPartitionSlot, TTimeSlotList>> unassignedDataPartitionSlotsMap =
+ partitionInfo.filterUnassignedDataPartitionSlots(req.getPartitionSlotsMap());
+ unassignedDataPartitionSlotsMap.forEach(
+ (database, unassignedDataPartitionSlots) ->
+ unassignedDataPartitionSlots.forEach(
+ (seriesPartitionSlot, timeSlotList) ->
+ unassignedSlotNum.addAndGet(timeSlotList.getTimePartitionSlots().size())));
+
+ String errMsg =
+ String.format(
+ "Lacked %d/%d DataPartition allocation result in the response of getOrCreateDataPartition method",
+ unassignedSlotNum.get(), totalSlotNum.get());
+ LOGGER.error(errMsg);
resp.setStatus(
- new TSStatus(TSStatusCode.LACK_PARTITION_ALLOCATION.getStatusCode())
- .setMessage("Lacked some DataPartition allocation result in the response"));
+ new TSStatus(TSStatusCode.LACK_PARTITION_ALLOCATION.getStatusCode()).setMessage(errMsg));
return resp;
}
return resp;