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

Dinesh Chitlangia commented on HDDS-99:
---------------------------------------

[~xyao] Thank you for reviewing the patch.

{quote}Line 159-161: can we avoid building the auditMap outside logWritexxx(), 
this might need refactoring of the AUDIT class that wen can handle it in a 
follow up JIRA.
{quote}
Sure. We can file a Jira to make that change in the framework and then across 
DN, SCM, OM, audit logging.

 
{quote}Line 162: auditSuccess variable can be removed if we remove the finally 
and move the logic out of finally{}. This applies to some other places too.
{quote}
The reason I took this approach is that we are returning an object (in this 
case an instance of AllocatedBlock). Since we don't really need to capture the 
value of AllocatedBlock, I wanted to avoid grabbing its instance in order to 
avoid the finally.
{code:java}
    boolean auditSuccess = true;
    try {
      return scm.getScmBlockManager().allocateBlock(size, type, factor, owner);
    } catch (Exception ex) {
      auditSuccess = false;
      AUDIT.logWriteFailure(
          buildAuditMessageForFailure(SCMAction.ALLOCATE_BLOCK, auditMap, ex)
      );
      throw ex;
    } finally {
      if(auditSuccess) {
        AUDIT.logWriteSuccess(
            buildAuditMessageForSuccess(SCMAction.ALLOCATE_BLOCK, auditMap)
        );
      }
    }
{code}

If we remove the finally block, the could would look like:
{code:java}
    try {
      AllocatedBlock allocatedBlock = 
scm.getScmBlockManager().allocateBlock(size, type, factor, owner);
      AUDIT.logWriteSuccess(
            buildAuditMessageForSuccess(SCMAction.ALLOCATE_BLOCK, auditMap)
        );
    } catch (Exception ex) {
      AUDIT.logWriteFailure(
          buildAuditMessageForFailure(SCMAction.ALLOCATE_BLOCK, auditMap, ex)
      );
      throw ex;
    }
    }
{code}

Since allocatedBlock really has no use inside this method, I wanted to avoid 
creating it here.

Let me know your thoughts.

> Adding SCM Audit log
> --------------------
>
>                 Key: HDDS-99
>                 URL: https://issues.apache.org/jira/browse/HDDS-99
>             Project: Hadoop Distributed Data Store
>          Issue Type: Sub-task
>          Components: SCM
>            Reporter: Xiaoyu Yao
>            Assignee: Dinesh Chitlangia
>            Priority: Major
>              Labels: alpha2
>         Attachments: HDDS-99.001.patch, HDDS-99.002.patch
>
>
> This ticket is opened to add SCM audit log.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: hdfs-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: hdfs-issues-h...@hadoop.apache.org

Reply via email to