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

Varun Vasudev commented on YARN-2045:
-------------------------------------

[~djp] Mostly looks good. Couple of things

{noformat}
    // if there is no version info, treat it as 1.0;
    if (loadedVersion == null) {
      throw new IOException("NM State version not found");
    }
{noformat}

The comment doesn't seem to match with the code.

{noformat}
  @Override
  protected void storeVersion() throws IOException {
    String key = DB_SCHEMA_VERSION_KEY;
    byte[] data = 
        ((NMDBSchemaVersionPBImpl) 
CURRENT_VERSION_INFO).getProto().toByteArray();
    try {
      db.put(bytes(key), data);
    } catch (DBException e) {
      throw new IOException(e.getMessage(), e);
    }
  }
  
  // Only used for test
  @VisibleForTesting
  public void storeVersion(NMDBSchemaVersion state) throws IOException {
    String key = DB_SCHEMA_VERSION_KEY;
    byte[] data = 
        ((NMDBSchemaVersionPBImpl) state).getProto().toByteArray();
    try {
      db.put(bytes(key), data);
    } catch (DBException e) {
      throw new IOException(e.getMessage(), e);
    }
  }
{noformat}

Three's a lot of common code. Is it possible to refactor this to something like 
-
{noformat}
  @Override
  protected void storeVersion() throws IOException {
    dbStoreVersion(CURRENT_VERSION_INFO);
  }

  // Only used for test
  @VisibleForTesting
  public void storeVersion(NMDBSchemaVersion state) throws IOException {
    dbStoreVersion(state);
  }

  private void dbStoreVersion(NMDBSchemaVersion state) throws IOException {
    String key = DB_SCHEMA_VERSION_KEY;
    byte[] data = 
        ((NMDBSchemaVersionPBImpl) state).getProto().toByteArray();
    try {
      db.put(bytes(key), data);
    } catch (DBException e) {
      throw new IOException(e.getMessage(), e);
    }
  }
{noformat}

That way the test code will execute most of the code the actual function uses.

> Data persisted in NM should be versioned
> ----------------------------------------
>
>                 Key: YARN-2045
>                 URL: https://issues.apache.org/jira/browse/YARN-2045
>             Project: Hadoop YARN
>          Issue Type: Sub-task
>          Components: nodemanager
>    Affects Versions: 2.4.1
>            Reporter: Junping Du
>            Assignee: Junping Du
>         Attachments: YARN-2045-v2.patch, YARN-2045.patch
>
>
> As a split task from YARN-667, we want to add version info to NM related 
> data, include:
> - NodeManager local LevelDB state
> - NodeManager directory structure



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to