use of co.rsk.metrics.profilers.Metric in project rskj by rsksmart.
the class LevelDbDataSource method get.
@Override
public byte[] get(byte[] key) {
Objects.requireNonNull(key);
Metric metric = profiler.start(Profiler.PROFILING_TYPE.DB_READ);
resetDbLock.readLock().lock();
try {
if (logger.isTraceEnabled()) {
logger.trace("~> LevelDbDataSource.get(): {}, key: {}", name, ByteUtil.toHexString(key));
}
try {
byte[] ret = db.get(key);
if (logger.isTraceEnabled()) {
logger.trace("<~ LevelDbDataSource.get(): {}, key: {}, return length: {}", name, ByteUtil.toHexString(key), (ret == null ? "null" : ret.length));
}
return ret;
} catch (DBException e) {
logger.error("Exception. Retrying again...", e);
try {
byte[] ret = db.get(key);
if (logger.isTraceEnabled()) {
logger.trace("<~ LevelDbDataSource.get(): {}, key: {}, return length: {}", name, ByteUtil.toHexString(key), (ret == null ? "null" : ret.length));
}
return ret;
} catch (DBException e2) {
logger.error("Exception. Not retrying.", e2);
panicProcessor.panic("leveldb", String.format("Exception. Not retrying. %s", e2.getMessage()));
throw e2;
}
}
} finally {
resetDbLock.readLock().unlock();
profiler.stop(metric);
}
}
use of co.rsk.metrics.profilers.Metric in project rskj by rsksmart.
the class LevelDbDataSource method init.
@Override
public void init() {
resetDbLock.writeLock().lock();
Metric metric = profiler.start(Profiler.PROFILING_TYPE.LEVEL_DB_INIT);
try {
logger.debug("~> LevelDbDataSource.init(): {}", name);
if (isAlive()) {
return;
}
Objects.requireNonNull(name, "no name set to the db");
Options options = new Options();
options.createIfMissing(true);
options.compressionType(CompressionType.NONE);
options.blockSize(10 * 1024 * 1024);
options.writeBufferSize(10 * 1024 * 1024);
options.cacheSize(0);
options.paranoidChecks(true);
options.verifyChecksums(true);
try {
logger.debug("Opening database");
Path dbPath = getPathForName(name, databaseDir);
Files.createDirectories(dbPath.getParent());
logger.debug("Initializing new or existing database: '{}'", name);
db = factory.open(dbPath.toFile(), options);
alive = true;
} catch (IOException ioe) {
logger.error(ioe.getMessage(), ioe);
panicProcessor.panic("leveldb", ioe.getMessage());
throw new RuntimeException("Can't initialize database");
}
logger.debug("<~ LevelDbDataSource.init(): {}", name);
} finally {
profiler.stop(metric);
resetDbLock.writeLock().unlock();
}
}
use of co.rsk.metrics.profilers.Metric in project rskj by rsksmart.
the class LevelDbDataSource method updateBatchInternal.
private void updateBatchInternal(Map<ByteArrayWrapper, byte[]> rows, Set<ByteArrayWrapper> deleteKeys) throws IOException {
Metric metric = profiler.start(Profiler.PROFILING_TYPE.DB_WRITE);
if (rows.containsKey(null) || rows.containsValue(null)) {
profiler.stop(metric);
throw new IllegalArgumentException("Cannot update null values");
}
// Note that this is not atomic.
try (WriteBatch batch = db.createWriteBatch()) {
for (Map.Entry<ByteArrayWrapper, byte[]> entry : rows.entrySet()) {
batch.put(entry.getKey().getData(), entry.getValue());
}
for (ByteArrayWrapper deleteKey : deleteKeys) {
batch.delete(deleteKey.getData());
}
db.write(batch);
profiler.stop(metric);
}
}
use of co.rsk.metrics.profilers.Metric in project rskj by rsksmart.
the class LevelDbDataSource method keys.
@Override
public Set<ByteArrayWrapper> keys() {
Metric metric = profiler.start(Profiler.PROFILING_TYPE.DB_READ);
resetDbLock.readLock().lock();
try {
if (logger.isTraceEnabled()) {
logger.trace("~> LevelDbDataSource.keys(): {}", name);
}
try (DBIterator iterator = db.iterator()) {
Set<ByteArrayWrapper> result = new HashSet<>();
for (iterator.seekToFirst(); iterator.hasNext(); iterator.next()) {
byte[] key = iterator.peekNext().getKey();
result.add(ByteUtil.wrap(key));
}
if (logger.isTraceEnabled()) {
logger.trace("<~ LevelDbDataSource.keys(): {}, {}", name, result.size());
}
return result;
} catch (IOException e) {
logger.error("Unexpected", e);
panicProcessor.panic("leveldb", String.format("Unexpected %s", e.getMessage()));
throw new RuntimeException(e);
}
} finally {
resetDbLock.readLock().unlock();
profiler.stop(metric);
}
}
use of co.rsk.metrics.profilers.Metric in project rskj by rsksmart.
the class IndexedBlockStore method flush.
@Override
public synchronized void flush() {
Metric metric = profiler.start(Profiler.PROFILING_TYPE.DB_WRITE);
index.flush();
blocks.flush();
profiler.stop(metric);
}
Aggregations