Skip to content

Commit 4592338

Browse files
authored
[IOTDB-4070] Memory control for Query Operators (apache#6999)
1 parent 2b0db16 commit 4592338

File tree

91 files changed

+3472
-258
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+3472
-258
lines changed

integration-test/src/main/java/org/apache/iotdb/it/env/DataNodeWrapper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ protected void updateConfig(Properties properties) {
5858
if (this.targetConfigNode != null) {
5959
properties.setProperty(IoTDBConstant.TARGET_CONFIG_NODES, this.targetConfigNode);
6060
}
61+
properties.setProperty("max_tsblock_size_in_bytes", "1024");
62+
properties.setProperty("page_size_in_byte", "1024");
6163
}
6264

6365
@Override

integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBNestedQueryIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ public void testInvalidNestedBuiltInAggregation() {
371371
statement.executeQuery(query);
372372
} catch (SQLException e) {
373373
Assert.assertTrue(
374+
e.getMessage(),
374375
e.getMessage()
375376
.contains("The argument of the aggregation function must be a time series."));
376377
}

integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBSameMeasurementsDifferentTypesIT.java

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
@Category({LocalStandaloneIT.class, ClusterIT.class})
4848
public class IoTDBSameMeasurementsDifferentTypesIT {
4949

50-
private static BaseConfig tsFileConfig = ConfigFactory.getConfig();
50+
private static final BaseConfig tsFileConfig = ConfigFactory.getConfig();
5151
private static int maxNumberOfPointsInPage;
5252
private static int pageSizeInByte;
5353
private static int groupSizeInByte;
@@ -88,10 +88,6 @@ private static void insertData() {
8888
try (Connection connection = EnvFactory.getEnv().getConnection();
8989
Statement statement = connection.createStatement()) {
9090

91-
for (String sql : TestConstant.createSql) {
92-
statement.execute(sql);
93-
}
94-
9591
statement.execute("SET STORAGE GROUP TO root.fans");
9692
statement.execute("CREATE TIMESERIES root.fans.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE");
9793
statement.execute("CREATE TIMESERIES root.fans.d1.s0 WITH DATATYPE=INT64, ENCODING=RLE");
@@ -127,29 +123,27 @@ public void selectAllTest() {
127123
ResultSet resultSet1 = statement1.executeQuery(selectSql);
128124
int cnt1 = 0;
129125
while (resultSet1.next() && cnt1 < 5) {
130-
StringBuilder builder = new StringBuilder();
131-
builder
132-
.append(resultSet1.getString(TestConstant.TIMESTAMP_STR))
133-
.append(",")
134-
.append(resultSet1.getString("root.fans.d0.s0"))
135-
.append(",")
136-
.append(resultSet1.getString("root.fans.d1.s0"));
137-
Assert.assertEquals(retArray[cnt1], builder.toString());
126+
String ans =
127+
resultSet1.getString(TestConstant.TIMESTAMP_STR)
128+
+ ","
129+
+ resultSet1.getString("root.fans.d0.s0")
130+
+ ","
131+
+ resultSet1.getString("root.fans.d1.s0");
132+
Assert.assertEquals(retArray[cnt1], ans);
138133
cnt1++;
139134
}
140135

141136
statement2.setFetchSize(10);
142137
ResultSet resultSet2 = statement2.executeQuery(selectSql);
143138
int cnt2 = 0;
144139
while (resultSet2.next()) {
145-
StringBuilder builder = new StringBuilder();
146-
builder
147-
.append(resultSet2.getString(TestConstant.TIMESTAMP_STR))
148-
.append(",")
149-
.append(resultSet2.getString("root.fans.d0.s0"))
150-
.append(",")
151-
.append(resultSet2.getString("root.fans.d1.s0"));
152-
Assert.assertEquals(retArray[cnt2], builder.toString());
140+
String ans =
141+
resultSet2.getString(TestConstant.TIMESTAMP_STR)
142+
+ ","
143+
+ resultSet2.getString("root.fans.d0.s0")
144+
+ ","
145+
+ resultSet2.getString("root.fans.d1.s0");
146+
Assert.assertEquals(retArray[cnt2], ans);
153147
cnt2++;
154148
}
155149
Assert.assertEquals(9, cnt2);
@@ -158,14 +152,13 @@ public void selectAllTest() {
158152
// function,
159153
// and the cursor has been moved to the next position, so we should fetch that value first.
160154
do {
161-
StringBuilder builder = new StringBuilder();
162-
builder
163-
.append(resultSet1.getString(TestConstant.TIMESTAMP_STR))
164-
.append(",")
165-
.append(resultSet1.getString("root.fans.d0.s0"))
166-
.append(",")
167-
.append(resultSet1.getString("root.fans.d1.s0"));
168-
Assert.assertEquals(retArray[cnt1], builder.toString());
155+
String ans =
156+
resultSet1.getString(TestConstant.TIMESTAMP_STR)
157+
+ ","
158+
+ resultSet1.getString("root.fans.d0.s0")
159+
+ ","
160+
+ resultSet1.getString("root.fans.d1.s0");
161+
Assert.assertEquals(retArray[cnt1], ans);
169162
cnt1++;
170163
} while (resultSet1.next());
171164
// Although the statement2 has the same sql as statement1, they shouldn't affect each other.

integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBSortedShowTimeseriesIT.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ public void showTimeseriesOrderByHeatTest1() throws ClassNotFoundException {
189189
count++;
190190
}
191191
assertEquals(retArray1.size(), count);
192+
resultSet.close();
192193

193194
resultSet = statement.executeQuery("show LATEST timeseries");
194195
count = 0;
@@ -214,6 +215,7 @@ public void showTimeseriesOrderByHeatTest1() throws ClassNotFoundException {
214215
count++;
215216
}
216217
assertEquals(retArray2.size(), count);
218+
resultSet.close();
217219

218220
} catch (Exception e) {
219221
e.printStackTrace();
@@ -266,6 +268,7 @@ public void showTimeseriesOrderByHeatWithLimitTest() {
266268
count++;
267269
}
268270
assertEquals(retSet.size(), count);
271+
resultSet.close();
269272

270273
} catch (Exception e) {
271274
e.printStackTrace();
@@ -313,6 +316,7 @@ public void showTimeseriesOrderByHeatWithWhereTest() {
313316
count++;
314317
}
315318
assertEquals(retArray.length, count);
319+
resultSet.close();
316320

317321
} catch (Exception e) {
318322
e.printStackTrace();

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@
5454
public class IoTDBManageTsFileResourceIT {
5555
private static final IoTDBConfig CONFIG = IoTDBDescriptor.getInstance().getConfig();
5656
private TsFileResourceManager tsFileResourceManager = TsFileResourceManager.getInstance();
57-
private double prevTimeIndexMemoryProportion;
58-
private double prevTimeIndexMemoryThreshold;
57+
private long prevTimeIndexMemoryThreshold;
5958
private int prevCompactionThreadNum;
6059

6160
private static String[] unSeqSQLs =
@@ -89,16 +88,14 @@ public class IoTDBManageTsFileResourceIT {
8988
@Before
9089
public void setUp() throws ClassNotFoundException {
9190
EnvironmentUtils.envSetUp();
92-
prevTimeIndexMemoryProportion = CONFIG.getTimeIndexMemoryProportion();
91+
prevTimeIndexMemoryThreshold = CONFIG.getAllocateMemoryForTimeIndex();
9392
prevCompactionThreadNum = CONFIG.getConcurrentCompactionThread();
9493
Class.forName(Config.JDBC_DRIVER_NAME);
9594
}
9695

9796
@After
9897
public void tearDown() throws Exception {
9998
EnvironmentUtils.cleanEnv();
100-
prevTimeIndexMemoryThreshold =
101-
prevTimeIndexMemoryProportion * CONFIG.getAllocateMemoryForRead();
10299
tsFileResourceManager.setTimeIndexMemoryThreshold(prevTimeIndexMemoryThreshold);
103100
CONFIG.setConcurrentCompactionThread(prevCompactionThreadNum);
104101
}

server/src/assembly/resources/conf/iotdb-datanode.properties

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -448,10 +448,6 @@ timestamp_precision=ms
448448
# Datatype: double
449449
# flush_proportion=0.4
450450

451-
# Ratio of read memory allocated for timeIndex, 0.2 by default
452-
# Datatype: double
453-
# time_index_memory_proportion=0.2
454-
455451
# Ratio of write memory allocated for buffered arrays, 0.6 by default
456452
# Datatype: double
457453
# buffered_arrays_memory_proportion=0.6
@@ -485,6 +481,10 @@ timestamp_precision=ms
485481
# Datatype: int
486482
# io_task_queue_size_for_flushing=10
487483

484+
# If true, we will estimate each query's possible memory footprint before executing it and deny it if its estimated memory exceeds current free memory
485+
# Datatype: bool
486+
# enable_query_memory_estimation=true
487+
488488
####################
489489
### Upgrade Configurations
490490
####################
@@ -646,9 +646,9 @@ timestamp_precision=ms
646646
# Datatype: boolean
647647
# meta_data_cache_enable=true
648648

649-
# Read memory Allocation Ratio: BloomFilterCache, ChunkCache, TimeSeriesMetadataCache, memory used for constructing QueryDataSet and Free Memory Used in Query.
650-
# The parameter form is a:b:c:d:e, where a, b, c, d and e are integers. for example: 1:1:1:1:1 , 1:100:200:300:400
651-
# chunk_timeseriesmeta_free_memory_proportion=1:100:200:300:400
649+
# Read memory Allocation Ratio: BloomFilterCache : ChunkCache : TimeSeriesMetadataCache : Coordinator : Operators : DataExchange : timeIndex in TsFileResourceList : others.
650+
# The parameter form is a:b:c:d:e:f:g:h, where a, b, c, d, e, f, g and h are integers. for example: 1:1:1:1:1:1:1:1 , 1:100:200:50:200:200:200:50
651+
# chunk_timeseriesmeta_free_memory_proportion=1:100:200:50:200:200:200:50
652652

653653
####################
654654
### LAST Cache Configuration

server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java

Lines changed: 63 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,13 @@ public class IoTDBConfig {
137137
private long allocateMemoryForRead = Runtime.getRuntime().maxMemory() * 3 / 10;
138138

139139
/** Memory allocated for the mtree */
140-
private long allocateMemoryForSchema = Runtime.getRuntime().maxMemory() * 1 / 10;
141-
142-
/** Memory allocated for the read process besides cache */
143-
private long allocateMemoryForReadWithoutCache = allocateMemoryForRead * 300 / 1001;
140+
private long allocateMemoryForSchema = Runtime.getRuntime().maxMemory() / 10;
144141

145142
private volatile int maxQueryDeduplicatedPathNum = 1000;
146143

147144
/** Ratio of memory allocated for buffered arrays */
148145
private double bufferedArraysMemoryProportion = 0.6;
149146

150-
/** Memory allocated proportion for timeIndex */
151-
private double timeIndexMemoryProportion = 0.2;
152-
153147
/** Flush proportion for system */
154148
private double flushProportion = 0.4;
155149

@@ -477,6 +471,24 @@ public class IoTDBConfig {
477471
/** Memory allocated for chunk cache in read process */
478472
private long allocateMemoryForChunkCache = allocateMemoryForRead * 100 / 1001;
479473

474+
/** Memory allocated for operators */
475+
private long allocateMemoryForCoordinator = allocateMemoryForRead * 50 / 1001;
476+
477+
/** Memory allocated for operators */
478+
private long allocateMemoryForOperators = allocateMemoryForRead * 200 / 1001;
479+
480+
/** Memory allocated for operators */
481+
private long allocateMemoryForDataExchange = allocateMemoryForRead * 200 / 1001;
482+
483+
/** Memory allocated proportion for timeIndex */
484+
private long allocateMemoryForTimeIndex = allocateMemoryForRead * 200 / 1001;
485+
486+
/**
487+
* If true, we will estimate each query's possible memory footprint before executing it and deny
488+
* it if its estimated memory exceeds current free memory
489+
*/
490+
private boolean enableQueryMemoryEstimation = true;
491+
480492
/** Whether to enable Last cache */
481493
private boolean lastCacheEnable = true;
482494

@@ -1358,6 +1370,10 @@ void setConcurrentSubRawQueryThread(int concurrentSubRawQueryThread) {
13581370
this.concurrentSubRawQueryThread = concurrentSubRawQueryThread;
13591371
}
13601372

1373+
public long getMaxBytesPerQuery() {
1374+
return allocateMemoryForDataExchange / concurrentQueryThread;
1375+
}
1376+
13611377
public int getRawQueryBlockingQueueCapacity() {
13621378
return rawQueryBlockingQueueCapacity;
13631379
}
@@ -1688,14 +1704,6 @@ public void setBufferedArraysMemoryProportion(double bufferedArraysMemoryProport
16881704
this.bufferedArraysMemoryProportion = bufferedArraysMemoryProportion;
16891705
}
16901706

1691-
public double getTimeIndexMemoryProportion() {
1692-
return timeIndexMemoryProportion;
1693-
}
1694-
1695-
public void setTimeIndexMemoryProportion(double timeIndexMemoryProportion) {
1696-
this.timeIndexMemoryProportion = timeIndexMemoryProportion;
1697-
}
1698-
16991707
public double getFlushProportion() {
17001708
return flushProportion;
17011709
}
@@ -1744,14 +1752,6 @@ void setAllocateMemoryForRead(long allocateMemoryForRead) {
17441752
this.allocateMemoryForRead = allocateMemoryForRead;
17451753
}
17461754

1747-
public long getAllocateMemoryForReadWithoutCache() {
1748-
return allocateMemoryForReadWithoutCache;
1749-
}
1750-
1751-
public void setAllocateMemoryForReadWithoutCache(long allocateMemoryForReadWithoutCache) {
1752-
this.allocateMemoryForReadWithoutCache = allocateMemoryForReadWithoutCache;
1753-
}
1754-
17551755
public boolean isEnableExternalSort() {
17561756
return enableExternalSort;
17571757
}
@@ -1963,6 +1963,46 @@ public void setAllocateMemoryForChunkCache(long allocateMemoryForChunkCache) {
19631963
this.allocateMemoryForChunkCache = allocateMemoryForChunkCache;
19641964
}
19651965

1966+
public long getAllocateMemoryForCoordinator() {
1967+
return allocateMemoryForCoordinator;
1968+
}
1969+
1970+
public void setAllocateMemoryForCoordinator(long allocateMemoryForCoordinator) {
1971+
this.allocateMemoryForCoordinator = allocateMemoryForCoordinator;
1972+
}
1973+
1974+
public long getAllocateMemoryForOperators() {
1975+
return allocateMemoryForOperators;
1976+
}
1977+
1978+
public void setAllocateMemoryForOperators(long allocateMemoryForOperators) {
1979+
this.allocateMemoryForOperators = allocateMemoryForOperators;
1980+
}
1981+
1982+
public long getAllocateMemoryForDataExchange() {
1983+
return allocateMemoryForDataExchange;
1984+
}
1985+
1986+
public void setAllocateMemoryForDataExchange(long allocateMemoryForDataExchange) {
1987+
this.allocateMemoryForDataExchange = allocateMemoryForDataExchange;
1988+
}
1989+
1990+
public long getAllocateMemoryForTimeIndex() {
1991+
return allocateMemoryForTimeIndex;
1992+
}
1993+
1994+
public void setAllocateMemoryForTimeIndex(long allocateMemoryForTimeIndex) {
1995+
this.allocateMemoryForTimeIndex = allocateMemoryForTimeIndex;
1996+
}
1997+
1998+
public boolean isEnableQueryMemoryEstimation() {
1999+
return enableQueryMemoryEstimation;
2000+
}
2001+
2002+
public void setEnableQueryMemoryEstimation(boolean enableQueryMemoryEstimation) {
2003+
this.enableQueryMemoryEstimation = enableQueryMemoryEstimation;
2004+
}
2005+
19662006
public boolean isLastCacheEnabled() {
19672007
return lastCacheEnable;
19682008
}

0 commit comments

Comments
 (0)