|
33 | 33 | import org.apache.iotdb.confignode.rpc.thrift.TDataPartitionTableResp; |
34 | 34 | import org.apache.iotdb.confignode.rpc.thrift.TDatabaseSchema; |
35 | 35 | import org.apache.iotdb.confignode.rpc.thrift.TGetDatabaseReq; |
| 36 | +import org.apache.iotdb.confignode.rpc.thrift.TGetRegionGroupsByTimeReq; |
| 37 | +import org.apache.iotdb.confignode.rpc.thrift.TGetRegionGroupsByTimeResp; |
36 | 38 | import org.apache.iotdb.confignode.rpc.thrift.TGetRegionIdReq; |
37 | 39 | import org.apache.iotdb.confignode.rpc.thrift.TGetRegionIdResp; |
38 | 40 | import org.apache.iotdb.confignode.rpc.thrift.TGetSeriesSlotListReq; |
@@ -519,6 +521,84 @@ public void testGetSlots() throws Exception { |
519 | 521 | } |
520 | 522 | } |
521 | 523 |
|
| 524 | + @Test |
| 525 | + public void testGetRegionGroupsByTime() throws Exception { |
| 526 | + final String sg0 = "root.sg0"; |
| 527 | + |
| 528 | + try (SyncConfigNodeIServiceClient client = |
| 529 | + (SyncConfigNodeIServiceClient) EnvFactory.getEnv().getLeaderConfigNodeConnection()) { |
| 530 | + |
| 531 | + // Get all region groups covering the full time range |
| 532 | + TGetRegionGroupsByTimeReq req = new TGetRegionGroupsByTimeReq(sg0, 0L, Long.MAX_VALUE); |
| 533 | + TGetRegionGroupsByTimeResp resp = client.getRegionGroupsByTime(req); |
| 534 | + Assert.assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), resp.getStatus().getCode()); |
| 535 | + Assert.assertNotNull(resp.getRegionReplicaSets()); |
| 536 | + Assert.assertFalse(resp.getRegionReplicaSets().isEmpty()); |
| 537 | + int allRegionGroupCount = resp.getRegionReplicaSetsSize(); |
| 538 | + |
| 539 | + // Each replica set should have testReplicationFactor replicas |
| 540 | + resp.getRegionReplicaSets() |
| 541 | + .forEach( |
| 542 | + replicaSet -> { |
| 543 | + Assert.assertEquals(testReplicationFactor, replicaSet.getDataNodeLocationsSize()); |
| 544 | + Assert.assertEquals( |
| 545 | + TConsensusGroupType.DataRegion, replicaSet.getRegionId().getType()); |
| 546 | + }); |
| 547 | + |
| 548 | + // Query with a single time slot range should return a subset |
| 549 | + TGetRegionGroupsByTimeReq singleSlotReq = |
| 550 | + new TGetRegionGroupsByTimeReq(sg0, 0L, testTimePartitionInterval - 1); |
| 551 | + TGetRegionGroupsByTimeResp singleSlotResp = client.getRegionGroupsByTime(singleSlotReq); |
| 552 | + Assert.assertEquals( |
| 553 | + TSStatusCode.SUCCESS_STATUS.getStatusCode(), singleSlotResp.getStatus().getCode()); |
| 554 | + Assert.assertNotNull(singleSlotResp.getRegionReplicaSets()); |
| 555 | + Assert.assertFalse(singleSlotResp.getRegionReplicaSets().isEmpty()); |
| 556 | + Assert.assertTrue(singleSlotResp.getRegionReplicaSetsSize() <= allRegionGroupCount); |
| 557 | + |
| 558 | + // Query with a disjoint time range should return empty result |
| 559 | + TGetRegionGroupsByTimeReq disjointReq = |
| 560 | + new TGetRegionGroupsByTimeReq( |
| 561 | + sg0, |
| 562 | + testTimePartitionSlotsNum * testTimePartitionInterval * 2, |
| 563 | + testTimePartitionSlotsNum * testTimePartitionInterval * 3); |
| 564 | + TGetRegionGroupsByTimeResp disjointResp = client.getRegionGroupsByTime(disjointReq); |
| 565 | + Assert.assertEquals( |
| 566 | + TSStatusCode.SUCCESS_STATUS.getStatusCode(), disjointResp.getStatus().getCode()); |
| 567 | + Assert.assertTrue( |
| 568 | + disjointResp.getRegionReplicaSets() == null |
| 569 | + || disjointResp.getRegionReplicaSets().isEmpty()); |
| 570 | + |
| 571 | + // Query non-existent database should return empty result |
| 572 | + TGetRegionGroupsByTimeReq nonExistReq = |
| 573 | + new TGetRegionGroupsByTimeReq("root.nonexistent", 0L, Long.MAX_VALUE); |
| 574 | + TGetRegionGroupsByTimeResp nonExistResp = client.getRegionGroupsByTime(nonExistReq); |
| 575 | + Assert.assertEquals( |
| 576 | + TSStatusCode.SUCCESS_STATUS.getStatusCode(), nonExistResp.getStatus().getCode()); |
| 577 | + Assert.assertTrue( |
| 578 | + nonExistResp.getRegionReplicaSets() == null |
| 579 | + || nonExistResp.getRegionReplicaSets().isEmpty()); |
| 580 | + |
| 581 | + // Verify consistency: union of per-slot queries should equal full-range query |
| 582 | + Set<TConsensusGroupId> unionRegionIds = new HashSet<>(); |
| 583 | + for (long t = 0; t < testTimePartitionSlotsNum; t++) { |
| 584 | + TGetRegionGroupsByTimeReq perSlotReq = |
| 585 | + new TGetRegionGroupsByTimeReq( |
| 586 | + sg0, t * testTimePartitionInterval, t * testTimePartitionInterval); |
| 587 | + TGetRegionGroupsByTimeResp perSlotResp = client.getRegionGroupsByTime(perSlotReq); |
| 588 | + Assert.assertEquals( |
| 589 | + TSStatusCode.SUCCESS_STATUS.getStatusCode(), perSlotResp.getStatus().getCode()); |
| 590 | + if (perSlotResp.getRegionReplicaSets() != null) { |
| 591 | + perSlotResp |
| 592 | + .getRegionReplicaSets() |
| 593 | + .forEach(replicaSet -> unionRegionIds.add(replicaSet.getRegionId())); |
| 594 | + } |
| 595 | + } |
| 596 | + Set<TConsensusGroupId> allRegionIds = new HashSet<>(); |
| 597 | + resp.getRegionReplicaSets().forEach(replicaSet -> allRegionIds.add(replicaSet.getRegionId())); |
| 598 | + Assert.assertEquals(allRegionIds, unionRegionIds); |
| 599 | + } |
| 600 | + } |
| 601 | + |
522 | 602 | @Test |
523 | 603 | public void testGetSchemaNodeManagementPartition() throws Exception { |
524 | 604 |
|
|
0 commit comments