Skip to content

Commit

Permalink
Fix GC issue (sirixdb#607)
Browse files Browse the repository at this point in the history
* Fix GC issue

* Disable tests and delete everything during setup

* Fix bug regarding concurrent/parallel access.

* Update build.gradle

---------

Co-authored-by: Johannes Lichtenberger <[email protected]>
  • Loading branch information
JohannesLichtenberger and Johannes Lichtenberger authored Apr 24, 2023
1 parent 0049706 commit 5d49a46
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ public LocalDatabase(final TransactionManager transactionManager, final Database

private void addResourceToBufferManagerMapping(Path resourceFile, ResourceConfiguration resourceConfig) {
if (resourceConfig.getStorageType() == StorageType.MEMORY_MAPPED) {
bufferManagers.put(resourceFile, new BufferManagerImpl(100, 10_000_000, 100_000, 50_000_000, 1_000, 20));
bufferManagers.put(resourceFile, new BufferManagerImpl(100, 1_000, 5_000, 50_000, 500, 20));
} else {
bufferManagers.put(resourceFile, new BufferManagerImpl(50_000, 10_000_000, 100_000, 50_000_000, 1_000, 20));
bufferManagers.put(resourceFile, new BufferManagerImpl(500, 1_000, 5_000, 50_000, 500, 20));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ void assertNotClosed() {
}
}

@SuppressWarnings("unchecked")
@Override
public <V extends DataRecord> V getRecord(final long recordKey, @NonNull final IndexType indexType,
@NonNegative final int index) {
Expand Down Expand Up @@ -571,7 +570,6 @@ PageReference getLeafPageReference(final PageReference pageReferenceToSubtree, f
* @return dereferenced pages
* @throws SirixIOException if an I/O-error occurs within the creation process
*/
@SuppressWarnings("unchecked")
List<KeyValuePage<DataRecord>> getPageFragments(final PageReference pageReference) {
assert pageReference != null;
final ResourceConfiguration config = resourceSession.getResourceConfig();
Expand Down Expand Up @@ -618,7 +616,6 @@ private List<KeyValuePage<DataRecord>> getPreviousPageFragments(final List<PageF
.collect(Collectors.toList());
}

@SuppressWarnings("unchecked")
private CompletableFuture<KeyValuePage<DataRecord>> readPage(final PageFragmentKey pageFragmentKey) {
final var pageReference = new PageReference().setKey(pageFragmentKey.key());
if (trxIntentLog == null) {
Expand All @@ -629,7 +626,6 @@ private CompletableFuture<KeyValuePage<DataRecord>> readPage(final PageFragmentK
}
}
final var pageReadOnlyTrx = resourceSession.beginPageReadOnlyTrx(pageFragmentKey.revision());
//noinspection unchecked
return (CompletableFuture<KeyValuePage<DataRecord>>) pageReadOnlyTrx.getReader()
.readAsync(pageReference, pageReadOnlyTrx)
.whenComplete((page, exception) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ public <V extends DataRecord> V getRecord(final long recordKey, @NonNull final I
if (node == null) {
node = pageRtx.getValue(((KeyValueLeafPage) pageCont.getComplete()), recordKey);
}
//noinspection unchecked
return (V) pageRtx.checkItemIfDeleted(node);
}
}
Expand Down
3 changes: 3 additions & 0 deletions bundles/sirix-core/src/main/java/org/sirix/cache/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package org.sirix.cache;

import com.github.benmanes.caffeine.cache.Scheduler;
import org.checkerframework.checker.nullness.qual.NonNull;

import java.util.Map;
Expand All @@ -37,6 +38,8 @@
* @param <V> the value
*/
public interface Cache<K, V> {
Scheduler scheduler = Scheduler.systemScheduler();

/**
* Clearing the cache. That is removing all elements.
*/
Expand Down
44 changes: 24 additions & 20 deletions bundles/sirix-core/src/main/java/org/sirix/cache/IndexLogKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
* @author Johannes Lichtenberger
*/
public final class IndexLogKey {
private final IndexType indexType;
private final long recordPageKey;
private final @NonNegative int indexNumber;
private final @NonNegative int revisionNumber;
private IndexType indexType;
private long recordPageKey;
private @NonNegative int indexNumber;
private @NonNegative int revisionNumber;

public IndexLogKey(IndexType indexType, long recordPageKey, @NonNegative int indexNumber,
@NonNegative int revisionNumber) {
Expand All @@ -22,6 +22,26 @@ public IndexLogKey(IndexType indexType, long recordPageKey, @NonNegative int ind
this.revisionNumber = revisionNumber;
}

public IndexLogKey setIndexType(IndexType indexType) {
this.indexType = indexType;
return this;
}

public IndexLogKey setRecordPageKey(long recordPageKey) {
this.recordPageKey = recordPageKey;
return this;
}

public IndexLogKey setIndexNumber(int indexNumber) {
this.indexNumber = indexNumber;
return this;
}

public IndexLogKey setRevisionNumber(int revisionNumber) {
this.revisionNumber = revisionNumber;
return this;
}

private int hash;

@Override
Expand All @@ -48,22 +68,6 @@ public int getRevisionNumber() {
return revisionNumber;
}

public IndexType indexType() {
return indexType;
}

public long recordPageKey() {
return recordPageKey;
}

public @NonNegative int indexNumber() {
return indexNumber;
}

public @NonNegative int revisionNumber() {
return revisionNumber;
}

@Override
public boolean equals(Object obj) {
if (obj == this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
import java.util.Map;
import java.util.concurrent.TimeUnit;

public class NamesCache implements Cache<NamesCacheKey, Names> {
public final class NamesCache implements Cache<NamesCacheKey, Names> {

private final com.github.benmanes.caffeine.cache.Cache<NamesCacheKey, Names> cache;

public NamesCache(final int maxSize) {
cache = Caffeine.newBuilder()
.maximumSize(maxSize)
.expireAfterAccess(5, TimeUnit.MINUTES)
.scheduler(scheduler)
.build();
}

Expand Down
14 changes: 11 additions & 3 deletions bundles/sirix-core/src/main/java/org/sirix/cache/PageCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,24 @@
import org.sirix.page.interfaces.Page;

import java.util.Map;
import java.util.concurrent.TimeUnit;

public final class PageCache implements Cache<PageReference, Page> {

private final com.github.benmanes.caffeine.cache.Cache<PageReference, Page> pageCache;

public PageCache(final int maxSize) {
RemovalListener<PageReference, Page> removalListener =
(PageReference key, Page value, RemovalCause cause) -> key.setPage(null);
RemovalListener<PageReference, Page> removalListener = (PageReference key, Page value, RemovalCause cause) -> {
key.setPage(null);
// if (value instanceof KeyValueLeafPage keyValueLeafPage) {
// keyValueLeafPage.clearPage();
// }
};

pageCache = Caffeine.newBuilder()
.maximumSize(maxSize)
.expireAfterAccess(5, TimeUnit.MINUTES)
.scheduler(scheduler)
.removalListener(removalListener)
.build();
}
Expand Down Expand Up @@ -58,5 +65,6 @@ public void remove(PageReference key) {
}

@Override
public void close() {}
public void close() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.benmanes.caffeine.cache.Caffeine;

import java.util.Map;
import java.util.concurrent.TimeUnit;

public class PathSummaryCache implements Cache<Integer, PathSummaryData> {

Expand All @@ -11,6 +12,7 @@ public class PathSummaryCache implements Cache<Integer, PathSummaryData> {
public PathSummaryCache(final int maxSize) {
cache = Caffeine.newBuilder()
.maximumSize(maxSize)
.expireAfterAccess(5, TimeUnit.MINUTES)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ public final class RecordPageCache implements Cache<PageReference, Page> {
private final com.github.benmanes.caffeine.cache.Cache<PageReference, Page> pageCache;

public RecordPageCache(final int maxSize) {
final RemovalListener<PageReference, Page> removalListener = (PageReference key, Page value, RemovalCause cause) -> {
assert key != null;
key.setPage(null);
};
final RemovalListener<PageReference, Page> removalListener =
(PageReference key, Page value, RemovalCause cause) -> {
key.setPage(null);
// if (value instanceof KeyValueLeafPage keyValueLeafPage) {
// keyValueLeafPage.clearPage();
// }
};

pageCache = Caffeine.newBuilder()
.maximumSize(maxSize)
.expireAfterWrite(15, TimeUnit.SECONDS)
.expireAfterAccess(15, TimeUnit.SECONDS)
.expireAfterAccess(5, TimeUnit.MINUTES)
.scheduler(scheduler)
.removalListener(removalListener)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public RedBlackTreeNodeCache(final int maxSize) {
}
};

cache = Caffeine.newBuilder().maximumSize(maxSize).removalListener(removalListener).build();
cache = Caffeine.newBuilder().maximumSize(maxSize).removalListener(removalListener).scheduler(scheduler).build();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
*/
package org.sirix.cache;

import com.github.benmanes.caffeine.cache.Caffeine;
import org.sirix.page.RevisionRootPage;

import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.sirix.page.RevisionRootPage;
import com.github.benmanes.caffeine.cache.Caffeine;

/**
* @author Johannes Lichtenberger <a href="mailto:[email protected]">mail</a>
Expand All @@ -42,8 +43,8 @@ public final class RevisionRootPageCache implements Cache<Integer, RevisionRootP
public RevisionRootPageCache(final int maxSize) {
pageCache = Caffeine.newBuilder()
.maximumSize(maxSize)
.expireAfterWrite(30, TimeUnit.SECONDS)
.expireAfterAccess(30, TimeUnit.SECONDS)
.expireAfterAccess(5, TimeUnit.MINUTES)
.scheduler(scheduler)
.build();
}

Expand Down Expand Up @@ -83,5 +84,6 @@ public void remove(Integer key) {
}

@Override
public void close() {}
public void close() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
public final class PageReference {

/** In-memory deserialized page instance. */
private Page page;
private volatile Page page;

/** Key in persistent storage. */
private long key = Constants.NULL_ID_LONG;
Expand Down
2 changes: 1 addition & 1 deletion libraries.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ implLibraries = [
guavaTestlib : 'com.google.guava:guava-testlib:31.0.1-jre',
checkerFramework : 'org.checkerframework:checker:3.21.2',
brackit : 'io.sirix:brackit:0.3-SNAPSHOT',
caffeine : 'com.github.ben-manes.caffeine:caffeine:2.8.1',
caffeine : 'com.github.ben-manes.caffeine:caffeine:3.1.6',
snappyJava : 'org.xerial.snappy:snappy-java:1.1.8.4',
lz4 : 'org.lz4:lz4-java:1.8.0',
browniesCollections : 'org.magicwerk:brownies-collections:0.9.14',
Expand Down

0 comments on commit 5d49a46

Please sign in to comment.