commit f749735f72860b2c371c5091a076e95c21af99b4 Author: Karsten Loesing karsten.loesing@gmx.net Date: Wed Aug 6 15:29:40 2014 +0200
Add explicit way to invalidate document cache.
There are two document types that are fully cached in memory for performance reasons: NodeStatus and SummaryDocument.
Before 6854b64 we initialized (or re-initialized) this cache when the user called the list() operation. That didn't seem very robust, because it was an implicit protocol the user had to follow: if they didn't call list(), but retrieve(), they would have run into an exception. And if they called list(), changed documents in the cache, did not call flushDocumentCache() but instead called list() again, all their changes would have been lost.
That's why we changed all methods in DocumentStore to initialize the cache in case that hasn't been done before.
However, and here's the bug, subsequent calls to list() wouldn't update the cache anymore, which the servlet implicitly relied on.
The fix is to add an explicit method invalidateDocumentCache() that clears all local caches. The next call to list() or any other method will re-initialize the cache.
Fixes #12797. --- src/main/java/org/torproject/onionoo/docs/DocumentStore.java | 5 +++++ src/main/java/org/torproject/onionoo/server/NodeIndexer.java | 1 + 2 files changed, 6 insertions(+)
diff --git a/src/main/java/org/torproject/onionoo/docs/DocumentStore.java b/src/main/java/org/torproject/onionoo/docs/DocumentStore.java index c4fe965..ea906ed 100644 --- a/src/main/java/org/torproject/onionoo/docs/DocumentStore.java +++ b/src/main/java/org/torproject/onionoo/docs/DocumentStore.java @@ -627,6 +627,11 @@ public class DocumentStore { } }
+ public void invalidateDocumentCache() { + this.cachedNodeStatuses = null; + this.cachedSummaryDocuments = null; + } + private void writeNodeStatuses() { File directory = this.statusDir; if (directory == null) { diff --git a/src/main/java/org/torproject/onionoo/server/NodeIndexer.java b/src/main/java/org/torproject/onionoo/server/NodeIndexer.java index 22d8608..19545ee 100644 --- a/src/main/java/org/torproject/onionoo/server/NodeIndexer.java +++ b/src/main/java/org/torproject/onionoo/server/NodeIndexer.java @@ -111,6 +111,7 @@ public class NodeIndexer implements ServletContextListener, Runnable { return; } } + documentStore.invalidateDocumentCache(); List<String> newRelaysByConsensusWeight = new ArrayList<String>(); Map<String, SummaryDocument> newRelayFingerprintSummaryLines =
tor-commits@lists.torproject.org