Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* 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.relational.it.schema;

import org.apache.iotdb.db.it.utils.TestUtils;
import org.apache.iotdb.it.env.EnvFactory;
import org.apache.iotdb.it.framework.IoTDBTestRunner;
import org.apache.iotdb.itbase.category.TableClusterIT;
import org.apache.iotdb.itbase.category.TableLocalStandaloneIT;
import org.apache.iotdb.itbase.env.BaseEnv;

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

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Collections;
import java.util.concurrent.TimeUnit;

import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

@RunWith(IoTDBTestRunner.class)
@Category({TableLocalStandaloneIT.class, TableClusterIT.class})
public class IoTDBDropTableModProgressIT {

@BeforeClass
public static void setUp() throws Exception {
EnvFactory.getEnv()
.getConfig()
.getCommonConfig()
.setEnforceStrongPassword(false)
.setDataRegionGroupExtensionPolicy("CUSTOM")
.setDefaultDataRegionGroupNumPerDatabase(1);
EnvFactory.getEnv().initClusterEnvironment();
}

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

@Test
public void testDropTableModFileProgress() throws Exception {
try (final Connection connection =
EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
final Statement statement = connection.createStatement()) {
statement.execute("create database async_drop_mod_db");
statement.execute("use async_drop_mod_db");
statement.execute("create table drop_target (device string tag, reading int32)");
statement.execute("create table retained (device string tag, reading int32)");
// One region ensures both tables share a TsFile. Dropping just one table must write a mod
// file rather than delete that TsFile outright, and replicas must not multiply the count.
statement.execute("insert into drop_target(time, device, reading) values (1, 'd1', 10)");
statement.execute("insert into retained(time, device, reading) values (1, 'd1', 20)");
statement.execute("flush");
statement.execute("drop table drop_target");
await()
.atMost(60, TimeUnit.SECONDS)
.untilAsserted(
() -> {
try (final ResultSet resultSet =
statement.executeQuery(
"select state, written_mod_file_count, remaining_mod_file_count "
+ "from information_schema.drop_table_procedures "
+ "where database = 'async_drop_mod_db' and table_name = 'drop_target'")) {
assertTrue(resultSet.next());
assertEquals("SUCCESS", resultSet.getString(1));
assertEquals(1, resultSet.getLong(2));
assertFalse(resultSet.wasNull());
assertEquals(0, resultSet.getLong(3));
assertFalse(resultSet.wasNull());
assertFalse(resultSet.next());
}
});
TestUtils.assertResultSetEqual(
statement.executeQuery("select device, reading from retained"),
"device,reading,",
Collections.singleton("d1,20,"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1250,14 +1250,19 @@ public void testAsyncDropTableProgress() throws Exception {
Collections.emptySet());
try (final ResultSet resultSet =
statement.executeQuery(
"select procedure_id, state, progress, error_message "
"select procedure_id, state, progress, error_message, "
+ "written_mod_file_count, remaining_mod_file_count "
+ "from information_schema.drop_table_procedures "
+ "where database = 'async_drop_db' and table_name = 'drop_target'")) {
assertTrue(resultSet.next());
assertTrue(resultSet.getLong(1) >= 0);
assertEquals("SUCCESS", resultSet.getString(2));
assertEquals("SUCCESS", resultSet.getString(3));
Assert.assertNull(resultSet.getString(4));
assertEquals(0, resultSet.getLong(5));
assertFalse(resultSet.wasNull());
assertEquals(0, resultSet.getLong(6));
assertFalse(resultSet.wasNull());
assertFalse(resultSet.next());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public enum CnToDnAsyncRequestType {
UPDATE_TABLE,
PRE_DELETE_TABLE,
DELETE_DATA_FOR_DROP_TABLE,
GET_DROP_TABLE_MOD_PROGRESS,
DELETE_DEVICES_FOR_DROP_TABLE,
INVALIDATE_COLUMN_CACHE,
DELETE_COLUMN_DATA,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.iotdb.confignode.client.async.handlers.rpc.DataNodeTSStatusRPCHandler;
import org.apache.iotdb.confignode.client.async.handlers.rpc.FetchSchemaBlackListRPCHandler;
import org.apache.iotdb.confignode.client.async.handlers.rpc.GetBuiltInExternalServiceRPCHandler;
import org.apache.iotdb.confignode.client.async.handlers.rpc.GetDropTableModProgressRPCHandler;
import org.apache.iotdb.confignode.client.async.handlers.rpc.PipeHeartbeatRPCHandler;
import org.apache.iotdb.confignode.client.async.handlers.rpc.PipePushMetaRPCHandler;
import org.apache.iotdb.confignode.client.async.handlers.rpc.SchemaUpdateRPCHandler;
Expand Down Expand Up @@ -78,6 +79,7 @@
import org.apache.iotdb.mpp.rpc.thrift.TDropPipePluginInstanceReq;
import org.apache.iotdb.mpp.rpc.thrift.TDropTriggerInstanceReq;
import org.apache.iotdb.mpp.rpc.thrift.TFetchSchemaBlackListReq;
import org.apache.iotdb.mpp.rpc.thrift.TGetDropTableModProgressReq;
import org.apache.iotdb.mpp.rpc.thrift.TInactiveTriggerInstanceReq;
import org.apache.iotdb.mpp.rpc.thrift.TInvalidateCacheReq;
import org.apache.iotdb.mpp.rpc.thrift.TInvalidateColumnCacheReq;
Expand Down Expand Up @@ -457,6 +459,11 @@ protected void initActionMapBuilder() {
(req, client, handler) ->
client.invalidateTableCache(
(TInvalidateTableCacheReq) req, (DataNodeTSStatusRPCHandler) handler));
actionMapBuilder.put(
CnToDnAsyncRequestType.GET_DROP_TABLE_MOD_PROGRESS,
(req, client, handler) ->
client.getDropTableModProgress(
(TGetDropTableModProgressReq) req, (GetDropTableModProgressRPCHandler) handler));
actionMapBuilder.put(
CnToDnAsyncRequestType.DELETE_DATA_FOR_DROP_TABLE,
(req, client, handler) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.iotdb.mpp.rpc.thrift.TCountPathsUsingTemplateResp;
import org.apache.iotdb.mpp.rpc.thrift.TDeviceViewResp;
import org.apache.iotdb.mpp.rpc.thrift.TFetchSchemaBlackListResp;
import org.apache.iotdb.mpp.rpc.thrift.TGetDropTableModProgressResp;
import org.apache.iotdb.mpp.rpc.thrift.TPullCommitProgressResp;
import org.apache.iotdb.mpp.rpc.thrift.TPushConsumerGroupMetaResp;
import org.apache.iotdb.mpp.rpc.thrift.TPushPipeMetaResp;
Expand Down Expand Up @@ -82,6 +83,14 @@ public static DataNodeAsyncRequestRPCHandler<?> buildHandler(
Map<Integer, ?> responseMap = context.getResponseMap();
CountDownLatch countDownLatch = context.getCountDownLatch();
switch (requestType) {
case GET_DROP_TABLE_MOD_PROGRESS:
return new GetDropTableModProgressRPCHandler(
requestType,
requestId,
targetDataNode,
dataNodeLocationMap,
(Map<Integer, TGetDropTableModProgressResp>) responseMap,
countDownLatch);
case CONSTRUCT_SCHEMA_BLACK_LIST:
case ROLLBACK_SCHEMA_BLACK_LIST:
case DELETE_DATA_FOR_DELETE_SCHEMA:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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.client.async.handlers.rpc;

import org.apache.iotdb.common.rpc.thrift.TDataNodeLocation;
import org.apache.iotdb.confignode.client.async.CnToDnAsyncRequestType;
import org.apache.iotdb.mpp.rpc.thrift.TGetDropTableModProgressResp;
import org.apache.iotdb.rpc.RpcUtils;
import org.apache.iotdb.rpc.TSStatusCode;

import java.util.Map;
import java.util.concurrent.CountDownLatch;

public class GetDropTableModProgressRPCHandler
extends DataNodeAsyncRequestRPCHandler<TGetDropTableModProgressResp> {

public GetDropTableModProgressRPCHandler(
CnToDnAsyncRequestType requestType,
int requestId,
TDataNodeLocation targetNode,
Map<Integer, TDataNodeLocation> nodeLocationMap,
Map<Integer, TGetDropTableModProgressResp> responseMap,
CountDownLatch countDownLatch) {
super(requestType, requestId, targetNode, nodeLocationMap, responseMap, countDownLatch);
}

@Override
public void onComplete(final TGetDropTableModProgressResp response) {
responseMap.put(requestId, response);
nodeLocationMap.remove(requestId);
countDownLatch.countDown();
}

@Override
public void onError(final Exception e) {
responseMap.put(
requestId,
new TGetDropTableModProgressResp(
RpcUtils.getStatus(TSStatusCode.CAN_NOT_CONNECT_DATANODE)));
countDownLatch.countDown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
import org.apache.iotdb.confignode.rpc.thrift.TUnsubscribeReq;
import org.apache.iotdb.consensus.ConsensusFactory;
import org.apache.iotdb.db.exception.BatchProcessException;
import org.apache.iotdb.mpp.rpc.thrift.TDropTableModProgress;
import org.apache.iotdb.rpc.RpcUtils;
import org.apache.iotdb.rpc.TSStatusCode;
import org.apache.iotdb.rpc.subscription.config.TopicConfig;
Expand Down Expand Up @@ -2549,6 +2550,9 @@ public List<TDropTableProcedureInfo> getDropTableProcedures() {
&& !(procedure instanceof DropViewProcedure))
.map(procedure -> (DropTableProcedure) procedure)
.forEach(procedure -> dropProcedures.put(procedure.getProcId(), procedure));
dropProcedures.values().stream()
.filter(procedure -> !procedure.isFinished())
.forEach(DropTableProcedure::updateModFileProgress);
return dropProcedures.values().stream()
.map(
procedure -> {
Expand All @@ -2559,6 +2563,13 @@ public List<TDropTableProcedureInfo> getDropTableProcedures() {
procedure.getProcId(),
procedure.getState().name(),
procedure.getDropProgress());
final TDropTableModProgress modProgress = procedure.getModFileProgress();
if (modProgress != null) {
info.setWrittenModFileCount(modProgress.getWrittenModFileCount());
if (modProgress.isSetRemainingModFileCount()) {
info.setRemainingModFileCount(modProgress.getRemainingModFileCount());
}
}
if (procedure.hasException()) {
info.setErrorMessage(procedure.getException().getMessage());
}
Expand Down
Loading
Loading