This is an automated email from the ASF dual-hosted git repository. Caideyipi pushed a commit to branch TimechoVisitor in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit bfe845b937368473152b7b5efe142290217aa245 Author: Caideyipi <[email protected]> AuthorDate: Mon May 18 15:23:44 2026 +0800 tp --- .../consensus/request/ConfigPhysicalPlan.java | 4 ++ .../request/ConfigPhysicalPlanVisitor.java | 10 +++ .../request/TimechoConfigPhysicalPlanVisitor.java | 34 ++++++++++ .../request/ConfigPhysicalPlanVisitorTest.java | 73 ++++++++++++++++++++++ 4 files changed, 121 insertions(+) diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/ConfigPhysicalPlan.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/ConfigPhysicalPlan.java index 1ad547f7845..f261555f631 100644 --- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/ConfigPhysicalPlan.java +++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/ConfigPhysicalPlan.java @@ -163,6 +163,10 @@ public abstract class ConfigPhysicalPlan implements IConsensusRequest { return this.type; } + public short getPlanTypeId() { + return type.getPlanType(); + } + @Override public ByteBuffer serializeToByteBuffer() { try (final PublicBAOS byteArrayOutputStream = new PublicBAOS(); diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/ConfigPhysicalPlanVisitor.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/ConfigPhysicalPlanVisitor.java index 8363f023bc4..117642caf67 100644 --- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/ConfigPhysicalPlanVisitor.java +++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/ConfigPhysicalPlanVisitor.java @@ -54,7 +54,13 @@ import org.apache.iotdb.confignode.consensus.request.write.template.DropSchemaTe import org.apache.iotdb.confignode.consensus.request.write.template.ExtendSchemaTemplatePlan; public abstract class ConfigPhysicalPlanVisitor<R, C> { + private final TimechoConfigPhysicalPlanVisitor<R, C> timechoVisitor = + new TimechoConfigPhysicalPlanVisitor<>(); + public R process(final ConfigPhysicalPlan plan, final C context) { + if (isTimechoPlan(plan)) { + return timechoVisitor.process(plan, context); + } switch (plan.getType()) { case CreateDatabase: return visitCreateDatabase((DatabaseSchemaPlan) plan, context); @@ -207,6 +213,10 @@ public abstract class ConfigPhysicalPlanVisitor<R, C> { } } + protected boolean isTimechoPlan(final ConfigPhysicalPlan plan) { + return plan.getPlanTypeId() < 0; + } + /** Top Level Description */ public abstract R visitPlan(final ConfigPhysicalPlan plan, final C context); diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/TimechoConfigPhysicalPlanVisitor.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/TimechoConfigPhysicalPlanVisitor.java new file mode 100644 index 00000000000..d3c22729265 --- /dev/null +++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/request/TimechoConfigPhysicalPlanVisitor.java @@ -0,0 +1,34 @@ +/* + * 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; + +public class TimechoConfigPhysicalPlanVisitor<R, C> { + + public R process(final ConfigPhysicalPlan plan, final C context) { + return visitPlan(plan, context); + } + + public R visitPlan(final ConfigPhysicalPlan plan, final C context) { + throw new UnsupportedOperationException( + String.format( + "Timecho config physical plan is not supported in Apache IoTDB: %s", + plan.getPlanTypeId())); + } +} diff --git a/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/consensus/request/ConfigPhysicalPlanVisitorTest.java b/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/consensus/request/ConfigPhysicalPlanVisitorTest.java new file mode 100644 index 00000000000..89fd5e7152d --- /dev/null +++ b/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/consensus/request/ConfigPhysicalPlanVisitorTest.java @@ -0,0 +1,73 @@ +/* + * 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; + +import org.junit.Assert; +import org.junit.Test; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; + +public class ConfigPhysicalPlanVisitorTest { + + @Test + public void testNegativePlanTypeIdIsDispatchedToTimechoVisitor() { + final boolean[] openSourceVisitorVisited = new boolean[] {false}; + final ConfigPhysicalPlanVisitor<String, Void> visitor = + new ConfigPhysicalPlanVisitor<String, Void>() { + @Override + public String visitPlan(final ConfigPhysicalPlan plan, final Void context) { + openSourceVisitorVisited[0] = true; + return "open-source"; + } + }; + + try { + visitor.process(new NegativePlan(), null); + Assert.fail("Expected timecho plan to be dispatched to the placeholder visitor"); + } catch (final UnsupportedOperationException e) { + Assert.assertFalse(openSourceVisitorVisited[0]); + Assert.assertTrue(e.getMessage().contains("-1")); + } + } + + private static class NegativePlan extends ConfigPhysicalPlan { + + private NegativePlan() { + super(ConfigPhysicalPlanType.TestOnly); + } + + @Override + public short getPlanTypeId() { + return -1; + } + + @Override + protected void serializeImpl(final DataOutputStream stream) throws IOException { + stream.writeShort(getPlanTypeId()); + } + + @Override + protected void deserializeImpl(final ByteBuffer buffer) throws IOException { + // Nothing to deserialize for the test-only placeholder plan. + } + } +}
