diff --git a/src/main/java/com/iota/iri/Iota.java b/src/main/java/com/iota/iri/Iota.java index ec90fcf8f8..dd24a03c0a 100644 --- a/src/main/java/com/iota/iri/Iota.java +++ b/src/main/java/com/iota/iri/Iota.java @@ -218,8 +218,7 @@ private void injectDependencies() throws SnapshotException, TransactionPruningEx ledgerService.init(tangle, snapshotProvider, snapshotService, milestoneService, spentAddressesService, bundleValidator); if (transactionPruner != null) { - transactionPruner.init(tangle, snapshotProvider, spentAddressesService, tipsViewModel, configuration) - .restoreState(); + transactionPruner.init(tangle, snapshotProvider, spentAddressesService, tipsViewModel, configuration); } transactionRequesterWorker.init(tangle, transactionRequester, tipsViewModel, node); } diff --git a/src/main/java/com/iota/iri/service/transactionpruning/TransactionPruner.java b/src/main/java/com/iota/iri/service/transactionpruning/TransactionPruner.java index ed6c62de3a..732a25c12c 100644 --- a/src/main/java/com/iota/iri/service/transactionpruning/TransactionPruner.java +++ b/src/main/java/com/iota/iri/service/transactionpruning/TransactionPruner.java @@ -30,30 +30,4 @@ public interface TransactionPruner { */ void processJobs() throws TransactionPruningException; - /** - * This method saves the current state of the {@link TransactionPruner}, so it can later be restored by - * {@link #restoreState()}. - * - * It is used to maintain the state between IRI restarts and pick up pruning where it stopped when IRI shut down. - * - * @throws TransactionPruningException if anything goes wrong while saving the current state - */ - void saveState() throws TransactionPruningException; - - /** - * Restores the state of the {@link TransactionPruner} after being saved before by {@link #saveState()}. - * - * It is used to keep the state between IRI restarts and pick up pruning where it stopped when IRI shut down. - * - * @throws TransactionPruningException if anything goes wrong while restoring the state - */ - void restoreState() throws TransactionPruningException; - - /** - * This method removes all queued jobs and resets the state of the {@link TransactionPruner}. It can for example be - * used to cleanup after tests. - * - * @throws TransactionPruningException if anything goes wrong while clearing the jobs - * */ - void clear() throws TransactionPruningException; } diff --git a/src/main/java/com/iota/iri/service/transactionpruning/async/AsyncTransactionPruner.java b/src/main/java/com/iota/iri/service/transactionpruning/async/AsyncTransactionPruner.java index dd7784b844..c0268a9f87 100644 --- a/src/main/java/com/iota/iri/service/transactionpruning/async/AsyncTransactionPruner.java +++ b/src/main/java/com/iota/iri/service/transactionpruning/async/AsyncTransactionPruner.java @@ -162,8 +162,6 @@ public void addJob(TransactionPrunerJob job) throws TransactionPruningException // this call is "unchecked" to a "raw" JobQueue and it is intended since the matching JobQueue is defined by the // registered job types getJobQueue(job.getClass()).addJob(job); - - saveState(); } /** @@ -184,65 +182,17 @@ public void processJobs() throws TransactionPruningException { } } - /** - * {@inheritDoc} - * - * We incorporate a background job that periodically saves the state rather than doing it "live", to reduce the cost - * of this operation. While this can theoretically lead to a situation where the saved state is not 100% correct and - * the latest changes get lost (if IRI crashes or gets restarted before the new changes could be persisted), the - * impact is marginal because it only leads to some floating "zombie" transactions that will stay in the database. - * This will be "solved" once we persist the changes in the database instead of a file on the hard disk. For now the - * trade off between faster processing times and leaving some garbage is reasonable. - */ - @Override - public void saveState() { - persistRequested = true; - } - - /** - * {@inheritDoc} - * - * It reads the state by parsing the state file and passing it into the registered parsers for each job type. - * - * Every line holds a job entry that starts with the fully qualified class name of the job followed by a ";" and the - * serialized representation of the job. - */ - @Override - public void restoreState() throws TransactionPruningException { - try (BufferedReader reader = new BufferedReader( - new InputStreamReader(new BufferedInputStream(new FileInputStream(getStateFile()))) - )) { - String line; - while ((line = reader.readLine()) != null) { - String[] parts = line.split(";", 2); - if (parts.length >= 2) { - JobParser jobParser = jobParsers.get(parts[0]); - if (jobParser == null) { - throw new TransactionPruningException("could not determine a parser for cleanup job of type " + parts[0]); - } - - addJob(jobParser.parse(parts[1])); - } - } - } catch (IOException e) { - if (getStateFile().exists()) { - throw new TransactionPruningException("could not read the state file", e); - } - } - } /** - * {@inheritDoc} + * This method removes all queued jobs and resets the state of the {@link TransactionPruner}. It can for example be + * used to cleanup after tests. * * It cycles through all registered {@link JobQueue}s and clears them before persisting the state. */ - @Override - public void clear() throws TransactionPruningException { + void clear() { for (JobQueue jobQueue : jobQueues.values()) { jobQueue.clear(); } - - saveStateNow(); } /** diff --git a/src/main/java/com/iota/iri/service/transactionpruning/async/MilestonePrunerJobQueue.java b/src/main/java/com/iota/iri/service/transactionpruning/async/MilestonePrunerJobQueue.java index afd741eb70..be74b0a5ff 100644 --- a/src/main/java/com/iota/iri/service/transactionpruning/async/MilestonePrunerJobQueue.java +++ b/src/main/java/com/iota/iri/service/transactionpruning/async/MilestonePrunerJobQueue.java @@ -111,21 +111,17 @@ public void clear() { public void processJobs() throws TransactionPruningException { MilestonePrunerJob currentJob; while (!Thread.currentThread().isInterrupted() && (currentJob = jobs.peek()) != null) { - try { - currentJob.process(); + currentJob.process(); - youngestFullyCleanedMilestoneIndex = currentJob.getTargetIndex(); + youngestFullyCleanedMilestoneIndex = currentJob.getTargetIndex(); - // we always leave the last job in the queue to be able to "serialize" the queue status and allow - // to skip already processed milestones even when IRI restarts - if (jobs.size() == 1) { - break; - } - - jobs.poll(); - } finally { - transactionPruner.saveState(); + // we always leave the last job in the queue to be able to "serialize" the queue status and allow + // to skip already processed milestones even when IRI restarts + if (jobs.size() == 1) { + break; } + + jobs.poll(); } } diff --git a/src/main/java/com/iota/iri/service/transactionpruning/async/SimpleJobQueue.java b/src/main/java/com/iota/iri/service/transactionpruning/async/SimpleJobQueue.java index e73ee81797..b4fe881219 100644 --- a/src/main/java/com/iota/iri/service/transactionpruning/async/SimpleJobQueue.java +++ b/src/main/java/com/iota/iri/service/transactionpruning/async/SimpleJobQueue.java @@ -88,8 +88,6 @@ public void processJobs() throws TransactionPruningException { } throw e; - } finally { - transactionPruner.saveState(); } } } diff --git a/src/main/java/com/iota/iri/service/transactionpruning/jobs/MilestonePrunerJob.java b/src/main/java/com/iota/iri/service/transactionpruning/jobs/MilestonePrunerJob.java index b795a3de83..b182cc37c9 100644 --- a/src/main/java/com/iota/iri/service/transactionpruning/jobs/MilestonePrunerJob.java +++ b/src/main/java/com/iota/iri/service/transactionpruning/jobs/MilestonePrunerJob.java @@ -131,8 +131,6 @@ public void process() throws TransactionPruningException { setStatus(TransactionPrunerJobStatus.DONE); } } - - getTransactionPruner().saveState(); } } catch (TransactionPruningException e) { setStatus(TransactionPrunerJobStatus.FAILED);