Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/apache/iotdb into support…
Browse files Browse the repository at this point in the history
…-delete
  • Loading branch information
Caideyipi committed Jan 29, 2024
2 parents 81360bb + fcae2b4 commit 01136c8
Show file tree
Hide file tree
Showing 237 changed files with 9,642 additions and 2,707 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,19 @@

package org.apache.iotdb.confignode.it.cluster;

import org.apache.iotdb.common.rpc.thrift.TSStatus;
import org.apache.iotdb.common.rpc.thrift.TSeriesPartitionSlot;
import org.apache.iotdb.commons.client.exception.ClientManagerException;
import org.apache.iotdb.commons.client.sync.SyncConfigNodeIServiceClient;
import org.apache.iotdb.commons.cluster.NodeStatus;
import org.apache.iotdb.confignode.it.utils.ConfigNodeTestUtils;
import org.apache.iotdb.confignode.rpc.thrift.TDataPartitionReq;
import org.apache.iotdb.confignode.rpc.thrift.TDataPartitionTableResp;
import org.apache.iotdb.confignode.rpc.thrift.TDatabaseSchema;
import org.apache.iotdb.confignode.rpc.thrift.TShowClusterResp;
import org.apache.iotdb.confignode.rpc.thrift.TShowRegionReq;
import org.apache.iotdb.confignode.rpc.thrift.TShowRegionResp;
import org.apache.iotdb.confignode.rpc.thrift.TTimeSlotList;
import org.apache.iotdb.it.env.EnvFactory;
import org.apache.iotdb.it.env.cluster.EnvUtils;
import org.apache.iotdb.it.env.cluster.config.MppBaseConfig;
Expand All @@ -33,9 +41,11 @@
import org.apache.iotdb.it.env.cluster.node.DataNodeWrapper;
import org.apache.iotdb.it.framework.IoTDBTestRunner;
import org.apache.iotdb.itbase.category.ClusterIT;
import org.apache.iotdb.rpc.TSStatusCode;

import org.apache.thrift.TException;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
Expand All @@ -46,7 +56,9 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import static org.apache.iotdb.consensus.ConsensusFactory.RATIS_CONSENSUS;

Expand All @@ -59,6 +71,8 @@ public class IoTDBClusterRestartIT {

private static final int testConfigNodeNum = 3, testDataNodeNum = 2;

private static final long testTimePartitionInterval = 604800000;

@Before
public void setUp() {
EnvFactory.getEnv()
Expand Down Expand Up @@ -114,6 +128,45 @@ public void clusterRestartTest() throws InterruptedException {
@Test
public void clusterRestartAfterUpdateDataNodeTest()
throws InterruptedException, ClientManagerException, IOException, TException {
// Create default Database
try (SyncConfigNodeIServiceClient client =
(SyncConfigNodeIServiceClient) EnvFactory.getEnv().getLeaderConfigNodeConnection()) {
TSStatus status = client.setDatabase(new TDatabaseSchema("root.database"));
Assert.assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
}
// Create some DataPartitions to extend 2 DataRegionGroups
Map<String, Map<TSeriesPartitionSlot, TTimeSlotList>> partitionSlotsMap =
ConfigNodeTestUtils.constructPartitionSlotsMap(
"root.database", 0, 10, 0, 10, testTimePartitionInterval);
TDataPartitionReq dataPartitionReq = new TDataPartitionReq(partitionSlotsMap);
TDataPartitionTableResp dataPartitionTableResp = null;
for (int retry = 0; retry < 5; retry++) {
// Build new Client since it's unstable in Win8 environment
try (SyncConfigNodeIServiceClient configNodeClient =
(SyncConfigNodeIServiceClient) EnvFactory.getEnv().getLeaderConfigNodeConnection()) {
dataPartitionTableResp = configNodeClient.getOrCreateDataPartitionTable(dataPartitionReq);
if (dataPartitionTableResp != null) {
break;
}
} catch (Exception e) {
// Retry sometimes in order to avoid request timeout
logger.error(e.getMessage());
TimeUnit.SECONDS.sleep(1);
}
}
Assert.assertNotNull(dataPartitionTableResp);
Assert.assertEquals(
TSStatusCode.SUCCESS_STATUS.getStatusCode(), dataPartitionTableResp.getStatus().getCode());
Assert.assertNotNull(dataPartitionTableResp.getDataPartitionTable());
ConfigNodeTestUtils.checkDataPartitionTable(
"root.database",
0,
10,
0,
10,
testTimePartitionInterval,
dataPartitionTableResp.getDataPartitionTable());

// Shutdown all DataNodes
for (int i = 0; i < testDataNodeNum; i++) {
EnvFactory.getEnv().shutdownDataNode(i);
Expand Down Expand Up @@ -151,12 +204,29 @@ public void clusterRestartAfterUpdateDataNodeTest()
// Check DataNode EndPoint
try (SyncConfigNodeIServiceClient client =
(SyncConfigNodeIServiceClient) EnvFactory.getEnv().getLeaderConfigNodeConnection()) {
// Check update in NodeInfo
TShowClusterResp showClusterResp = client.showCluster();
ConfigNodeTestUtils.checkNodeConfig(
showClusterResp.getConfigNodeList(),
showClusterResp.getDataNodeList(),
EnvFactory.getEnv().getConfigNodeWrapperList(),
dataNodeWrapperList);

// Check update in PartitionInfo
TShowRegionResp showRegionResp = client.showRegion(new TShowRegionReq());
showRegionResp
.getRegionInfoList()
.forEach(
regionInfo -> {
AtomicBoolean matched = new AtomicBoolean(false);
dataNodeWrapperList.forEach(
dataNodeWrapper -> {
if (regionInfo.getClientRpcPort() == dataNodeWrapper.getPort()) {
matched.set(true);
}
});
Assert.assertTrue(matched.get());
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,15 @@ public void testLoad() throws Exception {
}
}
}

// try delete after loading. Expect no deadlock
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
statement.execute(
String.format(
"delete timeseries %s.%s",
SchemaConfig.DEVICE_0, SchemaConfig.MEASUREMENT_00.getMeasurementId()));
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* 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.db.it;

import org.apache.iotdb.db.storageengine.dataregion.tsfile.generator.TsFileNameGenerator;
import org.apache.iotdb.it.env.EnvFactory;
import org.apache.iotdb.it.framework.IoTDBTestRunner;
import org.apache.iotdb.itbase.category.ClusterIT;
import org.apache.iotdb.itbase.category.LocalStandaloneIT;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.write.chunk.ChunkWriterImpl;
import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
import org.apache.iotdb.tsfile.write.writer.TsFileIOWriter;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.concurrent.TimeUnit;

import static org.apache.iotdb.db.utils.constant.TestConstant.TIMESTAMP_STR;
import static org.junit.Assert.assertNotNull;

@RunWith(IoTDBTestRunner.class)
@Category({LocalStandaloneIT.class, ClusterIT.class})
public class IoTDBRepairDataIT {

@BeforeClass
public static void setUp() throws Exception {
EnvFactory.getEnv().initClusterEnvironment();
}

@AfterClass
public static void tearDown() throws Exception {
EnvFactory.getEnv().initClusterEnvironment();
}

@Test
public void testRepairData() {
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
statement.execute("CREATE DATABASE root.tesgsg");
statement.execute("CREATE TIMESERIES root.testsg.d1.s1 WITH DATATYPE=INT32, ENCODING=PLAIN");
File tsfile = generateUnsortedFile();
statement.execute(
String.format("load \"%s\" verify=false", tsfile.getParentFile().getAbsolutePath()));

Assert.assertFalse(validate(statement));
statement.execute("REPAIR DATA");

int waitTimes = 20;
for (int i = 0; i < waitTimes; i++) {
boolean sorted = validate(statement);
if (sorted) {
return;
}
Thread.sleep(TimeUnit.SECONDS.toMillis(1));
}
Assert.fail();
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}

private File generateUnsortedFile() throws IOException {
Path tempDir = Files.createTempDirectory("");
tempDir.toFile().deleteOnExit();
String tsfileName =
TsFileNameGenerator.generateNewTsFileName(System.currentTimeMillis(), 1, 0, 0);
File tsfile = new File(tempDir + File.separator + tsfileName);
Files.createFile(tsfile.toPath());

try (TsFileIOWriter writer = new TsFileIOWriter(tsfile)) {
writer.startChunkGroup("root.testsg.d1");
ChunkWriterImpl chunkWriter =
new ChunkWriterImpl(new MeasurementSchema("s1", TSDataType.INT32));
chunkWriter.write(2, 1);
chunkWriter.write(3, 1);
chunkWriter.write(5, 1);
chunkWriter.write(4, 1);
chunkWriter.sealCurrentPage();

chunkWriter.writeToFileWriter(writer);
writer.endChunkGroup();
writer.endFile();
}
return tsfile;
}

private boolean validate(Statement statement) throws SQLException {
try (ResultSet resultSet = statement.executeQuery("SELECT s1 FROM root.testsg.d1")) {
assertNotNull(resultSet);
long time = Long.MIN_VALUE;
while (resultSet.next()) {
long currentTime = Long.parseLong(resultSet.getString(TIMESTAMP_STR));
if (currentTime <= time) {
return false;
}
time = currentTime;
}
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public void aggregationWithHavingTest() {

@Test
public void fillTest() {
// linear fill can not use TopKNode
String[] expectedHeader = new String[] {"Time,Device,s1,s2"};
String[] retArray =
new String[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public void testValidPipeName() throws Exception {
(SyncConfigNodeIServiceClient) senderEnv.getLeaderConfigNodeConnection()) {

List<String> validPipeNames = Arrays.asList("Pipe_1", "null", "`33`", "`root`", "中文", "with");
List<String> expectedPipeNames = Arrays.asList("Pipe_1", "null", "33", "root", "中文", "with");
for (String pipeName : validPipeNames) {
try (Connection connection = senderEnv.getConnection();
Statement statement = connection.createStatement()) {
Expand All @@ -77,7 +78,7 @@ public void testValidPipeName() throws Exception {
}

List<TShowPipeInfo> showPipeResult = client.showPipe(new TShowPipeReq()).pipeInfoList;
for (String pipeName : validPipeNames) {
for (String pipeName : expectedPipeNames) {
Assert.assertTrue(
showPipeResult.stream()
.anyMatch((o) -> o.id.equals(pipeName) && o.state.equals("RUNNING")));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.pipe.api.event;

/**
* User defined event is used to wrap data generated by users, keeping a source event to
* automatically report the processing progress to pipe engine.
*/
public abstract class UserDefinedEvent implements Event {

/** The user defined event is generated from this source event. */
protected final Event sourceEvent;

/**
* @param sourceEvent The source event of this user defined event which is used to report the
* processing progress to pipe engine. Please notice that the source event should satisfy the
* following conditions: 1. A source event can only be assigned to one user defined event. 2.
* If more than one user defined events are generated from the same source event, only the
* last generated user defined event can be assigned with the source event, others should be
* assigned {@code null}, or call {@link #UserDefinedEvent()} to generate a user defined event
* without source event.
*/
protected UserDefinedEvent(Event sourceEvent) {
this.sourceEvent = parseRootSourceEvent(sourceEvent);
}

/** Generate a user defined event without source event. */
protected UserDefinedEvent() {
this.sourceEvent = null;
}

private Event parseRootSourceEvent(Event sourceEvent) {
return sourceEvent instanceof UserDefinedEvent
? ((UserDefinedEvent) sourceEvent).getSourceEvent()
: sourceEvent;
}

public Event getSourceEvent() {
return sourceEvent;
}
}
Loading

0 comments on commit 01136c8

Please sign in to comment.