Search in sources :

Example 46 with DBException

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);
    }
}
Also used : DBException(org.iq80.leveldb.DBException) IOException(java.io.IOException)

Example 47 with DBException

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);
    }
}
Also used : DBException(org.iq80.leveldb.DBException) DataOutputStream(java.io.DataOutputStream) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) WriteBatch(org.iq80.leveldb.WriteBatch)

Example 48 with DBException

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
    }
}
Also used : DBIterator(org.iq80.leveldb.DBIterator) DBException(org.iq80.leveldb.DBException) Method(java.lang.reflect.Method) IOException(java.io.IOException) InvocationHandler(java.lang.reflect.InvocationHandler) InvocationTargetException(java.lang.reflect.InvocationTargetException) Test(org.junit.Test)

Example 49 with DBException

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;
}
Also used : DBException(org.iq80.leveldb.DBException) LeveldbIterator(org.apache.hadoop.yarn.server.utils.LeveldbIterator) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) IOException(java.io.IOException) ContainerManagerApplicationProto(org.apache.hadoop.yarn.proto.YarnServerNodemanagerRecoveryProtos.ContainerManagerApplicationProto)

Example 50 with DBException

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);
    }
}
Also used : DBException(org.iq80.leveldb.DBException) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) IOException(java.io.IOException) WriteBatch(org.iq80.leveldb.WriteBatch)

Aggregations

IOException (java.io.IOException)70 DBException (org.iq80.leveldb.DBException)70 JniDBFactory.asString (org.fusesource.leveldbjni.JniDBFactory.asString)39 LeveldbIterator (org.apache.hadoop.yarn.server.utils.LeveldbIterator)19 WriteBatch (org.iq80.leveldb.WriteBatch)18 Path (org.apache.hadoop.fs.Path)8 ByteString (com.google.protobuf.ByteString)6 File (java.io.File)6 Map (java.util.Map)6 NativeDB (org.fusesource.leveldbjni.internal.NativeDB)6 Options (org.iq80.leveldb.Options)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 DataOutputStream (java.io.DataOutputStream)5 TopicMetadata (co.cask.cdap.messaging.TopicMetadata)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 HashMap (java.util.HashMap)4 TopicNotFoundException (co.cask.cdap.api.messaging.TopicNotFoundException)3 RawMessageTableEntry (co.cask.cdap.messaging.store.RawMessageTableEntry)3 TreeMap (java.util.TreeMap)3 ImmutableMessageTableEntry (co.cask.cdap.messaging.store.ImmutableMessageTableEntry)2