You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by "Mikael Sitruk (Created) (JIRA)" <ji...@apache.org> on 2011/12/30 20:02:30 UTC
[jira] [Created] (HBASE-5110) code enhancement - remove unnecessary
if-checks in every loop in HLog class
code enhancement - remove unnecessary if-checks in every loop in HLog class
---------------------------------------------------------------------------
Key: HBASE-5110
URL: https://issues.apache.org/jira/browse/HBASE-5110
Project: HBase
Issue Type: Improvement
Components: wal
Affects Versions: 0.90.4, 0.90.2, 0.90.1, 0.92.0
Reporter: Mikael Sitruk
Priority: Minor
The HLog class (method findMemstoresWithEditsEqualOrOlderThan) has unnecessary if check in a loop.
static byte [][] findMemstoresWithEditsEqualOrOlderThan(final long oldestWALseqid,
final Map<byte [], Long> regionsToSeqids) {
// This method is static so it can be unit tested the easier.
List<byte []> regions = null;
for (Map.Entry<byte [], Long> e: regionsToSeqids.entrySet()) {
if (e.getValue().longValue() <= oldestWALseqid) {
if (regions == null) regions = new ArrayList<byte []>();
regions.add(e.getKey());
}
}
return regions == null?
null: regions.toArray(new byte [][] {HConstants.EMPTY_BYTE_ARRAY});
}
The following change is suggested
static byte [][] findMemstoresWithEditsEqualOrOlderThan(final long oldestWALseqid,
final Map<byte [], Long> regionsToSeqids) {
// This method is static so it can be unit tested the easier.
List<byte []> regions = new ArrayList<byte []>();
for (Map.Entry<byte [], Long> e: regionsToSeqids.entrySet()) {
if (e.getValue().longValue() <= oldestWALseqid) {
regions.add(e.getKey());
}
}
return regions.size() == 0?
null: regions.toArray(new byte [][] {HConstants.EMPTY_BYTE_ARRAY});
}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (HBASE-5110) code enhancement - remove
unnecessary if-checks in every loop in HLog class
Posted by "Todd Lipcon (Commented) (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HBASE-5110?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13177750#comment-13177750 ]
Todd Lipcon commented on HBASE-5110:
------------------------------------
why? This isn't a hot code path...
> code enhancement - remove unnecessary if-checks in every loop in HLog class
> ---------------------------------------------------------------------------
>
> Key: HBASE-5110
> URL: https://issues.apache.org/jira/browse/HBASE-5110
> Project: HBase
> Issue Type: Improvement
> Components: wal
> Affects Versions: 0.90.1, 0.90.2, 0.90.4, 0.92.0
> Reporter: Mikael Sitruk
> Priority: Minor
>
> The HLog class (method findMemstoresWithEditsEqualOrOlderThan) has unnecessary if check in a loop.
> static byte [][] findMemstoresWithEditsEqualOrOlderThan(final long oldestWALseqid,
> final Map<byte [], Long> regionsToSeqids) {
> // This method is static so it can be unit tested the easier.
> List<byte []> regions = null;
> for (Map.Entry<byte [], Long> e: regionsToSeqids.entrySet()) {
> if (e.getValue().longValue() <= oldestWALseqid) {
> if (regions == null) regions = new ArrayList<byte []>();
> regions.add(e.getKey());
> }
> }
> return regions == null?
> null: regions.toArray(new byte [][] {HConstants.EMPTY_BYTE_ARRAY});
> }
> The following change is suggested
> static byte [][] findMemstoresWithEditsEqualOrOlderThan(final long oldestWALseqid,
> final Map<byte [], Long> regionsToSeqids) {
> // This method is static so it can be unit tested the easier.
> List<byte []> regions = new ArrayList<byte []>();
> for (Map.Entry<byte [], Long> e: regionsToSeqids.entrySet()) {
> if (e.getValue().longValue() <= oldestWALseqid) {
> regions.add(e.getKey());
> }
> }
> return regions.size() == 0?
> null: regions.toArray(new byte [][] {HConstants.EMPTY_BYTE_ARRAY});
> }
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (HBASE-5110) code enhancement - remove
unnecessary if-checks in every loop in HLog class
Posted by "Todd Lipcon (Commented) (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HBASE-5110?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13177841#comment-13177841 ]
Todd Lipcon commented on HBASE-5110:
------------------------------------
Ah, I missed that thread... I just wanted to clarify if this is for readability or performance... do you see this function getting called a lot in a write workload? Your comments on the mailing list thread indicate that it's performance sensitive, but I don't see how that would be the case.
> code enhancement - remove unnecessary if-checks in every loop in HLog class
> ---------------------------------------------------------------------------
>
> Key: HBASE-5110
> URL: https://issues.apache.org/jira/browse/HBASE-5110
> Project: HBase
> Issue Type: Improvement
> Components: wal
> Affects Versions: 0.90.1, 0.90.2, 0.90.4, 0.92.0
> Reporter: Mikael Sitruk
> Priority: Minor
>
> The HLog class (method findMemstoresWithEditsEqualOrOlderThan) has unnecessary if check in a loop.
> static byte [][] findMemstoresWithEditsEqualOrOlderThan(final long oldestWALseqid,
> final Map<byte [], Long> regionsToSeqids) {
> // This method is static so it can be unit tested the easier.
> List<byte []> regions = null;
> for (Map.Entry<byte [], Long> e: regionsToSeqids.entrySet()) {
> if (e.getValue().longValue() <= oldestWALseqid) {
> if (regions == null) regions = new ArrayList<byte []>();
> regions.add(e.getKey());
> }
> }
> return regions == null?
> null: regions.toArray(new byte [][] {HConstants.EMPTY_BYTE_ARRAY});
> }
> The following change is suggested
> static byte [][] findMemstoresWithEditsEqualOrOlderThan(final long oldestWALseqid,
> final Map<byte [], Long> regionsToSeqids) {
> // This method is static so it can be unit tested the easier.
> List<byte []> regions = new ArrayList<byte []>();
> for (Map.Entry<byte [], Long> e: regionsToSeqids.entrySet()) {
> if (e.getValue().longValue() <= oldestWALseqid) {
> regions.add(e.getKey());
> }
> }
> return regions.size() == 0?
> null: regions.toArray(new byte [][] {HConstants.EMPTY_BYTE_ARRAY});
> }
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (HBASE-5110) code enhancement - remove
unnecessary if-checks in every loop in HLog class
Posted by "Mikael Sitruk (Commented) (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HBASE-5110?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13178192#comment-13178192 ]
Mikael Sitruk commented on HBASE-5110:
--------------------------------------
I see it a lot in the heavy write scenario when major compaction occurs in the background, but to be realistic even when i see this method called 2000 times during a test of 5 hours, across a cluster of 10 RS (each RS log contains +/-200 calls of this method), i don't think this method present a performance problem.
So for my point of view this is more readability issue before it becomes a performance problem. It is strange to me to see code asking each time in an iteration for object existence especially if creating the object is not heavy task.
> code enhancement - remove unnecessary if-checks in every loop in HLog class
> ---------------------------------------------------------------------------
>
> Key: HBASE-5110
> URL: https://issues.apache.org/jira/browse/HBASE-5110
> Project: HBase
> Issue Type: Improvement
> Components: wal
> Affects Versions: 0.90.1, 0.90.2, 0.90.4, 0.92.0
> Reporter: Mikael Sitruk
> Priority: Minor
>
> The HLog class (method findMemstoresWithEditsEqualOrOlderThan) has unnecessary if check in a loop.
> static byte [][] findMemstoresWithEditsEqualOrOlderThan(final long oldestWALseqid,
> final Map<byte [], Long> regionsToSeqids) {
> // This method is static so it can be unit tested the easier.
> List<byte []> regions = null;
> for (Map.Entry<byte [], Long> e: regionsToSeqids.entrySet()) {
> if (e.getValue().longValue() <= oldestWALseqid) {
> if (regions == null) regions = new ArrayList<byte []>();
> regions.add(e.getKey());
> }
> }
> return regions == null?
> null: regions.toArray(new byte [][] {HConstants.EMPTY_BYTE_ARRAY});
> }
> The following change is suggested
> static byte [][] findMemstoresWithEditsEqualOrOlderThan(final long oldestWALseqid,
> final Map<byte [], Long> regionsToSeqids) {
> // This method is static so it can be unit tested the easier.
> List<byte []> regions = new ArrayList<byte []>();
> for (Map.Entry<byte [], Long> e: regionsToSeqids.entrySet()) {
> if (e.getValue().longValue() <= oldestWALseqid) {
> regions.add(e.getKey());
> }
> }
> return regions.size() == 0?
> null: regions.toArray(new byte [][] {HConstants.EMPTY_BYTE_ARRAY});
> }
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
[jira] [Commented] (HBASE-5110) code enhancement - remove
unnecessary if-checks in every loop in HLog class
Posted by "Mikael Sitruk (Commented) (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HBASE-5110?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13177825#comment-13177825 ]
Mikael Sitruk commented on HBASE-5110:
--------------------------------------
Hi Todd,
There was a long discussion on this on the mailing list, it was decided to open a JIRA.
Mikael.S
> code enhancement - remove unnecessary if-checks in every loop in HLog class
> ---------------------------------------------------------------------------
>
> Key: HBASE-5110
> URL: https://issues.apache.org/jira/browse/HBASE-5110
> Project: HBase
> Issue Type: Improvement
> Components: wal
> Affects Versions: 0.90.1, 0.90.2, 0.90.4, 0.92.0
> Reporter: Mikael Sitruk
> Priority: Minor
>
> The HLog class (method findMemstoresWithEditsEqualOrOlderThan) has unnecessary if check in a loop.
> static byte [][] findMemstoresWithEditsEqualOrOlderThan(final long oldestWALseqid,
> final Map<byte [], Long> regionsToSeqids) {
> // This method is static so it can be unit tested the easier.
> List<byte []> regions = null;
> for (Map.Entry<byte [], Long> e: regionsToSeqids.entrySet()) {
> if (e.getValue().longValue() <= oldestWALseqid) {
> if (regions == null) regions = new ArrayList<byte []>();
> regions.add(e.getKey());
> }
> }
> return regions == null?
> null: regions.toArray(new byte [][] {HConstants.EMPTY_BYTE_ARRAY});
> }
> The following change is suggested
> static byte [][] findMemstoresWithEditsEqualOrOlderThan(final long oldestWALseqid,
> final Map<byte [], Long> regionsToSeqids) {
> // This method is static so it can be unit tested the easier.
> List<byte []> regions = new ArrayList<byte []>();
> for (Map.Entry<byte [], Long> e: regionsToSeqids.entrySet()) {
> if (e.getValue().longValue() <= oldestWALseqid) {
> regions.add(e.getKey());
> }
> }
> return regions.size() == 0?
> null: regions.toArray(new byte [][] {HConstants.EMPTY_BYTE_ARRAY});
> }
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira