[ 
https://issues.apache.org/jira/browse/HBASE-18573?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16135956#comment-16135956
 ] 

Jan Hentschel commented on HBASE-18573:
---------------------------------------

[~water] I'm sorry for the late response. I was out on vacation.

The reason behind the initial capacity is to avoid unnecessary allocations when 
you know the size of the list beforehand. If you look at the patch for 
HBASE-10699 you'll see that not only an initial capacity of 1 was used. The 
patch also contains lines like

{code:java}
List<String> families = new ArrayList<String>(this.familyMap.entrySet().size())
{code}

The change in the Append object looked something like the following

{code:java}
byte [] family = CellUtil.cloneFamily(cell);
     List<Cell> list = this.familyMap.get(family);
     if (list == null) {
-      list  = new ArrayList<Cell>();
+      list  = new ArrayList<Cell>(1);
     }
     // find where the new entry should be placed in the List
     list.add(cell);
{code}

As you see, there's only a single call to add(), which makes it safe to assume 
that the size of the list will be 1. Instead of allocating the default size of 
10, it's better to go for a size of 1. I only did it at the places where I was 
sure for a certain degree that the size of the list is known beforehand. There 
are some places, as [~jinghe] mentioned, where we don't know the size of the 
list for sure, f.e. if you have a while-loop, certain kinds of foreach-loops, 
if you initialize the list with another list or the list is an object field and 
is accessed from different places, and initializing the list with an initial 
capacity of 1 (or any other value) does not make sense at all.

To answer your last question: If I remember correctly, Put and Increment was 
not part of the patch, but I'm not sure why.

> Update Append and Delete to use Mutation#getCellList(family)
> ------------------------------------------------------------
>
>                 Key: HBASE-18573
>                 URL: https://issues.apache.org/jira/browse/HBASE-18573
>             Project: HBase
>          Issue Type: Improvement
>            Reporter: Xiang Li
>            Assignee: Xiang Li
>            Priority: Minor
>             Fix For: 3.0.0, 1.4.0, 1.5.0, 2.0.0-alpha-3
>
>         Attachments: HBASE-18573.master.000.patch
>
>
> In addxxx() of Put and Increment, Mutation#getCellList(family) is called to 
> get cell list from familyMap. But in the other 2 sub-class of Mutation: 
> Append and Delete, the logic like Mutation#getCellList(family) is used, like
> {code}
>     List<Cell> list = familyMap.get(family);
>     if(list == null) {
>       list = new ArrayList<>(1);
>     }
> {code}
> in
> {code}
> public Delete addColumn(byte [] family, byte [] qualifier, long timestamp)
> {code}
> of Delete
> We could make them to call Mutation#getCellList(family) to get better 
> encapsulation



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to