use of org.apache.hadoop.yarn.server.utils.LeveldbIterator in project hadoop by apache.
the class HistoryServerLeveldbStateStoreService method loadTokenMasterKeys.
private int loadTokenMasterKeys(HistoryServerState state) throws IOException {
int numKeys = 0;
LeveldbIterator iter = null;
try {
iter = new LeveldbIterator(db);
iter.seek(bytes(TOKEN_MASTER_KEY_KEY_PREFIX));
while (iter.hasNext()) {
Entry<byte[], byte[]> entry = iter.next();
String key = asString(entry.getKey());
if (!key.startsWith(TOKEN_MASTER_KEY_KEY_PREFIX)) {
break;
}
if (LOG.isDebugEnabled()) {
LOG.debug("Loading master key from " + key);
}
try {
loadTokenMasterKey(state, entry.getValue());
} catch (IOException e) {
throw new IOException("Error loading token master key from " + key, e);
}
++numKeys;
}
} catch (DBException e) {
throw new IOException(e);
} finally {
if (iter != null) {
iter.close();
}
}
return numKeys;
}
use of org.apache.hadoop.yarn.server.utils.LeveldbIterator in project hadoop by apache.
the class TestLeveldbTimelineStore method deleteNextEntity.
private boolean deleteNextEntity(String entityType, byte[] ts) throws IOException, InterruptedException {
LeveldbIterator iterator = null;
LeveldbIterator pfIterator = null;
try {
iterator = ((LeveldbTimelineStore) store).getDbIterator(false);
pfIterator = ((LeveldbTimelineStore) store).getDbIterator(false);
return ((LeveldbTimelineStore) store).deleteNextEntity(entityType, ts, iterator, pfIterator, false);
} catch (DBException e) {
throw new IOException(e);
} finally {
IOUtils.cleanup(null, iterator, pfIterator);
}
}
use of org.apache.hadoop.yarn.server.utils.LeveldbIterator in project hadoop by apache.
the class LeveldbTimelineStore method discardOldEntities.
/**
* Discards entities with start timestamp less than or equal to the given
* timestamp.
*/
@VisibleForTesting
void discardOldEntities(long timestamp) throws IOException, InterruptedException {
byte[] reverseTimestamp = writeReverseOrderedLong(timestamp);
long totalCount = 0;
long t1 = System.currentTimeMillis();
try {
List<String> entityTypes = getEntityTypes();
for (String entityType : entityTypes) {
LeveldbIterator iterator = null;
LeveldbIterator pfIterator = null;
long typeCount = 0;
try {
deleteLock.writeLock().lock();
iterator = getDbIterator(false);
pfIterator = getDbIterator(false);
if (deletionThread != null && deletionThread.isInterrupted()) {
throw new InterruptedException();
}
boolean seeked = false;
while (deleteNextEntity(entityType, reverseTimestamp, iterator, pfIterator, seeked)) {
typeCount++;
totalCount++;
seeked = true;
if (deletionThread != null && deletionThread.isInterrupted()) {
throw new InterruptedException();
}
}
} catch (IOException e) {
LOG.error("Got IOException while deleting entities for type " + entityType + ", continuing to next type", e);
} finally {
IOUtils.cleanup(LOG, iterator, pfIterator);
deleteLock.writeLock().unlock();
if (typeCount > 0) {
LOG.info("Deleted " + typeCount + " entities of type " + entityType);
}
}
}
} finally {
long t2 = System.currentTimeMillis();
LOG.info("Discarded " + totalCount + " entities for timestamp " + timestamp + " and earlier in " + (t2 - t1) / 1000.0 + " seconds");
}
}
use of org.apache.hadoop.yarn.server.utils.LeveldbIterator in project hadoop by apache.
the class LeveldbTimelineStore method getDomains.
@Override
public TimelineDomains getDomains(String owner) throws IOException {
LeveldbIterator iterator = null;
try {
byte[] prefix = KeyBuilder.newInstance().add(OWNER_LOOKUP_PREFIX).add(owner).getBytesForLookup();
List<TimelineDomain> domains = new ArrayList<TimelineDomain>();
for (iterator = new LeveldbIterator(db), iterator.seek(prefix); iterator.hasNext(); ) {
byte[] key = iterator.peekNext().getKey();
if (!prefixMatches(prefix, prefix.length, key)) {
break;
}
// Iterator to parse the rows of an individual domain
KeyParser kp = new KeyParser(key, prefix.length);
String domainId = kp.getNextString();
byte[] prefixExt = KeyBuilder.newInstance().add(OWNER_LOOKUP_PREFIX).add(owner).add(domainId).getBytesForLookup();
TimelineDomain domainToReturn = getTimelineDomain(iterator, domainId, prefixExt);
if (domainToReturn != null) {
domains.add(domainToReturn);
}
}
// Sort the domains to return
Collections.sort(domains, new Comparator<TimelineDomain>() {
@Override
public int compare(TimelineDomain domain1, TimelineDomain domain2) {
int result = domain2.getCreatedTime().compareTo(domain1.getCreatedTime());
if (result == 0) {
return domain2.getModifiedTime().compareTo(domain1.getModifiedTime());
} else {
return result;
}
}
});
TimelineDomains domainsToReturn = new TimelineDomains();
domainsToReturn.addDomains(domains);
return domainsToReturn;
} catch (DBException e) {
throw new IOException(e);
} finally {
IOUtils.cleanup(LOG, iterator);
}
}
use of org.apache.hadoop.yarn.server.utils.LeveldbIterator in project hadoop by apache.
the class LeveldbTimelineStore method getEntity.
@Override
public TimelineEntity getEntity(String entityId, String entityType, EnumSet<Field> fields) throws IOException {
Long revStartTime = getStartTimeLong(entityId, entityType);
if (revStartTime == null) {
return null;
}
byte[] prefix = KeyBuilder.newInstance().add(ENTITY_ENTRY_PREFIX).add(entityType).add(writeReverseOrderedLong(revStartTime)).add(entityId).getBytesForLookup();
LeveldbIterator iterator = null;
try {
iterator = new LeveldbIterator(db);
iterator.seek(prefix);
if (fields == null) {
fields = EnumSet.allOf(Field.class);
}
return getEntity(entityId, entityType, revStartTime, fields, iterator, prefix, prefix.length);
} catch (DBException e) {
throw new IOException(e);
} finally {
IOUtils.cleanup(LOG, iterator);
}
}
Aggregations