alpass163 commented on code in PR #18874:
URL: https://github.com/apache/iotdb/pull/18874#discussion_r4311506550
##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/schema/table/view/CreateTableViewProcedure.java:
##########
@@ -116,13 +121,91 @@ protected void checkTableExistence(final
ConfigNodeProcedureEnv env) {
}
}
final TSStatus status =
- new TreeDeviceViewFieldDetector(env.getConfigManager(), table, null)
- .detectMissingFieldTypes();
+ new TreeDeviceViewFieldDetector(env.getConfigManager(),
table).detectFieldsForCreation();
if (status.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
setFailure(new ProcedureException(new IoTDBException(status)));
}
}
+ @Override
+ protected TUpdateTableReq buildCommitReleaseTableReq() {
+ final boolean newAutoSync =
+ table
+ .getPropValue(TreeViewSchema.AUTO_SYNC_SCHEMA)
+ .map(Boolean::parseBoolean)
+ .orElse(false);
+ if (newAutoSync) {
+ // Whether the view is a new one, or replace the old table, just add view
+ final TUpdateTree2TableView viewInfo =
+ new
TUpdateTree2TableView(TreeToTableViewOperationType.ADD.getOperationType());
+
table.getPropValue(TreeViewSchema.TREE_PATH_PATTERN).ifPresent(viewInfo::setTreePath);
+ viewInfo.setIsRestrict(TreeViewSchema.isRestrict(table));
+ viewInfo.setTagNum(table.getTagNum());
+ return SchemaUtils.buildCommitUpdateTableReq(database,
table.getTableName(), null, viewInfo);
+ }
+ // Creating, or replacing with the auto detection turned off: the view the
old definition had
+ // registered has to go. drop a non-existing view is allowed.
+ final boolean oldAutoSync =
+ Objects.nonNull(oldView)
+ && oldView
+ .getPropValue(TreeViewSchema.AUTO_SYNC_SCHEMA)
+ .map(Boolean::parseBoolean)
+ .orElse(false);
+ if (oldAutoSync) {
+ return SchemaUtils.buildCommitUpdateTableReq(
+ database,
+ table.getTableName(),
+ null,
+ new
TUpdateTree2TableView(TreeToTableViewOperationType.REMOVE.getOperationType()));
+ }
+ return super.buildCommitReleaseTableReq();
+ }
+
+ /**
+ * A rolled-back replace restores the view the old definition had. A
DataNode which restarted
+ * while the replace was running does not hold it: the table such a DataNode
pulls is only
+ * pre-created, and a pre-created table does not enter the index.
Registering the old view again
+ * is idempotent, so a DataNode which never lost it is not affected.
+ */
+ @Override
+ protected TUpdateTableReq buildRollbackTableReq() {
+ final boolean oldAutoSync =
+ Objects.nonNull(oldView)
+ && oldView
+ .getPropValue(TreeViewSchema.AUTO_SYNC_SCHEMA)
+ .map(Boolean::parseBoolean)
+ .orElse(false);
+ if (!oldAutoSync) {
+ return super.buildRollbackTableReq();
+ }
+ final TUpdateTree2TableView viewInfo =
+ new
TUpdateTree2TableView(TreeToTableViewOperationType.ADD.getOperationType());
+
oldView.getPropValue(TreeViewSchema.TREE_PATH_PATTERN).ifPresent(viewInfo::setTreePath);
+ viewInfo.setIsRestrict(TreeViewSchema.isRestrict(oldView));
+ viewInfo.setTagNum(oldView.getTagNum());
+ return SchemaUtils.rollbackUpdateTableReq(database, table.getTableName(),
null, viewInfo);
+ }
+
+ @Override
+ protected void reconcileTree2TableViewColumns(final ConfigNodeProcedureEnv
env) {
+ // The series which already existed under the path pattern were created
before the DataNodes
+ // mounted the view, so they never triggered the addition of their column.
+ final List<TsTableColumnSchema> missingColumns =
+ TreeDeviceViewFieldDetector.detectMissingColumnsAfterCreation(
+ env.getConfigManager(), database, table);
+ if (missingColumns.isEmpty()) {
+ return;
+ }
+
+ addChildProcedure(
Review Comment:
it is expected that the createViewProcedure cannot be roll-backed once it
has gone through the commit-create phase
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]