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 numberDiff line numberDiff line change
Expand Up@@ -109,6 +109,9 @@ public void testSetConfiguration() {
statement.execute(
"set configuration inner_compaction_candidate_file_num='1',max_cross_compaction_candidate_file_num='1' on "
+ dnId);
if (dnId == 5) {
statement.execute("set configuration compaction_schedule_thread_num='2' on 5");
}
}
} catch (Exception e) {
Assert.fail(e.getMessage());
Expand All@@ -131,6 +134,17 @@ public void testSetConfiguration() {
"enable_cross_space_compaction=false",
"inner_compaction_candidate_file_num=1",
"max_cross_compaction_candidate_file_num=1"));
boolean scheduleThreadNumChanged =
checkConfigFileContains(
dnId,
EnvFactory.getEnv().getDataNodeWrapperList().get(i),
"compaction_schedule_thread_num=2");
if (scheduleThreadNumChanged && dnId != 5) {
Assert.fail();
}
if (!scheduleThreadNumChanged && dnId == 5) {
Assert.fail();
}
}
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -1052,7 +1052,7 @@ public List<TSStatus> setConfiguration(TSetConfigurationReq req) {
if (!targetDataNodes.isEmpty()) {
DataNodeAsyncRequestContext<Object, TSStatus> clientHandler =
new DataNodeAsyncRequestContext<>(
CnToDnAsyncRequestType.SET_CONFIGURATION, req, dataNodeLocationMap);
CnToDnAsyncRequestType.SET_CONFIGURATION, req, targetDataNodes);
CnToDnInternalServiceAsyncRequestManager.getInstance()
.sendAsyncRequestWithRetry(clientHandler);
responseList.addAll(clientHandler.getResponseList());
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -2453,7 +2453,7 @@
* lock if return true, the caller is responsible for unlocking all the already-acquiring lock
* in needToUnLockList
*/
private boolean tryGetFLushLock(

Check warning on line 2456 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java

View check run for this annotation

SonarQubeCloud/ SonarCloud Code Analysis

A "Brain Method" was detected. Refactor it to reduce at least one of the following metrics: LOC from 81 to 64, Complexity from 19 to 14, Nesting Level from 5 to 2, Number of Variables from 17 to 6.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ2J9qOj56xqTh8SzZtE&open=AZ2J9qOj56xqTh8SzZtE&pullRequest=17469
long waitTimeInMs,
IDeviceID singleDeviceId,
Filter globalTimeFilter,
Expand DownExpand Up@@ -2891,7 +2891,7 @@
}
}

public void deleteByTable(RelationalDeleteDataNode node) throws IOException {

Check warning on line 2894 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java

View check run for this annotation

SonarQubeCloud/ SonarCloud Code Analysis

A "Brain Method" was detected. Refactor it to reduce at least one of the following metrics: LOC from 94 to 64, Complexity from 17 to 14, Nesting Level from 7 to 2, Number of Variables from 24 to 6.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ2J9qOj56xqTh8SzZtF&open=AZ2J9qOj56xqTh8SzZtF&pullRequest=17469
if (node.getDatabaseName() != null && !node.getDatabaseName().equals(databaseName)) {
// not targeted on this database, return
return;
Expand DownExpand Up@@ -3277,7 +3277,7 @@
}
}

private void deleteDataInSealedFiles(Collection<TsFileResource> sealedTsFiles, ModEntry deletion)

Check warning on line 3280 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java

View check run for this annotation

SonarQubeCloud/ SonarCloud Code Analysis

A "Brain Method" was detected. Refactor it to reduce at least one of the following metrics: LOC from 143 to 64, Complexity from 28 to 14, Nesting Level from 5 to 2, Number of Variables from 26 to 6.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ2J9qOj56xqTh8SzZtG&open=AZ2J9qOj56xqTh8SzZtG&pullRequest=17469
throws IOException {
Set<ModificationFile> involvedModificationFiles = new HashSet<>();
List<TsFileResource> deletedByMods = new ArrayList<>();
Expand DownExpand Up@@ -3705,7 +3705,11 @@
if (!regionObjectDir.isDirectory()) {
continue;
}
CompactionUtils.executeTTLCheckObjectFilesForTableModel(regionObjectDir, databaseName);
try {
CompactionUtils.executeTTLCheckObjectFilesForTableModel(regionObjectDir, databaseName);
} catch (Exception e) {
logger.error("Failed to execute object ttl check", e);
}
}
CompactionMetrics.getInstance()
.updateTTLCheckForObjectFileCost(System.currentTimeMillis() - startTime);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -69,9 +69,11 @@
import javax.annotation.Nullable;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Collection;
Expand DownExpand Up@@ -595,7 +597,10 @@ private static void recursiveTTLCheckForTableDir(
checkTTLAndDeleteExpiredObjectFile(currentFile, basicFileAttributes, lowerBoundInMS);
return;
}
} catch (IOException ignored) {
} catch (FileNotFoundException | NoSuchFileException ignored) {
// may be deleted by other thread
} catch (IOException e) {
logger.warn("Failed to read file attributes: {}", currentFile, e);
}
}
File[] children = currentFile.listFiles();
Expand All@@ -606,8 +611,16 @@ private static void recursiveTTLCheckForTableDir(
// block-aligned and reflects allocated directory entry blocks.
acquireCompactionReadRate(currentFile.length());
for (File child : children) {
recursiveTTLCheckForTableDir(
child, depth + 1, maxObjectFileDepth, canDistinguishDirectoryByFileName, lowerBoundInMS);
try {
recursiveTTLCheckForTableDir(
child,
depth + 1,
maxObjectFileDepth,
canDistinguishDirectoryByFileName,
lowerBoundInMS);
} catch (Exception e) {
logger.warn("Failed to check table dir: {}", child, e);
}
}
}

Expand DownExpand Up@@ -637,7 +650,10 @@ private static void checkTTLAndDeleteExpiredObjectFile(
FileMetrics.getInstance().decreaseObjectFileNum(1);
FileMetrics.getInstance().decreaseObjectFileSize(attributes.size());
logger.info("Remove object file {}, size is {}(byte)", file.getPath(), attributes.size());
} catch (Exception ignored) {
} catch (FileNotFoundException | NoSuchFileException ignored) {
// may be deleted by other thread
} catch (Exception e) {
logger.warn("Failed to delete expired object file: {}", file, e);
}
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,6 +65,7 @@ public class CompactionScheduleTaskManager implements IService {
ConcurrentHashMap.newKeySet();
private ReentrantLock lock = new ReentrantLock();
private volatile boolean init = false;
private volatile boolean isStoppingAllScheduleTask = false;

@Override
public void start() throws StartupException {
Expand All@@ -76,8 +77,13 @@ public void start() throws StartupException {
logger.info("Compaction schedule task manager started.");
}

public boolean isStoppingAllScheduleTask() {
return isStoppingAllScheduleTask;
}

public void stopCompactionScheduleTasks() throws InterruptedException {
lock.lock();
isStoppingAllScheduleTask = true;
try {
for (Future<Void> task : submitCompactionScheduleTaskFutures) {
task.cancel(true);
Expand DownExpand Up@@ -121,6 +127,7 @@ public void checkAndMayApplyConfigurationChange() throws InterruptedException {

public void startScheduleTasks() {
lock.lock();
isStoppingAllScheduleTask = false;
try {
// compaction selector
for (int workerId = 0; workerId < compactionSelectorNum; workerId++) {
Expand All@@ -144,6 +151,7 @@ public void startScheduleTasks() {
@Override
public void stop() {
lock.lock();
isStoppingAllScheduleTask = true;
try {
if (!init) {
return;
Expand All@@ -160,6 +168,7 @@ public void stop() {
@Override
public void waitAndStop(long milliseconds) {
lock.lock();
isStoppingAllScheduleTask = true;
try {
if (!init) {
return;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,7 +49,7 @@

@Override
@SuppressWarnings("java:S2142")
public Void call() {

Check failure on line 52 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/schedule/CompactionScheduleTaskWorker.java

View check run for this annotation

SonarQubeCloud/ SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 22 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ2J9qJQ56xqTh8SzZtB&open=AZ2J9qJQ56xqTh8SzZtB&pullRequest=17469
while (true) {
try {
Thread.sleep(IoTDBDescriptor.getInstance().getConfig().getCompactionScheduleIntervalInMs());
Expand All@@ -72,9 +72,26 @@
dataRegion.executeCompaction();
}
} catch (InterruptedException ignored) {
boolean isStoppedByUser =
CompactionScheduleTaskManager.getInstance().isStoppingAllScheduleTask();
logger.info(
"[CompactionScheduleTaskWorker-{}] compaction schedule is interrupted", workerId);
return null;
"[CompactionScheduleTaskWorker-{}] compaction schedule is interrupted, isStopByUser: {}",

Check warning on line 78 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/schedule/CompactionScheduleTaskWorker.java

View check run for this annotation

SonarQubeCloud/ SonarCloud Code Analysis

Line is longer than 100 characters (found 101).

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ2J9qJQ56xqTh8SzZtC&open=AZ2J9qJQ56xqTh8SzZtC&pullRequest=17469
workerId,
isStoppedByUser);
if (isStoppedByUser) {
return null;
}
} catch (Exception e) {
logger.error(
"[CompactionScheduleTaskWorker-{}] Failed to execute compaction schedule task",
workerId,
e);
} catch (Throwable t) {

Check warning on line 89 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/schedule/CompactionScheduleTaskWorker.java

View check run for this annotation

SonarQubeCloud/ SonarCloud Code Analysis

Catch Exception instead of Throwable.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ2KM_XP2Etj696fjCvN&open=AZ2KM_XP2Etj696fjCvN&pullRequest=17469

Check warning on line 89 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/schedule/CompactionScheduleTaskWorker.java

View check run for this annotation

SonarQubeCloud/ SonarCloud Code Analysis

Either log this exception and handle it, or rethrow it with some contextual information.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ2KM_XP2Etj696fjCvO&open=AZ2KM_XP2Etj696fjCvO&pullRequest=17469
logger.error(
"[CompactionScheduleTaskWorker-{}] Failed to execute compaction schedule task and cannot recover",

Check warning on line 91 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/schedule/CompactionScheduleTaskWorker.java

View check run for this annotation

SonarQubeCloud/ SonarCloud Code Analysis

Line is longer than 100 characters (found 110).

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ2KM_XP2Etj696fjCvP&open=AZ2KM_XP2Etj696fjCvP&pullRequest=17469
workerId,
t);
throw t;
}
}
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -78,8 +78,21 @@
}
}
} catch (InterruptedException ignored) {
logger.info("[TTLCheckTask-{}] TTL checker is interrupted", workerId);
return null;
boolean isStoppedByUser =
CompactionScheduleTaskManager.getInstance().isStoppingAllScheduleTask();
logger.info(
"[TTLCheckTask-{}] TTL checker is interrupted, isStoppedByUser: {}",
workerId,
isStoppedByUser);
if (isStoppedByUser) {
return null;
}
} catch (Exception e) {
logger.error("[TTLCheckTask-{}] Failed to execute ttl check", workerId, e);
} catch (Throwable t) {

Check warning on line 92 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/schedule/TTLScheduleTask.java

View check run for this annotation

SonarQubeCloud/ SonarCloud Code Analysis

Either log this exception and handle it, or rethrow it with some contextual information.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ2KM_du2Etj696fjCvR&open=AZ2KM_du2Etj696fjCvR&pullRequest=17469

Check warning on line 92 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/schedule/TTLScheduleTask.java

View check run for this annotation

SonarQubeCloud/ SonarCloud Code Analysis

Catch Exception instead of Throwable.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ2KM_du2Etj696fjCvQ&open=AZ2KM_du2Etj696fjCvQ&pullRequest=17469
logger.error(
"[TTLCheckTask-{}] Failed to execute ttl check and cannot recover", workerId, t);
throw t;
}
}
}
Expand Down
Loading