Skip to content

Commit

Permalink
squash
Browse files Browse the repository at this point in the history
  • Loading branch information
dbw9580 committed Aug 17, 2023
1 parent 8fbcf0a commit bda3407
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import alluxio.grpc.DeletePOptions;
import alluxio.grpc.ExistsPOptions;
import alluxio.grpc.GetStatusPOptions;
import alluxio.grpc.GrpcUtils;
import alluxio.grpc.ListStatusPOptions;
import alluxio.grpc.OpenFilePOptions;
import alluxio.grpc.RenamePOptions;
Expand All @@ -48,6 +49,7 @@
import alluxio.wire.BlockLocation;
import alluxio.wire.BlockLocationInfo;
import alluxio.wire.FileBlockInfo;
import alluxio.wire.FileInfo;
import alluxio.wire.WorkerNetAddress;

import com.codahale.metrics.Counter;
Expand All @@ -61,6 +63,7 @@
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;

/**
* Dora Cache file system implementation.
Expand Down Expand Up @@ -139,7 +142,11 @@ public URIStatus getStatus(AlluxioURI path, GetStatusPOptions options)
GetStatusPOptions mergedOptions = FileSystemOptionsUtils.getStatusDefaults(
mFsContext.getClusterConf()).toBuilder().mergeFrom(options).build();

return mDoraClient.getStatus(ufsFullPath.toString(), mergedOptions);
final URIStatus status = mDoraClient.getStatus(ufsFullPath.toString(), mergedOptions);
FileInfo info = GrpcUtils.fromProto(GrpcUtils.toProto(status.getFileInfo()));
info.setPath(convertUfsPathToAlluxioPath(new AlluxioURI(info.getUfsPath())).getPath());
URIStatus statusWithRelativeAlluxioPath = new URIStatus(info, status.getCacheContext());
return statusWithRelativeAlluxioPath;
} catch (RuntimeException ex) {
if (ex instanceof StatusRuntimeException) {
if (((StatusRuntimeException) ex).getStatus().getCode() == Status.NOT_FOUND.getCode()) {
Expand Down Expand Up @@ -241,7 +248,15 @@ public List<URIStatus> listStatus(AlluxioURI path, ListStatusPOptions options)
ListStatusPOptions mergedOptions = FileSystemOptionsUtils.listStatusDefaults(
mFsContext.getClusterConf()).toBuilder().mergeFrom(options).build();

return mDoraClient.listStatus(ufsFullPath.toString(), mergedOptions);
final List<URIStatus> uriStatuses = mDoraClient.listStatus(ufsFullPath.toString(),
mergedOptions);
List<URIStatus> statusesWithRelativePath = uriStatuses.stream()
.map(status -> new URIStatus(
GrpcUtils.fromProto(GrpcUtils.toProto(status.getFileInfo()))
.setPath(convertUfsPathToAlluxioPath(new AlluxioURI(status.getUfsPath()))
.getPath())))
.collect(Collectors.toList());
return statusesWithRelativePath;
} catch (RuntimeException ex) {
if (ex instanceof StatusRuntimeException) {
if (((StatusRuntimeException) ex).getStatus().getCode() == Status.NOT_FOUND.getCode()) {
Expand Down Expand Up @@ -453,6 +468,24 @@ public AlluxioURI convertAlluxioPathToUFSPath(AlluxioURI alluxioPath) {
}
}

private AlluxioURI convertUfsPathToAlluxioPath(AlluxioURI ufsPath) {
if (mDelegatedFileSystem instanceof UfsBaseFileSystem) {
AlluxioURI rootUfs = ((UfsBaseFileSystem) mDelegatedFileSystem).getRootUFS();
try {
if (rootUfs.isAncestorOf(ufsPath)) {
return new AlluxioURI(PathUtils.concatPath(AlluxioURI.SEPARATOR,
PathUtils.subtractPaths(ufsPath.getPath(), rootUfs.getPath())));
}
} catch (InvalidPathException e) {
throw new RuntimeException(e);
}

return ufsPath;
} else {
return ufsPath;
}
}

@Override
public List<BlockLocationInfo> getBlockLocations(AlluxioURI path)
throws IOException, AlluxioException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ public static Builder fromConf(AlluxioConfiguration conf) {
return builder;
}

/**
* Copies options from an existing {@link FileSystemOptions} object.
*
* @param source source options to copy from
* @return builder
*/
public static Builder copyFrom(FileSystemOptions source) {
Builder builder = new Builder();
builder.setDataCacheEnabled(source.isDataCacheEnabled())
.setDoraCacheEnabled(source.isDoraCacheEnabled())
.setMetadataCacheEnabled(source.isMetadataCacheEnabled())
.setUfsFallbackEnabled(source.isUfsFallbackEnabled());
source.getUfsFileSystemOptions()
.ifPresent(builder::setUfsFileSystemOptions);
return builder;
}

/**
* @return whether client metadata cache is enabled
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

package alluxio.client.file.options;

import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;

/**
Expand All @@ -36,4 +37,11 @@ public UfsFileSystemOptions(String ufsAddress) {
public String getUfsAddress() {
return mUfsAddress;
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("mUfsAddress", mUfsAddress)
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ public static ListStatusPartialResult fromProto(ListStatusPartialPResponse respo
private final boolean mTruncated;
private final long mFileCount;

private ListStatusPartialResult(List<URIStatus> listings, boolean isTruncated, long fileCount) {
/**
* Constructor.
*
* @param listings
* @param isTruncated
* @param fileCount
*/
public ListStatusPartialResult(List<URIStatus> listings, boolean isTruncated, long fileCount) {
mListings = listings;
mTruncated = isTruncated;
mFileCount = fileCount;
Expand All @@ -64,8 +71,8 @@ public boolean isTruncated() {

/**
* @return the total number of files in the listed directory,
* (i.e. the size of the result if partial listing was not used
* or -1 if the listing was recursive)
* (i.e. the size of the result if partial listing was not used
* or -1 if the listing was recursive)
*/
public long getFileCount() {
return mFileCount;
Expand Down
2 changes: 1 addition & 1 deletion libexec/alluxio-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

# resolve links - $0 may be a softlink
this="${BASH_SOURCE-$0}"
common_bin=$(cd -P -- "$(dirname -- "${this}")" && pwd -P)
common_bin=$(cd -- "$(dirname -- "${this}")" && pwd )
script="$(basename -- "${this}")"
this="${common_bin}/${script}"

Expand Down

0 comments on commit bda3407

Please sign in to comment.