use of org.iq80.leveldb.DBException in project hadoop by apache.
the class LeveldbTimelineStateStore method storeTokenMasterKey.
@Override
public void storeTokenMasterKey(DelegationKey key) throws IOException {
try {
byte[] k = createTokenMasterKeyEntryKey(key.getKeyId());
if (db.get(k) != null) {
throw new IOException(key + " already exists");
}
byte[] v = buildTokenMasterKeyData(key);
db.put(k, v);
} catch (DBException e) {
throw new IOException(e);
}
}
use of org.iq80.leveldb.DBException in project hadoop by apache.
the class LeveldbTimelineStateStore method storeToken.
@Override
public void storeToken(TimelineDelegationTokenIdentifier tokenId, Long renewDate) throws IOException {
DataOutputStream ds = null;
WriteBatch batch = null;
try {
byte[] k = createTokenEntryKey(tokenId.getSequenceNumber());
if (db.get(k) != null) {
throw new IOException(tokenId + " already exists");
}
byte[] v = buildTokenData(tokenId, renewDate);
ByteArrayOutputStream bs = new ByteArrayOutputStream();
ds = new DataOutputStream(bs);
ds.writeInt(tokenId.getSequenceNumber());
batch = db.createWriteBatch();
batch.put(k, v);
batch.put(LATEST_SEQUENCE_NUMBER_KEY, bs.toByteArray());
db.write(batch);
} catch (DBException e) {
throw new IOException(e);
} finally {
IOUtils.cleanup(LOG, ds);
IOUtils.cleanup(LOG, batch);
}
}
use of org.iq80.leveldb.DBException in project hadoop by apache.
the class TestLeveldbIterator method testExceptionHandling.
@Test
public void testExceptionHandling() throws Exception {
InvocationHandler rtExcHandler = new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
throw new RuntimeException("forced runtime error");
}
};
DBIterator dbiter = (DBIterator) Proxy.newProxyInstance(DBIterator.class.getClassLoader(), new Class[] { DBIterator.class }, rtExcHandler);
LeveldbIterator iter = new LeveldbIterator(dbiter);
for (CallInfo ci : RTEXC_METHODS) {
Method method = iter.getClass().getMethod(ci.methodName, ci.argTypes);
assertNotNull("unable to locate method " + ci.methodName, method);
try {
method.invoke(iter, ci.args);
fail("operation should have thrown");
} catch (InvocationTargetException ite) {
Throwable exc = ite.getTargetException();
assertTrue("Method " + ci.methodName + " threw non-DBException: " + exc, exc instanceof DBException);
assertFalse("Method " + ci.methodName + " double-wrapped DBException", exc.getCause() instanceof DBException);
}
}
// check close() throws IOException
try {
iter.close();
fail("operation shoul have thrown");
} catch (IOException e) {
// expected
}
}
use of org.iq80.leveldb.DBException in project hadoop by apache.
the class NMLeveldbStateStoreService method loadApplicationsState.
@Override
public RecoveredApplicationsState loadApplicationsState() throws IOException {
RecoveredApplicationsState state = new RecoveredApplicationsState();
state.applications = new ArrayList<ContainerManagerApplicationProto>();
String keyPrefix = APPLICATIONS_KEY_PREFIX;
LeveldbIterator iter = null;
try {
iter = new LeveldbIterator(db);
iter.seek(bytes(keyPrefix));
while (iter.hasNext()) {
Entry<byte[], byte[]> entry = iter.next();
String key = asString(entry.getKey());
if (!key.startsWith(keyPrefix)) {
break;
}
state.applications.add(ContainerManagerApplicationProto.parseFrom(entry.getValue()));
}
} catch (DBException e) {
throw new IOException(e);
} finally {
if (iter != null) {
iter.close();
}
}
cleanupDeprecatedFinishedApps();
return state;
}
use of org.iq80.leveldb.DBException in project hadoop by apache.
the class NMLeveldbStateStoreService method removeContainer.
@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_QUEUED_KEY_SUFFIX));
batch.delete(bytes(keyPrefix + CONTAINER_KILLED_KEY_SUFFIX));
batch.delete(bytes(keyPrefix + CONTAINER_EXIT_CODE_KEY_SUFFIX));
List<String> unknownKeysForContainer = containerUnknownKeySuffixes.removeAll(containerId);
for (String unknownKeySuffix : unknownKeysForContainer) {
batch.delete(bytes(keyPrefix + unknownKeySuffix));
}
db.write(batch);
} finally {
batch.close();
}
} catch (DBException e) {
throw new IOException(e);
}
}
Aggregations