use of org.iq80.leveldb.DBException in project hadoop by apache.
the class LeveldbRMStateStore method dbStoreVersion.
void dbStoreVersion(Version state) throws IOException {
String key = VERSION_NODE;
byte[] data = ((VersionPBImpl) state).getProto().toByteArray();
try {
db.put(bytes(key), data);
} catch (DBException e) {
throw new IOException(e);
}
}
use of org.iq80.leveldb.DBException in project hadoop by apache.
the class LeveldbRMStateStore method getNumEntriesInDatabase.
@VisibleForTesting
int getNumEntriesInDatabase() throws IOException {
int numEntries = 0;
LeveldbIterator iter = null;
try {
iter = new LeveldbIterator(db);
iter.seekToFirst();
while (iter.hasNext()) {
Entry<byte[], byte[]> entry = iter.next();
LOG.info("entry: " + asString(entry.getKey()));
++numEntries;
}
} catch (DBException e) {
throw new IOException(e);
} finally {
if (iter != null) {
iter.close();
}
}
return numEntries;
}
use of org.iq80.leveldb.DBException in project hadoop by apache.
the class LeveldbRMStateStore method storeOrUpdateRMDT.
private void storeOrUpdateRMDT(RMDelegationTokenIdentifier tokenId, Long renewDate, boolean isUpdate) throws IOException {
String tokenKey = getRMDTTokenNodeKey(tokenId);
RMDelegationTokenIdentifierData tokenData = new RMDelegationTokenIdentifierData(tokenId, renewDate);
if (LOG.isDebugEnabled()) {
LOG.debug("Storing token to " + tokenKey);
}
try {
WriteBatch batch = db.createWriteBatch();
try {
batch.put(bytes(tokenKey), tokenData.toByteArray());
if (!isUpdate) {
ByteArrayOutputStream bs = new ByteArrayOutputStream();
try (DataOutputStream ds = new DataOutputStream(bs)) {
ds.writeInt(tokenId.getSequenceNumber());
}
if (LOG.isDebugEnabled()) {
LOG.debug("Storing " + tokenId.getSequenceNumber() + " to " + RM_DT_SEQUENCE_NUMBER_KEY);
}
batch.put(bytes(RM_DT_SEQUENCE_NUMBER_KEY), bs.toByteArray());
}
db.write(batch);
} finally {
batch.close();
}
} catch (DBException e) {
throw new IOException(e);
}
}
use of org.iq80.leveldb.DBException in project hadoop by apache.
the class LeveldbRMStateStore method storeRMDTMasterKeyState.
@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);
}
}
use of org.iq80.leveldb.DBException in project hadoop by apache.
the class HistoryServerLeveldbStateStoreService method startStorage.
@Override
protected void startStorage() throws IOException {
Path storeRoot = createStorageDir(getConfig());
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;
}
}
checkVersion();
}
Aggregations