Murtadha Hubail has submitted this change and it was merged. ( 
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
Reviewed-on: https://asterix-gerrit.ics.uci.edu/3425
Contrib: Jenkins <jenk...@fulliautomatix.ics.uci.edu>
Sonar-Qube: Jenkins <jenk...@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenk...@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenk...@fulliautomatix.ics.uci.edu>
Reviewed-by: Murtadha Hubail <mhub...@apache.org>
Reviewed-by: Michael Blow <mb...@apache.org>
---
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, 99 insertions(+), 0 deletions(-)

Approvals:
  Jenkins: Verified; No violations found; ; Verified
  Murtadha Hubail: Looks good to me, but someone else must approve
  Michael Blow: Looks good to me, approved



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..6500c8a
--- /dev/null
+++ 
b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/storage/DatasetCopyIdentifier.java
@@ -0,0 +1,81 @@
+/*
+ * 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;
+    }
+
+    public boolean isMatch(ResourceReference resourceReference) {
+        return resourceReference.getDataverse().equals(dataverse) && 
resourceReference.getDataset().equals(dataset)
+                && resourceReference.getRebalance().equals(rebalance);
+    }
+
+    @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..e170779 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 datasetIdentifier.isMatch(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 {

--
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: merged
Gerrit-Change-Id: Iaff87bbe1f2417689f7827deaf03fcddd64ca7e4
Gerrit-Change-Number: 3425
Gerrit-PatchSet: 4
Gerrit-Owner: Murtadha Hubail <mhub...@apache.org>
Gerrit-Reviewer: Anon. E. Moose (1000171)
Gerrit-Reviewer: Jenkins <jenk...@fulliautomatix.ics.uci.edu>
Gerrit-Reviewer: Michael Blow <mb...@apache.org>
Gerrit-Reviewer: Murtadha Hubail <mhub...@apache.org>
Gerrit-Reviewer: Till Westmann <ti...@apache.org>

Reply via email to