use of org.iq80.leveldb.DBException in project hadoop by apache.
the class LeveldbTimelineStateStore method removeToken.
@Override
public void removeToken(TimelineDelegationTokenIdentifier tokenId) throws IOException {
try {
byte[] key = createTokenEntryKey(tokenId.getSequenceNumber());
db.delete(key);
} catch (DBException e) {
throw new IOException(e);
}
}
use of org.iq80.leveldb.DBException in project hadoop by apache.
the class LeveldbTimelineStateStore method startStorage.
@Override
protected void startStorage() throws IOException {
Options options = new Options();
Path dbPath = new Path(getConfig().get(YarnConfiguration.TIMELINE_SERVICE_LEVELDB_STATE_STORE_PATH), DB_NAME);
FileSystem localFS = null;
try {
localFS = FileSystem.getLocal(getConfig());
if (!localFS.exists(dbPath)) {
if (!localFS.mkdirs(dbPath)) {
throw new IOException("Couldn't create directory for leveldb " + "timeline store " + dbPath);
}
localFS.setPermission(dbPath, LEVELDB_DIR_UMASK);
}
} finally {
IOUtils.cleanup(LOG, localFS);
}
JniDBFactory factory = new JniDBFactory();
try {
options.createIfMissing(false);
db = factory.open(new File(dbPath.toString()), options);
LOG.info("Loading the existing database at th path: " + dbPath.toString());
checkVersion();
} catch (NativeDB.DBException e) {
if (e.isNotFound() || e.getMessage().contains(" does not exist ")) {
try {
options.createIfMissing(true);
db = factory.open(new File(dbPath.toString()), options);
LOG.info("Creating a new database at th path: " + dbPath.toString());
storeVersion(CURRENT_VERSION_INFO);
} catch (DBException ex) {
throw new IOException(ex);
}
} else {
throw new IOException(e);
}
} catch (DBException e) {
throw new IOException(e);
}
}
use of org.iq80.leveldb.DBException 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.iq80.leveldb.DBException in project cdap by caskdata.
the class LevelDBMessageTable method rollback.
@Override
protected void rollback(byte[] startKey, byte[] stopKey, byte[] txWritePtr) throws IOException {
WriteBatch writeBatch = levelDB.createWriteBatch();
try (CloseableIterator<Map.Entry<byte[], byte[]>> rowIterator = new DBScanIterator(levelDB, startKey, stopKey)) {
while (rowIterator.hasNext()) {
Map.Entry<byte[], byte[]> rowValue = rowIterator.next();
byte[] value = rowValue.getValue();
Map<String, byte[]> columns = decodeValue(value);
writeBatch.put(rowValue.getKey(), encodeValue(txWritePtr, columns.get(PAYLOAD_COL)));
}
}
try {
levelDB.write(writeBatch, WRITE_OPTIONS);
} catch (DBException ex) {
throw new IOException(ex);
}
}
use of org.iq80.leveldb.DBException in project cdap by caskdata.
the class LevelDBMessageTable method persist.
@Override
protected void persist(Iterator<RawMessageTableEntry> entries) throws IOException {
try (WriteBatch writeBatch = levelDB.createWriteBatch()) {
while (entries.hasNext()) {
RawMessageTableEntry entry = entries.next();
byte[] rowKey = entry.getKey();
// LevelDB doesn't make copies, and since we reuse RawMessageTableEntry object, we need to create copies.
writeBatch.put(Arrays.copyOf(rowKey, rowKey.length), encodeValue(entry.getTxPtr(), entry.getPayload()));
}
levelDB.write(writeBatch, WRITE_OPTIONS);
} catch (DBException ex) {
throw new IOException(ex);
}
}
Aggregations