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

Jonathan Hsieh commented on HBASE-8372:
---------------------------------------

bq. Can you clarify the meaning of 'a new mutableConf' ? Once mutableConf is 
materialized inside CompoundConfiguration, the list of ImmutableConfigMap's are 
no longer needed.

I believe this is false.  Let me spend the time to explicitly illustrate the 
different approaches with a pseudo code unit test.  

{code}
Conf hbase = <from hbase-site.xml/hbasedefault.xml>. 
Conf htd = <from htabledescription of table t>
Conf hri = <from hregioninfo of region r in table t>
Conf compound = new CompoundConfiguration;
compound.add(hbase);
compound.add(htd);
compound.add(hri);

compound.set("key", "value");
assertEquals("value", compound.get("key")); // passes

Map<..> map = <new map that doesn't overlap any values>; 
compound.add(map); // trigger freeze

hbase.set("hbasekey", "hbasevalue");
assertEquals("hbasevalue", compound.get("hbasekey")); // should pass.  If the 
triggered freeze did deep copy, it would fail because there is no reference to 
the higher level's table
hri.setProp("...", "blah");
assertEquals("blah", compound.get("...")); // should pass.  If the triggered 
freeze did deep copy, it would fail because there is no reference to the higher 
level's table
{code}

If we did a deep copy, and eliminated the list of ImmutableConfigMaps, we'd 
have a copy of each configuration value, essentially taking up an entry per 
property in each of the levels instead of a single pointer to the previous 
level's map.  This is a common pattern used to manage hierarchical scope.

----

bq. In patch v5, each time freezeMutableConf() is called, ImmutableConfWrapper 
would keep a reference to mutableConf. This leads to more memory consumption.

Only if there is a mutableConf present.  If I do multiple add* in a row, no new 
mutableConf will be added.

I'm surprised I need to be this explicit.  I've numbered the relevant lines in 
the code.

{code}

+  /**
+   * If set has been called, it will create a mutableConf.  This converts the 
mutableConf to an
+   * immutable one and resets it to allow a new mutable conf.  This is used 
when a new map or
+   * conf is added to the compound configuration to preserve proper override 
semantics.
+   */
+  void freezeMutableConf() {
1:+    if (mutableConf == null) {
2:+      // do nothing if there is no current mutableConf
3:+      return;
4:+    }
5:+
6:+    this.configs.add(0, new ImmutableConfWrapper(mutableConf));
7:+    mutableConf = null;
8:+  }
+
{code}

# Let's say there has never been a set call.  mutableConf is null.  At line 1, 
we see this is null, and then as the comment says in line 2, we return at line 
3.
# Let's say set has been called and mutableConf is not null.  At line 1 we see 
that mutableConf is not null.  We go to line 6 and then wrap and include the 
mutable conf to the configs maps.  Then at line 7 we null out the mutableConf
#* If set is not called and freeze is called again, mutableConf will be null -- 
and we proceed via option 1 and exit at line 3.  No new memory allocations.
#* If set is called and then freeze is called again, mutableConf will be 
non-null -- and we proceed via option 2 and exit at line 7.  One new memory 
allocation with a pointer to the old mutableConf.






                
> Provide mutability to CompoundConfiguration
> -------------------------------------------
>
>                 Key: HBASE-8372
>                 URL: https://issues.apache.org/jira/browse/HBASE-8372
>             Project: HBase
>          Issue Type: New Feature
>            Reporter: Ted Yu
>            Assignee: Jonathan Hsieh
>         Attachments: hbase-8372.patch, hbase-8372.v2.patch, 
> hbase-8372.v3.patch, hbase-8372.v4.patch, hbase-8372.v5.patch
>
>
> In discussion of HBASE-8347, it was proposed that CompoundConfiguration 
> should support mutability.
> This can be done by consolidating ImmutableConfigMap's on first modification 
> to CompoundConfiguration.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to