Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support set/get xattr #18053

Merged
merged 25 commits into from
Oct 10, 2023
Merged

Conversation

Jackson-Wang-7
Copy link
Contributor

@Jackson-Wang-7 Jackson-Wang-7 commented Aug 23, 2023

What changes are proposed in this pull request?

Supports setXattr API of Alluxio FileSystem, it will set the corresponding attributes to UFS. If UFS is a filesystem, it's set through the setXattr interface of UFS. if UFS is object storage, it's set through setTagging API.

Why are the changes needed?

Based on the 3.x architecture, recover support for the setXattr interface. There are still many places where the interface is used, and it should not be supported at present.

byte[] value) {
try {
UserDefinedFileAttributeView attributeView =
Files.getFileAttributeView(Paths.get(filePath), UserDefinedFileAttributeView.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a comment to explain what is an attribute view what is this for?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the attr only set locally and will lose after a worker restarts?

Copy link
Contributor Author

@Jackson-Wang-7 Jackson-Wang-7 Sep 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the attr only set locally and will lose after a worker restarts?

No, it sets the attribute to the local file system, so it will not change after a worker restarts. (works in CentOS, not work in MacOS)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to add an example in javadoc.

* @return a FileInfo
*/
public alluxio.grpc.FileInfo buildFileInfoFromUfsStatus(UfsStatus status, String ufsFullPath) {
public alluxio.grpc.FileInfo buildFileInfoFromUfsStatus(UfsStatus status, String ufsFullPath,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add a nullable annotation here

Copy link
Contributor

@jiacheliu3 jiacheliu3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the work! I left some comments PTAL

byte[] value) {
try {
UserDefinedFileAttributeView attributeView =
Files.getFileAttributeView(Paths.get(filePath), UserDefinedFileAttributeView.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to add an example in javadoc.

@@ -214,7 +214,12 @@ public Response continueTask() {
try {
List<URIStatus> children = mHandler.getMetaFS().listStatus(new AlluxioURI(
S3RestUtils.MULTIPART_UPLOADS_METADATA_DIR));
return ListMultipartUploadsResult.buildFromStatuses(bucket, children);
List<URIStatus> mpuList = new ArrayList<>();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add an annotation to explain why we need to get file status again.

// GetListing doesn't contain the xattr info, so get status for MPU files.
List<URIStatus> mpuList = new ArrayList<>();
for (URIStatus status : children) {
URIStatus filemeta = mHandler.getMetaFS().getStatus(new AlluxioURI(status.getPath()));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, when we use the MPU APIs of the north bound s3 api

@@ -457,6 +461,11 @@ public alluxio.grpc.FileInfo buildFileInfoFromUfsStatus(UfsStatus status, String
.setGroup(status.getGroup())
.setCompleted(true)
.setPersisted(true);
if (xattrMap != null) {
for (Map.Entry<String, String> entry : xattrMap.entrySet()) {
infoBuilder.putXattr(entry.getKey(), ByteString.copyFromUtf8(entry.getValue()));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

@@ -220,7 +220,6 @@ public synchronized void close() throws IOException {
}
mClosed = true;
mPositionReader.close();
mUfs.close();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a bugfix that is already in main branch, cherrypick it for testing. will remove it.

@@ -232,8 +232,9 @@ public void listStatus(ListStatusPRequest request,
UfsStatus status = statuses[i];
String ufsFullPath = PathUtils.concatPath(request.getPath(), status.getName());

// the list statues do not include xattr now.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Tag tag = new Tag(name, value);
tagList.add(tag);
}
mClient.setObjectTagging(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a comment like this to mention the case:

    // It's a read-and-update race condition. When there is a competive conflict scenario,
    // it may lead to inconsistent final results. The final conflict occurs in UFS,
    // UFS will determine the final result.

Copy link
Contributor

@jiacheliu3 jiacheliu3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM with some relatively minor comments. Good to go when you see fit, and I'm stamping ahead of time. Thanks a lot for the work!

We might be able to add more UT cases, but you can do that in follow up PRs (and not necessarily but you alone)

@@ -1172,17 +1173,17 @@ public String methodName() {

@Override
public String toString() {
return String.format("path=%s, name=%s, value=%s", path, name, value);
return String.format("path=%s, name=%s, value=%s", path, name, Arrays.toString(value));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we have helpers you can use, it's fine as-is here but you have more options next time

return MoreObjects.toStringHelper(this).add(xxx,xxx).toString();

Map<String, String> attrMap = new HashMap<>();
for (String attributeName : attributeView.list()) {
int attributeSize = attributeView.size(attributeName);
ByteBuffer attributeBuffer = ByteBuffer.allocate(attributeSize);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sanity check ^

Map<String, String> attrMap = mUfs.getAttributes(testFilePath);
assertEquals(attrMap.size(), 1);
assertEquals(attrMap.get(attrKey), attrValue2);
mUfs.deleteFile(testFilePath);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete at the end of the test is not guaranted to happen. Could you move that to @After?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will move it to the finally part. I'm not sure if deletion is necessary. I haven't seen it in other test cases, I just follow my personal habits.

@yyongycy
Copy link
Contributor

What is the max size of tagging?

@Jackson-Wang-7
Copy link
Contributor Author

What is the max size of tagging?

we have the configuration property to limit the tag number we can set, the max size is 10.

@Jackson-Wang-7
Copy link
Contributor Author

alluxio-bot, merge this please

@alluxio-bot
Copy link
Contributor

merge failed:
Merge refused because pull request does not have label start with type-

@Jackson-Wang-7 Jackson-Wang-7 added the type-feature This issue is a feature request label Oct 10, 2023
@Jackson-Wang-7
Copy link
Contributor Author

alluxio-bot, merge this please

@alluxio-bot alluxio-bot merged commit bf997fe into Alluxio:main Oct 10, 2023
14 checks passed
ssz1997 pushed a commit to ssz1997/alluxio that referenced this pull request Dec 15, 2023
### What changes are proposed in this pull request?

Supports setXattr API of Alluxio FileSystem, it will set the corresponding attributes to UFS. If UFS is a filesystem, it's set through the setXattr interface of UFS. if UFS is object storage, it's set through setTagging API.

### Why are the changes needed?
Based on the 3.x architecture, recover support for the setXattr interface. There are still many places where the interface is used, and it should not be supported at present.


			pr-link: Alluxio#18053
			change-id: cid-4f8c96c88cced4374d54b6387bfc618b47d2a423
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature This issue is a feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants