Skip to content

Commit

Permalink
Merge pull request #5088 from apache/decaffeinated
Browse files Browse the repository at this point in the history
Use our own logic for index management
  • Loading branch information
rnewson committed Jun 18, 2024
2 parents f9afe9f + 930c6c4 commit 3dee4e7
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 183 deletions.
1 change: 0 additions & 1 deletion nouveau/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ dependencies {
implementation 'io.dropwizard:dropwizard-core'
implementation 'io.dropwizard:dropwizard-http2'
implementation 'io.dropwizard.metrics:metrics-core'
implementation 'io.dropwizard.metrics:metrics-caffeine'
implementation 'io.dropwizard.metrics:metrics-jersey2'
testImplementation 'io.dropwizard:dropwizard-testing'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

package org.apache.couchdb.nouveau;

import com.github.benmanes.caffeine.cache.Scheduler;
import io.dropwizard.core.Application;
import io.dropwizard.core.setup.Environment;
import io.swagger.v3.jaxrs2.integration.resources.OpenApiResource;
Expand Down Expand Up @@ -54,13 +53,12 @@ public void run(NouveauApplicationConfiguration configuration, Environment envir
indexManager.setCommitIntervalSeconds(configuration.getCommitIntervalSeconds());
indexManager.setIdleSeconds(configuration.getIdleSeconds());
indexManager.setMaxIndexesOpen(configuration.getMaxIndexesOpen());
indexManager.setMetricRegistry(environment.metrics());
final ScheduledExecutorService schedulerExecutorService = environment
.lifecycle()
.scheduledExecutorService("index-manager-%d")
.threads(configuration.getSchedulerThreadCount())
.build();
indexManager.setScheduler(Scheduler.forScheduledExecutorService(schedulerExecutorService));
indexManager.setScheduledExecutorService(schedulerExecutorService);
indexManager.setSearcherFactory(new ParallelSearcherFactory(ForkJoinPool.commonPool()));
indexManager.setObjectMapper(environment.getObjectMapper());
indexManager.setRootDir(configuration.getRootDir());
Expand Down
17 changes: 0 additions & 17 deletions nouveau/src/main/java/org/apache/couchdb/nouveau/core/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import jakarta.ws.rs.core.Response.Status;
import java.io.Closeable;
import java.io.IOException;
import java.util.concurrent.Semaphore;
import org.apache.couchdb.nouveau.api.DocumentDeleteRequest;
import org.apache.couchdb.nouveau.api.DocumentUpdateRequest;
import org.apache.couchdb.nouveau.api.IndexInfo;
Expand All @@ -39,21 +38,12 @@ public abstract class Index implements Closeable {
private long updateSeq;
private long purgeSeq;
private boolean deleteOnClose = false;
private final Semaphore semaphore = new Semaphore(Integer.MAX_VALUE);

protected Index(final long updateSeq, final long purgeSeq) {
this.updateSeq = updateSeq;
this.purgeSeq = purgeSeq;
}

public final boolean tryAcquire() {
return semaphore.tryAcquire();
}

public final void release() {
semaphore.release();
}

public final IndexInfo info() throws IOException {
final int numDocs = doNumDocs();
final long diskSize = doDiskSize();
Expand Down Expand Up @@ -130,10 +120,7 @@ public final synchronized void setPurgeSeq(final long matchSeq, final long purge

@Override
public final void close() throws IOException {
// Ensures exclusive access to the index before closing.
semaphore.acquireUninterruptibly(Integer.MAX_VALUE);
doClose();
// Never release semaphore.
}

protected abstract void doClose() throws IOException;
Expand All @@ -146,10 +133,6 @@ public synchronized void setDeleteOnClose(final boolean deleteOnClose) {
this.deleteOnClose = deleteOnClose;
}

public final boolean isActive() {
return semaphore.availablePermits() < Integer.MAX_VALUE || semaphore.hasQueuedThreads();
}

protected final void assertUpdateSeqProgress(final long matchSeq, final long updateSeq)
throws UpdatesOutOfOrderException {
assert Thread.holdsLock(this);
Expand Down
Loading

0 comments on commit 3dee4e7

Please sign in to comment.