Skip to content

Implement table & tree disk usage statistics - #17169

Merged
JackieTien97 merged 76 commits into
masterfrom
table_disk_usage_statistics_with_cache
Mar 18, 2026
Merged

JackieTien97 merged 76 commits into
masterfrom
table_disk_usage_statistics_with_cache

Conversation

@shuwenwei

@shuwenwei shuwenwei commented Feb 5, 2026 •

Copy link
Copy Markdown
Member

Description

This PR implements disk-usage statistics collection in table level and device level for tree model. It adds the necessary data structures, background tasks, and read APIs to compute and expose disk usage metrics used by monitoring, admission control and operational tooling.

Tree Model (No Cache)

IoTDB> show disk_usage from root.test.**
+---------+----------+--------+-------------+-----------+
| Database|DataNodeId|RegionId|TimePartition|SizeInBytes|
+---------+----------+--------+-------------+-----------+
|root.test|         1|       3|            0|         70|
+---------+----------+--------+-------------+-----------+
Total line number = 1
It costs 0.959s

Implements ShowDiskUsageNode and ShowDiskUsageOperator.
• Disk usage is calculated by scanning relevant TsFiles at query time.
• Supports:
• Path pattern matching
• Time partition filtering
• Existing SQL semantics (SHOW DISK_USAGE)

Table Model (With Cache)

IoTDB:information_schema> select * from table_disk_usage
+--------+----------+-------+---------+--------------+-------------+
|database|table_name|datanode_id|region_id|time_partition|size_in_bytes|
+--------+----------+-------+---------+--------------+-------------+
|   test1|        t1|          1|        5|             0|          142|
|   test1|        t2|          1|        5|             0|            0|
|   test1|        t1|          1|        6|             0|            0|
|   test1|        t2|          1|        6|             0|           82|
+--------+----------+-------+---------+--------------+-------------+
Total line number = 4
It costs 2.821s

Table Model introduces a dedicated disk usage cache:
• TableDiskUsageCache manages all cache operations.
• A single-threaded background worker processes write, read, and maintenance tasks via an operation queue.
• Cache state is persistent across restarts.

Cached Data
• TsFile-level table size statistics
• Object file size deltas, recorded incrementally
• Periodic snapshot + delta compaction

Query Integration
• Exposes statistics via information_schema.table_disk_usage.
• Supports:
• Predicate pushdown (except on aggregated size columns)
• Limit / offset
• Parallel region-level scanning

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements comprehensive disk usage statistics collection for both Tree Model (device-based) and Table Model databases in IoTDB. The implementation provides monitoring capabilities at the table/device level and time partition level.

Changes:

  • Adds SHOW DISK_USAGE SQL statement for Tree Model with on-demand calculation
  • Implements table_disk_usage information schema table for Table Model with persistent cache
  • Introduces background task infrastructure for cache maintenance with periodic compaction
  • Adds predicate push-down and limit/offset optimization support for information schema tables

Reviewed changes

Copilot reviewed 95 out of 95 changed files in this pull request and generated 33 comments.

Show a summary per file
File Description
pom.xml Updates tsfile version to 2.2.1-260205-SNAPSHOT
TsFileID.java Adds SHALLOW_SIZE constant (contains bug)
InformationSchema.java Adds table_disk_usage schema and push-down support (contains bug)
TableDiskUsageCache*.java Core cache implementation with writer/reader classes
ShowDiskUsageNode.java Plan node for tree model disk usage queries
TableDiskUsageInformationSchemaTableScanNode.java Plan node for table model information schema scans
ShowDiskUsageOperator.java Execution operator for tree model
DiskUsageStatisticUtil.java Base utility class for disk usage calculation
IoTDBDescriptor.java Configuration support (contains bug)
Integration tests Comprehensive tests for both tree and table models

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov

codecov Bot commented Feb 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 53.82075% with 979 lines in your changes missing coverage. Please review.
✅ Project coverage is 39.85%. Comparing base (ccece97) to head (a5bd10e).
⚠️ Report is 9 commits behind head on master.

Files with missing lines Patch % Lines
...ional/InformationSchemaContentSupplierFactory.java 0.00% 188 Missing ⚠️
...ecution/operator/source/ShowDiskUsageOperator.java 0.00% 77 Missing ⚠️
...e/dataregion/utils/TreeDiskUsageStatisticUtil.java 0.00% 64 Missing ⚠️
...utils/tableDiskUsageIndex/TableDiskUsageIndex.java 75.93% 58 Missing ⚠️
...nner/distribute/TableDistributedPlanGenerator.java 8.51% 43 Missing ⚠️
...b/queryengine/plan/planner/LogicalPlanBuilder.java 0.00% 41 Missing ⚠️
...ngine/dataregion/utils/DiskUsageStatisticUtil.java 63.96% 40 Missing ⚠️
...db/db/queryengine/plan/analyze/AnalyzeVisitor.java 0.00% 38 Missing ⚠️
...kUsageIndex/tsfile/TsFileTableSizeIndexReader.java 81.12% 37 Missing ⚠️
...an/planner/plan/node/source/ShowDiskUsageNode.java 47.05% 36 Missing ⚠️
... and 38 more
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #17169      +/-   ##
============================================
+ Coverage     39.76%   39.85%   +0.09%     
  Complexity      282      282              
============================================
  Files          5100     5118      +18     
  Lines        342150   344310    +2160     
  Branches      43596    43854     +258     
============================================
+ Hits         136044   137216    +1172     
- Misses       206106   207094     +988     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 99 out of 99 changed files in this pull request and generated 9 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


keyFile1.createNewFile();
valueFile1.createNewFile();
tempKeyFile2.createNewFile();

Copilot AI Feb 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method testRecoverWriter2 ignores exceptional return value of File.createNewFile.

Copilot uses AI. Check for mistakes.
keyFile1.createNewFile();
valueFile1.createNewFile();
tempKeyFile2.createNewFile();
tempValueFile2.createNewFile();

Copilot AI Feb 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method testRecoverWriter2 ignores exceptional return value of File.createNewFile.

Copilot uses AI. Check for mistakes.

keyFile1.createNewFile();
valueFile1.createNewFile();
keyFile2.createNewFile();

Copilot AI Feb 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method testRecoverWriter3 ignores exceptional return value of File.createNewFile.

Copilot uses AI. Check for mistakes.
keyFile1.createNewFile();
valueFile1.createNewFile();
keyFile2.createNewFile();
valueFile2.createNewFile();

Copilot AI Feb 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method testRecoverWriter3 ignores exceptional return value of File.createNewFile.

Copilot uses AI. Check for mistakes.

keyFile1.createNewFile();
valueFile1.createNewFile();
keyFile2.createNewFile();

Copilot AI Feb 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method testRecoverWriter4 ignores exceptional return value of File.createNewFile.

Copilot uses AI. Check for mistakes.
keyFile1.createNewFile();
valueFile1.createNewFile();
keyFile2.createNewFile();
tempValueFile2.createNewFile();

Copilot AI Feb 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method testRecoverWriter4 ignores exceptional return value of File.createNewFile.

Copilot uses AI. Check for mistakes.
+ AbstractTableSizeCacheWriter.TEMP_CACHE_FILE_SUBFIX);

keyFile1.createNewFile();
tempKeyFile2.createNewFile();

Copilot AI Feb 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method testRecoverWriter5 ignores exceptional return value of File.createNewFile.

Copilot uses AI. Check for mistakes.

keyFile1.createNewFile();
tempKeyFile2.createNewFile();
tempValueFile2.createNewFile();

Copilot AI Feb 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method testRecoverWriter5 ignores exceptional return value of File.createNewFile.

Copilot uses AI. Check for mistakes.
context.getTimePartitionTableSizeQueryContextMap().entrySet()) {
Map<String, Long> tableSizeResultMap = entry.getValue().getTableSizeResultMap();
for (Map.Entry<String, Long> tableSizeEntry : tableSizeResultMap.entrySet()) {
int i = Integer.parseInt(tableSizeEntry.getKey().substring(5));

Copilot AI Feb 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential uncaught 'java.lang.NumberFormatException'.

Copilot uses AI. Check for mistakes.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 98 out of 98 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +417 to +425
static {
columnsThatSupportPushDownPredicate.put(
TABLE_DISK_USAGE,
ImmutableSet.of(
ColumnHeaderConstant.DATABASE,
ColumnHeaderConstant.TABLE_NAME_TABLE_MODEL,
ColumnHeaderConstant.DATA_NODE_ID_TABLE_MODEL,
ColumnHeaderConstant.REGION_ID_TABLE_MODEL,
ColumnHeaderConstant.TIME_PARTITION_TABLE_MODEL));
Comment on lines +104 to +110
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
return false;
}
false, operatorContext.getInstanceContext());
return true;
}),
Optional.empty());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why here is empty, time filter cannot push down?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add some comments about this weird codes.

try {
currentDataRegionCacheReader.close();
currentDataRegionCacheReader = null;
} catch (IOException ignored) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why ignore? should at least logger.info or warn

this.objectTableSizeCacheReader = readerPair.right;
break;
} else {
Thread.sleep(1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Thread.sleep(1);
prepareReaderFuture.wait(System.nanoTime() - startTime);

return analysis;
}

private boolean analyzeWhere(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add java doc about the method, at least including when return true, when retrun false

Comment on lines +193 to +196
if (node.getChildren().size() > 1) {
// keep parent limit/offset node
context.setEnablePushDown(false);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when will collectnode has only one child?

public static final String TSFILE_CACHE_KEY_FILENAME_PREFIX = "TableSizeKeyFile_";
public static final String TSFILE_CACHE_VALUE_FILENAME_PREFIX = "TableSizeValueFile_";
public static final int KEY_FILE_OFFSET_RECORD_LENGTH = 5 * Long.BYTES + 1;
public static final int KEY_FILE_REDIRECT_RECORD_LENGTH = 7 * Long.BYTES + 1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never used

import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

public class TsFileTableDiskUsageCacheWriter extends AbstractTableSizeCacheWriter {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public class TsFileTableDiskUsageCacheWriter extends AbstractTableSizeCacheWriter {
public class TsFileTableDiskUsageIndexWriter extends AbstractTableSizeCacheWriter {

import java.util.List;
import java.util.Map;

public class TsFileTableSizeCacheReader {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public class TsFileTableSizeCacheReader {
public class TsFileTableSizeIndexReader {


package org.apache.iotdb.db.storageengine.dataregion.utils.tableDiskUsageCache;

public class DefaultTableDiskUsageCacheProvider implements TableDiskUsageCacheProvider {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public class DefaultTableDiskUsageCacheProvider implements TableDiskUsageCacheProvider {
public class DefaultTableDiskUsageIndexProvider implements TableDiskUsageCacheProvider {

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class TableDiskUsageCache {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public class TableDiskUsageCache {
public class TableDiskUsageIndex {

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@JackieTien97
JackieTien97 merged commit e593fcb into master Mar 18, 2026
29 of 30 checks passed
@JackieTien97
JackieTien97 deleted the table_disk_usage_statistics_with_cache branch March 18, 2026 08:20
Caideyipi pushed a commit to Caideyipi/iotdb that referenced this pull request Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants