Search in sources :

Example 21 with WriteBatch

use of org.iq80.leveldb.WriteBatch 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)

Example 22 with WriteBatch

use of org.iq80.leveldb.WriteBatch in project hadoop by apache.

the class NMLeveldbStateStoreService method removeApplication.

@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));
            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)

Example 23 with WriteBatch

use of org.iq80.leveldb.WriteBatch in project hadoop by apache.

the class LeveldbRMStateStore method removeApplicationStateInternal.

@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);
    }
}
Also used : DBException(org.iq80.leveldb.DBException) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) IOException(java.io.IOException) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) WriteBatch(org.iq80.leveldb.WriteBatch)

Example 24 with WriteBatch

use of org.iq80.leveldb.WriteBatch 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);
    }
}
Also used : DBException(org.iq80.leveldb.DBException) RMDelegationTokenIdentifierData(org.apache.hadoop.yarn.server.resourcemanager.recovery.records.RMDelegationTokenIdentifierData) DataOutputStream(java.io.DataOutputStream) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) WriteBatch(org.iq80.leveldb.WriteBatch)

Example 25 with WriteBatch

use of org.iq80.leveldb.WriteBatch in project qi4j-sdk by Qi4j.

the class LevelDBEntityStoreMixin method applyChanges.

@Override
public void applyChanges(MapChanges changes) throws IOException {
    final WriteBatch writeBatch = db.createWriteBatch();
    try {
        changes.visitMap(new MapChanger() {

            @Override
            public Writer newEntity(final EntityReference ref, EntityDescriptor entityDescriptor) throws IOException {
                return new StringWriter(1000) {

                    @Override
                    public void close() throws IOException {
                        super.close();
                        String jsonState = toString();
                        writeBatch.put(ref.identity().getBytes(charset), jsonState.getBytes(charset));
                    }
                };
            }

            @Override
            public Writer updateEntity(final EntityReference ref, EntityDescriptor entityDescriptor) throws IOException {
                return new StringWriter(1000) {

                    @Override
                    public void close() throws IOException {
                        super.close();
                        String jsonState = toString();
                        writeBatch.put(ref.identity().getBytes(charset), jsonState.getBytes(charset));
                    }
                };
            }

            @Override
            public void removeEntity(EntityReference ref, EntityDescriptor entityDescriptor) throws EntityNotFoundException {
                writeBatch.delete(ref.identity().getBytes(charset));
            }
        });
        db.write(writeBatch);
    } finally {
        writeBatch.close();
    }
}
Also used : EntityDescriptor(org.qi4j.api.entity.EntityDescriptor) StringWriter(java.io.StringWriter) EntityReference(org.qi4j.api.entity.EntityReference) IOException(java.io.IOException) EntityNotFoundException(org.qi4j.spi.entitystore.EntityNotFoundException) WriteBatch(org.iq80.leveldb.WriteBatch) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Aggregations

WriteBatch (org.iq80.leveldb.WriteBatch)30 IOException (java.io.IOException)21 DBException (org.iq80.leveldb.DBException)17 JniDBFactory.asString (org.fusesource.leveldbjni.JniDBFactory.asString)12 Map (java.util.Map)9 DB (org.iq80.leveldb.DB)8 DBIterator (org.iq80.leveldb.DBIterator)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)4 NavigableMap (java.util.NavigableMap)4 RawMessageTableEntry (co.cask.cdap.messaging.store.RawMessageTableEntry)3 RollingWriteBatch (org.apache.hadoop.yarn.server.timeline.RollingLevelDB.RollingWriteBatch)3 ImmutableMessageTableEntry (co.cask.cdap.messaging.store.ImmutableMessageTableEntry)2 RawPayloadTableEntry (co.cask.cdap.messaging.store.RawPayloadTableEntry)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataOutputStream (java.io.DataOutputStream)2 HashMap (java.util.HashMap)2 Row (co.cask.cdap.api.dataset.table.Row)1 Scanner (co.cask.cdap.api.dataset.table.Scanner)1 AbstractMessageTable (co.cask.cdap.messaging.store.AbstractMessageTable)1