Skip to content

Commit fef95aa

Browse files
committed
Add IT
1 parent 4cbf3e0 commit fef95aa

File tree

3 files changed

+166
-3
lines changed

3 files changed

+166
-3
lines changed

integration-test/src/test/java/org/apache/iotdb/relational/it/session/IoTDBObjectDeleteIT.java

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public static void classTearDown() {
8383
}
8484

8585
@Test
86-
public void deleteObjectTest()
86+
public void dropObjectTableTest()
8787
throws IoTDBConnectionException, StatementExecutionException, IOException {
8888
String testObject =
8989
System.getProperty("user.dir")
@@ -172,6 +172,96 @@ public void deleteObjectTest()
172172
Assert.assertFalse(success);
173173
}
174174

175+
@Test
176+
public void dropObjectColumnTest()
177+
throws IoTDBConnectionException, StatementExecutionException, IOException {
178+
String testObject =
179+
System.getProperty("user.dir")
180+
+ File.separator
181+
+ "target"
182+
+ File.separator
183+
+ "test-classes"
184+
+ File.separator
185+
+ "object-example.pt";
186+
187+
try (ITableSession session = EnvFactory.getEnv().getTableSessionConnection()) {
188+
session.executeNonQueryStatement("USE \"db1\"");
189+
// insert table data by tablet
190+
List<String> columnNameList =
191+
Arrays.asList("region_id", "plant_id", "device_id", "temperature", "file");
192+
List<TSDataType> dataTypeList =
193+
Arrays.asList(
194+
TSDataType.STRING,
195+
TSDataType.STRING,
196+
TSDataType.STRING,
197+
TSDataType.FLOAT,
198+
TSDataType.OBJECT);
199+
List<ColumnCategory> columnTypeList =
200+
new ArrayList<>(
201+
Arrays.asList(
202+
ColumnCategory.TAG,
203+
ColumnCategory.TAG,
204+
ColumnCategory.TAG,
205+
ColumnCategory.FIELD,
206+
ColumnCategory.FIELD));
207+
Tablet tablet = new Tablet("object_table", columnNameList, dataTypeList, columnTypeList, 1);
208+
int rowIndex = tablet.getRowSize();
209+
tablet.addTimestamp(rowIndex, 1);
210+
tablet.addValue(rowIndex, 0, "1");
211+
tablet.addValue(rowIndex, 1, "5");
212+
tablet.addValue(rowIndex, 2, "3");
213+
tablet.addValue(rowIndex, 3, 37.6F);
214+
tablet.addValue(rowIndex, 4, true, 0, Files.readAllBytes(Paths.get(testObject)));
215+
session.insert(tablet);
216+
tablet.reset();
217+
218+
try (SessionDataSet dataSet =
219+
session.executeQueryStatement(
220+
"select READ_OBJECT(file) from object_table where time = 1")) {
221+
SessionDataSet.DataIterator iterator = dataSet.iterator();
222+
while (iterator.next()) {
223+
Binary binary = iterator.getBlob(1);
224+
Assert.assertArrayEquals(Files.readAllBytes(Paths.get(testObject)), binary.getValues());
225+
}
226+
session.executeNonQueryStatement("ALTER TABLE object_table drop column file");
227+
}
228+
}
229+
230+
// test object file path
231+
boolean success = false;
232+
for (DataNodeWrapper dataNodeWrapper : EnvFactory.getEnv().getDataNodeWrapperList()) {
233+
String objectDirStr = dataNodeWrapper.getDataNodeObjectDir();
234+
File objectDir = new File(objectDirStr);
235+
if (objectDir.exists() && objectDir.isDirectory()) {
236+
File[] regionDirs = objectDir.listFiles();
237+
if (regionDirs != null) {
238+
for (File regionDir : regionDirs) {
239+
if (regionDir.isDirectory()) {
240+
File objectFile =
241+
new File(
242+
regionDir,
243+
convertPathString("object_table")
244+
+ File.separator
245+
+ convertPathString("1")
246+
+ File.separator
247+
+ convertPathString("5")
248+
+ File.separator
249+
+ convertPathString("3")
250+
+ File.separator
251+
+ convertPathString("file")
252+
+ File.separator
253+
+ "1.bin");
254+
if (objectFile.exists() && objectFile.isFile()) {
255+
success = true;
256+
}
257+
}
258+
}
259+
}
260+
}
261+
}
262+
Assert.assertFalse(success);
263+
}
264+
175265
@Test
176266
public void deleteObjectSegmentsTest()
177267
throws IoTDBConnectionException, StatementExecutionException, IOException {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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.relational.it.session;
21+
22+
import org.apache.iotdb.it.env.EnvFactory;
23+
import org.apache.iotdb.itbase.category.TableClusterIT;
24+
import org.apache.iotdb.itbase.category.TableLocalStandaloneIT;
25+
26+
import org.junit.AfterClass;
27+
import org.junit.BeforeClass;
28+
import org.junit.experimental.categories.Category;
29+
30+
@Category({TableLocalStandaloneIT.class, TableClusterIT.class})
31+
public class IoTDBObjectDeleteIT2 extends IoTDBObjectDeleteIT {
32+
33+
@BeforeClass
34+
public static void classSetUp() throws Exception {
35+
EnvFactory.getEnv().getConfig().getCommonConfig().setRestrictObjectLimit(true);
36+
EnvFactory.getEnv().initClusterEnvironment();
37+
}
38+
39+
@AfterClass
40+
public static void classTearDown() {
41+
EnvFactory.getEnv().cleanClusterEnvironment();
42+
}
43+
44+
@Override
45+
protected String convertPathString(String path) {
46+
return path;
47+
}
48+
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@
218218
import java.util.concurrent.Future;
219219
import java.util.concurrent.TimeUnit;
220220
import java.util.concurrent.atomic.AtomicBoolean;
221+
import java.util.concurrent.atomic.AtomicInteger;
221222
import java.util.concurrent.atomic.AtomicLong;
222223
import java.util.concurrent.locks.Condition;
223224
import java.util.concurrent.locks.ReadWriteLock;
@@ -1999,6 +2000,8 @@ private void deleteAllSGFolders(List<String> folder) {
19992000
private void deleteAllObjectFiles(List<String> folders) {
20002001
for (String objectFolder : folders) {
20012002
File dataRegionObjectFolder = fsFactory.getFile(objectFolder, dataRegionIdString);
2003+
AtomicLong totalSize = new AtomicLong(0);
2004+
AtomicInteger count = new AtomicInteger(0);
20022005
try (Stream<Path> paths = Files.walk(dataRegionObjectFolder.toPath())) {
20032006
paths
20042007
.filter(Files::isRegularFile)
@@ -2009,12 +2012,14 @@ private void deleteAllObjectFiles(List<String> folders) {
20092012
})
20102013
.forEach(
20112014
path -> {
2012-
FileMetrics.getInstance().decreaseObjectFileNum(1);
2013-
FileMetrics.getInstance().decreaseObjectFileSize(path.toFile().length());
2015+
count.incrementAndGet();
2016+
totalSize.addAndGet(path.toFile().length());
20142017
});
20152018
} catch (IOException e) {
20162019
logger.error("Failed to check Object Files: {}", e.getMessage());
20172020
}
2021+
FileMetrics.getInstance().decreaseObjectFileNum(count.get());
2022+
FileMetrics.getInstance().decreaseObjectFileSize(totalSize.get());
20182023
if (FSUtils.getFSType(dataRegionObjectFolder) != FSType.LOCAL) {
20192024
try {
20202025
fsFactory.deleteDirectory(dataRegionObjectFolder.getPath());
@@ -2773,10 +2778,30 @@ public void deleteByTable(RelationalDeleteDataNode node) throws IOException {
27732778
boolean droppingTable = false;
27742779
for (TableDeletionEntry entry : modEntries) {
27752780
if (entry.isDroppingTable()) {
2781+
AtomicLong totalSize = new AtomicLong(0);
2782+
AtomicInteger count = new AtomicInteger(0);
27762783
for (File objectTableDir : objectTableDirs) {
27772784
droppingTable = true;
2785+
try (Stream<Path> paths = Files.walk(objectTableDir.toPath())) {
2786+
paths
2787+
.filter(Files::isRegularFile)
2788+
.filter(
2789+
path -> {
2790+
String name = path.getFileName().toString();
2791+
return name.endsWith(".bin");
2792+
})
2793+
.forEach(
2794+
path -> {
2795+
count.incrementAndGet();
2796+
totalSize.addAndGet(path.toFile().length());
2797+
});
2798+
} catch (IOException e) {
2799+
logger.error("Failed to check Object Files: {}", e.getMessage());
2800+
}
27782801
FileUtils.deleteQuietly(objectTableDir);
27792802
}
2803+
FileMetrics.getInstance().decreaseObjectFileNum(count.get());
2804+
FileMetrics.getInstance().decreaseObjectFileSize(totalSize.get());
27802805
}
27812806
}
27822807
if (!droppingTable) {

0 commit comments

Comments
 (0)