You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2024/06/19 17:06:53 UTC
(couchdb) branch nouveau-lru-max created (now 6f9fe27c8)
This is an automated email from the ASF dual-hosted git repository.
rnewson pushed a change to branch nouveau-lru-max
in repository https://gitbox.apache.org/repos/asf/couchdb.git
at 6f9fe27c8 close oldest indexes before opening new if over capacity
This branch includes the following new commits:
new 6f9fe27c8 close oldest indexes before opening new if over capacity
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(couchdb) 01/01: close oldest indexes before opening new if over capacity
Posted by rn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rnewson pushed a commit to branch nouveau-lru-max
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 6f9fe27c84678968589af2d07175ddc2f5c0620f
Author: Robert Newson <Ro...@ibm.com>
AuthorDate: Wed Jun 19 17:49:41 2024 +0100
close oldest indexes before opening new if over capacity
---
.../apache/couchdb/nouveau/core/IndexManager.java | 38 ++++++++++------------
1 file changed, 18 insertions(+), 20 deletions(-)
diff --git a/nouveau/src/main/java/org/apache/couchdb/nouveau/core/IndexManager.java b/nouveau/src/main/java/org/apache/couchdb/nouveau/core/IndexManager.java
index 481572f3f..a3a2cdcfc 100644
--- a/nouveau/src/main/java/org/apache/couchdb/nouveau/core/IndexManager.java
+++ b/nouveau/src/main/java/org/apache/couchdb/nouveau/core/IndexManager.java
@@ -56,28 +56,8 @@ public final class IndexManager implements Managed {
private class LRUMap extends LinkedHashMap<String, IndexHolder> {
- private int capacity;
-
private LRUMap(final int capacity) {
super(capacity, 0.75f, true);
- this.capacity = capacity;
- }
-
- @Override
- protected boolean removeEldestEntry(final java.util.Map.Entry<String, IndexHolder> eldest) {
- if (size() > capacity) {
- schedulerExecutorService.execute(() -> {
- try {
- unload(eldest.getKey(), false);
- } catch (final InterruptedException e) {
- Thread.currentThread().interrupt();
- LOGGER.warn("Interrupted while evicting eldest entry {}", eldest.getKey(), e);
- } catch (final IOException e) {
- LOGGER.warn("I/O exception while evicting eldest entry {}", eldest.getKey(), e);
- }
- });
- }
- return false;
}
}
@@ -124,11 +104,14 @@ public final class IndexManager implements Managed {
public <R> R with(final String name, final IndexFunction<Index, R> indexFun)
throws IOException, InterruptedException {
+ evictIfOverCapacity();
+
retry:
while (true) {
if (!exists(name)) {
throw new WebApplicationException("Index does not exist", Status.NOT_FOUND);
}
+
final IndexHolder holder;
synchronized (cache) {
holder = cache.computeIfAbsent(name, (k) -> new IndexHolder());
@@ -172,6 +155,21 @@ public final class IndexManager implements Managed {
}
}
+ private void evictIfOverCapacity() throws IOException, InterruptedException {
+ while (true) {
+ final String candidate;
+ synchronized (cache) {
+ candidate = cache.size() > maxIndexesOpen
+ ? cache.entrySet().iterator().next().getKey()
+ : null;
+ }
+ if (candidate == null) {
+ return;
+ }
+ unload(candidate, false);
+ }
+ }
+
public void unload(final String name, final boolean forceDelete) throws IOException, InterruptedException {
final IndexHolder holder;
synchronized (cache) {