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);
}
}
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);
}
}
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);
}
}
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);
}
}
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();
}
}
Aggregations