org.iq80.leveldb.DBException Java Examples

The following examples show how to use org.iq80.leveldb.DBException. 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: LeveldbRMStateStore.java    From hadoop with Apache License 2.0 6 votes vote down vote up
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);
  }
}
 
Example #2
Source File: NMLeveldbStateStoreService.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public void removeContainer(ContainerId containerId)
    throws IOException {
  if (LOG.isDebugEnabled()) {
    LOG.debug("removeContainer: containerId=" + containerId);
  }

  String keyPrefix = CONTAINERS_KEY_PREFIX + containerId.toString();
  try {
    WriteBatch batch = db.createWriteBatch();
    try {
      batch.delete(bytes(keyPrefix + CONTAINER_REQUEST_KEY_SUFFIX));
      batch.delete(bytes(keyPrefix + CONTAINER_DIAGS_KEY_SUFFIX));
      batch.delete(bytes(keyPrefix + CONTAINER_LAUNCHED_KEY_SUFFIX));
      batch.delete(bytes(keyPrefix + CONTAINER_KILLED_KEY_SUFFIX));
      batch.delete(bytes(keyPrefix + CONTAINER_EXIT_CODE_KEY_SUFFIX));
      db.write(batch);
    } finally {
      batch.close();
    }
  } catch (DBException e) {
    throw new IOException(e);
  }
}
 
Example #3
Source File: LeveldbTimelineStateStore.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private int loadTokens(TimelineServiceState state) throws IOException {
  byte[] base = KeyBuilder.newInstance().add(TOKEN_ENTRY_PREFIX)
      .getBytesForLookup();
  int numTokens = 0;
  LeveldbIterator iterator = null;
  try {
    for (iterator = new LeveldbIterator(db), iterator.seek(base);
        iterator.hasNext(); iterator.next()) {
      byte[] k = iterator.peekNext().getKey();
      if (!prefixMatches(base, base.length, k)) {
        break;
      }
      byte[] v = iterator.peekNext().getValue();
      loadTokenData(state, v);
      ++numTokens;
    }
  } catch (DBException e) {
    throw new IOException(e);
  } finally {
    IOUtils.cleanup(LOG, iterator);
  }
  return numTokens;
}
 
Example #4
Source File: WarpDB.java    From warp10-platform with Apache License 2.0 6 votes vote down vote up
@Override
public Snapshot put(byte[] key, byte[] value, WriteOptions options) throws DBException {
  if (options.snapshot()) {
    throw new RuntimeException("Snapshots are unsupported.");      
  }
  
  try {
    mutex.lockInterruptibly();
    pendingOps.incrementAndGet();
  } catch (InterruptedException ie) {
    throw new DBException("Interrupted while acquiring DB mutex.", ie);
  } finally {
    if (mutex.isHeldByCurrentThread()) {
      mutex.unlock();
    }
  }
  try {
    return this.db.put(key, value, options);
  } finally {
    this.pendingOps.decrementAndGet();
  }
}
 
Example #5
Source File: NMLeveldbStateStoreService.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public void removeApplication(ApplicationId appId)
    throws IOException {
  if (LOG.isDebugEnabled()) {
    LOG.debug("removeApplication: appId=" + appId);
  }

  try {
    WriteBatch batch = db.createWriteBatch();
    try {
      String key = APPLICATIONS_KEY_PREFIX + appId;
      batch.delete(bytes(key));
      key = FINISHED_APPS_KEY_PREFIX + appId;
      batch.delete(bytes(key));
      db.write(batch);
    } finally {
      batch.close();
    }
  } catch (DBException e) {
    throw new IOException(e);
  }
}
 
Example #6
Source File: WarpDB.java    From warp10-platform with Apache License 2.0 6 votes vote down vote up
@Override
public Snapshot write(WriteBatch updates, WriteOptions options) throws DBException {
  if (options.snapshot()) {
    throw new RuntimeException("Snapshots are unsupported.");      
  }
  
  try {
    mutex.lockInterruptibly();
    pendingOps.incrementAndGet();
  } catch (InterruptedException ie) {
    throw new DBException("Interrupted while acquiring DB mutex.", ie);
  } finally {
    if (mutex.isHeldByCurrentThread()) {
      mutex.unlock();
    }
  }
  try {
    return this.db.write(updates, options);
  } finally {
    this.pendingOps.decrementAndGet();
  }    
}
 
Example #7
Source File: HistoryServerLeveldbStateStoreService.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
public void storeTokenMasterKey(DelegationKey masterKey)
    throws IOException {
  if (LOG.isDebugEnabled()) {
    LOG.debug("Storing master key " + masterKey.getKeyId());
  }

  ByteArrayOutputStream memStream = new ByteArrayOutputStream();
  DataOutputStream dataStream = new DataOutputStream(memStream);
  try {
    masterKey.write(dataStream);
    dataStream.close();
    dataStream = null;
  } finally {
    IOUtils.cleanup(LOG, dataStream);
  }

  String dbKey = getTokenMasterKeyDatabaseKey(masterKey);
  try {
    db.put(bytes(dbKey), memStream.toByteArray());
  } catch (DBException e) {
    throw new IOException(e);
  }
}
 
Example #8
Source File: NMLeveldbStateStoreService.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public void storeContainerDiagnostics(ContainerId containerId,
    StringBuilder diagnostics) throws IOException {
  if (LOG.isDebugEnabled()) {
    LOG.debug("storeContainerDiagnostics: containerId=" + containerId
    + ", diagnostics=" + diagnostics);
  }

  String key = CONTAINERS_KEY_PREFIX + containerId.toString()
      + CONTAINER_DIAGS_KEY_SUFFIX;
  try {
    db.put(bytes(key), bytes(diagnostics.toString()));
  } catch (DBException e) {
    throw new IOException(e);
  }
}
 
Example #9
Source File: LeveldbRMStateStore.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
protected void removeApplicationStateInternal(ApplicationStateData appState)
    throws IOException {
  ApplicationId appId =
      appState.getApplicationSubmissionContext().getApplicationId();
  String appKey = getApplicationNodeKey(appId);
  try {
    WriteBatch batch = db.createWriteBatch();
    try {
      batch.delete(bytes(appKey));
      for (ApplicationAttemptId attemptId : appState.attempts.keySet()) {
        String attemptKey = getApplicationAttemptNodeKey(appKey, attemptId);
        batch.delete(bytes(attemptKey));
      }
      if (LOG.isDebugEnabled()) {
        LOG.debug("Removing state for app " + appId + " and "
            + appState.attempts.size() + " attempts" + " at " + appKey);
      }
      db.write(batch);
    } finally {
      batch.close();
    }
  } catch (DBException e) {
    throw new IOException(e);
  }
}
 
Example #10
Source File: ShuffleHandler.java    From tez with Apache License 2.0 6 votes vote down vote up
private void startStore(Path recoveryRoot) throws IOException {
  Options options = new Options();
  options.createIfMissing(false);
  options.logger(new LevelDBLogger());
  Path dbPath = new Path(recoveryRoot, STATE_DB_NAME);
  LOG.info("Using state database at " + dbPath + " for recovery");
  File dbfile = new File(dbPath.toString());
  try {
    stateDb = JniDBFactory.factory.open(dbfile, options);
  } catch (NativeDB.DBException e) {
    if (e.isNotFound() || e.getMessage().contains(" does not exist ")) {
      LOG.info("Creating state database at " + dbfile);
      options.createIfMissing(true);
      try {
        stateDb = JniDBFactory.factory.open(dbfile, options);
        storeVersion();
      } catch (DBException dbExc) {
        throw new IOException("Unable to create state store", dbExc);
      }
    } else {
      throw e;
    }
  }
  checkVersion();
}
 
Example #11
Source File: LeveldbTimelineStateStore.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
Version loadVersion() throws IOException {
  try {
    byte[] data = db.get(TIMELINE_STATE_STORE_VERSION_KEY);
    // if version is not stored previously, treat it as CURRENT_VERSION_INFO.
    if (data == null || data.length == 0) {
      return getCurrentVersion();
    }
    Version version =
        new VersionPBImpl(
            YarnServerCommonProtos.VersionProto.parseFrom(data));
    return version;
  } catch (DBException e) {
    throw new IOException(e);
  }
}
 
Example #12
Source File: HistoryServerLeveldbStateStoreService.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
public void storeToken(MRDelegationTokenIdentifier tokenId, Long renewDate)
    throws IOException {
  if (LOG.isDebugEnabled()) {
    LOG.debug("Storing token " + tokenId.getSequenceNumber());
  }

  ByteArrayOutputStream memStream = new ByteArrayOutputStream();
  DataOutputStream dataStream = new DataOutputStream(memStream);
  try {
    tokenId.write(dataStream);
    dataStream.writeLong(renewDate);
    dataStream.close();
    dataStream = null;
  } finally {
    IOUtils.cleanup(LOG, dataStream);
  }

  String dbKey = getTokenDatabaseKey(tokenId);
  try {
    db.put(bytes(dbKey), memStream.toByteArray());
  } catch (DBException e) {
    throw new IOException(e);
  }
}
 
Example #13
Source File: ShuffleHandler.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private void startStore(Path recoveryRoot) throws IOException {
  Options options = new Options();
  options.createIfMissing(false);
  options.logger(new LevelDBLogger());
  Path dbPath = new Path(recoveryRoot, STATE_DB_NAME);
  LOG.info("Using state database at " + dbPath + " for recovery");
  File dbfile = new File(dbPath.toString());
  try {
    stateDb = JniDBFactory.factory.open(dbfile, options);
  } catch (NativeDB.DBException e) {
    if (e.isNotFound() || e.getMessage().contains(" does not exist ")) {
      LOG.info("Creating state database at " + dbfile);
      options.createIfMissing(true);
      try {
        stateDb = JniDBFactory.factory.open(dbfile, options);
        storeVersion();
      } catch (DBException dbExc) {
        throw new IOException("Unable to create state store", dbExc);
      }
    } else {
      throw e;
    }
  }
  checkVersion();
}
 
Example #14
Source File: LeveldbTimelineStateStore.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private void loadLatestSequenceNumber(TimelineServiceState state)
    throws IOException {
  byte[] data = null;
  try {
    data = db.get(LATEST_SEQUENCE_NUMBER_KEY);
  } catch (DBException e) {
    throw new IOException(e);
  }
  if (data != null) {
    DataInputStream in = new DataInputStream(new ByteArrayInputStream(data));
    try {
      state.latestSequenceNumber = in.readInt();
    } finally {
      IOUtils.cleanup(LOG, in);
    }
  }
}
 
Example #15
Source File: NMLeveldbStateStoreService.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public void finishResourceLocalization(String user, ApplicationId appId,
    LocalizedResourceProto proto) throws IOException {
  String localPath = proto.getLocalPath();
  String startedKey = getResourceStartedKey(user, appId, localPath);
  String completedKey = getResourceCompletedKey(user, appId, localPath);
  if (LOG.isDebugEnabled()) {
    LOG.debug("Storing localized resource to " + completedKey);
  }
  try {
    WriteBatch batch = db.createWriteBatch();
    try {
      batch.delete(bytes(startedKey));
      batch.put(bytes(completedKey), proto.toByteArray());
      db.write(batch);
    } finally {
      batch.close();
    }
  } catch (DBException e) {
    throw new IOException(e);
  }
}
 
Example #16
Source File: NMLeveldbStateStoreService.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
public void finishResourceLocalization(String user, ApplicationId appId,
    LocalizedResourceProto proto) throws IOException {
  String localPath = proto.getLocalPath();
  String startedKey = getResourceStartedKey(user, appId, localPath);
  String completedKey = getResourceCompletedKey(user, appId, localPath);
  if (LOG.isDebugEnabled()) {
    LOG.debug("Storing localized resource to " + completedKey);
  }
  try {
    WriteBatch batch = db.createWriteBatch();
    try {
      batch.delete(bytes(startedKey));
      batch.put(bytes(completedKey), proto.toByteArray());
      db.write(batch);
    } finally {
      batch.close();
    }
  } catch (DBException e) {
    throw new IOException(e);
  }
}
 
Example #17
Source File: HistoryServerLeveldbStateStoreService.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public void storeToken(MRDelegationTokenIdentifier tokenId, Long renewDate)
    throws IOException {
  if (LOG.isDebugEnabled()) {
    LOG.debug("Storing token " + tokenId.getSequenceNumber());
  }

  ByteArrayOutputStream memStream = new ByteArrayOutputStream();
  DataOutputStream dataStream = new DataOutputStream(memStream);
  try {
    tokenId.write(dataStream);
    dataStream.writeLong(renewDate);
    dataStream.close();
    dataStream = null;
  } finally {
    IOUtils.cleanup(LOG, dataStream);
  }

  String dbKey = getTokenDatabaseKey(tokenId);
  try {
    db.put(bytes(dbKey), memStream.toByteArray());
  } catch (DBException e) {
    throw new IOException(e);
  }
}
 
Example #18
Source File: NMLeveldbStateStoreService.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
public void removeApplication(ApplicationId appId)
    throws IOException {
  try {
    WriteBatch batch = db.createWriteBatch();
    try {
      String key = APPLICATIONS_KEY_PREFIX + appId;
      batch.delete(bytes(key));
      key = FINISHED_APPS_KEY_PREFIX + appId;
      batch.delete(bytes(key));
      db.write(batch);
    } finally {
      batch.close();
    }
  } catch (DBException e) {
    throw new IOException(e);
  }
}
 
Example #19
Source File: LeveldbRMStateStore.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
protected void storeRMDTMasterKeyState(DelegationKey masterKey)
    throws IOException {
  String dbKey = getRMDTMasterKeyNodeKey(masterKey);
  if (LOG.isDebugEnabled()) {
    LOG.debug("Storing token master key to " + dbKey);
  }
  ByteArrayOutputStream os = new ByteArrayOutputStream();
  DataOutputStream out = new DataOutputStream(os);
  try {
    masterKey.write(out);
  } finally {
    out.close();
  }
  try {
    db.put(bytes(dbKey), os.toByteArray());
  } catch (DBException e) {
    throw new IOException(e);
  }
}
 
Example #20
Source File: WarpDB.java    From warp10-platform with Apache License 2.0 6 votes vote down vote up
@Override
public void put(byte[] key, byte[] value) throws DBException {
  try {
    mutex.lockInterruptibly();
    pendingOps.incrementAndGet();
  } catch (InterruptedException ie) {
    throw new DBException("Interrupted while acquiring DB mutex.", ie);
  } finally {
    if (mutex.isHeldByCurrentThread()) {
      mutex.unlock();
    }
  }
  try {
    this.db.put(key, value);
  } finally {
    this.pendingOps.decrementAndGet();
  }
}
 
Example #21
Source File: NMLeveldbStateStoreService.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
public void removeContainer(ContainerId containerId)
    throws IOException {
  String keyPrefix = CONTAINERS_KEY_PREFIX + containerId.toString();
  try {
    WriteBatch batch = db.createWriteBatch();
    try {
      batch.delete(bytes(keyPrefix + CONTAINER_REQUEST_KEY_SUFFIX));
      batch.delete(bytes(keyPrefix + CONTAINER_DIAGS_KEY_SUFFIX));
      batch.delete(bytes(keyPrefix + CONTAINER_LAUNCHED_KEY_SUFFIX));
      batch.delete(bytes(keyPrefix + CONTAINER_KILLED_KEY_SUFFIX));
      batch.delete(bytes(keyPrefix + CONTAINER_EXIT_CODE_KEY_SUFFIX));
      db.write(batch);
    } finally {
      batch.close();
    }
  } catch (DBException e) {
    throw new IOException(e);
  }
}
 
Example #22
Source File: LeveldbTimelineStateStore.java    From big-c with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
Version loadVersion() throws IOException {
  try {
    byte[] data = db.get(TIMELINE_STATE_STORE_VERSION_KEY);
    // if version is not stored previously, treat it as CURRENT_VERSION_INFO.
    if (data == null || data.length == 0) {
      return getCurrentVersion();
    }
    Version version =
        new VersionPBImpl(
            YarnServerCommonProtos.VersionProto.parseFrom(data));
    return version;
  } catch (DBException e) {
    throw new IOException(e);
  }
}
 
Example #23
Source File: HistoryServerLeveldbStateStoreService.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public void storeTokenMasterKey(DelegationKey masterKey)
    throws IOException {
  if (LOG.isDebugEnabled()) {
    LOG.debug("Storing master key " + masterKey.getKeyId());
  }

  ByteArrayOutputStream memStream = new ByteArrayOutputStream();
  DataOutputStream dataStream = new DataOutputStream(memStream);
  try {
    masterKey.write(dataStream);
    dataStream.close();
    dataStream = null;
  } finally {
    IOUtils.cleanup(LOG, dataStream);
  }

  String dbKey = getTokenMasterKeyDatabaseKey(masterKey);
  try {
    db.put(bytes(dbKey), memStream.toByteArray());
  } catch (DBException e) {
    throw new IOException(e);
  }
}
 
Example #24
Source File: LeveldbRMStateStore.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
protected void removeApplicationStateInternal(ApplicationStateData appState)
    throws IOException {
  ApplicationId appId =
      appState.getApplicationSubmissionContext().getApplicationId();
  String appKey = getApplicationNodeKey(appId);
  try {
    WriteBatch batch = db.createWriteBatch();
    try {
      batch.delete(bytes(appKey));
      for (ApplicationAttemptId attemptId : appState.attempts.keySet()) {
        String attemptKey = getApplicationAttemptNodeKey(appKey, attemptId);
        batch.delete(bytes(attemptKey));
      }
      if (LOG.isDebugEnabled()) {
        LOG.debug("Removing state for app " + appId + " and "
            + appState.attempts.size() + " attempts" + " at " + appKey);
      }
      db.write(batch);
    } finally {
      batch.close();
    }
  } catch (DBException e) {
    throw new IOException(e);
  }
}
 
Example #25
Source File: LeveldbRMStateStore.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
protected void startInternal() throws Exception {
  Path storeRoot = createStorageDir();
  Options options = new Options();
  options.createIfMissing(false);
  options.logger(new LeveldbLogger());
  LOG.info("Using state database at " + storeRoot + " for recovery");
  File dbfile = new File(storeRoot.toString());
  try {
    db = JniDBFactory.factory.open(dbfile, options);
  } catch (NativeDB.DBException e) {
    if (e.isNotFound() || e.getMessage().contains(" does not exist ")) {
      LOG.info("Creating state database at " + dbfile);
      options.createIfMissing(true);
      try {
        db = JniDBFactory.factory.open(dbfile, options);
        // store version
        storeVersion();
      } catch (DBException dbErr) {
        throw new IOException(dbErr.getMessage(), dbErr);
      }
    } else {
      throw e;
    }
  }
}
 
Example #26
Source File: LeveldbRMStateStore.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #27
Source File: LeveldbRMStateStore.java    From hadoop with Apache License 2.0 6 votes vote down vote up
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);
    }
  }
}
 
Example #28
Source File: WarpDB.java    From warp10-platform with Apache License 2.0 6 votes vote down vote up
@Override
public DBIterator iterator(ReadOptions options) {
  if (null == options) {
    return iterator();
  }
  if (null != options.snapshot()) {
    throw new RuntimeException("Snapshots are unsupported.");
  }
  try {
    mutex.lockInterruptibly();
    pendingOps.incrementAndGet();
  } catch (InterruptedException ie) {
    throw new DBException("Interrupted while acquiring DB mutex.", ie);
  } finally {
    if (mutex.isHeldByCurrentThread()) {
      mutex.unlock();
    }
  }    
  return new WarpIterator(pendingOps, this.db.iterator(options));    
}
 
Example #29
Source File: NMLeveldbStateStoreService.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void storeContainerCompleted(ContainerId containerId,
    int exitCode) throws IOException {
  String key = CONTAINERS_KEY_PREFIX + containerId.toString()
      + CONTAINER_EXIT_CODE_KEY_SUFFIX;
  try {
    db.put(bytes(key), bytes(Integer.toString(exitCode)));
  } catch (DBException e) {
    throw new IOException(e);
  }
}
 
Example #30
Source File: HistoryServerLeveldbStateStoreService.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void removeTokenMasterKey(DelegationKey masterKey)
    throws IOException {
  if (LOG.isDebugEnabled()) {
    LOG.debug("Removing master key " + masterKey.getKeyId());
  }

  String dbKey = getTokenMasterKeyDatabaseKey(masterKey);
  try {
    db.delete(bytes(dbKey));
  } catch (DBException e) {
    throw new IOException(e);
  }
}