Skip to content

Commit 5b22e7b

Browse files
authored
Handle commit failure of table procedures
1 parent 737c4cc commit 5b22e7b

File tree

25 files changed

+531
-106
lines changed

25 files changed

+531
-106
lines changed

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/ConfigPhysicalPlanType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ public enum ConfigPhysicalPlanType {
161161
AddTableColumn((short) 853),
162162
SetTableProperties((short) 854),
163163
ShowTable((short) 855),
164+
FetchTable((short) 856),
164165

165166
/** Deprecated types for sync, restored them for upgrade. */
166167
@Deprecated
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.iotdb.confignode.consensus.request.read.table;
21+
22+
import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlanType;
23+
import org.apache.iotdb.confignode.consensus.request.read.ConfigPhysicalReadPlan;
24+
25+
import java.util.Map;
26+
import java.util.Set;
27+
28+
public class FetchTablePlan extends ConfigPhysicalReadPlan {
29+
30+
private final Map<String, Set<String>> fetchTableMap;
31+
32+
public FetchTablePlan(final Map<String, Set<String>> fetchTableMap) {
33+
super(ConfigPhysicalPlanType.FetchTable);
34+
this.fetchTableMap = fetchTableMap;
35+
}
36+
37+
public Map<String, Set<String>> getFetchTableMap() {
38+
return fetchTableMap;
39+
}
40+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.iotdb.confignode.consensus.response.table;
21+
22+
import org.apache.iotdb.common.rpc.thrift.TSStatus;
23+
import org.apache.iotdb.commons.schema.table.TsTable;
24+
import org.apache.iotdb.commons.schema.table.TsTableInternalRPCUtil;
25+
import org.apache.iotdb.confignode.rpc.thrift.TFetchTableResp;
26+
import org.apache.iotdb.consensus.common.DataSet;
27+
28+
import java.util.Map;
29+
30+
public class FetchTableResp implements DataSet {
31+
private final TSStatus status;
32+
private final Map<String, Map<String, TsTable>> fetchTableMap;
33+
34+
public FetchTableResp(
35+
final TSStatus status, final Map<String, Map<String, TsTable>> fetchTableMap) {
36+
this.status = status;
37+
this.fetchTableMap = fetchTableMap;
38+
}
39+
40+
public TFetchTableResp convertToTFetchTableResp() {
41+
return new TFetchTableResp(status)
42+
.setTableInfoMap(TsTableInternalRPCUtil.serializeTableFetchResult(fetchTableMap));
43+
}
44+
}

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@
166166
import org.apache.iotdb.confignode.rpc.thrift.TDropPipeReq;
167167
import org.apache.iotdb.confignode.rpc.thrift.TDropTopicReq;
168168
import org.apache.iotdb.confignode.rpc.thrift.TDropTriggerReq;
169+
import org.apache.iotdb.confignode.rpc.thrift.TFetchTableResp;
169170
import org.apache.iotdb.confignode.rpc.thrift.TGetAllPipeInfoResp;
170171
import org.apache.iotdb.confignode.rpc.thrift.TGetAllSubscriptionInfoResp;
171172
import org.apache.iotdb.confignode.rpc.thrift.TGetAllTemplatesResp;
@@ -2582,6 +2583,28 @@ public TShowTableResp showTables(final String database) {
25822583
: new TShowTableResp(status);
25832584
}
25842585

2586+
@Override
2587+
public TFetchTableResp fetchTables(final Map<String, Set<String>> fetchTableMap) {
2588+
final TSStatus status = confirmLeader();
2589+
return status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()
2590+
? clusterSchemaManager.fetchTables(
2591+
fetchTableMap.entrySet().stream()
2592+
.filter(
2593+
entry -> {
2594+
entry
2595+
.getValue()
2596+
.removeIf(
2597+
table ->
2598+
procedureManager
2599+
.checkDuplicateTableTask(
2600+
entry.getKey(), null, table, null, null)
2601+
.getRight());
2602+
return !entry.getValue().isEmpty();
2603+
})
2604+
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))
2605+
: new TFetchTableResp(status);
2606+
}
2607+
25852608
@Override
25862609
public DataSet registerAINode(TAINodeRegisterReq req) {
25872610
TSStatus status = confirmLeader();

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/IManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
import org.apache.iotdb.confignode.rpc.thrift.TDropPipeReq;
9292
import org.apache.iotdb.confignode.rpc.thrift.TDropTopicReq;
9393
import org.apache.iotdb.confignode.rpc.thrift.TDropTriggerReq;
94+
import org.apache.iotdb.confignode.rpc.thrift.TFetchTableResp;
9495
import org.apache.iotdb.confignode.rpc.thrift.TGetAllPipeInfoResp;
9596
import org.apache.iotdb.confignode.rpc.thrift.TGetAllSubscriptionInfoResp;
9697
import org.apache.iotdb.confignode.rpc.thrift.TGetAllTemplatesResp;
@@ -148,6 +149,7 @@
148149
import java.nio.ByteBuffer;
149150
import java.util.List;
150151
import java.util.Map;
152+
import java.util.Set;
151153

152154
/**
153155
* A subset of services provided by {@link ConfigManager}. For use internally only, passed to
@@ -833,4 +835,6 @@ TDataPartitionTableResp getOrCreateDataPartition(
833835
TSStatus alterTable(final TAlterTableReq req);
834836

835837
TShowTableResp showTables(final String database);
838+
839+
TFetchTableResp fetchTables(final Map<String, Set<String>> fetchTableMap);
836840
}

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ProcedureManager.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public TSStatus deleteDatabases(
231231
while (executor.isRunning()
232232
&& System.currentTimeMillis() - startCheckTimeForProcedures < PROCEDURE_WAIT_TIME_OUT) {
233233
final Pair<Long, Boolean> procedureIdDuplicatePair =
234-
awaitDuplicateTableTask(
234+
checkDuplicateTableTask(
235235
database, null, null, null, ProcedureType.CREATE_TABLE_PROCEDURE);
236236
hasOverlappedTask = procedureIdDuplicatePair.getRight();
237237

@@ -1362,7 +1362,7 @@ private TSStatus executeWithoutDuplicate(
13621362
long procedureId;
13631363
synchronized (this) {
13641364
final Pair<Long, Boolean> procedureIdDuplicatePair =
1365-
awaitDuplicateTableTask(database, table, tableName, queryId, thisType);
1365+
checkDuplicateTableTask(database, table, tableName, queryId, thisType);
13661366
procedureId = procedureIdDuplicatePair.getLeft();
13671367

13681368
if (procedureId == -1) {
@@ -1375,16 +1375,12 @@ private TSStatus executeWithoutDuplicate(
13751375
}
13761376
}
13771377
final List<TSStatus> procedureStatus = new ArrayList<>();
1378-
final boolean isSucceed =
1379-
waitingProcedureFinished(Collections.singletonList(procedureId), procedureStatus);
1380-
if (isSucceed) {
1381-
return StatusUtils.OK;
1382-
} else {
1383-
return procedureStatus.get(0);
1384-
}
1378+
return waitingProcedureFinished(Collections.singletonList(procedureId), procedureStatus)
1379+
? StatusUtils.OK
1380+
: procedureStatus.get(0);
13851381
}
13861382

1387-
private Pair<Long, Boolean> awaitDuplicateTableTask(
1383+
public Pair<Long, Boolean> checkDuplicateTableTask(
13881384
final String database,
13891385
final TsTable table,
13901386
final String tableName,

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/schema/ClusterSchemaManager.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.apache.iotdb.confignode.conf.ConfigNodeDescriptor;
4040
import org.apache.iotdb.confignode.consensus.request.read.database.CountDatabasePlan;
4141
import org.apache.iotdb.confignode.consensus.request.read.database.GetDatabasePlan;
42+
import org.apache.iotdb.confignode.consensus.request.read.table.FetchTablePlan;
4243
import org.apache.iotdb.confignode.consensus.request.read.table.ShowTablePlan;
4344
import org.apache.iotdb.confignode.consensus.request.read.template.GetAllSchemaTemplatePlan;
4445
import org.apache.iotdb.confignode.consensus.request.read.template.GetAllTemplateSetInfoPlan;
@@ -63,6 +64,7 @@
6364
import org.apache.iotdb.confignode.consensus.response.database.CountDatabaseResp;
6465
import org.apache.iotdb.confignode.consensus.response.database.DatabaseSchemaResp;
6566
import org.apache.iotdb.confignode.consensus.response.partition.PathInfoResp;
67+
import org.apache.iotdb.confignode.consensus.response.table.FetchTableResp;
6668
import org.apache.iotdb.confignode.consensus.response.table.ShowTableResp;
6769
import org.apache.iotdb.confignode.consensus.response.template.AllTemplateSetInfoResp;
6870
import org.apache.iotdb.confignode.consensus.response.template.TemplateInfoResp;
@@ -76,6 +78,7 @@
7678
import org.apache.iotdb.confignode.persistence.schema.ClusterSchemaInfo;
7779
import org.apache.iotdb.confignode.rpc.thrift.TDatabaseInfo;
7880
import org.apache.iotdb.confignode.rpc.thrift.TDatabaseSchema;
81+
import org.apache.iotdb.confignode.rpc.thrift.TFetchTableResp;
7982
import org.apache.iotdb.confignode.rpc.thrift.TGetAllTemplatesResp;
8083
import org.apache.iotdb.confignode.rpc.thrift.TGetPathsSetTemplatesResp;
8184
import org.apache.iotdb.confignode.rpc.thrift.TGetTemplateResp;
@@ -1073,6 +1076,19 @@ public TShowTableResp showTables(final String database) {
10731076
}
10741077
}
10751078

1079+
public TFetchTableResp fetchTables(final Map<String, Set<String>> fetchTableMap) {
1080+
try {
1081+
return ((FetchTableResp)
1082+
configManager.getConsensusManager().read(new FetchTablePlan(fetchTableMap)))
1083+
.convertToTFetchTableResp();
1084+
} catch (final ConsensusException e) {
1085+
LOGGER.warn("Failed in the read API executing the consensus layer due to: ", e);
1086+
final TSStatus res = new TSStatus(TSStatusCode.EXECUTE_STATEMENT_ERROR.getStatusCode());
1087+
res.setMessage(e.getMessage());
1088+
return new TFetchTableResp(res);
1089+
}
1090+
}
1091+
10761092
public byte[] getAllTableInfoForDataNodeActivation() {
10771093
return TsTableInternalRPCUtil.serializeTableInitializationInfo(
10781094
clusterSchemaInfo.getAllUsingTables(), clusterSchemaInfo.getAllPreCreateTables());

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/executor/ConfigPlanExecutor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.apache.iotdb.confignode.consensus.request.read.pipe.plugin.GetPipePluginJarPlan;
4646
import org.apache.iotdb.confignode.consensus.request.read.region.GetRegionIdPlan;
4747
import org.apache.iotdb.confignode.consensus.request.read.region.GetRegionInfoListPlan;
48+
import org.apache.iotdb.confignode.consensus.request.read.table.FetchTablePlan;
4849
import org.apache.iotdb.confignode.consensus.request.read.table.ShowTablePlan;
4950
import org.apache.iotdb.confignode.consensus.request.read.template.CheckTemplateSettablePlan;
5051
import org.apache.iotdb.confignode.consensus.request.read.template.GetPathsSetTemplatePlan;
@@ -311,6 +312,8 @@ public DataSet executeQueryPlan(final ConfigPhysicalReadPlan req)
311312
return clusterSchemaInfo.getTemplateSetInfo((GetTemplateSetInfoPlan) req);
312313
case ShowTable:
313314
return clusterSchemaInfo.showTables((ShowTablePlan) req);
315+
case FetchTable:
316+
return clusterSchemaInfo.fetchTables((FetchTablePlan) req);
314317
case GetTriggerTable:
315318
return triggerInfo.getTriggerTable((GetTriggerTablePlan) req);
316319
case GetTriggerLocation:

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ClusterSchemaInfo.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.iotdb.commons.utils.TestOnly;
3636
import org.apache.iotdb.confignode.consensus.request.read.database.CountDatabasePlan;
3737
import org.apache.iotdb.confignode.consensus.request.read.database.GetDatabasePlan;
38+
import org.apache.iotdb.confignode.consensus.request.read.table.FetchTablePlan;
3839
import org.apache.iotdb.confignode.consensus.request.read.table.ShowTablePlan;
3940
import org.apache.iotdb.confignode.consensus.request.read.template.CheckTemplateSettablePlan;
4041
import org.apache.iotdb.confignode.consensus.request.read.template.GetPathsSetTemplatePlan;
@@ -63,6 +64,7 @@
6364
import org.apache.iotdb.confignode.consensus.response.database.CountDatabaseResp;
6465
import org.apache.iotdb.confignode.consensus.response.database.DatabaseSchemaResp;
6566
import org.apache.iotdb.confignode.consensus.response.partition.PathInfoResp;
67+
import org.apache.iotdb.confignode.consensus.response.table.FetchTableResp;
6668
import org.apache.iotdb.confignode.consensus.response.table.ShowTableResp;
6769
import org.apache.iotdb.confignode.consensus.response.template.AllTemplateSetInfoResp;
6870
import org.apache.iotdb.confignode.consensus.response.template.TemplateInfoResp;
@@ -1102,6 +1104,27 @@ public ShowTableResp showTables(final ShowTablePlan plan) {
11021104
}
11031105
}
11041106

1107+
public FetchTableResp fetchTables(final FetchTablePlan plan) {
1108+
databaseReadWriteLock.readLock().lock();
1109+
try {
1110+
final Map<String, Map<String, TsTable>> result = new HashMap<>();
1111+
for (final Map.Entry<String, Set<String>> database2Tables :
1112+
plan.getFetchTableMap().entrySet()) {
1113+
result.put(
1114+
database2Tables.getKey(),
1115+
mTree.getSpecificTablesUnderSpecificDatabase(
1116+
getQualifiedDatabasePartialPath(database2Tables.getKey()),
1117+
database2Tables.getValue()));
1118+
}
1119+
return new FetchTableResp(StatusUtils.OK, result);
1120+
} catch (final MetadataException e) {
1121+
return new FetchTableResp(
1122+
RpcUtils.getStatus(e.getErrorCode(), e.getMessage()), Collections.emptyMap());
1123+
} finally {
1124+
databaseReadWriteLock.readLock().unlock();
1125+
}
1126+
}
1127+
11051128
public Map<String, List<TsTable>> getAllUsingTables() {
11061129
databaseReadWriteLock.readLock().lock();
11071130
try {

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ConfigMTree.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,23 @@ public List<TsTable> getAllUsingTablesUnderSpecificDatabase(final PartialPath da
685685
.collect(Collectors.toList());
686686
}
687687

688+
public Map<String, TsTable> getSpecificTablesUnderSpecificDatabase(
689+
final PartialPath databasePath, final Set<String> tables) throws MetadataException {
690+
final IConfigMNode databaseNode = getDatabaseNodeByDatabasePath(databasePath).getAsMNode();
691+
final Map<String, TsTable> result = new HashMap<>();
692+
tables.forEach(
693+
table -> {
694+
final IConfigMNode child = databaseNode.getChildren().get(table);
695+
if (child instanceof ConfigTableNode
696+
&& ((ConfigTableNode) child).getStatus().equals(TableNodeStatus.USING)) {
697+
result.put(table, ((ConfigTableNode) child).getTable());
698+
} else {
699+
result.put(table, null);
700+
}
701+
});
702+
return result;
703+
}
704+
688705
public Map<String, List<TsTable>> getAllUsingTables() {
689706
return getAllDatabasePaths().stream()
690707
.collect(

0 commit comments

Comments
 (0)