Murtadha Hubail has uploaded this change for review. ( https://asterix-gerrit.ics.uci.edu/3425
Change subject: [NO ISSUE][OTH] Add API To Get Dataset Size ...................................................................... [NO ISSUE][OTH] Add API To Get Dataset Size - user model changes: no - storage format changes: no - interface changes: no Details: - Add an API that returns the on disk total size of a dataset and its indexes on a node. Change-Id: Iaff87bbe1f2417689f7827deaf03fcddd64ca7e4 --- A asterixdb/asterix-common/src/main/java/org/apache/asterix/common/storage/DatasetCopyIdentifier.java M asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/PersistentLocalResourceRepository.java 2 files changed, 100 insertions(+), 0 deletions(-) git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/25/3425/1 diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/storage/DatasetCopyIdentifier.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/storage/DatasetCopyIdentifier.java new file mode 100644 index 0000000..bc91fe4 --- /dev/null +++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/storage/DatasetCopyIdentifier.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.asterix.common.storage; + +import java.io.Serializable; +import java.util.Objects; + +public class DatasetCopyIdentifier implements Serializable { + + private static final long serialVersionUID = 1L; + private final String dataset; + private final String dataverse; + private final String rebalance; + + private DatasetCopyIdentifier(String dataverse, String datasetName, String rebalance) { + this.dataverse = dataverse; + this.dataset = datasetName; + this.rebalance = rebalance; + } + + public static DatasetCopyIdentifier of(String dataverse, String datasetName, String rebalance) { + return new DatasetCopyIdentifier(dataverse, datasetName, rebalance); + } + + public String getDataset() { + return dataset; + } + + public String getRebalance() { + return rebalance; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + DatasetCopyIdentifier that = (DatasetCopyIdentifier) o; + return Objects.equals(dataverse, that.dataverse) && Objects.equals(dataset, that.dataset) + && Objects.equals(rebalance, that.rebalance); + } + + @Override + public int hashCode() { + return Objects.hash(dataverse, dataset, rebalance); + } + + public String getDataverse() { + return dataverse; + } + + @Override + public String toString() { + return "DatasetCopyIdentifier{" + "dataset='" + dataset + '\'' + ", dataverse='" + dataverse + '\'' + + ", rebalance='" + rebalance + '\'' + '}'; + } +} \ No newline at end of file diff --git a/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/PersistentLocalResourceRepository.java b/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/PersistentLocalResourceRepository.java index aef7bbd..d6efa2b 100644 --- a/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/PersistentLocalResourceRepository.java +++ b/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/PersistentLocalResourceRepository.java @@ -47,6 +47,7 @@ import org.apache.asterix.common.replication.IReplicationManager; import org.apache.asterix.common.replication.IReplicationStrategy; import org.apache.asterix.common.replication.ReplicationJob; +import org.apache.asterix.common.storage.DatasetCopyIdentifier; import org.apache.asterix.common.storage.DatasetResourceReference; import org.apache.asterix.common.storage.IIndexCheckpointManager; import org.apache.asterix.common.storage.IIndexCheckpointManagerProvider; @@ -557,6 +558,23 @@ return null; } + public long getDatasetSize(DatasetCopyIdentifier datasetIdentifier) throws HyracksDataException { + long totalSize = 0; + final Map<Long, LocalResource> dataverse = getResources(lr -> { + final ResourceReference resourceReference = ResourceReference.ofIndex(lr.getPath()); + return isMatch(datasetIdentifier, resourceReference); + }); + final List<DatasetResourceReference> allResources = + dataverse.values().stream().map(DatasetResourceReference::of).collect(Collectors.toList()); + for (DatasetResourceReference res : allResources) { + final ResourceStorageStats resourceStats = getResourceStats(res); + if (resourceStats != null) { + totalSize += resourceStats.getTotalSize(); + } + } + return totalSize; + } + private void createResourceFileMask(FileReference resourceFile) throws HyracksDataException { Path maskFile = getResourceMaskFilePath(resourceFile); try { @@ -595,4 +613,10 @@ private static boolean isComponentFile(File indexDir, String fileName) { return COMPONENT_FILES_FILTER.accept(indexDir, fileName); } + + private static boolean isMatch(DatasetCopyIdentifier datasetIdentifier, ResourceReference resourceReference) { + return resourceReference.getDataverse().equals(datasetIdentifier.getDataverse()) + && resourceReference.getDataset().equals(datasetIdentifier.getDataset()) + && resourceReference.getRebalance().equals(datasetIdentifier.getRebalance()); + } } -- To view, visit https://asterix-gerrit.ics.uci.edu/3425 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-MessageType: newchange Gerrit-Change-Id: Iaff87bbe1f2417689f7827deaf03fcddd64ca7e4 Gerrit-Change-Number: 3425 Gerrit-PatchSet: 1 Gerrit-Owner: Murtadha Hubail <[email protected]>
