@Override protected Version loadVersion() throws Exception { Version version = null; try { byte[] data = db.get(bytes(VERSION_NODE)); if (data != null) { version = new VersionPBImpl(VersionProto.parseFrom(data)); } } catch (DBException e) { throw new IOException(e); } return version; }
private void loadAMRMTokenSecretManagerState(RMState rmState) throws IOException { try { byte[] data = db.get(bytes(AMRMTOKEN_SECRET_MANAGER_ROOT)); if (data != null) { AMRMTokenSecretManagerStatePBImpl stateData = new AMRMTokenSecretManagerStatePBImpl(AMRMTokenSecretManagerStateProto.parseFrom(data)); rmState.amrmTokenSecretManagerState = AMRMTokenSecretManagerState.newInstance( stateData.getCurrentMasterKey(), stateData.getNextMasterKey()); } } catch (DBException e) { throw new IOException(e); } }
@VisibleForTesting ApplicationStateData loadRMAppState(ApplicationId appId) throws IOException { String appKey = getApplicationNodeKey(appId); byte[] data = null; try { data = db.get(bytes(appKey)); } catch (DBException e) { throw new IOException(e); } if (data == null) { return null; } return createApplicationState(appId.toString(), data); }
private void loadRMDTSecretManagerTokenSequenceNumber(RMState state) throws IOException { byte[] data = null; try { data = db.get(bytes(RM_DT_SEQUENCE_NUMBER_KEY)); } catch (DBException e) { throw new IOException(e); } if (data != null) { DataInputStream in = new DataInputStream(new ByteArrayInputStream(data)); try { state.rmSecretManagerState.dtSequenceNumber = in.readInt(); } finally { IOUtils.cleanup(LOG, in); } } }
@Override public synchronized long getAndIncrementEpoch() throws Exception { long currentEpoch = 0; byte[] dbKeyBytes = bytes(EPOCH_NODE); try { byte[] data = db.get(dbKeyBytes); if (data != null) { currentEpoch = EpochProto.parseFrom(data).getEpoch(); } EpochProto proto = Epoch.newInstance(currentEpoch + 1).getProto(); db.put(dbKeyBytes, proto.toByteArray()); } catch (DBException e) { throw new IOException(e); } return currentEpoch; }
/** * Simple major.minor versioning scheme. Any incompatible changes should be across major versions. * Minor version differences are allowed -- meaning we should be able to read dbs that are either * earlier *or* later on the minor version. */ private static void checkVersion(DB db) throws IOException { byte[] bytes = db.get(StoreVersion.KEY); if (bytes == null) { storeVersion(db); } else { StoreVersion version = mapper.readValue(bytes, StoreVersion.class); if (version.major != CURRENT_VERSION.major) { throw new IOException( "cannot read state DB with version " + version + ", incompatible " + "with current version " + CURRENT_VERSION); } storeVersion(db); } }
public byte[] get(byte[] key) throws IOException { return db.get(key); }