This is an automated email from the ASF dual-hosted git repository.
haonan pushed a commit to branch branch-fixsonarbug202405
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/branch-fixsonarbug202405 by
this push:
new 15a3e7c13cb fix sonar step 2
15a3e7c13cb is described below
commit 15a3e7c13cb8d9ab90cacfd1b369526d06f762d7
Author: HTHou <[email protected]>
AuthorDate: Tue May 21 12:38:04 2024 +0800
fix sonar step 2
---
.../dataregion/compaction/tool/PrintUtil.java | 2 +-
.../compaction/tool/TimePartitionProcessTask.java | 2 +
.../dataregion/modification/ModificationFile.java | 2 +-
.../io/LocalTextModificationAccessor.java | 7 +-
.../file/UnsealedTsFileRecoverPerformer.java | 6 +-
.../db/tools/schema/PBTreeFileSketchTool.java | 9 +-
.../db/tools/schema/SRStatementGenerator.java | 123 +++++++++++----------
.../iotdb/db/utils/datastructure/BackwardSort.java | 2 +-
.../apache/iotdb/commons/conf/CommonConfig.java | 2 +-
.../commons/service/metric/GcTimeAlerter.java | 2 +-
.../apache/iotdb/commons/udf/builtin/UDTFAbs.java | 8 +-
.../java/org/apache/iotdb/library/util/Util.java | 10 +-
12 files changed, 91 insertions(+), 84 deletions(-)
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/tool/PrintUtil.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/tool/PrintUtil.java
index 7df1bffc014..bbe5133fd2c 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/tool/PrintUtil.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/tool/PrintUtil.java
@@ -23,7 +23,7 @@ class PrintUtil {
static String[] header_1 = {"", "Total", "Overlap", "Overlap/Total"};
static String[] header_2 = {"", "Total", "Sequence", "UnSequence",
"UnSequence/Total"};
- static long MSize = 1024 * 1024;
+ static long MSize = 1024 * 1024L;
public static void printOneStatistics(OverlapStatistic overlapStatistic,
String label) {
System.out.println();
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/tool/TimePartitionProcessTask.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/tool/TimePartitionProcessTask.java
index a95b19c2dc3..0b04093e86f 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/tool/TimePartitionProcessTask.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/tool/TimePartitionProcessTask.java
@@ -131,6 +131,8 @@ public class TimePartitionProcessTask {
try {
SequenceFileTaskSummary sequenceFileTaskSummary = future.get();
overlapStatistic.mergeSingleSequenceFileTaskResult(sequenceFileTaskSummary);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
} catch (Exception e) {
e.printStackTrace();
}
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/modification/ModificationFile.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/modification/ModificationFile.java
index ce60cdba0d2..6489c7e5299 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/modification/ModificationFile.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/modification/ModificationFile.java
@@ -63,7 +63,7 @@ public class ModificationFile implements AutoCloseable {
private String filePath;
private final SecureRandom random = new SecureRandom();
- private static final long COMPACT_THRESHOLD = 1024 * 1024;
+ private static final long COMPACT_THRESHOLD = 1024 * 1024L;
private boolean hasCompacted = false;
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/modification/io/LocalTextModificationAccessor.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/modification/io/LocalTextModificationAccessor.java
index 3b23991205e..ccee47c55d6 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/modification/io/LocalTextModificationAccessor.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/modification/io/LocalTextModificationAccessor.java
@@ -172,8 +172,11 @@ public class LocalTextModificationAccessor
if (fos == null) {
fos = new FileOutputStream(filePath, true);
}
- fos.write(encodeModification(mod).getBytes());
- fos.write(System.lineSeparator().getBytes());
+ String line = encodeModification(mod);
+ if (line != null) {
+ fos.write(line.getBytes());
+ fos.write(System.lineSeparator().getBytes());
+ }
}
@TestOnly
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/recover/file/UnsealedTsFileRecoverPerformer.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/recover/file/UnsealedTsFileRecoverPerformer.java
index 5c05f68d6d0..de424923408 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/recover/file/UnsealedTsFileRecoverPerformer.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/recover/file/UnsealedTsFileRecoverPerformer.java
@@ -218,7 +218,11 @@ public class UnsealedTsFileRecoverPerformer extends
AbstractTsFileRecoverPerform
throw new RuntimeException("Unsupported type " + walEntry.getType());
}
} catch (Exception e) {
- logger.warn("meet error when redo wal of {}",
tsFileResource.getTsFile(), e);
+ if (tsFileResource != null) {
+ logger.warn("meet error when redo wal of {}",
tsFileResource.getTsFile(), e);
+ } else {
+ logger.warn("meet error when redo wal of null resource");
+ }
}
}
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/tools/schema/PBTreeFileSketchTool.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/tools/schema/PBTreeFileSketchTool.java
index 8e27f9fe2b6..db7bf2bc01d 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/tools/schema/PBTreeFileSketchTool.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/tools/schema/PBTreeFileSketchTool.java
@@ -20,7 +20,6 @@ package org.apache.iotdb.db.tools.schema;
import org.apache.iotdb.commons.exception.MetadataException;
import org.apache.iotdb.commons.file.SystemFileFactory;
-import
org.apache.iotdb.db.schemaengine.schemaregion.mtree.impl.pbtree.schemafile.ISchemaFile;
import
org.apache.iotdb.db.schemaengine.schemaregion.mtree.impl.pbtree.schemafile.SchemaFile;
import org.apache.commons.cli.CommandLine;
@@ -147,14 +146,12 @@ public class PBTreeFileSketchTool {
@SuppressWarnings("squid:S106")
public static void sketchFile(String inputFile, String outputFile)
throws IOException, MetadataException {
- PrintWriter pw = new PrintWriter(new FileWriter(outputFile, false));
- ISchemaFile sf =
SchemaFile.loadSchemaFile(SystemFileFactory.INSTANCE.getFile(inputFile));
- try {
- String res = ((SchemaFile) sf).inspect(pw);
+ SchemaFile sf =
SchemaFile.loadSchemaFile(SystemFileFactory.INSTANCE.getFile(inputFile));
+ try (PrintWriter pw = new PrintWriter(new FileWriter(outputFile, false))) {
+ String res = sf.inspect(pw);
System.out.println(res);
} finally {
sf.close();
- pw.close();
}
}
}
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/tools/schema/SRStatementGenerator.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/tools/schema/SRStatementGenerator.java
index dcfa7958077..8421974f353 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/tools/schema/SRStatementGenerator.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/tools/schema/SRStatementGenerator.java
@@ -67,7 +67,7 @@ import static
org.apache.iotdb.commons.schema.SchemaConstant.STORAGE_GROUP_MNODE
import static
org.apache.iotdb.commons.schema.SchemaConstant.isStorageGroupType;
import static
org.apache.iotdb.db.schemaengine.schemaregion.tag.TagLogFile.parseByteBuffer;
-public class SRStatementGenerator implements Iterator<Statement>,
Iterable<Statement> {
+public class SRStatementGenerator implements Iterable<Statement> {
private static final Logger LOGGER =
LoggerFactory.getLogger(SRStatementGenerator.class);
private IMemMNode curNode;
@@ -121,75 +121,76 @@ public class SRStatementGenerator implements
Iterator<Statement>, Iterable<State
@Override
public Iterator<Statement> iterator() {
- return this;
- }
-
- @Override
- public boolean hasNext() {
- if (!statements.isEmpty()) {
- return true;
- }
- if (lastExcept != null) {
- return false;
- }
- while (!ancestors.isEmpty()) {
- final int childNum = restChildrenNum.pop();
- if (childNum == 0) {
- final IMemMNode node = ancestors.pop();
- if (node.isDevice() && node.getAsDeviceMNode().isAligned()) {
- final Statement stmt =
- genAlignedTimeseriesStatement(
- node,
databaseFullPath.getDevicePath().concatPath(node.getPartialPath()));
- statements.push(stmt);
- }
- cleanMtreeNode(node);
+ return new Iterator<Statement>() {
+ @Override
+ public boolean hasNext() {
if (!statements.isEmpty()) {
return true;
}
- } else {
- restChildrenNum.push(childNum - 1);
- try {
- curNode = deserializeMNode(ancestors, restChildrenNum, deserializer,
inputStream);
- nodeCount++;
- } catch (IOException ioe) {
- lastExcept = ioe;
- try {
- inputStream.close();
- tagFileChannel.close();
-
- } catch (IOException e) {
- lastExcept = e;
- }
+ if (lastExcept != null) {
return false;
}
- final List<Statement> stmts =
- curNode.accept(
- translater,
databaseFullPath.getDevicePath().concatPath(curNode.getPartialPath()));
- if (stmts != null) {
- statements.addAll(stmts);
+ while (!ancestors.isEmpty()) {
+ final int childNum = restChildrenNum.pop();
+ if (childNum == 0) {
+ final IMemMNode node = ancestors.pop();
+ if (node.isDevice() && node.getAsDeviceMNode().isAligned()) {
+ final Statement stmt =
+ genAlignedTimeseriesStatement(
+ node,
databaseFullPath.getDevicePath().concatPath(node.getPartialPath()));
+ statements.push(stmt);
+ }
+ cleanMtreeNode(node);
+ if (!statements.isEmpty()) {
+ return true;
+ }
+ } else {
+ restChildrenNum.push(childNum - 1);
+ try {
+ curNode = deserializeMNode(ancestors, restChildrenNum,
deserializer, inputStream);
+ nodeCount++;
+ } catch (IOException ioe) {
+ lastExcept = ioe;
+ try {
+ inputStream.close();
+ tagFileChannel.close();
+
+ } catch (IOException e) {
+ lastExcept = e;
+ }
+ return false;
+ }
+ final List<Statement> stmts =
+ curNode.accept(
+ translater,
+
databaseFullPath.getDevicePath().concatPath(curNode.getPartialPath()));
+ if (stmts != null) {
+ statements.addAll(stmts);
+ }
+ if (!statements.isEmpty()) {
+ return true;
+ }
+ }
}
- if (!statements.isEmpty()) {
- return true;
+ try {
+ inputStream.close();
+ if (tagFileChannel != null) {
+ tagFileChannel.close();
+ }
+ } catch (IOException e) {
+ lastExcept = e;
}
+ return false;
}
- }
- try {
- inputStream.close();
- if (tagFileChannel != null) {
- tagFileChannel.close();
- }
- } catch (IOException e) {
- lastExcept = e;
- }
- return false;
- }
- @Override
- public Statement next() {
- if (!hasNext()) {
- throw new NoSuchElementException();
- }
- return statements.pop();
+ @Override
+ public Statement next() {
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
+ return statements.pop();
+ }
+ };
}
public void checkException() throws IOException {
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/BackwardSort.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/BackwardSort.java
index 6271a31734e..9f1981327ee 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/BackwardSort.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/BackwardSort.java
@@ -73,7 +73,7 @@ public interface BackwardSort extends QuickSort {
i += step;
blocks += 1;
}
- double ratio = overlap / blocks;
+ double ratio = blocks == 0 ? 0 : overlap / blocks;
int mul = (int) Math.ceil(ratio / INVERSION_RATIOS_THRESHOLD);
// System.out.printf("Overlap ratio=%.4f mul=%d, step=%d\n", ratio, mul,
step);
// ensure inversion ratio < INVERSION_RATIOS_THRESHOLD
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonConfig.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonConfig.java
index 6563c1fde4d..0dc186eef12 100644
---
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonConfig.java
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonConfig.java
@@ -257,7 +257,7 @@ public class CommonConfig {
// maximum number of Cluster Databases allowed
private int databaseLimitThreshold = -1;
- private long datanodeTokenTimeoutMS = 180 * 1000; // 3 minutes
+ private long datanodeTokenTimeoutMS = 180 * 1000L; // 3 minutes
// timeseries and device limit
private long seriesLimitThreshold = -1;
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/metric/GcTimeAlerter.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/metric/GcTimeAlerter.java
index e4396c09b11..093142b4775 100644
---
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/metric/GcTimeAlerter.java
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/metric/GcTimeAlerter.java
@@ -26,7 +26,7 @@ import java.text.SimpleDateFormat;
import java.util.Date;
public class GcTimeAlerter implements JvmGcMonitorMetrics.GcTimeAlertHandler {
- private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd
HH:mm:ss");
+ private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd
HH:mm:ss");
private static final Logger logger =
LoggerFactory.getLogger(GcTimeAlerter.class);
/**
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/udf/builtin/UDTFAbs.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/udf/builtin/UDTFAbs.java
index b57c32df531..b330794b8eb 100644
---
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/udf/builtin/UDTFAbs.java
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/udf/builtin/UDTFAbs.java
@@ -132,7 +132,7 @@ public class UDTFAbs extends UDTFMath {
throw new UnsupportedOperationException("UDTFAbs#setTransformer()");
}
- protected void transformInt(Column[] columns, ColumnBuilder builder) {
+ private void transformInt(Column[] columns, ColumnBuilder builder) {
int[] inputs = columns[0].getInts();
boolean[] isNulls = columns[0].isNull();
@@ -146,7 +146,7 @@ public class UDTFAbs extends UDTFMath {
}
}
- protected void transformLong(Column[] columns, ColumnBuilder builder) {
+ private void transformLong(Column[] columns, ColumnBuilder builder) {
long[] inputs = columns[0].getLongs();
boolean[] isNulls = columns[0].isNull();
@@ -160,7 +160,7 @@ public class UDTFAbs extends UDTFMath {
}
}
- protected void transformFloat(Column[] columns, ColumnBuilder builder) {
+ private void transformFloat(Column[] columns, ColumnBuilder builder) {
float[] inputs = columns[0].getFloats();
boolean[] isNulls = columns[0].isNull();
@@ -174,7 +174,7 @@ public class UDTFAbs extends UDTFMath {
}
}
- protected void transformDouble(Column[] columns, ColumnBuilder builder) {
+ private void transformDouble(Column[] columns, ColumnBuilder builder) {
double[] inputs = columns[0].getDoubles();
boolean[] isNulls = columns[0].isNull();
diff --git a/library-udf/src/main/java/org/apache/iotdb/library/util/Util.java
b/library-udf/src/main/java/org/apache/iotdb/library/util/Util.java
index d7060de7692..40f7d2ccd8a 100644
--- a/library-udf/src/main/java/org/apache/iotdb/library/util/Util.java
+++ b/library-udf/src/main/java/org/apache/iotdb/library/util/Util.java
@@ -124,19 +124,19 @@ public class Util {
public static void putValue(PointCollector pc, Type type, long t, Object o)
throws IOException {
switch (type) {
case INT32:
- pc.putInt(t, (Integer) o);
+ pc.putInt(t, (int) o);
break;
case INT64:
- pc.putLong(t, (Long) o);
+ pc.putLong(t, (long) o);
break;
case FLOAT:
- pc.putFloat(t, (Float) o);
+ pc.putFloat(t, (float) o);
break;
case DOUBLE:
- pc.putDouble(t, (Double) o);
+ pc.putDouble(t, (double) o);
break;
case BOOLEAN:
- pc.putBoolean(t, (Boolean) o);
+ pc.putBoolean(t, (boolean) o);
break;
default:
break;