Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -712,7 +712,8 @@ public void setStorageGroup(PartialPath storageGroup) throws MetadataException {
public void deleteStorageGroups(List<PartialPath> storageGroups) throws MetadataException {
try {
for (PartialPath storageGroup : storageGroups) {
totalSeriesNumber.addAndGet(-mtree.getAllTimeseriesCount(storageGroup));
totalSeriesNumber.addAndGet(
-mtree.getAllTimeseriesCount(storageGroup, (int) totalSeriesNumber.get()));
// clear cached MNode
if (!allowToCreateNewSeries
&& totalSeriesNumber.get() * ESTIMATED_SERIES_SIZE < MTREE_SIZE_THRESHOLD) {
Expand Down Expand Up @@ -884,7 +885,7 @@ public Pair<List<PartialPath>, Integer> getAllTimeseriesPathWithAlias(

/** To calculate the count of timeseries for given prefix path. */
public int getAllTimeseriesCount(PartialPath prefixPath) throws MetadataException {
return mtree.getAllTimeseriesCount(prefixPath);
return mtree.getAllTimeseriesCount(prefixPath, (int) totalSeriesNumber.get());
}

/** To calculate the count of devices for given prefix path. */
Expand Down
11 changes: 8 additions & 3 deletions server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@
import java.util.stream.Stream;

import static java.util.stream.Collectors.toList;
import static org.apache.iotdb.db.conf.IoTDBConstant.PATH_SEPARATOR;
import static org.apache.iotdb.db.conf.IoTDBConstant.PATH_WILDCARD;
import static org.apache.iotdb.db.conf.IoTDBConstant.*;

/** The hierarchical struct of the Metadata Tree is implemented in this class. */
public class MTree implements Serializable {
Expand Down Expand Up @@ -981,11 +980,17 @@ Pair<List<PartialPath>, Integer> getAllTimeseriesPathWithAlias(
* throw PathNotExistException()
*
* @param prefixPath a prefix path or a full path, may contain '*'.
* @param totalSeriesNumber MManger generated total series number under the root path , if MManger
* don't generated, can transmission - 1
*/
int getAllTimeseriesCount(PartialPath prefixPath) throws MetadataException {
int getAllTimeseriesCount(PartialPath prefixPath, int totalSeriesNumber)
throws MetadataException {
String[] nodes = prefixPath.getNodes();
if (nodes.length == 0 || !nodes[0].equals(root.getName())) {
throw new IllegalPathException(prefixPath.getFullPath());
} else if (totalSeriesNumber >= 0
&& (nodes.length == 1 || (nodes.length == 2 && nodes[1].equals(PATH_WILDCARD)))) {
return totalSeriesNumber;
}
try {
return getCount(root, nodes, 1, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,11 +677,11 @@ public void testGetAllTimeseriesCount() {
null,
null);

assertEquals(4, root.getAllTimeseriesCount(new PartialPath("root.laptop")));
assertEquals(2, root.getAllTimeseriesCount(new PartialPath("root.laptop.*.s1")));
assertEquals(4, root.getAllTimeseriesCount(new PartialPath("root.laptop"), -1));
assertEquals(2, root.getAllTimeseriesCount(new PartialPath("root.laptop.*.s1"), -1));
PartialPath partialPath = new PartialPath("root.laptop.d1.s3");
try {
root.getAllTimeseriesCount(partialPath);
root.getAllTimeseriesCount(partialPath, -1);
fail("Expected exception");
} catch (MetadataException e) {
assertEquals("Path [root.laptop.d1.s3] does not exist", e.getMessage());
Expand Down Expand Up @@ -719,7 +719,7 @@ public void testAddSubDevice() throws MetadataException {
null);

assertEquals(2, root.getDevices(new PartialPath("root")).size());
assertEquals(2, root.getAllTimeseriesCount(new PartialPath("root")));
assertEquals(2, root.getAllTimeseriesCount(new PartialPath("root"), -1));
assertEquals(2, root.getAllTimeseriesPath(new PartialPath("root")).size());
assertEquals(2, root.getAllTimeseriesPathWithAlias(new PartialPath("root"), 0, 0).left.size());
}
Expand Down