[ 
https://issues.apache.org/jira/browse/HDDS-16279?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Huang Kuan Hao reassigned HDDS-16279:
-------------------------------------

    Assignee: Huang Kuan Hao

> Cache replica index map in Pipeline
> -----------------------------------
>
>                 Key: HDDS-16279
>                 URL: https://issues.apache.org/jira/browse/HDDS-16279
>             Project: Apache Ozone
>          Issue Type: Sub-task
>            Reporter: Huang Kuan Hao
>            Assignee: Huang Kuan Hao
>            Priority: Major
>
> Pipeline is immutable, but getReplicaIndexes() re-derives a map (list + toMap 
> + boxing) on every call, on the per-block-read command-build path:
> public Map<DatanodeDetails, Integer> getReplicaIndexes() {
>   return this.getNodes().stream()
>       .collect(Collectors.toMap(Function.identity(), this::getReplicaIndex));
> }
> Fix: memoize the derived map with a lazy holder:
> private volatile Map<DatanodeDetails, Integer> replicaIndexesView;
> public Map<DatanodeDetails, Integer> getReplicaIndexes() {
>   Map<DatanodeDetails, Integer> v = replicaIndexesView;
>   if (v == null) {
>     v = getNodes().stream().collect(Collectors.toMap(Function.identity(), 
> this::getReplicaIndex));
>     replicaIndexesView = v;   // benign race; Pipeline is immutable
>   }
>   return v;
> }
> Note: cache the derived map — it covers all nodes with a 0 default 
> (getReplicaIndex), unlike the internal replicaIndexes field (explicit-index 
> nodes only). Do not return the field. Behavior unchanged.
> File: hadoop-hdds/common/.../hdds/scm/pipeline/Pipeline.java:247



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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

Reply via email to