xichen01 commented on PR #4572:
URL: https://github.com/apache/ozone/pull/4572#issuecomment-1541463653

   > > If the array is not dynamically expandable, we need to create an array 
of size 10000 directly, because we need to add the new PartkeyInfo to the array 
each time we execute CommitMultiupload, We don't know in advance which "parts" 
will be added. ...
   > 
   > That's why we need to build a TreeMap first. Then, we know the size.
   > 
   > > ... simply (1) build a TreeMap, (2) copy the result to a sorted 
(immutable) list, ...
   
   Yes, we can know the size of the `TreeMap`, but the size of the array should 
be  the largest `partNumber`.
   Such as:
   We have a TreeMap that includes two `partKeyInfo`.
   ```java
   private TreeMap<Integer, PartKeyInfo> partKeyInfoList.
   partKeyInfoList = {1, partKeyInfo1, 1000, partKeyInfo1000}
   ```
   Then we need to create an array of size 1001, not an array of size 2  (The 
index of the array is used as `partNumber`)
   ```java
   Array[1] = partKeyInfo1
   Array[2] = null
   //...
   Array[999] = null
   Array[1000] = partKeyInfo1000
   ```
   
   If the user is uploading the 2000th slice at this point, we also need to 
expand the array to 2001
   
https://github.com/apache/ozone/blob/e8fb1744e63b0f87379f7cb0eb1cb8a98520bd95/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmMultipartKeyInfo.java#L115-L117
   
   The final array looks like this
   ```java
   addPartKeyInfo(2000, partKeyInfo2000)
   
   Array[1] = partKeyInfo1
   Array[2] = null
   //...
   Array[999] = null
   Array[1000] = partKeyInfo1000
   Array[1001] = null
   //...
   Array[1999] = null
   Array[2000] = partKeyInfo2000
   ```
   
   


-- 
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]

Reply via email to