cxzl25 opened a new pull request, #8977:
URL: https://github.com/apache/hadoop/pull/8977
### Description of PR
`LocalReplica#getBlockURI()` and `getMetadataURI()` call `File#toURI()`,
which calls `isDirectory()` to decide whether to append a trailing slash. That
is a stat system call on every invocation, and block and meta files are never
directories. Several callers are on per-block paths and some hold a dataset
lock (`invalidate`, `removeReplicaFromMem`, `checkAndUpdate`, block finalize,
move to trash, `ReplicaInfo#toString`).
This PR:
- Adds `DatanodeUtil#fileToURI(File)`, which builds the `file:` URI of a
file that is known not to be a directory without accessing the file system. For
regular files it returns the same URI as `File#toURI()`.
- Uses it in `LocalReplica#getBlockURI()` and `getMetadataURI()`, which
covers all callers that go through `ReplicaInfo`.
- Uses it where local block or meta files are converted to URIs directly:
`FsDatasetImpl#moveBlockFiles`, replica copy, `checkAndUpdate`,
`FsDatasetAsyncDiskService` (move to trash) and `FsDatasetUtil`.
`ProvidedReplica` is not changed and no `ReplicaInfo` signature changes.
Behaviour difference: if a block or meta path is actually a directory, the
URI no longer ends with a slash. Both sides of the comparison in
`checkAndUpdate` use the new method.
This removes the system call only. The cost of building the URI and
converting it back to a `File` remains; removing that would need a `File`-based
API on `ReplicaInfo`, which is out of scope here. No benchmark was run.
### How was this patch tested?
Added `TestDatanodeUtil`, which checks that `fileToURI` equals
`File#toURI()` for regular files, missing files, paths with characters that
need escaping and relative paths, and that it does not append a slash for a
directory.
### For code changes:
- [ ] Does the title of this PR start with the corresponding JIRA issue id
(e.g. 'HADOOP-17799. Your PR title ...')?
- [ ] Object storage: Have the integration tests been executed and the
endpoint
declared according to the connector-specific documentation? *Note:
Automated CI
testing doesn't cover all cases so manual testing with cloud storage
is still
required.*
- [ ] If adding new dependencies to the code, are these dependencies
licensed in a way that is compatible for inclusion under [ASF
2.0](http://www.apache.org/legal/resolved.html#category-a)?
- [ ] If applicable, have you updated the `LICENSE`, `LICENSE-binary`,
`NOTICE-binary` files?
### AI Tooling
If an AI tool was used:
- [ ] The PR includes the phrase "Contains content generated by <tool>"
where <tool> is the name of the AI tool used.
- [ ] My use of AI contributions follows the ASF legal policy
https://www.apache.org/legal/generative-tooling.html
--
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]