This is an automated email from the ASF dual-hosted git repository.

dlych pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git


The following commit(s) were added to refs/heads/master by this push:
     new f9725e4  [NO ISSUE][OTH] Add API To Get Dataset Size
f9725e4 is described below

commit f9725e4bfa463c13fe78dc66994038e0c8d702c2
Author: Murtadha Hubail <[email protected]>
AuthorDate: Sat Jun 8 03:23:31 2019 +0300

    [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 <[email protected]>
    Sonar-Qube: Jenkins <[email protected]>
    Tested-by: Jenkins <[email protected]>
    Integration-Tests: Jenkins <[email protected]>
    Reviewed-by: Murtadha Hubail <[email protected]>
    Reviewed-by: Michael Blow <[email protected]>
---
 .../common/storage/DatasetCopyIdentifier.java      | 81 ++++++++++++++++++++++
 .../PersistentLocalResourceRepository.java         | 18 +++++
 2 files changed, 99 insertions(+)

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.exceptions.AsterixException;
 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 @@ public class PersistentLocalResourceRepository implements 
ILocalResourceReposito
         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 {

Reply via email to