Skip to content

Commit 1934321

Browse files
committed
Support some configurations about data partition base on database level
1 parent 75bfa23 commit 1934321

7 files changed

Lines changed: 372 additions & 92 deletions

File tree

iotdb-core/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ databaseAttributeClause
118118
databaseAttributeKey
119119
: TTL
120120
| TIME_PARTITION_INTERVAL
121+
| TIME_PARTITION_ORIGIN
121122
| SCHEMA_REGION_GROUP_NUM
122123
| DATA_REGION_GROUP_NUM
123124
;

iotdb-core/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/SqlLexer.g4

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,10 @@ TIME_PARTITION_INTERVAL
12111211
: T I M E '_' P A R T I T I O N '_' I N T E R V A L
12121212
;
12131213

1214+
TIME_PARTITION_ORIGIN
1215+
: T I M E '_' P A R T I T I O N '_' O R I G I N
1216+
;
1217+
12141218
SCHEMA_REGION_GROUP_NUM
12151219
: S C H E M A '_' R E G I O N '_' G R O U P '_' N U M
12161220
;

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ClusterSchemaInfo.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.apache.iotdb.commons.utils.PathUtils;
3939
import org.apache.iotdb.commons.utils.StatusUtils;
4040
import org.apache.iotdb.commons.utils.TestOnly;
41+
import org.apache.iotdb.commons.utils.TimePartitionUtils;
4142
import org.apache.iotdb.confignode.consensus.request.read.database.CountDatabasePlan;
4243
import org.apache.iotdb.confignode.consensus.request.read.database.GetDatabasePlan;
4344
import org.apache.iotdb.confignode.consensus.request.read.table.DescTablePlan;
@@ -196,6 +197,10 @@ public TSStatus createDatabase(final DatabaseSchemaPlan plan) {
196197
final TDatabaseSchema databaseSchema = plan.getSchema();
197198
final PartialPath partialPathName = getQualifiedDatabasePartialPath(databaseSchema.getName());
198199

200+
// Update TimePartitionUtils cache with database-specific time partition settings
201+
TimePartitionUtils.updateDatabaseTimePartitionConfig(
202+
databaseSchema.getName(), databaseSchema);
203+
199204
final ConfigMTree mTree = databaseSchema.isIsTableModel() ? tableModelMTree : treeModelMTree;
200205
mTree.setStorageGroup(partialPathName);
201206

@@ -280,6 +285,9 @@ public TSStatus alterDatabase(final DatabaseSchemaPlan plan) {
280285
.getAsMNode()
281286
.setDatabaseSchema(currentSchema);
282287

288+
// Update TimePartitionUtils cache with new time partition settings
289+
TimePartitionUtils.updateDatabaseTimePartitionConfig(currentSchema.getName(), currentSchema);
290+
283291
result.setCode(TSStatusCode.SUCCESS_STATUS.getStatusCode());
284292
} catch (final MetadataException e) {
285293
LOGGER.error(ERROR_NAME, e);
@@ -305,6 +313,9 @@ public TSStatus deleteDatabase(final DeleteDatabasePlan plan) {
305313
(isTableModel ? tableModelMTree : treeModelMTree)
306314
.deleteDatabase(getQualifiedDatabasePartialPath(plan.getName()));
307315

316+
// Remove database-specific time partition configuration from cache
317+
TimePartitionUtils.removeDatabaseTimePartitionConfig(plan.getName());
318+
308319
result.setCode(TSStatusCode.SUCCESS_STATUS.getStatusCode());
309320
} catch (final MetadataException e) {
310321
LOGGER.warn("Database not exist", e);

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessor.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -446,19 +446,20 @@ public TSStatus alterDatabase(final TDatabaseSchema databaseSchema) {
446446
"Failed to alter database. Doesn't support ALTER DataReplicationFactor yet.");
447447
}
448448

449-
if (databaseSchema.isSetTimePartitionOrigin()) {
450-
errorResp =
451-
new TSStatus(TSStatusCode.DATABASE_CONFIG_ERROR.getStatusCode())
452-
.setMessage(
453-
"Failed to alter database. Doesn't support ALTER TimePartitionOrigin yet.");
454-
}
455-
456-
if (databaseSchema.isSetTimePartitionInterval()) {
457-
errorResp =
458-
new TSStatus(TSStatusCode.DATABASE_CONFIG_ERROR.getStatusCode())
459-
.setMessage(
460-
"Failed to alter database. Doesn't support ALTER TimePartitionInterval yet.");
461-
}
449+
// Time partition settings are now supported for database-level configuration
450+
// if (databaseSchema.isSetTimePartitionOrigin()) {
451+
// errorResp =
452+
// new TSStatus(TSStatusCode.DATABASE_CONFIG_ERROR.getStatusCode())
453+
// .setMessage(
454+
// "Failed to alter database. Doesn't support ALTER TimePartitionOrigin yet.");
455+
// }
456+
457+
// if (databaseSchema.isSetTimePartitionInterval()) {
458+
// errorResp =
459+
// new TSStatus(TSStatusCode.DATABASE_CONFIG_ERROR.getStatusCode())
460+
// .setMessage(
461+
// "Failed to alter database. Doesn't support ALTER TimePartitionInterval yet.");
462+
// }
462463

463464
if (errorResp != null) {
464465
LOGGER.warn("Execute AlterDatabase: {} with result: {}", databaseSchema, errorResp);

iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/partition/DataPartition.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ public List<List<TTimePartitionSlot>> getTimePartitionRange(
109109
dataPartitionMap.get(storageGroup).get(seriesPartitionSlot);
110110
List<TTimePartitionSlot> timePartitionSlotList =
111111
map.keySet().stream()
112-
.filter(key -> TimePartitionUtils.satisfyPartitionStartTime(timeFilter, key.startTime))
112+
.filter(
113+
key ->
114+
TimePartitionUtils.satisfyPartitionStartTime(
115+
timeFilter, key.startTime, storageGroup))
113116
.sorted(Comparator.comparingLong(TTimePartitionSlot::getStartTime))
114117
.collect(toList());
115118

@@ -152,7 +155,8 @@ public List<TRegionReplicaSet> getDataRegionReplicaSetWithTimeFilter(
152155
return regionReplicaSetMap.entrySet().stream()
153156
.filter(
154157
entry ->
155-
TimePartitionUtils.satisfyPartitionStartTime(timeFilter, entry.getKey().startTime))
158+
TimePartitionUtils.satisfyPartitionStartTime(
159+
timeFilter, entry.getKey().startTime, storageGroup))
156160
.flatMap(entry -> entry.getValue().stream())
157161
.distinct()
158162
.collect(toList());
@@ -175,7 +179,8 @@ public List<TRegionReplicaSet> getDataRegionReplicaSetWithTimeFilter(
175179
return dataPartitionMap.get(database).get(seriesPartitionSlot).entrySet().stream()
176180
.filter(
177181
entry ->
178-
TimePartitionUtils.satisfyPartitionStartTime(timeFilter, entry.getKey().startTime))
182+
TimePartitionUtils.satisfyPartitionStartTime(
183+
timeFilter, entry.getKey().startTime, database))
179184
.flatMap(entry -> entry.getValue().stream())
180185
.distinct()
181186
.collect(toList());

0 commit comments

Comments
 (0)