Skip to content

Commit bfe845b

Browse files
committed
tp
1 parent 4ac0b7e commit bfe845b

4 files changed

Lines changed: 121 additions & 0 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ public ConfigPhysicalPlanType getType() {
163163
return this.type;
164164
}
165165

166+
public short getPlanTypeId() {
167+
return type.getPlanType();
168+
}
169+
166170
@Override
167171
public ByteBuffer serializeToByteBuffer() {
168172
try (final PublicBAOS byteArrayOutputStream = new PublicBAOS();

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,13 @@
5454
import org.apache.iotdb.confignode.consensus.request.write.template.ExtendSchemaTemplatePlan;
5555

5656
public abstract class ConfigPhysicalPlanVisitor<R, C> {
57+
private final TimechoConfigPhysicalPlanVisitor<R, C> timechoVisitor =
58+
new TimechoConfigPhysicalPlanVisitor<>();
59+
5760
public R process(final ConfigPhysicalPlan plan, final C context) {
61+
if (isTimechoPlan(plan)) {
62+
return timechoVisitor.process(plan, context);
63+
}
5864
switch (plan.getType()) {
5965
case CreateDatabase:
6066
return visitCreateDatabase((DatabaseSchemaPlan) plan, context);
@@ -207,6 +213,10 @@ public R process(final ConfigPhysicalPlan plan, final C context) {
207213
}
208214
}
209215

216+
protected boolean isTimechoPlan(final ConfigPhysicalPlan plan) {
217+
return plan.getPlanTypeId() < 0;
218+
}
219+
210220
/** Top Level Description */
211221
public abstract R visitPlan(final ConfigPhysicalPlan plan, final C context);
212222

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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;
21+
22+
public class TimechoConfigPhysicalPlanVisitor<R, C> {
23+
24+
public R process(final ConfigPhysicalPlan plan, final C context) {
25+
return visitPlan(plan, context);
26+
}
27+
28+
public R visitPlan(final ConfigPhysicalPlan plan, final C context) {
29+
throw new UnsupportedOperationException(
30+
String.format(
31+
"Timecho config physical plan is not supported in Apache IoTDB: %s",
32+
plan.getPlanTypeId()));
33+
}
34+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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;
21+
22+
import org.junit.Assert;
23+
import org.junit.Test;
24+
25+
import java.io.DataOutputStream;
26+
import java.io.IOException;
27+
import java.nio.ByteBuffer;
28+
29+
public class ConfigPhysicalPlanVisitorTest {
30+
31+
@Test
32+
public void testNegativePlanTypeIdIsDispatchedToTimechoVisitor() {
33+
final boolean[] openSourceVisitorVisited = new boolean[] {false};
34+
final ConfigPhysicalPlanVisitor<String, Void> visitor =
35+
new ConfigPhysicalPlanVisitor<String, Void>() {
36+
@Override
37+
public String visitPlan(final ConfigPhysicalPlan plan, final Void context) {
38+
openSourceVisitorVisited[0] = true;
39+
return "open-source";
40+
}
41+
};
42+
43+
try {
44+
visitor.process(new NegativePlan(), null);
45+
Assert.fail("Expected timecho plan to be dispatched to the placeholder visitor");
46+
} catch (final UnsupportedOperationException e) {
47+
Assert.assertFalse(openSourceVisitorVisited[0]);
48+
Assert.assertTrue(e.getMessage().contains("-1"));
49+
}
50+
}
51+
52+
private static class NegativePlan extends ConfigPhysicalPlan {
53+
54+
private NegativePlan() {
55+
super(ConfigPhysicalPlanType.TestOnly);
56+
}
57+
58+
@Override
59+
public short getPlanTypeId() {
60+
return -1;
61+
}
62+
63+
@Override
64+
protected void serializeImpl(final DataOutputStream stream) throws IOException {
65+
stream.writeShort(getPlanTypeId());
66+
}
67+
68+
@Override
69+
protected void deserializeImpl(final ByteBuffer buffer) throws IOException {
70+
// Nothing to deserialize for the test-only placeholder plan.
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)