Java Code Examples for org.apache.hadoop.yarn.server.records.Version#newInstance()

The following examples show how to use org.apache.hadoop.yarn.server.records.Version#newInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RMStateStoreTestBase.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public void testCheckVersion(RMStateStoreHelper stateStoreHelper)
    throws Exception {
  RMStateStore store = stateStoreHelper.getRMStateStore();
  store.setRMDispatcher(new TestDispatcher());

  // default version
  Version defaultVersion = stateStoreHelper.getCurrentVersion();
  store.checkVersion();
  Assert.assertEquals(defaultVersion, store.loadVersion());

  // compatible version
  Version compatibleVersion =
      Version.newInstance(defaultVersion.getMajorVersion(),
        defaultVersion.getMinorVersion() + 2);
  stateStoreHelper.writeVersion(compatibleVersion);
  Assert.assertEquals(compatibleVersion, store.loadVersion());
  store.checkVersion();
  // overwrite the compatible version
  Assert.assertEquals(defaultVersion, store.loadVersion());

  // incompatible version
  Version incompatibleVersion =
      Version.newInstance(defaultVersion.getMajorVersion() + 2,
        defaultVersion.getMinorVersion());
  stateStoreHelper.writeVersion(incompatibleVersion);
  try {
    store.checkVersion();
    Assert.fail("Invalid version, should fail.");
  } catch (Throwable t) {
    Assert.assertTrue(t instanceof RMStateVersionIncompatibleException);
  }
}
 
Example 2
Source File: HistoryServerLeveldbStateStoreService.java    From big-c with Apache License 2.0 5 votes vote down vote up
Version loadVersion() throws IOException {
  byte[] data = db.get(bytes(DB_SCHEMA_VERSION_KEY));
  // if version is not stored previously, treat it as 1.0.
  if (data == null || data.length == 0) {
    return Version.newInstance(1, 0);
  }
  Version version =
      new VersionPBImpl(VersionProto.parseFrom(data));
  return version;
}
 
Example 3
Source File: TestLeveldbTimelineStateStore.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testCheckVersion() throws IOException {
  LeveldbTimelineStateStore store =
      initAndStartTimelineServiceStateStoreService();
  // default version
  Version defaultVersion = store.getCurrentVersion();
  Assert.assertEquals(defaultVersion, store.loadVersion());

  // compatible version
  Version compatibleVersion =
      Version.newInstance(defaultVersion.getMajorVersion(),
          defaultVersion.getMinorVersion() + 2);
  store.storeVersion(compatibleVersion);
  Assert.assertEquals(compatibleVersion, store.loadVersion());
  store.stop();

  // overwrite the compatible version
  store = initAndStartTimelineServiceStateStoreService();
  Assert.assertEquals(defaultVersion, store.loadVersion());

  // incompatible version
  Version incompatibleVersion =
      Version.newInstance(defaultVersion.getMajorVersion() + 1,
          defaultVersion.getMinorVersion());
  store.storeVersion(incompatibleVersion);
  store.stop();

  try {
    initAndStartTimelineServiceStateStoreService();
    Assert.fail("Incompatible version, should expect fail here.");
  } catch (ServiceStateException e) {
    Assert.assertTrue("Exception message mismatch",
        e.getMessage().contains("Incompatible version for timeline state store"));
  }
}
 
Example 4
Source File: TestLeveldbTimelineStore.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testCheckVersion() throws IOException {
  LeveldbTimelineStore dbStore = (LeveldbTimelineStore) store;
  // default version
  Version defaultVersion = dbStore.getCurrentVersion();
  Assert.assertEquals(defaultVersion, dbStore.loadVersion());

  // compatible version
  Version compatibleVersion =
      Version.newInstance(defaultVersion.getMajorVersion(),
        defaultVersion.getMinorVersion() + 2);
  dbStore.storeVersion(compatibleVersion);
  Assert.assertEquals(compatibleVersion, dbStore.loadVersion());
  restartTimelineStore();
  dbStore = (LeveldbTimelineStore) store;
  // overwrite the compatible version
  Assert.assertEquals(defaultVersion, dbStore.loadVersion());

  // incompatible version
  Version incompatibleVersion =
    Version.newInstance(defaultVersion.getMajorVersion() + 1,
        defaultVersion.getMinorVersion());
  dbStore.storeVersion(incompatibleVersion);
  try {
    restartTimelineStore();
    Assert.fail("Incompatible version, should expect fail here.");
  } catch (ServiceStateException e) {
    Assert.assertTrue("Exception message mismatch", 
      e.getMessage().contains("Incompatible version for timeline store"));
  }
}
 
Example 5
Source File: RMStateStoreTestBase.java    From big-c with Apache License 2.0 5 votes vote down vote up
public void testCheckVersion(RMStateStoreHelper stateStoreHelper)
    throws Exception {
  RMStateStore store = stateStoreHelper.getRMStateStore();
  store.setRMDispatcher(new TestDispatcher());

  // default version
  Version defaultVersion = stateStoreHelper.getCurrentVersion();
  store.checkVersion();
  Assert.assertEquals(defaultVersion, store.loadVersion());

  // compatible version
  Version compatibleVersion =
      Version.newInstance(defaultVersion.getMajorVersion(),
        defaultVersion.getMinorVersion() + 2);
  stateStoreHelper.writeVersion(compatibleVersion);
  Assert.assertEquals(compatibleVersion, store.loadVersion());
  store.checkVersion();
  // overwrite the compatible version
  Assert.assertEquals(defaultVersion, store.loadVersion());

  // incompatible version
  Version incompatibleVersion =
      Version.newInstance(defaultVersion.getMajorVersion() + 2,
        defaultVersion.getMinorVersion());
  stateStoreHelper.writeVersion(incompatibleVersion);
  try {
    store.checkVersion();
    Assert.fail("Invalid version, should fail.");
  } catch (Throwable t) {
    Assert.assertTrue(t instanceof RMStateVersionIncompatibleException);
  }
}
 
Example 6
Source File: TestNMLeveldbStateStoreService.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testCheckVersion() throws IOException {
  // default version
  Version defaultVersion = stateStore.getCurrentVersion();
  Assert.assertEquals(defaultVersion, stateStore.loadVersion());

  // compatible version
  Version compatibleVersion =
      Version.newInstance(defaultVersion.getMajorVersion(),
        defaultVersion.getMinorVersion() + 2);
  stateStore.storeVersion(compatibleVersion);
  Assert.assertEquals(compatibleVersion, stateStore.loadVersion());
  restartStateStore();
  // overwrite the compatible version
  Assert.assertEquals(defaultVersion, stateStore.loadVersion());

  // incompatible version
  Version incompatibleVersion =
    Version.newInstance(defaultVersion.getMajorVersion() + 1,
        defaultVersion.getMinorVersion());
  stateStore.storeVersion(incompatibleVersion);
  try {
    restartStateStore();
    Assert.fail("Incompatible version, should expect fail here.");
  } catch (ServiceStateException e) {
    Assert.assertTrue("Exception message mismatch", 
      e.getMessage().contains("Incompatible version for NM state:"));
  }
}
 
Example 7
Source File: HistoryServerLeveldbStateStoreService.java    From hadoop with Apache License 2.0 5 votes vote down vote up
Version loadVersion() throws IOException {
  byte[] data = db.get(bytes(DB_SCHEMA_VERSION_KEY));
  // if version is not stored previously, treat it as 1.0.
  if (data == null || data.length == 0) {
    return Version.newInstance(1, 0);
  }
  Version version =
      new VersionPBImpl(VersionProto.parseFrom(data));
  return version;
}
 
Example 8
Source File: TestLeveldbTimelineStateStore.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testCheckVersion() throws IOException {
  LeveldbTimelineStateStore store =
      initAndStartTimelineServiceStateStoreService();
  // default version
  Version defaultVersion = store.getCurrentVersion();
  Assert.assertEquals(defaultVersion, store.loadVersion());

  // compatible version
  Version compatibleVersion =
      Version.newInstance(defaultVersion.getMajorVersion(),
          defaultVersion.getMinorVersion() + 2);
  store.storeVersion(compatibleVersion);
  Assert.assertEquals(compatibleVersion, store.loadVersion());
  store.stop();

  // overwrite the compatible version
  store = initAndStartTimelineServiceStateStoreService();
  Assert.assertEquals(defaultVersion, store.loadVersion());

  // incompatible version
  Version incompatibleVersion =
      Version.newInstance(defaultVersion.getMajorVersion() + 1,
          defaultVersion.getMinorVersion());
  store.storeVersion(incompatibleVersion);
  store.stop();

  try {
    initAndStartTimelineServiceStateStoreService();
    Assert.fail("Incompatible version, should expect fail here.");
  } catch (ServiceStateException e) {
    Assert.assertTrue("Exception message mismatch",
        e.getMessage().contains("Incompatible version for timeline state store"));
  }
}
 
Example 9
Source File: TestLeveldbTimelineStore.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testCheckVersion() throws IOException {
  LeveldbTimelineStore dbStore = (LeveldbTimelineStore) store;
  // default version
  Version defaultVersion = dbStore.getCurrentVersion();
  Assert.assertEquals(defaultVersion, dbStore.loadVersion());

  // compatible version
  Version compatibleVersion =
      Version.newInstance(defaultVersion.getMajorVersion(),
        defaultVersion.getMinorVersion() + 2);
  dbStore.storeVersion(compatibleVersion);
  Assert.assertEquals(compatibleVersion, dbStore.loadVersion());
  restartTimelineStore();
  dbStore = (LeveldbTimelineStore) store;
  // overwrite the compatible version
  Assert.assertEquals(defaultVersion, dbStore.loadVersion());

  // incompatible version
  Version incompatibleVersion =
    Version.newInstance(defaultVersion.getMajorVersion() + 1,
        defaultVersion.getMinorVersion());
  dbStore.storeVersion(incompatibleVersion);
  try {
    restartTimelineStore();
    Assert.fail("Incompatible version, should expect fail here.");
  } catch (ServiceStateException e) {
    Assert.assertTrue("Exception message mismatch", 
      e.getMessage().contains("Incompatible version for timeline store"));
  }
}
 
Example 10
Source File: TestNMLeveldbStateStoreService.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testCheckVersion() throws IOException {
  // default version
  Version defaultVersion = stateStore.getCurrentVersion();
  Assert.assertEquals(defaultVersion, stateStore.loadVersion());

  // compatible version
  Version compatibleVersion =
      Version.newInstance(defaultVersion.getMajorVersion(),
        defaultVersion.getMinorVersion() + 2);
  stateStore.storeVersion(compatibleVersion);
  Assert.assertEquals(compatibleVersion, stateStore.loadVersion());
  restartStateStore();
  // overwrite the compatible version
  Assert.assertEquals(defaultVersion, stateStore.loadVersion());

  // incompatible version
  Version incompatibleVersion =
    Version.newInstance(defaultVersion.getMajorVersion() + 1,
        defaultVersion.getMinorVersion());
  stateStore.storeVersion(incompatibleVersion);
  try {
    restartStateStore();
    Assert.fail("Incompatible version, should expect fail here.");
  } catch (ServiceStateException e) {
    Assert.assertTrue("Exception message mismatch", 
      e.getMessage().contains("Incompatible version for NM state:"));
  }
}
 
Example 11
Source File: TestHistoryServerLeveldbStateStoreService.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Test
public void testCheckVersion() throws IOException {
  HistoryServerLeveldbStateStoreService store =
      new HistoryServerLeveldbStateStoreService();
  store.init(conf);
  store.start();

  // default version
  Version defaultVersion = store.getCurrentVersion();
  assertEquals(defaultVersion, store.loadVersion());

  // compatible version
  Version compatibleVersion =
      Version.newInstance(defaultVersion.getMajorVersion(),
        defaultVersion.getMinorVersion() + 2);
  store.dbStoreVersion(compatibleVersion);
  assertEquals(compatibleVersion, store.loadVersion());
  store.close();
  store = new HistoryServerLeveldbStateStoreService();
  store.init(conf);
  store.start();

  // overwrite the compatible version
  assertEquals(defaultVersion, store.loadVersion());

  // incompatible version
  Version incompatibleVersion =
    Version.newInstance(defaultVersion.getMajorVersion() + 1,
        defaultVersion.getMinorVersion());
  store.dbStoreVersion(incompatibleVersion);
  store.close();
  store = new HistoryServerLeveldbStateStoreService();
  try {
    store.init(conf);
    store.start();
    fail("Incompatible version, should have thrown before here.");
  } catch (ServiceStateException e) {
    assertTrue("Exception message mismatch",
      e.getMessage().contains("Incompatible version for state:"));
  }
  store.close();
}
 
Example 12
Source File: TestShuffleHandler.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Test
public void testRecoveryFromOtherVersions() throws IOException {
  final String user = "someuser";
  final ApplicationId appId = ApplicationId.newInstance(12345, 1);
  final File tmpDir = new File(System.getProperty("test.build.data",
      System.getProperty("java.io.tmpdir")),
      TestShuffleHandler.class.getName());
  Configuration conf = new Configuration();
  conf.setInt(ShuffleHandler.SHUFFLE_PORT_CONFIG_KEY, 0);
  conf.setInt(ShuffleHandler.MAX_SHUFFLE_CONNECTIONS, 3);
  ShuffleHandler shuffle = new ShuffleHandler();
  // emulate aux services startup with recovery enabled
  shuffle.setRecoveryPath(new Path(tmpDir.toString()));
  tmpDir.mkdirs();
  try {
    shuffle.init(conf);
    shuffle.start();

    // setup a shuffle token for an application
    DataOutputBuffer outputBuffer = new DataOutputBuffer();
    outputBuffer.reset();
    Token<JobTokenIdentifier> jt = new Token<JobTokenIdentifier>(
        "identifier".getBytes(), "password".getBytes(), new Text(user),
        new Text("shuffleService"));
    jt.write(outputBuffer);
    shuffle.initializeApplication(new ApplicationInitializationContext(user,
        appId, ByteBuffer.wrap(outputBuffer.getData(), 0,
            outputBuffer.getLength())));

    // verify we are authorized to shuffle
    int rc = getShuffleResponseCode(shuffle, jt);
    Assert.assertEquals(HttpURLConnection.HTTP_OK, rc);

    // emulate shuffle handler restart
    shuffle.close();
    shuffle = new ShuffleHandler();
    shuffle.setRecoveryPath(new Path(tmpDir.toString()));
    shuffle.init(conf);
    shuffle.start();

    // verify we are still authorized to shuffle to the old application
    rc = getShuffleResponseCode(shuffle, jt);
    Assert.assertEquals(HttpURLConnection.HTTP_OK, rc);
    Version version = Version.newInstance(1, 0);
    Assert.assertEquals(version, shuffle.getCurrentVersion());
  
    // emulate shuffle handler restart with compatible version
    Version version11 = Version.newInstance(1, 1);
    // update version info before close shuffle
    shuffle.storeVersion(version11);
    Assert.assertEquals(version11, shuffle.loadVersion());
    shuffle.close();
    shuffle = new ShuffleHandler();
    shuffle.setRecoveryPath(new Path(tmpDir.toString()));
    shuffle.init(conf);
    shuffle.start();
    // shuffle version will be override by CURRENT_VERSION_INFO after restart
    // successfully.
    Assert.assertEquals(version, shuffle.loadVersion());
    // verify we are still authorized to shuffle to the old application
    rc = getShuffleResponseCode(shuffle, jt);
    Assert.assertEquals(HttpURLConnection.HTTP_OK, rc);
  
    // emulate shuffle handler restart with incompatible version
    Version version21 = Version.newInstance(2, 1);
    shuffle.storeVersion(version21);
    Assert.assertEquals(version21, shuffle.loadVersion());
    shuffle.close();
    shuffle = new ShuffleHandler();
    shuffle.setRecoveryPath(new Path(tmpDir.toString()));
    shuffle.init(conf);
  
    try {
      shuffle.start();
      Assert.fail("Incompatible version, should expect fail here.");
    } catch (ServiceStateException e) {
      Assert.assertTrue("Exception message mismatch", 
      e.getMessage().contains("Incompatible version for state DB schema:"));
    } 
  
  } finally {
    if (shuffle != null) {
      shuffle.close();
    }
    FileUtil.fullyDelete(tmpDir);
  }
}
 
Example 13
Source File: TestFSRMStateStore.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 60000)
public void testCheckMajorVersionChange() throws Exception {
  HdfsConfiguration conf = new HdfsConfiguration();
  MiniDFSCluster cluster =
      new MiniDFSCluster.Builder(conf).numDataNodes(1).build();
  try {
    fsTester = new TestFSRMStateStoreTester(cluster, false) {
      Version VERSION_INFO = Version.newInstance(Integer.MAX_VALUE, 0);

      @Override
      public Version getCurrentVersion() throws Exception {
        return VERSION_INFO;
      }

      @Override
      public RMStateStore getRMStateStore() throws Exception {
        YarnConfiguration conf = new YarnConfiguration();
        conf.set(YarnConfiguration.FS_RM_STATE_STORE_URI,
            workingDirPathURI.toString());
        conf.set(YarnConfiguration.FS_RM_STATE_STORE_RETRY_POLICY_SPEC,
            "100,6000");
        this.store = new TestFileSystemRMStore(conf) {
          Version storedVersion = null;

          @Override
          public Version getCurrentVersion() {
            return VERSION_INFO;
          }

          @Override
          protected synchronized Version loadVersion() throws Exception {
            return storedVersion;
          }

          @Override
          protected synchronized void storeVersion() throws Exception {
            storedVersion = VERSION_INFO;
          }
        };
        return store;
      }
    };

    // default version
    RMStateStore store = fsTester.getRMStateStore();
    Version defaultVersion = fsTester.getCurrentVersion();
    store.checkVersion();
    Assert.assertEquals(defaultVersion, store.loadVersion());
  } finally {
    cluster.shutdown();
  }
}
 
Example 14
Source File: TestFSRMStateStore.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 60000)
public void testCheckMajorVersionChange() throws Exception {
  HdfsConfiguration conf = new HdfsConfiguration();
  MiniDFSCluster cluster =
      new MiniDFSCluster.Builder(conf).numDataNodes(1).build();
  try {
    fsTester = new TestFSRMStateStoreTester(cluster, false) {
      Version VERSION_INFO = Version.newInstance(Integer.MAX_VALUE, 0);

      @Override
      public Version getCurrentVersion() throws Exception {
        return VERSION_INFO;
      }

      @Override
      public RMStateStore getRMStateStore() throws Exception {
        YarnConfiguration conf = new YarnConfiguration();
        conf.set(YarnConfiguration.FS_RM_STATE_STORE_URI,
            workingDirPathURI.toString());
        conf.set(YarnConfiguration.FS_RM_STATE_STORE_RETRY_POLICY_SPEC,
            "100,6000");
        this.store = new TestFileSystemRMStore(conf) {
          Version storedVersion = null;

          @Override
          public Version getCurrentVersion() {
            return VERSION_INFO;
          }

          @Override
          protected synchronized Version loadVersion() throws Exception {
            return storedVersion;
          }

          @Override
          protected synchronized void storeVersion() throws Exception {
            storedVersion = VERSION_INFO;
          }
        };
        return store;
      }
    };

    // default version
    RMStateStore store = fsTester.getRMStateStore();
    Version defaultVersion = fsTester.getCurrentVersion();
    store.checkVersion();
    Assert.assertEquals(defaultVersion, store.loadVersion());
  } finally {
    cluster.shutdown();
  }
}
 
Example 15
Source File: TestShuffleHandler.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Test
public void testRecoveryFromOtherVersions() throws IOException {
  final String user = "someuser";
  final ApplicationId appId = ApplicationId.newInstance(12345, 1);
  final File tmpDir = new File(System.getProperty("test.build.data",
      System.getProperty("java.io.tmpdir")),
      TestShuffleHandler.class.getName());
  Configuration conf = new Configuration();
  conf.setInt(ShuffleHandler.SHUFFLE_PORT_CONFIG_KEY, 0);
  conf.setInt(ShuffleHandler.MAX_SHUFFLE_CONNECTIONS, 3);
  ShuffleHandler shuffle = new ShuffleHandler();
  // emulate aux services startup with recovery enabled
  shuffle.setRecoveryPath(new Path(tmpDir.toString()));
  tmpDir.mkdirs();
  try {
    shuffle.init(conf);
    shuffle.start();

    // setup a shuffle token for an application
    DataOutputBuffer outputBuffer = new DataOutputBuffer();
    outputBuffer.reset();
    Token<JobTokenIdentifier> jt = new Token<JobTokenIdentifier>(
        "identifier".getBytes(), "password".getBytes(), new Text(user),
        new Text("shuffleService"));
    jt.write(outputBuffer);
    shuffle.initializeApplication(new ApplicationInitializationContext(user,
        appId, ByteBuffer.wrap(outputBuffer.getData(), 0,
            outputBuffer.getLength())));

    // verify we are authorized to shuffle
    int rc = getShuffleResponseCode(shuffle, jt);
    Assert.assertEquals(HttpURLConnection.HTTP_OK, rc);

    // emulate shuffle handler restart
    shuffle.close();
    shuffle = new ShuffleHandler();
    shuffle.setRecoveryPath(new Path(tmpDir.toString()));
    shuffle.init(conf);
    shuffle.start();

    // verify we are still authorized to shuffle to the old application
    rc = getShuffleResponseCode(shuffle, jt);
    Assert.assertEquals(HttpURLConnection.HTTP_OK, rc);
    Version version = Version.newInstance(1, 0);
    Assert.assertEquals(version, shuffle.getCurrentVersion());
  
    // emulate shuffle handler restart with compatible version
    Version version11 = Version.newInstance(1, 1);
    // update version info before close shuffle
    shuffle.storeVersion(version11);
    Assert.assertEquals(version11, shuffle.loadVersion());
    shuffle.close();
    shuffle = new ShuffleHandler();
    shuffle.setRecoveryPath(new Path(tmpDir.toString()));
    shuffle.init(conf);
    shuffle.start();
    // shuffle version will be override by CURRENT_VERSION_INFO after restart
    // successfully.
    Assert.assertEquals(version, shuffle.loadVersion());
    // verify we are still authorized to shuffle to the old application
    rc = getShuffleResponseCode(shuffle, jt);
    Assert.assertEquals(HttpURLConnection.HTTP_OK, rc);
  
    // emulate shuffle handler restart with incompatible version
    Version version21 = Version.newInstance(2, 1);
    shuffle.storeVersion(version21);
    Assert.assertEquals(version21, shuffle.loadVersion());
    shuffle.close();
    shuffle = new ShuffleHandler();
    shuffle.setRecoveryPath(new Path(tmpDir.toString()));
    shuffle.init(conf);
  
    try {
      shuffle.start();
      Assert.fail("Incompatible version, should expect fail here.");
    } catch (ServiceStateException e) {
      Assert.assertTrue("Exception message mismatch", 
      e.getMessage().contains("Incompatible version for state DB schema:"));
    } 
  
  } finally {
    if (shuffle != null) {
      shuffle.close();
    }
    FileUtil.fullyDelete(tmpDir);
  }
}
 
Example 16
Source File: TestHistoryServerLeveldbStateStoreService.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Test
public void testCheckVersion() throws IOException {
  HistoryServerLeveldbStateStoreService store =
      new HistoryServerLeveldbStateStoreService();
  store.init(conf);
  store.start();

  // default version
  Version defaultVersion = store.getCurrentVersion();
  assertEquals(defaultVersion, store.loadVersion());

  // compatible version
  Version compatibleVersion =
      Version.newInstance(defaultVersion.getMajorVersion(),
        defaultVersion.getMinorVersion() + 2);
  store.dbStoreVersion(compatibleVersion);
  assertEquals(compatibleVersion, store.loadVersion());
  store.close();
  store = new HistoryServerLeveldbStateStoreService();
  store.init(conf);
  store.start();

  // overwrite the compatible version
  assertEquals(defaultVersion, store.loadVersion());

  // incompatible version
  Version incompatibleVersion =
    Version.newInstance(defaultVersion.getMajorVersion() + 1,
        defaultVersion.getMinorVersion());
  store.dbStoreVersion(incompatibleVersion);
  store.close();
  store = new HistoryServerLeveldbStateStoreService();
  try {
    store.init(conf);
    store.start();
    fail("Incompatible version, should have thrown before here.");
  } catch (ServiceStateException e) {
    assertTrue("Exception message mismatch",
      e.getMessage().contains("Incompatible version for state:"));
  }
  store.close();
}
 
Example 17
Source File: TestShuffleHandler.java    From tez with Apache License 2.0 4 votes vote down vote up
@Test
public void testRecoveryFromOtherVersions() throws IOException {
  final String user = "someuser";
  final ApplicationId appId = ApplicationId.newInstance(12345, 1);
  final File tmpDir = new File(System.getProperty("test.build.data",
      System.getProperty("java.io.tmpdir")),
      TestShuffleHandler.class.getName());
  Configuration conf = new Configuration();
  conf.set(HADOOP_TMP_DIR, TEST_DIR.getAbsolutePath());
  conf.setInt(ShuffleHandler.SHUFFLE_PORT_CONFIG_KEY, 0);
  conf.setInt(ShuffleHandler.MAX_SHUFFLE_CONNECTIONS, 3);
  ShuffleHandler shuffle = new ShuffleHandler();
  // emulate aux services startup with recovery enabled
  shuffle.setRecoveryPath(new Path(tmpDir.toString()));
  tmpDir.mkdirs();
  try {
    shuffle.init(conf);
    shuffle.start();

    // setup a shuffle token for an application
    DataOutputBuffer outputBuffer = new DataOutputBuffer();
    outputBuffer.reset();
    Token<JobTokenIdentifier> jt = new Token<JobTokenIdentifier>(
        "identifier".getBytes(), "password".getBytes(), new Text(user),
        new Text("shuffleService"));
    jt.write(outputBuffer);
    shuffle.initializeApplication(new ApplicationInitializationContext(user,
        appId, ByteBuffer.wrap(outputBuffer.getData(), 0,
            outputBuffer.getLength())));

    // verify we are authorized to shuffle
    int rc = getShuffleResponseCode(shuffle, jt);
    Assert.assertEquals(HttpURLConnection.HTTP_OK, rc);

    // emulate shuffle handler restart
    shuffle.close();
    shuffle = new ShuffleHandler();
    shuffle.setRecoveryPath(new Path(tmpDir.toString()));
    shuffle.init(conf);
    shuffle.start();

    // verify we are still authorized to shuffle to the old application
    rc = getShuffleResponseCode(shuffle, jt);
    Assert.assertEquals(HttpURLConnection.HTTP_OK, rc);
    Version version = Version.newInstance(1, 0);
    Assert.assertEquals(version, shuffle.getCurrentVersion());

    // emulate shuffle handler restart with compatible version
    Version version11 = Version.newInstance(1, 1);
    // update version info before close shuffle
    shuffle.storeVersion(version11);
    Assert.assertEquals(version11, shuffle.loadVersion());
    shuffle.close();
    shuffle = new ShuffleHandler();
    shuffle.setRecoveryPath(new Path(tmpDir.toString()));
    shuffle.init(conf);
    shuffle.start();
    // shuffle version will be override by CURRENT_VERSION_INFO after restart
    // successfully.
    Assert.assertEquals(version, shuffle.loadVersion());
    // verify we are still authorized to shuffle to the old application
    rc = getShuffleResponseCode(shuffle, jt);
    Assert.assertEquals(HttpURLConnection.HTTP_OK, rc);

    // emulate shuffle handler restart with incompatible version
    Version version21 = Version.newInstance(2, 1);
    shuffle.storeVersion(version21);
    Assert.assertEquals(version21, shuffle.loadVersion());
    shuffle.close();
    shuffle = new ShuffleHandler();
    shuffle.setRecoveryPath(new Path(tmpDir.toString()));
    shuffle.init(conf);
  
    try {
      shuffle.start();
      Assert.fail("Incompatible version, should expect fail here.");
    } catch (ServiceStateException e) {
      Assert.assertTrue("Exception message mismatch",
      e.getMessage().contains("Incompatible version for state DB schema:"));
    }

  } finally {
    if (shuffle != null) {
      shuffle.close();
    }
    FileUtil.fullyDelete(tmpDir);
  }
}