Skip to content

Commit

Permalink
Fix/build issues outside of china
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdutz authored May 29, 2024
1 parent 6d708ca commit b4989ed
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class MppJVMConfig implements JVMConfig {
private int initHeapSize;
private int maxHeapSize;
private int maxDirectMemorySize;
private String timezone;

@Override
public JVMConfig setInitHeapSize(int initSize) {
Expand All @@ -52,6 +53,13 @@ public JVMConfig setMaxDirectMemorySize(int maxSize) {
return this;
}

public JVMConfig setTimezone(String timezone) {
if (timezone != null) {
this.timezone = timezone;
}
return this;
}

public int getInitHeapSize() {
return initHeapSize;
}
Expand All @@ -64,6 +72,10 @@ public int getMaxDirectMemorySize() {
return maxDirectMemorySize;
}

public String getTimezone() {
return timezone;
}

private void validate() {
if (initHeapSize > maxHeapSize) {
throw new IllegalArgumentException(
Expand All @@ -81,6 +93,7 @@ public void override(@Nullable MppJVMConfig config) {
this.setInitHeapSize(config.getInitHeapSize());
this.setMaxHeapSize(config.getMaxHeapSize());
this.setMaxDirectMemorySize(config.getMaxDirectMemorySize());
this.setTimezone(config.getTimezone());
}

public static Builder builder() {
Expand Down Expand Up @@ -109,6 +122,11 @@ public Builder setMaxDirectMemorySize(int size) {
return this;
}

public Builder setTimezone(String timezone) {
this.config.setTimezone(timezone);
return this;
}

public MppJVMConfig build() {
config.validate();
return config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ public void start() {
"-Djava.rmi.server.hostname=" + getIp(),
"-Xms" + jvmConfig.getInitHeapSize() + "m",
"-Xmx" + jvmConfig.getMaxHeapSize() + "m",
"-Duser.timezone=" + jvmConfig.getTimezone(),
"-XX:MaxDirectMemorySize=" + jvmConfig.getMaxDirectMemorySize() + "m",
"-Djdk.nio.maxCachedBufferSize=262144",
"-D" + IoTDBConstant.INTEGRATION_TEST_KILL_POINTS + "=" + killPoints.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ protected MppJVMConfig initVMConfig() {
.setMaxHeapSize(EnvUtils.getIntFromSysVar(CONFIG_NODE_MAX_HEAP_SIZE, 256, clusterIndex))
.setMaxDirectMemorySize(
EnvUtils.getIntFromSysVar(CONFIG_NODE_MAX_DIRECT_MEMORY_SIZE, 256, clusterIndex))
.setTimezone("Asia/Shanghai")
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.stream.Stream;

public class IoTDBTestReporter {
Expand All @@ -52,11 +55,13 @@ public static void main(String[] args) throws IOException {
for (String l : lines) {
String[] parts = l.split("\t");
if (parts.length == 2) {
IoTDBTestStat stat = new IoTDBTestStat(parts[1], Double.parseDouble(parts[0]));
NumberFormat f = NumberFormat.getInstance(Locale.getDefault());
double seconds = f.parse(parts[0]).doubleValue();
IoTDBTestStat stat = new IoTDBTestStat(parts[1], seconds);
stats.add(stat);
}
}
} catch (IOException e) {
} catch (IOException | ParseException e) {
IoTDBTestLogger.logger.error("read stats file failed", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Locale;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -113,22 +114,22 @@ public void testFlushGivenGroup() {

for (int i = 1; i <= 3; i++) {
for (int j = 10; j < 20; j++) {
statement.execute(String.format(insertTemplate, i, j, j, j * 0.1, j));
statement.execute(String.format(Locale.CHINA, insertTemplate, i, j, j, j * 0.1, j));
}
}
statement.execute("FLUSH");

for (int i = 1; i <= 3; i++) {
for (int j = 0; j < 10; j++) {
statement.execute(String.format(insertTemplate, i, j, j, j * 0.1, j));
statement.execute(String.format(Locale.CHINA, insertTemplate, i, j, j, j * 0.1, j));
}
}
statement.execute("FLUSH root.group1");
statement.execute("FLUSH root.group2,root.group3");

for (int i = 1; i <= 3; i++) {
for (int j = 0; j < 30; j++) {
statement.execute(String.format(insertTemplate, i, j, j, j * 0.1, j));
statement.execute(String.format(Locale.CHINA, insertTemplate, i, j, j, j * 0.1, j));
}
}
statement.execute("FLUSH root.group1 TRUE");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Random;

import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -83,8 +84,15 @@ private static String generateInsertionSQL(
boolean boolValue,
String _text) {
return String.format(
Locale.CHINA,
"insert into root.sg.d1(time, s1, s2, s3, s4, s5, s6) values (%d, %d, %d, %f, %f, %s, %s);",
time, intValue32, intValue64, floatValue, doubleValue, boolValue ? "true" : "false", _text);
time,
intValue32,
intValue64,
floatValue,
doubleValue,
boolValue ? "true" : "false",
_text);
}

@BeforeClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.junit.runners.model.InitializationError;
import org.slf4j.Logger;

import java.util.TimeZone;

public class IoTDBTestRunner extends BlockJUnit4ClassRunner {

private static final Logger logger = IoTDBTestLogger.logger;
Expand All @@ -41,6 +43,7 @@ public IoTDBTestRunner(Class<?> testClass) throws InitializationError {

@Override
public void run(RunNotifier notifier) {
TimeZone.setDefault(TimeZone.getTimeZone("Bejing"));
listener = new IoTDBTestListener(this.getName());
notifier.addListener(listener);
super.run(notifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@

import org.apache.iotdb.db.queryengine.execution.operator.process.fill.IFillFilter;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZoneOffset;

public abstract class AbstractMonthIntervalFillFilter implements IFillFilter {

Expand All @@ -35,12 +33,9 @@ public abstract class AbstractMonthIntervalFillFilter implements IFillFilter {
// non-month part of time duration, its precision is same as current time_precision
protected final long nonMonthDuration;

protected final ZoneOffset zoneOffset;

AbstractMonthIntervalFillFilter(int monthDuration, long nonMonthDuration, ZoneId zone) {
this.monthDuration = monthDuration;
this.nonMonthDuration = nonMonthDuration;
this.zone = zone;
this.zoneOffset = zone.getRules().getOffset(Instant.now());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;

public class MonthIntervalMSFillFilter extends AbstractMonthIntervalFillFilter {

Expand All @@ -33,10 +34,11 @@ public MonthIntervalMSFillFilter(int monthDuration, long nonMonthDuration, ZoneI
public boolean needFill(long time, long previousTime) {
long smaller = Math.min(time, previousTime);
long greater = Math.max(time, previousTime);
Instant instant = Instant.ofEpochMilli(smaller);
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zone);
Instant smallerInstant = Instant.ofEpochMilli(smaller);
LocalDateTime smallerDateTime = LocalDateTime.ofInstant(smallerInstant, zone);
ZoneOffset smallerOffset = zone.getRules().getStandardOffset(smallerInstant);
long epochMilli =
localDateTime.plusMonths(monthDuration).toInstant(zoneOffset).toEpochMilli()
smallerDateTime.plusMonths(monthDuration).toInstant(smallerOffset).toEpochMilli()
+ nonMonthDuration;
return epochMilli >= greater;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.temporal.ChronoField;

public class MonthIntervalNSFillFilter extends AbstractMonthIntervalFillFilter {
Expand All @@ -34,10 +35,15 @@ public MonthIntervalNSFillFilter(int monthDuration, long nonMonthDuration, ZoneI
public boolean needFill(long time, long previousTime) {
long smaller = Math.min(time, previousTime);
long greater = Math.max(time, previousTime);
Instant instant = Instant.ofEpochSecond(smaller / 1_000_000_000L, smaller % 1_000_000_000L);
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zone);
Instant smallerInstant =
Instant.ofEpochSecond(smaller / 1_000_000_000L, smaller % 1_000_000_000L);
LocalDateTime smallerDateTime = LocalDateTime.ofInstant(smallerInstant, zone);
ZoneOffset smallerOffset = zone.getRules().getStandardOffset(smallerInstant);
Instant upper =
localDateTime.plusMonths(monthDuration).plusNanos(nonMonthDuration).toInstant(zoneOffset);
smallerDateTime
.plusMonths(monthDuration)
.plusNanos(nonMonthDuration)
.toInstant(smallerOffset);
long timeInNs =
upper.getLong(ChronoField.NANO_OF_SECOND) + upper.getEpochSecond() * 1_000_000_000L;
return timeInNs >= greater;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.temporal.ChronoField;

import static java.time.temporal.ChronoUnit.MICROS;
Expand All @@ -36,13 +37,14 @@ public MonthIntervalUSFillFilter(int monthDuration, long nonMonthDuration, ZoneI
public boolean needFill(long time, long previousTime) {
long smaller = Math.min(time, previousTime);
long greater = Math.max(time, previousTime);
Instant instant = Instant.ofEpochSecond(smaller / 1_000_000L, smaller % 1_000_000L);
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zone);
Instant smallerInstant = Instant.ofEpochSecond(smaller / 1_000_000L, smaller % 1_000_000L);
LocalDateTime smallerDateTime = LocalDateTime.ofInstant(smallerInstant, zone);
ZoneOffset smallerOffset = zone.getRules().getStandardOffset(smallerInstant);
Instant upper =
localDateTime
smallerDateTime
.plusMonths(monthDuration)
.plus(nonMonthDuration, MICROS)
.toInstant(zoneOffset);
.toInstant(smallerOffset);
long timeInUs =
upper.getLong(ChronoField.MICRO_OF_SECOND) + upper.getEpochSecond() * 1_000_000L;
return timeInUs >= greater;
Expand Down
Loading

0 comments on commit b4989ed

Please sign in to comment.