Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/apache/iotdb into iotdb-c…
Browse files Browse the repository at this point in the history
…ollector
  • Loading branch information
SteveYurongSu committed Jan 24, 2025
2 parents 015007d + 5933818 commit d46a46b
Show file tree
Hide file tree
Showing 271 changed files with 8,781 additions and 1,975 deletions.
36 changes: 34 additions & 2 deletions .github/workflows/daily-it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ jobs:
java-version: ${{ matrix.java }}
- name: IT/UT Test
shell: bash
# we do not compile client-cpp for saving time, it is tested in client.yml
# we can skip influxdb-protocol because it has been tested separately in influxdb-protocol.yml
run: |
mvn clean verify \
-P with-integration-tests \
Expand All @@ -49,3 +47,37 @@ jobs:
name: cluster-log-java${{ matrix.java }}-${{ runner.os }}
path: integration-test/target/cluster-logs
retention-days: 3
SingleRegionTableModel:
strategy:
fail-fast: false
max-parallel: 15
matrix:
java: [ 8, 17 ]
runs-on: [ self-hosted, iotdb ]
# group: self-hosted
# labels: iotdb
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: liberica
java-version: ${{ matrix.java }}
- name: IT/UT Test
shell: bash
# we do not compile client-cpp for saving time, it is tested in client.yml
# we can skip influxdb-protocol because it has been tested separately in influxdb-protocol.yml
run: |
mvn clean verify \
-P with-integration-tests \
-DskipUTs \
-DintegrationTest.forkCount=2 -DDataNodeMaxHeapSize=1024 -DintegrationTest.dataRegionPerDataNode=1\
-pl integration-test \
-am -PTableSimpleIT
- name: Upload Artifact
if: failure()
uses: actions/upload-artifact@v4
with:
name: table-standalone-log-java${{ matrix.java }}-${{ runner.os }}
path: integration-test/target/cluster-logs
retention-days: 3
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import org.apache.iotdb.rpc.subscription.config.ConsumerConstant;
import org.apache.iotdb.rpc.subscription.config.TopicConstant;
import org.apache.iotdb.session.Session;
import org.apache.iotdb.session.subscription.SubscriptionSession;
import org.apache.iotdb.session.subscription.SubscriptionTreeSession;
import org.apache.iotdb.session.subscription.consumer.AckStrategy;
import org.apache.iotdb.session.subscription.consumer.ConsumeResult;
import org.apache.iotdb.session.subscription.consumer.SubscriptionPullConsumer;
import org.apache.iotdb.session.subscription.consumer.SubscriptionPushConsumer;
import org.apache.iotdb.session.subscription.consumer.tree.SubscriptionTreePullConsumer;
import org.apache.iotdb.session.subscription.consumer.tree.SubscriptionTreePushConsumer;
import org.apache.iotdb.session.subscription.payload.SubscriptionMessage;
import org.apache.iotdb.session.subscription.payload.SubscriptionSessionDataSet;
import org.apache.iotdb.session.subscription.payload.SubscriptionTsFileHandler;
Expand Down Expand Up @@ -122,7 +122,8 @@ private static void dataQuery() throws Exception {
/** single pull consumer subscribe topic with path and time range */
private static void dataSubscription1() throws Exception {
// Create topics
try (final SubscriptionSession subscriptionSession = new SubscriptionSession(HOST, PORT)) {
try (final SubscriptionTreeSession subscriptionSession =
new SubscriptionTreeSession(HOST, PORT)) {
subscriptionSession.open();
final Properties config = new Properties();
config.put(TopicConstant.PATH_KEY, "root.db.d1.s1");
Expand All @@ -136,7 +137,7 @@ private static void dataSubscription1() throws Exception {
final Properties config = new Properties();
config.put(ConsumerConstant.CONSUMER_ID_KEY, "c1");
config.put(ConsumerConstant.CONSUMER_GROUP_ID_KEY, "cg1");
try (SubscriptionPullConsumer consumer1 = new SubscriptionPullConsumer(config)) {
try (SubscriptionTreePullConsumer consumer1 = new SubscriptionTreePullConsumer(config)) {
consumer1.open();
consumer1.subscribe(TOPIC_1);
while (true) {
Expand All @@ -160,7 +161,8 @@ private static void dataSubscription1() throws Exception {
}

// Show topics and subscriptions
try (final SubscriptionSession subscriptionSession = new SubscriptionSession(HOST, PORT)) {
try (final SubscriptionTreeSession subscriptionSession =
new SubscriptionTreeSession(HOST, PORT)) {
subscriptionSession.open();
subscriptionSession.getTopics().forEach((System.out::println));
subscriptionSession.getSubscriptions().forEach((System.out::println));
Expand All @@ -172,7 +174,8 @@ private static void dataSubscription1() throws Exception {

/** multi pull consumer subscribe topic with tsfile format */
private static void dataSubscription2() throws Exception {
try (final SubscriptionSession subscriptionSession = new SubscriptionSession(HOST, PORT)) {
try (final SubscriptionTreeSession subscriptionSession =
new SubscriptionTreeSession(HOST, PORT)) {
subscriptionSession.open();
final Properties config = new Properties();
config.put(TopicConstant.START_TIME_KEY, CURRENT_TIME + 33);
Expand All @@ -189,8 +192,8 @@ private static void dataSubscription2() throws Exception {
() -> {
int retryCount = 0;
// Subscription: builder-style ctor
try (final SubscriptionPullConsumer consumer2 =
new SubscriptionPullConsumer.Builder()
try (final SubscriptionTreePullConsumer consumer2 =
new SubscriptionTreePullConsumer.Builder()
.consumerId("c" + idx)
.consumerGroupId("cg2")
.autoCommit(false)
Expand Down Expand Up @@ -238,7 +241,8 @@ private static void dataSubscription2() throws Exception {

/** multi push consumer subscribe topic with tsfile format and snapshot mode */
private static void dataSubscription3() throws Exception {
try (final SubscriptionSession subscriptionSession = new SubscriptionSession(HOST, PORT)) {
try (final SubscriptionTreeSession subscriptionSession =
new SubscriptionTreeSession(HOST, PORT)) {
subscriptionSession.open();
final Properties config = new Properties();
config.put(TopicConstant.FORMAT_KEY, TopicConstant.FORMAT_TS_FILE_HANDLER_VALUE);
Expand All @@ -253,8 +257,8 @@ private static void dataSubscription3() throws Exception {
new Thread(
() -> {
// Subscription: builder-style ctor
try (final SubscriptionPushConsumer consumer3 =
new SubscriptionPushConsumer.Builder()
try (final SubscriptionTreePushConsumer consumer3 =
new SubscriptionTreePushConsumer.Builder()
.consumerId("c" + idx)
.consumerGroupId("cg3")
.ackStrategy(AckStrategy.AFTER_CONSUME)
Expand Down Expand Up @@ -284,7 +288,8 @@ private static void dataSubscription3() throws Exception {

/** multi pull consumer subscribe topic with tsfile format and snapshot mode */
private static void dataSubscription4() throws Exception {
try (final SubscriptionSession subscriptionSession = new SubscriptionSession(HOST, PORT)) {
try (final SubscriptionTreeSession subscriptionSession =
new SubscriptionTreeSession(HOST, PORT)) {
subscriptionSession.open();
final Properties config = new Properties();
config.put(TopicConstant.FORMAT_KEY, TopicConstant.FORMAT_TS_FILE_HANDLER_VALUE);
Expand All @@ -300,8 +305,8 @@ private static void dataSubscription4() throws Exception {
new Thread(
() -> {
// Subscription: builder-style ctor
try (final SubscriptionPullConsumer consumer4 =
new SubscriptionPullConsumer.Builder()
try (final SubscriptionTreePullConsumer consumer4 =
new SubscriptionTreePullConsumer.Builder()
.consumerId("c" + idx)
.consumerGroupId("cg4")
.autoCommit(true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
/*
* 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;

import org.apache.iotdb.isession.ITableSession;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.rpc.subscription.config.TopicConstant;
import org.apache.iotdb.session.TableSessionBuilder;
import org.apache.iotdb.session.subscription.ISubscriptionTableSession;
import org.apache.iotdb.session.subscription.SubscriptionTableSessionBuilder;
import org.apache.iotdb.session.subscription.consumer.ISubscriptionTablePullConsumer;
import org.apache.iotdb.session.subscription.consumer.table.SubscriptionTablePullConsumerBuilder;
import org.apache.iotdb.session.subscription.payload.SubscriptionMessage;
import org.apache.iotdb.session.subscription.payload.SubscriptionSessionDataSet;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Properties;

public class TableModelSubscriptionSessionExample {

private static final String HOST = "127.0.0.1";
private static final int PORT = 6667;

private static final String TOPIC_1 = "topic1";
private static final String TOPIC_2 = "`'topic2'`";
private static final String TOPIC_3 = "`\"topic3\"`";
private static final String TOPIC_4 = "`\"top \\.i.c4\"`";

private static final long SLEEP_NS = 1_000_000_000L;
private static final long POLL_TIMEOUT_MS = 10_000L;
private static final int MAX_RETRY_TIMES = 3;
private static final int PARALLELISM = 8;
private static final long CURRENT_TIME = System.currentTimeMillis();

private static void createDataBaseAndTable(
final ITableSession session, final String database, final String table)
throws IoTDBConnectionException, StatementExecutionException {
session.executeNonQueryStatement("create database if not exists " + database);
session.executeNonQueryStatement("use " + database);
session.executeNonQueryStatement(
String.format(
"CREATE TABLE %s (s0 string tag, s1 string tag, s2 string tag, s3 string tag, s4 int64 field, s5 float field, s6 string field, s7 timestamp field, s8 int32 field, s9 double field, s10 date field, s11 text field)",
table));
}

private static void insertData(
final ITableSession session,
final String dataBaseName,
final String tableName,
final int start,
final int end)
throws IoTDBConnectionException, StatementExecutionException {
List<String> list = new ArrayList<>(end - start + 1);
for (int i = start; i < end; ++i) {
list.add(
String.format(
"insert into %s (s0, s3, s2, s1, s4, s5, s6, s7, s8, s9, s10, s11, time) values ('t%s','t%s','t%s','t%s','%s', %s.0, %s, %s, %d, %d.0, '%s', '%s', %s)",
tableName, i, i, i, i, i, i, i, i, i, i, getDateStr(i), i, i));
}
list.add("flush");
session.executeNonQueryStatement("use " + dataBaseName);
for (String s : list) {
session.executeNonQueryStatement(s);
}
}

private static String getDateStr(int value) {
Date date = new Date(value);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
try {
return dateFormat.format(date);
} catch (Exception e) {
return "1970-01-01";
}
}

private static void dataSubscription() throws Exception {
// Create topics
try (final ISubscriptionTableSession session =
new SubscriptionTableSessionBuilder()
.host("127.0.0.1")
.port(6667)
.username("root")
.password("root")
.build()) {
final Properties config = new Properties();
config.put(TopicConstant.DATABASE_KEY, "db");
config.put(TopicConstant.TABLE_KEY, "test");
config.put(TopicConstant.START_TIME_KEY, 25);
config.put(TopicConstant.END_TIME_KEY, 75);
config.put(TopicConstant.STRICT_KEY, "true");
session.createTopic(TOPIC_1, config);
}

int retryCount = 0;
try (ISubscriptionTablePullConsumer consumer1 =
new SubscriptionTablePullConsumerBuilder()
.consumerId("c1")
.consumerGroupId("cg1")
.buildTablePullConsumer()) {
consumer1.open();
consumer1.subscribe(TOPIC_1);
while (true) {
final List<SubscriptionMessage> messages = consumer1.poll(POLL_TIMEOUT_MS);
if (messages.isEmpty()) {
retryCount++;
if (retryCount >= MAX_RETRY_TIMES) {
break;
}
}
for (final SubscriptionMessage message : messages) {
for (final SubscriptionSessionDataSet dataSet : message.getSessionDataSetsHandler()) {
System.out.println(dataSet.getColumnNames());
System.out.println(dataSet.getColumnTypes());
while (dataSet.hasNext()) {
System.out.println(dataSet.next());
}
}
}
// Auto commit
}

// Show topics and subscriptions
try (final ISubscriptionTableSession session =
new SubscriptionTableSessionBuilder()
.host("127.0.0.1")
.port(6667)
.username("root")
.password("root")
.build()) {
session.getTopics().forEach((System.out::println));
session.getSubscriptions().forEach((System.out::println));
}

consumer1.unsubscribe(TOPIC_1);
}
}

public static void main(final String[] args) throws Exception {
try (ITableSession session =
new TableSessionBuilder()
.nodeUrls(Collections.singletonList(HOST + ":" + PORT))
.username("root")
.password("root")
.build()) {
createDataBaseAndTable(session, "db", "test");
insertData(session, "db", "test", 0, 100);
dataSubscription();
}
}
}
2 changes: 2 additions & 0 deletions integration-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<integrationTest.nodeNewHeapSize>200m</integrationTest.nodeNewHeapSize>
<integrationTest.randomSelectWriteNode>true</integrationTest.randomSelectWriteNode>
<integrationTest.readAndVerifyWithMultiNode>true</integrationTest.readAndVerifyWithMultiNode>
<integrationTest.dataRegionPerDataNode>0</integrationTest.dataRegionPerDataNode>
<integrationTest.testEnv/>
<lightWeightStandaloneMode.configNodeConsensus>Simple</lightWeightStandaloneMode.configNodeConsensus>
<!-- -DClusterConfigurations values configured here -->
Expand Down Expand Up @@ -300,6 +301,7 @@
<TestEnv>${integrationTest.testEnv}</TestEnv>
<RandomSelectWriteNode>${integrationTest.randomSelectWriteNode}</RandomSelectWriteNode>
<ReadAndVerifyWithMultiNode>${integrationTest.readAndVerifyWithMultiNode}</ReadAndVerifyWithMultiNode>
<DataRegionPerDataNode>${integrationTest.dataRegionPerDataNode}</DataRegionPerDataNode>
<lightWeightStandaloneMode.configNodeNumber>${lightWeightStandaloneMode.configNodeNumber}</lightWeightStandaloneMode.configNodeNumber>
<lightWeightStandaloneMode.dataNodeNumber>${lightWeightStandaloneMode.dataNodeNumber}</lightWeightStandaloneMode.dataNodeNumber>
<lightWeightStandaloneMode.configNodeConsensus>${lightWeightStandaloneMode.configNodeConsensus}</lightWeightStandaloneMode.configNodeConsensus>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class ClusterConstant {
public static final String DEFAULT_DATA_NODE_PROPERTIES = "DefaultDataNodeProperties";
public static final String DEFAULT_DATA_NODE_COMMON_PROPERTIES =
"DefaultDataNodeCommonProperties";
public static final String DATA_REGION_PER_DATANODE = "integrationTest.dataRegionPerDataNode";

// Cluster Configurations
public static final String CLUSTER_CONFIGURATIONS = "ClusterConfigurations";
Expand Down Expand Up @@ -202,6 +203,7 @@ public class ClusterConstant {
"schema_region_ratis_log_appender_buffer_size_max";
public static final String DATA_REGION_RATIS_LOG_APPENDER_BUFFER_SIZE_MAX =
"data_region_ratis_log_appender_buffer_size_max";
public static final String DATA_REGION_PER_DATA_NODE = "data_region_per_data_node";

// Paths
public static final String USER_DIR = "user.dir";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@ public CommonConfig setTimePartitionInterval(long timePartitionInterval) {
return this;
}

@Override
public CommonConfig setTTLCheckInterval(long ttlCheckInterval) {
setProperty("ttl_check_interval", String.valueOf(ttlCheckInterval));
return this;
}

@Override
public CommonConfig setTimePartitionOrigin(long timePartitionOrigin) {
setProperty("time_partition_origin", String.valueOf(timePartitionOrigin));
Expand Down Expand Up @@ -381,6 +387,12 @@ public CommonConfig setSeriesSlotNum(int seriesSlotNum) {
return this;
}

@Override
public CommonConfig setSeriesPartitionExecutorClass(String seriesPartitionExecutorClass) {
setProperty("series_partition_executor_class", seriesPartitionExecutorClass);
return this;
}

@Override
public CommonConfig setSchemaMemoryAllocate(String schemaMemoryAllocate) {
setProperty("schema_memory_proportion", String.valueOf(schemaMemoryAllocate));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,11 @@ public DataNodeConfig setLoadTsFileAnalyzeSchemaMemorySizeInBytes(
String.valueOf(loadTsFileAnalyzeSchemaMemorySizeInBytes));
return this;
}

@Override
public DataNodeConfig setCompactionScheduleInterval(long compactionScheduleInterval) {
properties.setProperty(
"compaction_schedule_interval_in_ms", String.valueOf(compactionScheduleInterval));
return this;
}
}
Loading

0 comments on commit d46a46b

Please sign in to comment.