Search in sources :

Example 11 with Metric

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);
    }
}
Also used : Metric(co.rsk.metrics.profilers.Metric)

Example 12 with 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();
    }
}
Also used : Path(java.nio.file.Path) Metric(co.rsk.metrics.profilers.Metric) IOException(java.io.IOException)

Example 13 with Metric

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);
    }
}
Also used : ByteArrayWrapper(org.ethereum.db.ByteArrayWrapper) Metric(co.rsk.metrics.profilers.Metric)

Example 14 with 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);
    }
}
Also used : ByteArrayWrapper(org.ethereum.db.ByteArrayWrapper) Metric(co.rsk.metrics.profilers.Metric) IOException(java.io.IOException)

Example 15 with 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);
}
Also used : Metric(co.rsk.metrics.profilers.Metric)

Aggregations

Metric (co.rsk.metrics.profilers.Metric)20 Coin (co.rsk.core.Coin)3 IOException (java.io.IOException)3 RskAddress (co.rsk.core.RskAddress)2 ECKey (org.ethereum.crypto.ECKey)2 ByteArrayWrapper (org.ethereum.db.ByteArrayWrapper)2 VMException (org.ethereum.vm.exception.VMException)2 BlockDifficulty (co.rsk.core.BlockDifficulty)1 Path (java.nio.file.Path)1 SignatureException (java.security.SignatureException)1 Nullable (javax.annotation.Nullable)1 DataWord (org.ethereum.vm.DataWord)1 Program (org.ethereum.vm.program.Program)1 ProgramInvoke (org.ethereum.vm.program.invoke.ProgramInvoke)1