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
commit bb3c8b95976071f9abd68ef2625b8f8793b75263 Author: Michael Blow <[email protected]> AuthorDate: Wed Jan 13 12:20:53 2021 -0500 [NO ISSUE][*DB][STO] Minor performance improvements Change-Id: Ia95198caf8f8368e56411fc077bdf0684042bf8f Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/9584 Tested-by: Jenkins <[email protected]> Integration-Tests: Jenkins <[email protected]> Reviewed-by: Michael Blow <[email protected]> Reviewed-by: Murtadha Hubail <[email protected]> Reviewed-by: Till Westmann <[email protected]> Reviewed-by: Ali Alsuliman <[email protected]> --- .../common/storage/DatasetResourceReference.java | 50 ++++-------------- .../asterix/common/storage/ResourceReference.java | 61 +++++++++++----------- 2 files changed, 41 insertions(+), 70 deletions(-) diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/storage/DatasetResourceReference.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/storage/DatasetResourceReference.java index 6fd1c6a..297f08e 100644 --- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/storage/DatasetResourceReference.java +++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/storage/DatasetResourceReference.java @@ -25,14 +25,19 @@ import org.apache.asterix.common.dataflow.DatasetLocalResource; import org.apache.asterix.common.utils.StorageConstants; import org.apache.hyracks.storage.common.LocalResource; +@SuppressWarnings("squid:S2160") // don't override equals public class DatasetResourceReference extends ResourceReference { - private int datasetId; - private int partitionId; - private long resourceId; + private final int datasetId; + private final int partitionId; + private final long resourceId; - private DatasetResourceReference() { - super(); + private DatasetResourceReference(LocalResource localResource) { + super(Paths.get(localResource.getPath(), StorageConstants.METADATA_FILE_NAME).toString()); + final DatasetLocalResource dsResource = (DatasetLocalResource) localResource.getResource(); + datasetId = dsResource.getDatasetId(); + partitionId = dsResource.getPartition(); + resourceId = localResource.getId(); } public static DatasetResourceReference of(LocalResource localResource) { @@ -53,39 +58,6 @@ public class DatasetResourceReference extends ResourceReference { } private static DatasetResourceReference parse(LocalResource localResource) { - final DatasetResourceReference datasetResourceReference = new DatasetResourceReference(); - final String filePath = Paths.get(localResource.getPath(), StorageConstants.METADATA_FILE_NAME).toString(); - parse(datasetResourceReference, filePath); - assignIds(localResource, datasetResourceReference); - return datasetResourceReference; - } - - private static void assignIds(LocalResource localResource, DatasetResourceReference lrr) { - final DatasetLocalResource dsResource = (DatasetLocalResource) localResource.getResource(); - lrr.datasetId = dsResource.getDatasetId(); - lrr.partitionId = dsResource.getPartition(); - lrr.resourceId = localResource.getId(); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o instanceof ResourceReference) { - ResourceReference that = (ResourceReference) o; - return getRelativePath().toString().equals(that.getRelativePath().toString()); - } - return false; - } - - @Override - public int hashCode() { - return getRelativePath().toString().hashCode(); - } - - @Override - public String toString() { - return getRelativePath().toString(); + return new DatasetResourceReference(localResource); } } diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/storage/ResourceReference.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/storage/ResourceReference.java index c3b6229..7791926 100644 --- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/storage/ResourceReference.java +++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/storage/ResourceReference.java @@ -28,15 +28,29 @@ import org.apache.hyracks.storage.am.lsm.common.impls.IndexComponentFileReferenc public class ResourceReference { - protected String root; - protected String partition; - protected String dataverse; // == DataverseName.getCanonicalForm() - protected String dataset; - protected String rebalance; - protected String index; - protected String name; - - protected ResourceReference() { + protected final String root; + protected final String partition; + protected final String dataverse; // == DataverseName.getCanonicalForm() + protected final String dataset; + protected final String rebalance; + protected final String index; + protected final String name; + private volatile Path relativePath; + + protected ResourceReference(String path) { + // format: root/partition/dataverse/dataset/rebalanceCount/index/fileName + final String[] tokens = StringUtils.split(path, File.separatorChar); + if (tokens.length < 6) { + throw new IllegalStateException("Unrecognized path structure: " + path); + } + int offset = tokens.length; + name = tokens[--offset]; + index = tokens[--offset]; + rebalance = tokens[--offset]; + dataset = tokens[--offset]; + dataverse = tokens[--offset]; //TODO(MULTI_PART_DATAVERSE_NAME):REVISIT + partition = tokens[--offset]; + root = tokens[--offset]; } public static ResourceReference ofIndex(String indexPath) { @@ -44,9 +58,7 @@ public class ResourceReference { } public static ResourceReference of(String localResourcePath) { - ResourceReference lrr = new ResourceReference(); - parse(lrr, localResourcePath); - return lrr; + return new ResourceReference(localResourcePath); } public String getPartition() { @@ -74,7 +86,10 @@ public class ResourceReference { } public Path getRelativePath() { - return Paths.get(root, partition, dataverse, dataset, rebalance, index); + if (relativePath == null) { + relativePath = Paths.get(root, partition, dataverse, dataset, rebalance, index); + } + return relativePath; } public ResourceReference getDatasetReference() { @@ -86,22 +101,6 @@ public class ResourceReference { return Paths.get(root, partition, dataverse, dataset, rebalance, index, name); } - protected static void parse(ResourceReference ref, String path) { - // format: root/partition/dataverse/dataset/rebalanceCount/index/fileName - final String[] tokens = StringUtils.split(path, File.separatorChar); - if (tokens.length < 6) { - throw new IllegalStateException("Unrecognized path structure: " + path); - } - int offset = tokens.length; - ref.name = tokens[--offset]; - ref.index = tokens[--offset]; - ref.rebalance = tokens[--offset]; - ref.dataset = tokens[--offset]; - ref.dataverse = tokens[--offset]; //TODO(MULTI_PART_DATAVERSE_NAME):REVISIT - ref.partition = tokens[--offset]; - ref.root = tokens[--offset]; - } - public int getPartitionNum() { return Integer.parseInt(partition.substring(StorageConstants.PARTITION_DIR_PREFIX.length())); } @@ -113,14 +112,14 @@ public class ResourceReference { } if (o instanceof ResourceReference) { ResourceReference that = (ResourceReference) o; - return getRelativePath().toString().equals(that.getRelativePath().toString()); + return getRelativePath().equals(that.getRelativePath()); } return false; } @Override public int hashCode() { - return getRelativePath().toString().hashCode(); + return getRelativePath().hashCode(); } @Override
