Skip to content

Commit 93c7c2e

Browse files
authored
[To rel/0.13][IOTDB-4640] Allow setting the same data archiving task after canceling it (#7609)
1 parent b7c7772 commit 93c7c2e

File tree

4 files changed

+67
-15
lines changed

4 files changed

+67
-15
lines changed

integration/src/test/java/org/apache/iotdb/db/integration/IoTDBArchivingIT.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public void testShowArchiving() throws SQLException {
293293

294294
@Test
295295
@Category({ClusterTest.class})
296-
public void testSetArchive() throws SQLException {
296+
public void testSetArchiving() throws SQLException {
297297
try (Connection connection = EnvFactory.getEnv().getConnection();
298298
Statement statement = connection.createStatement()) {
299299
StorageEngine.getInstance().getArchivingManager().setCheckThreadTime(Long.MAX_VALUE);
@@ -342,4 +342,46 @@ public void testSetArchive() throws SQLException {
342342
}
343343
}
344344
}
345+
346+
@Test
347+
@Category({ClusterTest.class})
348+
public void testReSubmitArchiving() throws SQLException {
349+
try (Connection connection = EnvFactory.getEnv().getConnection();
350+
Statement statement = connection.createStatement()) {
351+
StorageEngine.getInstance().getArchivingManager().setCheckThreadTime(Long.MAX_VALUE);
352+
353+
statement.execute("SET STORAGE GROUP TO root.ARCHIVING_SG4");
354+
355+
statement.execute(
356+
"SET ARCHIVING TO root.ARCHIVING_SG4 3000-12-13 100 '" + testTargetDir.getPath() + "'");
357+
ResultSet resultSet = statement.executeQuery("SHOW ARCHIVING");
358+
boolean flag = false;
359+
while (resultSet.next()) {
360+
if (resultSet.getString(3).equals("root.ARCHIVING_SG4")) {
361+
flag = true;
362+
assertEquals("READY", resultSet.getString(4));
363+
assertTrue(resultSet.getString(5).startsWith("3000-12-13"));
364+
assertEquals(100, resultSet.getLong(6));
365+
assertEquals(testTargetDir.getPath(), resultSet.getString(7));
366+
}
367+
}
368+
assertTrue(flag);
369+
370+
statement.execute("CANCEL ARCHIVING 0");
371+
statement.execute(
372+
"SET ARCHIVING TO root.ARCHIVING_SG4 3000-12-13 100 '" + testTargetDir.getPath() + "'");
373+
resultSet = statement.executeQuery("SHOW ARCHIVING");
374+
flag = false;
375+
while (resultSet.next()) {
376+
if (resultSet.getString(3).equals("root.ARCHIVING_SG4")) {
377+
flag = true;
378+
assertEquals("READY", resultSet.getString(4));
379+
assertTrue(resultSet.getString(5).startsWith("3000-12-13"));
380+
assertEquals(100, resultSet.getLong(6));
381+
assertEquals(testTargetDir.getPath(), resultSet.getString(7));
382+
}
383+
}
384+
assertTrue(flag);
385+
}
386+
}
345387
}

server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,13 +1316,8 @@ protected void getSeriesSchemas(InsertPlan insertPlan, VirtualStorageGroupProces
13161316
}
13171317

13181318
/** push the archiving info to archivingManager */
1319-
public void setArchiving(PartialPath storageGroup, File targetDir, long ttl, long startTime) {
1320-
boolean result = archivingManager.setArchiving(storageGroup, targetDir, ttl, startTime);
1321-
if (result) {
1322-
logger.info("set archiving task successfully.");
1323-
} else {
1324-
logger.info("set archiving task failed.");
1325-
}
1319+
public boolean setArchiving(PartialPath storageGroup, File targetDir, long ttl, long startTime) {
1320+
return archivingManager.setArchiving(storageGroup, targetDir, ttl, startTime);
13261321
}
13271322

13281323
public boolean operateArchiving(

server/src/main/java/org/apache/iotdb/db/engine/archiving/ArchivingManager.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,14 @@ public boolean setArchiving(PartialPath storageGroup, File targetDir, long ttl,
212212

213213
// check if there are duplicates
214214
for (ArchivingTask archivingTask : archivingTasks) {
215-
if (archivingTask.getStorageGroup().getFullPath().equals(storageGroup.getFullPath())
215+
if (archivingTask.isActive()
216+
&& archivingTask.getStorageGroup().getFullPath().equals(storageGroup.getFullPath())
216217
&& archivingTask.getTargetDir().equals(targetDir)
217218
&& archivingTask.getTTL() == ttl
218219
&& archivingTask.getStartTime() == startTime) {
219-
logger.warn("archiving task already equals archiving task {}", archivingTask.getTaskId());
220+
logger.warn(
221+
"Fail to set archiving task, it's same as the archiving task {}",
222+
archivingTask.getTaskId());
220223
return false;
221224
}
222225
}

server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,16 +1713,28 @@ private void operateSetArchiving(SetArchivingPlan plan) throws QueryProcessExcep
17131713
throw new QueryProcessException("Fail to cancel archiving task.");
17141714
}
17151715
} else {
1716+
List<PartialPath> storageGroupPaths;
17161717
try {
1717-
List<PartialPath> storageGroupPaths =
1718+
storageGroupPaths =
17181719
IoTDB.metaManager.getMatchedStorageGroups(plan.getStorageGroup(), plan.isPrefixMatch());
1719-
for (PartialPath storagePath : storageGroupPaths) {
1720-
StorageEngine.getInstance()
1721-
.setArchiving(storagePath, plan.getTargetDir(), plan.getTTL(), plan.getStartTime());
1722-
}
17231720
} catch (MetadataException e) {
17241721
throw new QueryProcessException(e);
17251722
}
1723+
1724+
List<String> failedStorageGroups = new ArrayList<>();
1725+
for (PartialPath storagePath : storageGroupPaths) {
1726+
boolean success =
1727+
StorageEngine.getInstance()
1728+
.setArchiving(storagePath, plan.getTargetDir(), plan.getTTL(), plan.getStartTime());
1729+
if (!success) {
1730+
failedStorageGroups.add(storagePath.getFullPath());
1731+
}
1732+
}
1733+
if (!failedStorageGroups.isEmpty()) {
1734+
throw new QueryProcessException(
1735+
String.format(
1736+
"Fail to set archiving tasks for %s", String.join(", ", failedStorageGroups)));
1737+
}
17261738
}
17271739
}
17281740

0 commit comments

Comments
 (0)