Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f854824
Update SchemaRegionMemMetric.java
Caideyipi May 26, 2025
226c1f8
partial
Caideyipi May 26, 2025
cc16c6c
May be final
Caideyipi May 26, 2025
689d1c1
Merge branch 'master' of https://github.com/apache/iotdb into add_sch…
Caideyipi May 26, 2025
8f9ba90
partially
Caideyipi May 27, 2025
2d3e442
Next fix
Caideyipi May 27, 2025
9d0f1b5
Partial
Caideyipi May 27, 2025
bfbc6d1
Merge branch 'master' of https://github.com/apache/iotdb into add_sch…
Caideyipi May 27, 2025
6a94f25
Partial completion
Caideyipi May 27, 2025
8645995
Update PartitionMetrics.java
Caideyipi May 27, 2025
e838314
Refactor
Caideyipi May 27, 2025
bd52f04
Implement countDB
Caideyipi May 27, 2025
4be33e7
Update Coordinator.java
Caideyipi May 27, 2025
588cc03
Next
Caideyipi May 27, 2025
ca8be5f
Update IoTDBDatabaseIT.java
Caideyipi May 27, 2025
dfc7f10
Update ConfigMTreeTest.java
Caideyipi May 27, 2025
4ba4ab5
Fix
Caideyipi May 27, 2025
04045ee
partial
Caideyipi Jun 16, 2025
377f0b9
Merge branch 'master' of https://github.com/apache/iotdb into add_sch…
Caideyipi Jun 16, 2025
9698f65
partial
Caideyipi Jun 16, 2025
25ea87d
Merge branch 'master' of https://github.com/apache/iotdb into add_sch…
Caideyipi Jun 17, 2025
e09017c
Merge branch 'master' of https://github.com/apache/iotdb into add_sch…
Caideyipi Oct 27, 2025
c4cf057
fixfix
Caideyipi Oct 27, 2025
bb674bf
Merge branch 'master' of https://github.com/apache/iotdb into add_sch…
Caideyipi Nov 18, 2025
24b7d4b
apply
Caideyipi Nov 18, 2025
3307cf4
fix
Caideyipi Nov 18, 2025
646560e
partial
Caideyipi Nov 18, 2025
34c911d
fix
Caideyipi Nov 18, 2025
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 number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ public void testManageDatabase() {
assertEquals(databaseNames.length, cnt);
}

TestUtils.assertResultSetEqual(
statement.executeQuery("count databases"), "count,", Collections.singleton("2,"));

final int[] schemaRegionGroupNum = new int[] {0};
final int[] dataRegionGroupNum = new int[] {0};
// show
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@
import org.apache.iotdb.common.rpc.thrift.TConsensusGroupType;
import org.apache.iotdb.common.rpc.thrift.TDataNodeConfiguration;
import org.apache.iotdb.commons.cluster.RegionStatus;
import org.apache.iotdb.commons.schema.table.InformationSchema;
import org.apache.iotdb.commons.schema.table.TableType;
import org.apache.iotdb.commons.service.metric.enums.Metric;
import org.apache.iotdb.commons.service.metric.enums.Tag;
import org.apache.iotdb.commons.utils.NodeUrlUtils;
import org.apache.iotdb.commons.utils.PathUtils;
import org.apache.iotdb.confignode.exception.DatabaseNotExistsException;
import org.apache.iotdb.confignode.manager.IManager;
import org.apache.iotdb.confignode.manager.load.LoadManager;
import org.apache.iotdb.confignode.manager.node.NodeManager;
import org.apache.iotdb.confignode.manager.schema.ClusterSchemaManager;
import org.apache.iotdb.confignode.persistence.schema.ConfigSchemaStatistics;
import org.apache.iotdb.metrics.AbstractMetricService;
import org.apache.iotdb.metrics.metricsets.IMetricSet;
import org.apache.iotdb.metrics.utils.MetricLevel;
Expand Down Expand Up @@ -267,18 +271,34 @@ private void unbindRegionPartitionMetrics(AbstractMetricService metricService) {

// region Database Partition Metrics

private void bindDatabaseRelatedMetrics(AbstractMetricService metricService) {
ClusterSchemaManager clusterSchemaManager = getClusterSchemaManager();
private void bindDatabaseRelatedMetrics(final AbstractMetricService metricService) {
final ClusterSchemaManager clusterSchemaManager = getClusterSchemaManager();
final ConfigSchemaStatistics statistics = clusterSchemaManager.getConfigSchemaStatistics();
// Count the number of Databases
metricService.createAutoGauge(
Metric.DATABASE_NUM.toString(),
MetricLevel.CORE,
clusterSchemaManager,
// Add 1 for information schema
c -> c.getDatabaseNames(null).size() + 1);
statistics,
s -> s.getTableDatabaseNum() + s.getTreeDatabaseNum());
metricService.createAutoGauge(
Metric.TABLE_DATABASE_NUM.toString(),
MetricLevel.CORE,
statistics,
ConfigSchemaStatistics::getTableDatabaseNum);

List<String> databases = clusterSchemaManager.getDatabaseNames(null);
for (String database : databases) {
// Enable table num gauge for information_schema
metricService
.getOrCreateGauge(
Metric.TABLE_NUM.toString(),
MetricLevel.CORE,
Tag.TYPE.toString(),
TableType.SYSTEM_VIEW.getName(),
Tag.DATABASE.toString(),
InformationSchema.INFORMATION_DATABASE)
.set(InformationSchema.getSchemaTables().size());

final List<String> databases = clusterSchemaManager.getDatabaseNames(null);
for (final String database : databases) {
int dataReplicationFactor = 1;
int schemaReplicationFactor = 1;
try {
Expand All @@ -291,16 +311,28 @@ private void bindDatabaseRelatedMetrics(AbstractMetricService metricService) {
}
bindDatabaseRelatedMetricsWhenUpdate(
metricService, configManager, database, dataReplicationFactor, schemaReplicationFactor);
bindDatabaseTableMetrics(metricService, statistics, database);
}
}

private void unbindDatabaseRelatedMetrics(AbstractMetricService metricService) {
// Remove the number of Databases
metricService.remove(MetricType.AUTO_GAUGE, Metric.DATABASE_NUM.toString());
metricService.remove(MetricType.AUTO_GAUGE, Metric.TABLE_DATABASE_NUM.toString());

// Remove gauge for information_schema
metricService.remove(
MetricType.GAUGE,
Metric.TABLE_NUM.toString(),
Tag.TYPE.toString(),
TableType.SYSTEM_VIEW.getName(),
Tag.DATABASE.toString(),
InformationSchema.INFORMATION_DATABASE);

List<String> databases = getClusterSchemaManager().getDatabaseNames(null);
for (String database : databases) {
unbindDatabaseRelatedMetricsWhenUpdate(metricService, database);
unbindDatabaseTableMetrics(metricService, database);
}
}

Expand Down Expand Up @@ -446,6 +478,54 @@ public static void bindDatabaseReplicationFactorMetricsWhenUpdate(
.set(schemaReplicationFactor);
}

public static void bindDatabaseTableMetrics(
final AbstractMetricService metricService,
final ConfigSchemaStatistics statistics,
final String database) {
if (!PathUtils.isTableModelDatabase(database)) {
return;
}
metricService.createAutoGauge(
Metric.TABLE_NUM.toString(),
MetricLevel.CORE,
statistics,
s -> s.getTreeViewTableNum(database),
Tag.TYPE.toString(),
TableType.VIEW_FROM_TREE.getName(),
Tag.DATABASE.toString(),
database);
metricService.createAutoGauge(
Metric.TABLE_NUM.toString(),
MetricLevel.CORE,
statistics,
s -> s.getBaseTableNum(database),
Tag.TYPE.toString(),
TableType.BASE_TABLE.getName(),
Tag.DATABASE.toString(),
database);
}

public static void unbindDatabaseTableMetrics(
final AbstractMetricService metricService, final String database) {
if (!PathUtils.isTableModelDatabase(database)) {
return;
}
metricService.remove(
MetricType.AUTO_GAUGE,
Metric.TABLE_NUM.toString(),
Tag.TYPE.toString(),
TableType.VIEW_FROM_TREE.getName(),
Tag.DATABASE.toString(),
database);
metricService.remove(
MetricType.AUTO_GAUGE,
Metric.TABLE_NUM.toString(),
Tag.TYPE.toString(),
TableType.BASE_TABLE.getName(),
Tag.DATABASE.toString(),
database);
}

// endregion

private NodeManager getNodeManager() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
import org.apache.iotdb.confignode.manager.partition.PartitionManager;
import org.apache.iotdb.confignode.manager.partition.PartitionMetrics;
import org.apache.iotdb.confignode.persistence.schema.ClusterSchemaInfo;
import org.apache.iotdb.confignode.persistence.schema.ConfigSchemaStatistics;
import org.apache.iotdb.confignode.rpc.thrift.TDatabaseInfo;
import org.apache.iotdb.confignode.rpc.thrift.TDatabaseSchema;
import org.apache.iotdb.confignode.rpc.thrift.TDescTable4InformationSchemaResp;
Expand Down Expand Up @@ -198,6 +199,10 @@ public TSStatus setDatabase(
schema.getName(),
schema.getDataReplicationFactor(),
schema.getSchemaReplicationFactor());
PartitionMetrics.bindDatabaseTableMetrics(
MetricService.getInstance(),
clusterSchemaInfo.getConfigSchemaStatistics(),
schema.getName());
// Adjust the maximum RegionGroup number of each Database
adjustMaxRegionGroupNum();
} catch (final ConsensusException e) {
Expand Down Expand Up @@ -615,6 +620,10 @@ public List<String> getDatabaseNames(final Boolean isTableModel) {
.collect(Collectors.toList());
}

public ConfigSchemaStatistics getConfigSchemaStatistics() {
return clusterSchemaInfo.getConfigSchemaStatistics();
}

/**
* Only leader use this interface. Get the specified Database's schemaengine
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ private void generateDatabasePhysicalPlan() {
name = internalMNode.getName();
break;
case DATABASE_MNODE_TYPE:
databaseMNode = deserializeDatabaseMNode(bufferedInputStream).getAsMNode();
databaseMNode = deserializeDatabaseMNode(bufferedInputStream);
while (!stack.isEmpty() && !stack.peek().right) {
databaseMNode.addChild(stack.pop().left);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.iotdb.commons.utils.PathUtils;
import org.apache.iotdb.commons.utils.StatusUtils;
import org.apache.iotdb.commons.utils.TestOnly;
import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlanType;
import org.apache.iotdb.confignode.consensus.request.read.database.CountDatabasePlan;
import org.apache.iotdb.confignode.consensus.request.read.database.GetDatabasePlan;
import org.apache.iotdb.confignode.consensus.request.read.table.DescTablePlan;
Expand Down Expand Up @@ -151,6 +152,7 @@ public class ClusterSchemaInfo implements SnapshotProcessor {
private final ReentrantReadWriteLock databaseReadWriteLock;
private final ConfigMTree treeModelMTree;
private final ConfigMTree tableModelMTree;
private final ConfigSchemaStatistics configSchemaStatistics;

private static final String TREE_SNAPSHOT_FILENAME = "cluster_schema.bin";
private static final String TABLE_SNAPSHOT_FILENAME = "table_cluster_schema.bin";
Expand All @@ -166,6 +168,7 @@ public ClusterSchemaInfo() throws IOException {
try {
treeModelMTree = new ConfigMTree(false);
tableModelMTree = new ConfigMTree(true);
configSchemaStatistics = new ConfigSchemaStatistics();
templateTable = new TemplateTable();
templatePreSetTable = new TemplatePreSetTable();
} catch (final MetadataException e) {
Expand Down Expand Up @@ -201,6 +204,12 @@ public TSStatus createDatabase(final DatabaseSchemaPlan plan) {
.getAsMNode()
.setDatabaseSchema(databaseSchema);

if (databaseSchema.isIsTableModel()) {
configSchemaStatistics.increaseTableDatabaseNum();
} else {
configSchemaStatistics.increaseTreeDatabaseNum();
}

result.setCode(TSStatusCode.SUCCESS_STATUS.getStatusCode());
} catch (final MetadataException e) {
LOGGER.error(ERROR_NAME, e);
Expand Down Expand Up @@ -301,6 +310,12 @@ public TSStatus deleteDatabase(final DeleteDatabasePlan plan) {
(isTableModel ? tableModelMTree : treeModelMTree)
.deleteDatabase(getQualifiedDatabasePartialPath(plan.getName()));

if (isTableModel) {
configSchemaStatistics.decreaseTableDatabaseNum();
} else {
configSchemaStatistics.decreaseTreeDatabaseNum();
}

result.setCode(TSStatusCode.SUCCESS_STATUS.getStatusCode());
} catch (final MetadataException e) {
LOGGER.warn("Database not exist", e);
Expand Down Expand Up @@ -785,14 +800,14 @@ public void processLoadSnapshot(final File snapshotDir) throws IOException {
TREE_SNAPSHOT_FILENAME,
stream -> {
treeModelMTree.clear();
treeModelMTree.deserialize(stream);
treeModelMTree.deserialize(stream, configSchemaStatistics);
});
processMTreeLoadSnapshot(
snapshotDir,
TABLE_SNAPSHOT_FILENAME,
stream -> {
tableModelMTree.clear();
tableModelMTree.deserialize(stream);
tableModelMTree.deserialize(stream, configSchemaStatistics);
});
templateTable.processLoadSnapshot(snapshotDir);
templatePreSetTable.processLoadSnapshot(snapshotDir);
Expand Down Expand Up @@ -1168,25 +1183,42 @@ public TSStatus extendSchemaTemplate(ExtendSchemaTemplatePlan extendSchemaTempla

public TSStatus preCreateTable(final PreCreateTablePlan plan) {
return executeWithLock(
() ->
tableModelMTree.preCreateTable(
getQualifiedDatabasePartialPath(plan.getDatabase()), plan.getTable()));
() -> {
tableModelMTree.preCreateTable(
getQualifiedDatabasePartialPath(plan.getDatabase()), plan.getTable());
configSchemaStatistics.increaseBaseTableNum(plan.getDatabase());
});
}

public TSStatus preCreateTableView(final PreCreateTableViewPlan plan) {
return executeWithLock(
() ->
tableModelMTree.preCreateTableView(
getQualifiedDatabasePartialPath(plan.getDatabase()),
plan.getTable(),
plan.getStatus()));
() -> {
tableModelMTree.preCreateTableView(
getQualifiedDatabasePartialPath(plan.getDatabase()),
plan.getTable(),
plan.getStatus());
configSchemaStatistics.increaseTreeViewTableNum(plan.getDatabase());
});
}

public TSStatus rollbackCreateTable(final RollbackCreateTablePlan plan) {
return executeWithLock(
() ->
tableModelMTree.rollbackCreateTable(
getQualifiedDatabasePartialPath(plan.getDatabase()), plan.getTableName()));
() -> {
final PartialPath database = getQualifiedDatabasePartialPath(plan.getDatabase());
final String tableName = plan.getTableName();
tableModelMTree
.getTableAndStatusIfExists(database, tableName)
.map(Pair::getLeft)
.ifPresent(
table -> {
if (TreeViewSchema.isTreeViewTable(table)) {
configSchemaStatistics.decreaseTreeViewTableNum(tableName);
} else {
configSchemaStatistics.decreaseBaseTableNum(tableName);
}
});
tableModelMTree.rollbackCreateTable(database, tableName);
});
}

public TSStatus commitCreateTable(final CommitCreateTablePlan plan) {
Expand All @@ -1207,9 +1239,15 @@ public TSStatus preDeleteTable(final PreDeleteTablePlan plan) {

public TSStatus dropTable(final CommitDeleteTablePlan plan) {
return executeWithLock(
() ->
tableModelMTree.dropTable(
getQualifiedDatabasePartialPath(plan.getDatabase()), plan.getTableName()));
() -> {
tableModelMTree.dropTable(
getQualifiedDatabasePartialPath(plan.getDatabase()), plan.getTableName());
if (plan.getType() == ConfigPhysicalPlanType.CommitDeleteView) {
configSchemaStatistics.decreaseTreeViewTableNum(plan.getDatabase());
} else {
configSchemaStatistics.decreaseBaseTableNum(plan.getDatabase());
}
});
}

public TSStatus renameTable(final RenameTablePlan plan) {
Expand Down Expand Up @@ -1530,6 +1568,10 @@ public TSStatus commitDeleteColumn(final CommitDeleteColumnPlan plan) {
plan.getColumnName()));
}

public ConfigSchemaStatistics getConfigSchemaStatistics() {
return configSchemaStatistics;
}

// endregion

@TestOnly
Expand Down
Loading
Loading