Do not use persistNow for snapshots but requestPersistence

This avoids frequent write at dao sync and better performance.
This commit is contained in:
chimp1984 2020-10-04 13:34:28 -05:00
parent f9f33aa16d
commit d18b243322
No known key found for this signature in database
GPG key ID: 9801B4EC591F90E3
2 changed files with 9 additions and 9 deletions

View file

@ -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);
}

View file

@ -76,10 +76,10 @@ public class DaoStateStorageService extends StoreService<DaoStateStore> {
return FILE_NAME;
}
public void persistNow(DaoState daoState, LinkedList<DaoStateHash> daoStateHashChain, Runnable completeHandler) {
public void requestPersistence(DaoState daoState, LinkedList<DaoStateHash> daoStateHashChain) {
store.setDaoState(daoState);
store.setDaoStateHashChain(daoStateHashChain);
persistenceManager.persistNow(completeHandler);
persistenceManager.requestPersistence();
}
public DaoState getPersistedBsqState() {
@ -91,7 +91,9 @@ public class DaoStateStorageService extends StoreService<DaoStateStore> {
}
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 {