Andrey Yarovoy created HDDS-17715:
-------------------------------------

             Summary: Avoid Enum.valueOf round trips in OzoneAcl 
toProtobuf/fromProtobuf
                 Key: HDDS-17715
                 URL: https://issues.apache.org/jira/browse/HDDS-17715
             Project: Apache Ozone
          Issue Type: Improvement
          Components: OM, Ozone Client
            Reporter: Andrey Yarovoy
            Assignee: Andrey Yarovoy


*Description*

`OzoneAcl.toProtobuf` and `OzoneAcl.fromProtobuf` 
(`hadoop-ozone/common/.../OzoneAcl.java`) map between the Java ACL enums and 
their
protobuf counterparts through a name round trip:

{code:java}
.setType(OzoneAclType.valueOf(acl.getType().name()))
.setAclScope(OzoneAclScope.valueOf(acl.getAclScope().name()))
...
new OzoneAcl(ACLIdentityType.valueOf(protoAcl.getType().name()), 
protoAcl.getName(),
AclScope.valueOf(protoAcl.getAclScope().name()), aclRights);
{code}

That is `name()` + `Enum.valueOf` (a `HashMap` lookup in 
`Enum.enumConstantDirectory`) twice per ACL entry, in both directions. It runs 
for every
ACL of every volume, bucket and key that OM serializes (getKeyInfo, 
getFileStatus, getBucketInfo, list*), and again on the client when parsing.

Evidence:
- OM: the ACL-conversion frames showed up in the OM read-path jstack censusas 
the one self-contained Ozone-code item.
HDDS-16289's projection removed the ACL rebuild from intermediate FSO path 
segments. The final-segment key and every response still pay it.
- RS client (HBase YCSB on EC): `OzoneAcl.fromProtobuf` is ~0.1% of RS CPU, of 
which `valueOf` is ~0.06%. **The client-side win is small; the value is OM CPU 
per read RPC.**

*Proposed fix*

Four ordinal-indexed lookup arrays, built once in a `static {}` block. Iterate 
the **Java** enums' `values()` and resolve each counterpart
once with the existing `name()`/`valueOf` contract:

{code:java}
private static final OzoneAclType[] TYPE_TO_PROTO = new 
OzoneAclType[ACLIdentityType.values().length];
private static final ACLIdentityType[] TYPE_FROM_PROTO = ...; // indexed by 
proto ordinal
private static final OzoneAclScope[] SCOPE_TO_PROTO = ...;
private static final AclScope[] SCOPE_FROM_PROTO = ...;
// call sites: TYPE_TO_PROTO[acl.getType().ordinal()], 
TYPE_FROM_PROTO[protoAcl.getType().ordinal()], ...
{code}

- Iterate the Java enums, not the protobuf ones, so the protobuf `UNRECOGNIZED` 
sentinel never enters the tables. The proto file is proto2,
so ordinals are stable.
- Behavior-preserving, including a class-load-time failure if a name ever 
diverges.
- `parseAcl` (CLI/config string parsing) stays on `valueOf`: it handles 
arbitrary user input and is cold.

*Compatibility / side effects*

None. No wire or API change.

*Tests*

- `TestOzoneAcls`, `TestOzoneAclUtil`, `TestOzoneObjInfo` round-trip tests.
- New unit test: every `ACLIdentityType`/`AclScope` value round-trips through 
to/fromProtobuf to the same constant.
- Optional: JMH micro-benchmark of `toProtobuf`/`fromProtobuf` for a 3-entry 
ACL list, plus OM CPU per `getKeyInfo` in the existing OM read benchmark.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to