andyhuangdev commented on PR #11813:
URL: https://github.com/apache/ozone/pull/11813#issuecomment-6982939787
> After this change, `CreateFile` goes through `validateAndNormalizeKey`,
which (via `OzoneFSUtils.isValidKeyPath`) rejects `:` in any path component.
`CreateDirectory` deliberately skips that check, so on FSO buckets (and LEGACY
buckets with `ozone.om.enable.filesystem.paths=true`):
>
> * `createDirectory("a:b")` succeeds,
> * `createFile("a:b/f")` now fails in `preExecute` with `INVALID_KEY_NAME`,
> * and committing `a:b/f` fails too. `OMKeyCommitRequest.preExecute`
already rejects it on master, as does `OMAllocateBlockRequest`.
>
> So the directory can be created, but it can never hold a file. The
commit-time rejection already exists on master, so this patch doesn't introduce
the gap. It does make the inconsistency more visible, because the two create
requests now treat `:` differently. This test may be added to
`TestOMDirectoryCreateRequest` to showcase the problem (it passes on this
branch), though I would expect it to fail, as if I can create a directory I
should be able to create files in it... :
>
> ```java
> /**
> * With path normalization on (FSO, or LEGACY with filesystem paths
enabled), a directory whose name contains ':'
> * can be created, but no file can be created or committed under it, as
those requests reject ':' in any component.
> */
> @Test
> public void testFileCannotBeCreatedUnderDirectoryWithColon() throws
Exception {
> when(ozoneManager.getEnableFileSystemPaths()).thenReturn(true);
> String volumeName = "vol1";
> String bucketName = "bucket1";
> String dirName = "a:b";
> String fileName = dirName + OZONE_URI_DELIMITER + "f";
> OMRequestTestUtils.addVolumeAndBucketToDB(volumeName, bucketName,
omMetadataManager);
>
> // The directory is accepted.
> OMRequest modifiedOmRequest = new OMDirectoryCreateRequest(
> createDirectoryRequest(volumeName, bucketName, dirName),
getBucketLayout()).preExecute(ozoneManager);
> OMDirectoryCreateRequest omDirectoryCreateRequest =
> new OMDirectoryCreateRequest(modifiedOmRequest, getBucketLayout());
> omDirectoryCreateRequest.setUGI(UserGroupInformation.getCurrentUser());
> OMClientResponse omClientResponse =
omDirectoryCreateRequest.validateAndUpdateCache(ozoneManager, 100L);
> assertEquals(OzoneManagerProtocolProtos.Status.OK,
omClientResponse.getOMResponse().getStatus());
> assertNotNull(omMetadataManager.getKeyTable(getBucketLayout())
> .get(omMetadataManager.getOzoneDirKey(volumeName, bucketName,
dirName)));
>
> KeyArgs fileKeyArgs = KeyArgs.newBuilder()
> .setVolumeName(volumeName)
> .setBucketName(bucketName)
> .setKeyName(fileName)
> .build();
>
> // A file under it cannot be created...
> OMRequest createFileRequest = OMRequest.newBuilder()
> .setCreateFileRequest(CreateFileRequest.newBuilder()
> .setKeyArgs(fileKeyArgs)
> .setIsRecursive(false)
> .setIsOverwrite(false))
> .setCmdType(OzoneManagerProtocolProtos.Type.CreateFile)
> .setClientId(UUID.randomUUID().toString()).build();
> OMException createFileException = assertThrows(OMException.class,
> () -> new OMFileCreateRequest(createFileRequest,
getBucketLayout()).preExecute(ozoneManager));
> assertEquals(OMException.ResultCodes.INVALID_KEY_NAME,
createFileException.getResult());
>
> // ...nor committed.
> OMRequest commitKeyRequest = OMRequest.newBuilder()
> .setCommitKeyRequest(CommitKeyRequest.newBuilder()
> .setKeyArgs(fileKeyArgs)
> .setClientID(1L))
> .setCmdType(OzoneManagerProtocolProtos.Type.CommitKey)
> .setClientId(UUID.randomUUID().toString()).build();
> OMException commitException = assertThrows(OMException.class,
> () -> new OMKeyCommitRequest(commitKeyRequest,
getBucketLayout()).preExecute(ozoneManager));
> assertEquals(OMException.ResultCodes.INVALID_KEY_NAME,
commitException.getResult());
> }
> ```
>
> (It needs imports for `OMKeyCommitRequest`, `CommitKeyRequest` and
`CreateFileRequest`.)
>
> I am fine with creating a follow up JIRA to fix this, or if you would like
then to fix it within this one.
Fixed! Thanks for the suggestion and the test case.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]