From d18b24332256ab8cb6be11fd37f35160a4851f33 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Sun, 4 Oct 2020 13:34:28 -0500 Subject: [PATCH] Do not use persistNow for snapshots but requestPersistence This avoids frequent write at dao sync and better performance. --- .../bisq/core/dao/state/DaoStateSnapshotService.java | 10 ++++------ .../core/dao/state/storage/DaoStateStorageService.java | 8 +++++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/bisq/core/dao/state/DaoStateSnapshotService.java b/core/src/main/java/bisq/core/dao/state/DaoStateSnapshotService.java index def504d4f7..0c0e506016 100644 --- a/core/src/main/java/bisq/core/dao/state/DaoStateSnapshotService.java +++ b/core/src/main/java/bisq/core/dao/state/DaoStateSnapshotService.java @@ -94,12 +94,10 @@ public class DaoStateSnapshotService { long ts = System.currentTimeMillis(); if (daoStateSnapshotCandidate != null) { // Serialisation happens on the userThread so we do not need to clone the data. Write to disk happens - // in a thread but does not interfere with out objects as they got already serialized when passed to the - // write thread. - daoStateStorageService.persistNow(daoStateSnapshotCandidate, - daoStateHashChainSnapshotCandidate, - () -> { - }); + // in a thread but does not interfere with our objects as they got already serialized when passed to the + // write thread. We use requestPersistence so we do not write immediately but at next scheduled interval. + // This avoids frequent write at dao sync and better performance. + daoStateStorageService.requestPersistence(daoStateSnapshotCandidate, daoStateHashChainSnapshotCandidate); log.info("Serializing snapshotCandidate for writing to Disc with height {} at height {} took {} ms", daoStateSnapshotCandidate.getChainHeight(), chainHeight, System.currentTimeMillis() - ts); } diff --git a/core/src/main/java/bisq/core/dao/state/storage/DaoStateStorageService.java b/core/src/main/java/bisq/core/dao/state/storage/DaoStateStorageService.java index fee66f7db2..ece0166da8 100644 --- a/core/src/main/java/bisq/core/dao/state/storage/DaoStateStorageService.java +++ b/core/src/main/java/bisq/core/dao/state/storage/DaoStateStorageService.java @@ -76,10 +76,10 @@ public class DaoStateStorageService extends StoreService { return FILE_NAME; } - public void persistNow(DaoState daoState, LinkedList daoStateHashChain, Runnable completeHandler) { + public void requestPersistence(DaoState daoState, LinkedList daoStateHashChain) { store.setDaoState(daoState); store.setDaoStateHashChain(daoStateHashChain); - persistenceManager.persistNow(completeHandler); + persistenceManager.requestPersistence(); } public DaoState getPersistedBsqState() { @@ -91,7 +91,9 @@ public class DaoStateStorageService extends StoreService { } public void resyncDaoStateFromGenesis(Runnable resultHandler) { - persistNow(new DaoState(), new LinkedList<>(), resultHandler); + store.setDaoState(new DaoState()); + store.setDaoStateHashChain(new LinkedList<>()); + persistenceManager.persistNow(resultHandler); } public void resyncDaoStateFromResources(File storageDir) throws IOException {