@Override public void beginDatabaseBatchWrite() throws BlockStoreException { // This is often called twice in row! But they are not nested // transactions! // We just ignore the second call. if (!autoCommit) { return; } if (instrument) beginMethod("beginDatabaseBatchWrite"); batch = db.createWriteBatch(); uncommited = new HashMap<>(); uncommitedDeletes = new HashSet<>(); utxoUncommittedCache = new HashMap<>(); utxoUncommittedDeletedCache = new HashSet<>(); autoCommit = false; if (instrument) endMethod("beginDatabaseBatchWrite"); }
@Override public void beginDatabaseBatchWrite() throws BlockStoreException { // This is often called twice in row! But they are not nested // transactions! // We just ignore the second call. if (!autoCommit) { return; } if (instrument) beginMethod("beginDatabaseBatchWrite"); batch = db.createWriteBatch(); uncommited = new HashMap<ByteBuffer, byte[]>(); uncommitedDeletes = new HashSet<ByteBuffer>(); utxoUncommittedCache = new HashMap<ByteBuffer, UTXO>(); utxoUncommittedDeletedCache = new HashSet<ByteBuffer>(); autoCommit = false; if (instrument) endMethod("beginDatabaseBatchWrite"); }
@Override public void beginDatabaseBatchWrite() throws BlockStoreException { // This is often called twice in row! But they are not nested // transactions! // We just ignore the second call. if (!autoCommit) { return; } if (instrument) beginMethod("beginDatabaseBatchWrite"); batch = db.createWriteBatch(); uncommited = new HashMap<>(); uncommitedDeletes = new HashSet<>(); utxoUncommittedCache = new HashMap<>(); utxoUncommittedDeletedCache = new HashSet<>(); autoCommit = false; if (instrument) endMethod("beginDatabaseBatchWrite"); }
@Override public void beginDatabaseBatchWrite() throws BlockStoreException { // This is often called twice in row! But they are not nested // transactions! // We just ignore the second call. if (!autoCommit) { return; } if (instrument) beginMethod("beginDatabaseBatchWrite"); batch = db.createWriteBatch(); uncommited = new HashMap<ByteBuffer, byte[]>(); uncommitedDeletes = new HashSet<ByteBuffer>(); utxoUncommittedCache = new HashMap<ByteBuffer, UTXO>(); utxoUncommittedDeletedCache = new HashSet<ByteBuffer>(); autoCommit = false; if (instrument) endMethod("beginDatabaseBatchWrite"); }
protected void putUpdateStoredBlock(StoredBlock storedBlock, boolean wasUndoable) { // We put as one record as then the get is much faster. if (instrument) beginMethod("putUpdateStoredBlock"); Sha256Hash hash = storedBlock.getHeader().getHash(); ByteBuffer bb = ByteBuffer.allocate(97); storedBlock.serializeCompact(bb); bb.put((byte) (wasUndoable ? 1 : 0)); batchPut(getKey(KeyType.HEADERS_ALL, hash), bb.array()); if (instrument) endMethod("putUpdateStoredBlock"); }
protected void putUpdateStoredBlock(StoredBlock storedBlock, boolean wasUndoable) { // We put as one record as then the get is much faster. if (instrument) beginMethod("putUpdateStoredBlock"); Sha256Hash hash = storedBlock.getHeader().getHash(); ByteBuffer bb = ByteBuffer.allocate(97); storedBlock.serializeCompact(bb); bb.put((byte) (wasUndoable ? 1 : 0)); batchPut(getKey(KeyType.HEADERS_ALL, hash), bb.array()); if (instrument) endMethod("putUpdateStoredBlock"); }
protected void putUpdateStoredBlock(StoredBlock storedBlock, boolean wasUndoable) { // We put as one record as then the get is much faster. if (instrument) beginMethod("putUpdateStoredBlock"); Sha256Hash hash = storedBlock.getHeader().getHash(); ByteBuffer bb = ByteBuffer.allocate(97); storedBlock.serializeCompact(bb); bb.put((byte) (wasUndoable ? 1 : 0)); batchPut(getKey(KeyType.HEADERS_ALL, hash), bb.array()); if (instrument) endMethod("putUpdateStoredBlock"); }
protected void putUpdateStoredBlock(StoredBlock storedBlock, boolean wasUndoable) { // We put as one record as then the get is much faster. if (instrument) beginMethod("putUpdateStoredBlock"); Sha256Hash hash = storedBlock.getHeader().getHash(); ByteBuffer bb = ByteBuffer.allocate(97); storedBlock.serializeCompact(bb); bb.put((byte) (wasUndoable ? 1 : 0)); batchPut(getKey(KeyType.HEADERS_ALL, hash), bb.array()); if (instrument) endMethod("putUpdateStoredBlock"); }
uncommitedDeletes = null; if (instrument) beginMethod("commitDatabaseBatchWrite");
@Override public void setChainHead(StoredBlock chainHead) throws BlockStoreException { if (instrument) beginMethod("setChainHead"); Sha256Hash hash = chainHead.getHeader().getHash(); this.chainHeadHash = hash; this.chainHeadBlock = chainHead; batchPut(getKey(KeyType.CHAIN_HEAD_SETTING), hash.getBytes()); if (instrument) endMethod("setChainHead"); }
@Override public void setChainHead(StoredBlock chainHead) throws BlockStoreException { if (instrument) beginMethod("setChainHead"); Sha256Hash hash = chainHead.getHeader().getHash(); this.chainHeadHash = hash; this.chainHeadBlock = chainHead; batchPut(getKey(KeyType.CHAIN_HEAD_SETTING), hash.getBytes()); if (instrument) endMethod("setChainHead"); }
@Override public void setChainHead(StoredBlock chainHead) throws BlockStoreException { if (instrument) beginMethod("setChainHead"); Sha256Hash hash = chainHead.getHeader().getHash(); this.chainHeadHash = hash; this.chainHeadBlock = chainHead; batchPut(getKey(KeyType.CHAIN_HEAD_SETTING), hash.getBytes()); if (instrument) endMethod("setChainHead"); }
@Override public void setChainHead(StoredBlock chainHead) throws BlockStoreException { if (instrument) beginMethod("setChainHead"); Sha256Hash hash = chainHead.getHeader().getHash(); this.chainHeadHash = hash; this.chainHeadBlock = chainHead; batchPut(getKey(KeyType.CHAIN_HEAD_SETTING), hash.getBytes()); if (instrument) endMethod("setChainHead"); }
public StoredBlock get(Sha256Hash hash, boolean wasUndoableOnly) throws BlockStoreException { // Optimize for chain head if (chainHeadHash != null && chainHeadHash.equals(hash)) return chainHeadBlock; if (verifiedChainHeadHash != null && verifiedChainHeadHash.equals(hash)) return verifiedChainHeadBlock; if (instrument) beginMethod("get");// ignore optimised case as not interesting for // tuning. boolean undoableResult; byte[] result = batchGet(getKey(KeyType.HEADERS_ALL, hash)); if (result == null) { if (instrument) endMethod("get"); return null; } undoableResult = (result[96] == 1 ? true : false); if (wasUndoableOnly && !undoableResult) { if (instrument) endMethod("get"); return null; } // TODO Should I chop the last byte off? Seems to work with it left // there... StoredBlock stored = StoredBlock.deserializeCompact(params, ByteBuffer.wrap(result)); stored.getHeader().verifyHeader(); if (instrument) endMethod("get"); return stored; }
public StoredBlock get(Sha256Hash hash, boolean wasUndoableOnly) throws BlockStoreException { // Optimize for chain head if (chainHeadHash != null && chainHeadHash.equals(hash)) return chainHeadBlock; if (verifiedChainHeadHash != null && verifiedChainHeadHash.equals(hash)) return verifiedChainHeadBlock; if (instrument) beginMethod("get");// ignore optimised case as not interesting for // tuning. boolean undoableResult; byte[] result = batchGet(getKey(KeyType.HEADERS_ALL, hash)); if (result == null) { if (instrument) endMethod("get"); return null; } undoableResult = (result[96] == 1 ? true : false); if (wasUndoableOnly && !undoableResult) { if (instrument) endMethod("get"); return null; } // TODO Should I chop the last byte off? Seems to work with it left // there... StoredBlock stored = StoredBlock.deserializeCompact(params, ByteBuffer.wrap(result)); stored.getHeader().verifyHeader(); if (instrument) endMethod("get"); return stored; }
public StoredBlock get(Sha256Hash hash, boolean wasUndoableOnly) throws BlockStoreException { // Optimize for chain head if (chainHeadHash != null && chainHeadHash.equals(hash)) return chainHeadBlock; if (verifiedChainHeadHash != null && verifiedChainHeadHash.equals(hash)) return verifiedChainHeadBlock; if (instrument) beginMethod("get");// ignore optimised case as not interesting for // tuning. boolean undoableResult; byte[] result = batchGet(getKey(KeyType.HEADERS_ALL, hash)); if (result == null) { if (instrument) endMethod("get"); return null; } undoableResult = (result[96] == 1 ? true : false); if (wasUndoableOnly && !undoableResult) { if (instrument) endMethod("get"); return null; } // TODO Should I chop the last byte off? Seems to work with it left // there... StoredBlock stored = StoredBlock.deserializeCompact(params, ByteBuffer.wrap(result)); stored.getHeader().verifyHeader(); if (instrument) endMethod("get"); return stored; }
@Override public void setVerifiedChainHead(StoredBlock chainHead) throws BlockStoreException { if (instrument) beginMethod("setVerifiedChainHead"); Sha256Hash hash = chainHead.getHeader().getHash(); this.verifiedChainHeadHash = hash; this.verifiedChainHeadBlock = chainHead; batchPut(getKey(KeyType.VERIFIED_CHAIN_HEAD_SETTING), hash.getBytes()); if (this.chainHeadBlock.getHeight() < chainHead.getHeight()) setChainHead(chainHead); removeUndoableBlocksWhereHeightIsLessThan(chainHead.getHeight() - fullStoreDepth); if (instrument) endMethod("setVerifiedChainHead"); }
@Override public void setVerifiedChainHead(StoredBlock chainHead) throws BlockStoreException { if (instrument) beginMethod("setVerifiedChainHead"); Sha256Hash hash = chainHead.getHeader().getHash(); this.verifiedChainHeadHash = hash; this.verifiedChainHeadBlock = chainHead; batchPut(getKey(KeyType.VERIFIED_CHAIN_HEAD_SETTING), hash.getBytes()); if (this.chainHeadBlock.getHeight() < chainHead.getHeight()) setChainHead(chainHead); removeUndoableBlocksWhereHeightIsLessThan(chainHead.getHeight() - fullStoreDepth); if (instrument) endMethod("setVerifiedChainHead"); }
@Override public void setVerifiedChainHead(StoredBlock chainHead) throws BlockStoreException { if (instrument) beginMethod("setVerifiedChainHead"); Sha256Hash hash = chainHead.getHeader().getHash(); this.verifiedChainHeadHash = hash; this.verifiedChainHeadBlock = chainHead; batchPut(getKey(KeyType.VERIFIED_CHAIN_HEAD_SETTING), hash.getBytes()); if (this.chainHeadBlock.getHeight() < chainHead.getHeight()) setChainHead(chainHead); removeUndoableBlocksWhereHeightIsLessThan(chainHead.getHeight() - fullStoreDepth); if (instrument) endMethod("setVerifiedChainHead"); }
@Override public void setVerifiedChainHead(StoredBlock chainHead) throws BlockStoreException { if (instrument) beginMethod("setVerifiedChainHead"); Sha256Hash hash = chainHead.getHeader().getHash(); this.verifiedChainHeadHash = hash; this.verifiedChainHeadBlock = chainHead; batchPut(getKey(KeyType.VERIFIED_CHAIN_HEAD_SETTING), hash.getBytes()); if (this.chainHeadBlock.getHeight() < chainHead.getHeight()) setChainHead(chainHead); removeUndoableBlocksWhereHeightIsLessThan(chainHead.getHeight() - fullStoreDepth); if (instrument) endMethod("setVerifiedChainHead"); }