Use new netty resource leak detector

This commit is contained in:
Andrea Cavalli 2021-10-16 16:56:10 +02:00
parent 06f3889b3f
commit 3a591c38f2
16 changed files with 39 additions and 99 deletions

View File

@ -2,17 +2,11 @@ package it.cavallium.dbengine.client;
import io.net5.buffer.api.Drop; import io.net5.buffer.api.Drop;
import io.net5.buffer.api.Owned; import io.net5.buffer.api.Owned;
import io.net5.buffer.api.internal.ResourceSupport;
import it.cavallium.dbengine.client.query.current.data.TotalHitsCount; import it.cavallium.dbengine.client.query.current.data.TotalHitsCount;
import it.cavallium.dbengine.database.LLSearchResultShard; import it.cavallium.dbengine.database.DatabaseResourceSupport;
import it.cavallium.dbengine.database.LiveResourceSupport;
import java.util.Objects;
import org.warp.commonutils.log.Logger;
import org.warp.commonutils.log.LoggerFactory;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
public final class SearchResult<T, U> extends LiveResourceSupport<SearchResult<T, U>, SearchResult<T, U>> { public final class SearchResult<T, U> extends DatabaseResourceSupport<SearchResult<T, U>, SearchResult<T, U>> {
private static final Drop<SearchResult<?, ?>> DROP = new Drop<>() { private static final Drop<SearchResult<?, ?>> DROP = new Drop<>() {
@Override @Override

View File

@ -3,14 +3,14 @@ package it.cavallium.dbengine.client;
import io.net5.buffer.api.Drop; import io.net5.buffer.api.Drop;
import io.net5.buffer.api.Owned; import io.net5.buffer.api.Owned;
import it.cavallium.dbengine.client.query.current.data.TotalHitsCount; import it.cavallium.dbengine.client.query.current.data.TotalHitsCount;
import it.cavallium.dbengine.database.LiveResourceSupport; import it.cavallium.dbengine.database.DatabaseResourceSupport;
import it.cavallium.dbengine.database.collections.ValueGetter; import it.cavallium.dbengine.database.collections.ValueGetter;
import org.warp.commonutils.log.Logger; import org.warp.commonutils.log.Logger;
import org.warp.commonutils.log.LoggerFactory; import org.warp.commonutils.log.LoggerFactory;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public final class SearchResultKeys<T> extends LiveResourceSupport<SearchResultKeys<T>, SearchResultKeys<T>> { public final class SearchResultKeys<T> extends DatabaseResourceSupport<SearchResultKeys<T>, SearchResultKeys<T>> {
private static final Logger logger = LoggerFactory.getLogger(SearchResultKeys.class); private static final Logger logger = LoggerFactory.getLogger(SearchResultKeys.class);

View File

@ -0,0 +1,14 @@
package it.cavallium.dbengine.database;
import io.net5.buffer.api.Drop;
import io.net5.buffer.api.Resource;
import io.net5.buffer.api.internal.ResourceSupport;
public abstract class DatabaseResourceSupport<I extends Resource<I>, T extends DatabaseResourceSupport<I, T>>
extends ResourceSupport<I, T> {
protected DatabaseResourceSupport(Drop<T> drop) {
super(drop);
}
}

View File

@ -4,14 +4,12 @@ import io.net5.buffer.api.Buffer;
import io.net5.buffer.api.Drop; import io.net5.buffer.api.Drop;
import io.net5.buffer.api.Owned; import io.net5.buffer.api.Owned;
import io.net5.buffer.api.Send; import io.net5.buffer.api.Send;
import io.net5.buffer.api.internal.ResourceSupport;
import it.cavallium.dbengine.client.SearchResultKeys;
import java.util.StringJoiner; import java.util.StringJoiner;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.warp.commonutils.log.Logger; import org.warp.commonutils.log.Logger;
import org.warp.commonutils.log.LoggerFactory; import org.warp.commonutils.log.LoggerFactory;
public class LLDelta extends LiveResourceSupport<LLDelta, LLDelta> { public class LLDelta extends DatabaseResourceSupport<LLDelta, LLDelta> {
private static final Logger logger = LoggerFactory.getLogger(LLDelta.class); private static final Logger logger = LoggerFactory.getLogger(LLDelta.class);

View File

@ -4,7 +4,6 @@ import io.net5.buffer.api.Buffer;
import io.net5.buffer.api.Drop; import io.net5.buffer.api.Drop;
import io.net5.buffer.api.Owned; import io.net5.buffer.api.Owned;
import io.net5.buffer.api.Send; import io.net5.buffer.api.Send;
import io.net5.buffer.api.internal.ResourceSupport;
import java.util.Objects; import java.util.Objects;
import java.util.StringJoiner; import java.util.StringJoiner;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -12,7 +11,7 @@ import org.jetbrains.annotations.Nullable;
import org.warp.commonutils.log.Logger; import org.warp.commonutils.log.Logger;
import org.warp.commonutils.log.LoggerFactory; import org.warp.commonutils.log.LoggerFactory;
public class LLEntry extends LiveResourceSupport<LLEntry, LLEntry> { public class LLEntry extends DatabaseResourceSupport<LLEntry, LLEntry> {
private static final Logger logger = LoggerFactory.getLogger(LLEntry.class); private static final Logger logger = LoggerFactory.getLogger(LLEntry.class);

View File

@ -6,7 +6,6 @@ import io.net5.buffer.api.Buffer;
import io.net5.buffer.api.Drop; import io.net5.buffer.api.Drop;
import io.net5.buffer.api.Owned; import io.net5.buffer.api.Owned;
import io.net5.buffer.api.Send; import io.net5.buffer.api.Send;
import io.net5.buffer.api.internal.ResourceSupport;
import java.util.StringJoiner; import java.util.StringJoiner;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.warp.commonutils.log.Logger; import org.warp.commonutils.log.Logger;
@ -15,7 +14,7 @@ import org.warp.commonutils.log.LoggerFactory;
/** /**
* Range of data, from min (inclusive),to max (exclusive) * Range of data, from min (inclusive),to max (exclusive)
*/ */
public class LLRange extends LiveResourceSupport<LLRange, LLRange> { public class LLRange extends DatabaseResourceSupport<LLRange, LLRange> {
private static final Logger logger = LoggerFactory.getLogger(LLRange.class); private static final Logger logger = LoggerFactory.getLogger(LLRange.class);

View File

@ -2,14 +2,13 @@ package it.cavallium.dbengine.database;
import io.net5.buffer.api.Drop; import io.net5.buffer.api.Drop;
import io.net5.buffer.api.Owned; import io.net5.buffer.api.Owned;
import io.net5.buffer.api.internal.ResourceSupport;
import it.cavallium.dbengine.client.query.current.data.TotalHitsCount; import it.cavallium.dbengine.client.query.current.data.TotalHitsCount;
import java.util.Objects; import java.util.Objects;
import org.warp.commonutils.log.Logger; import org.warp.commonutils.log.Logger;
import org.warp.commonutils.log.LoggerFactory; import org.warp.commonutils.log.LoggerFactory;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
public final class LLSearchResultShard extends LiveResourceSupport<LLSearchResultShard, LLSearchResultShard> { public final class LLSearchResultShard extends DatabaseResourceSupport<LLSearchResultShard, LLSearchResultShard> {
private static final Logger logger = LoggerFactory.getLogger(LLSearchResultShard.class); private static final Logger logger = LoggerFactory.getLogger(LLSearchResultShard.class);

View File

@ -1,32 +0,0 @@
package it.cavallium.dbengine.database;
import io.net5.buffer.api.Drop;
import io.net5.buffer.api.Owned;
import io.net5.buffer.api.Resource;
import io.net5.buffer.api.internal.LifecycleTracer;
import io.net5.buffer.api.internal.ResourceSupport;
import org.warp.commonutils.log.Logger;
import org.warp.commonutils.log.LoggerFactory;
public abstract class LiveResourceSupport<I extends Resource<I>, T extends LiveResourceSupport<I, T>> extends ResourceSupport<I, T> {
private static final Logger logger = LoggerFactory.getLogger(LiveResourceSupport.class);
protected LiveResourceSupport(Drop<T> drop) {
super(drop);
}
@Override
protected void finalize() throws Throwable {
if (this.isAccessible()) {
var ise = new IllegalStateException("Resource not released");
ise.setStackTrace(new StackTraceElement[0]);
logger.error("Resource not released: {}", this, attachTrace(ise));
try {
this.close();
} catch (Throwable ignored) {
}
}
super.finalize();
}
}

View File

@ -6,17 +6,14 @@ import io.net5.buffer.api.Drop;
import io.net5.buffer.api.Owned; import io.net5.buffer.api.Owned;
import io.net5.buffer.api.Resource; import io.net5.buffer.api.Resource;
import io.net5.buffer.api.Send; import io.net5.buffer.api.Send;
import io.net5.buffer.api.internal.ResourceSupport;
import io.net5.util.IllegalReferenceCountException;
import it.cavallium.dbengine.client.BadBlock; import it.cavallium.dbengine.client.BadBlock;
import it.cavallium.dbengine.client.CompositeSnapshot; import it.cavallium.dbengine.client.CompositeSnapshot;
import it.cavallium.dbengine.database.LLDictionary; import it.cavallium.dbengine.database.LLDictionary;
import it.cavallium.dbengine.database.LLDictionaryResultType; import it.cavallium.dbengine.database.LLDictionaryResultType;
import it.cavallium.dbengine.database.LLEntry;
import it.cavallium.dbengine.database.LLRange; import it.cavallium.dbengine.database.LLRange;
import it.cavallium.dbengine.database.LLSnapshot; import it.cavallium.dbengine.database.LLSnapshot;
import it.cavallium.dbengine.database.LLUtils; import it.cavallium.dbengine.database.LLUtils;
import it.cavallium.dbengine.database.LiveResourceSupport; import it.cavallium.dbengine.database.DatabaseResourceSupport;
import it.cavallium.dbengine.database.UpdateMode; import it.cavallium.dbengine.database.UpdateMode;
import it.cavallium.dbengine.database.serialization.SerializationException; import it.cavallium.dbengine.database.serialization.SerializationException;
import it.cavallium.dbengine.database.serialization.SerializerFixedBinaryLength; import it.cavallium.dbengine.database.serialization.SerializerFixedBinaryLength;
@ -31,8 +28,7 @@ import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
// todo: implement optimized methods (which?) // todo: implement optimized methods (which?)
public class DatabaseMapDictionaryDeep<T, U, US extends DatabaseStage<U>> extends public class DatabaseMapDictionaryDeep<T, U, US extends DatabaseStage<U>> extends DatabaseResourceSupport<DatabaseStage<Map<T, U>>, DatabaseMapDictionaryDeep<T, U, US>>
LiveResourceSupport<DatabaseStage<Map<T, U>>, DatabaseMapDictionaryDeep<T, U, US>>
implements DatabaseStageMap<T, U, US> { implements DatabaseStageMap<T, U, US> {
private static final Logger logger = LoggerFactory.getLogger(DatabaseMapDictionaryDeep.class); private static final Logger logger = LoggerFactory.getLogger(DatabaseMapDictionaryDeep.class);

View File

@ -9,9 +9,8 @@ import io.net5.buffer.api.Send;
import it.cavallium.dbengine.client.BadBlock; import it.cavallium.dbengine.client.BadBlock;
import it.cavallium.dbengine.client.CompositeSnapshot; import it.cavallium.dbengine.client.CompositeSnapshot;
import it.cavallium.dbengine.database.LLDictionary; import it.cavallium.dbengine.database.LLDictionary;
import it.cavallium.dbengine.database.LLEntry;
import it.cavallium.dbengine.database.LLUtils; import it.cavallium.dbengine.database.LLUtils;
import it.cavallium.dbengine.database.LiveResourceSupport; import it.cavallium.dbengine.database.DatabaseResourceSupport;
import it.cavallium.dbengine.database.UpdateMode; import it.cavallium.dbengine.database.UpdateMode;
import it.cavallium.dbengine.database.serialization.Serializer; import it.cavallium.dbengine.database.serialization.Serializer;
import it.cavallium.dbengine.database.serialization.SerializerFixedBinaryLength; import it.cavallium.dbengine.database.serialization.SerializerFixedBinaryLength;
@ -31,8 +30,7 @@ import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class DatabaseMapDictionaryHashed<T, U, TH> extends public class DatabaseMapDictionaryHashed<T, U, TH> extends DatabaseResourceSupport<DatabaseStage<Map<T, U>>, DatabaseMapDictionaryHashed<T, U, TH>>
LiveResourceSupport<DatabaseStage<Map<T, U>>, DatabaseMapDictionaryHashed<T, U, TH>>
implements DatabaseStageMap<T, U, DatabaseStageEntry<U>> { implements DatabaseStageMap<T, U, DatabaseStageEntry<U>> {
private static final Logger logger = LoggerFactory.getLogger(DatabaseMapDictionaryHashed.class); private static final Logger logger = LoggerFactory.getLogger(DatabaseMapDictionaryHashed.class);

View File

@ -5,25 +5,18 @@ import io.net5.buffer.api.Owned;
import io.net5.buffer.api.Send; import io.net5.buffer.api.Send;
import it.cavallium.dbengine.client.BadBlock; import it.cavallium.dbengine.client.BadBlock;
import it.cavallium.dbengine.client.CompositeSnapshot; import it.cavallium.dbengine.client.CompositeSnapshot;
import it.cavallium.dbengine.database.Column;
import it.cavallium.dbengine.database.Delta; import it.cavallium.dbengine.database.Delta;
import it.cavallium.dbengine.database.LLEntry;
import it.cavallium.dbengine.database.LLUtils; import it.cavallium.dbengine.database.LLUtils;
import it.cavallium.dbengine.database.LiveResourceSupport; import it.cavallium.dbengine.database.DatabaseResourceSupport;
import it.cavallium.dbengine.database.UpdateReturnMode; import it.cavallium.dbengine.database.UpdateReturnMode;
import it.cavallium.dbengine.database.serialization.SerializationFunction; import it.cavallium.dbengine.database.serialization.SerializationFunction;
import it.unimi.dsi.fastutil.objects.ObjectArraySet; import it.unimi.dsi.fastutil.objects.ObjectArraySet;
import it.unimi.dsi.fastutil.objects.ObjectSets;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.Function;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.warp.commonutils.functional.TriFunction;
import org.warp.commonutils.log.Logger; import org.warp.commonutils.log.Logger;
import org.warp.commonutils.log.LoggerFactory; import org.warp.commonutils.log.LoggerFactory;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
@ -31,7 +24,7 @@ import reactor.core.publisher.Mono;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class DatabaseSingleBucket<K, V, TH> public class DatabaseSingleBucket<K, V, TH>
extends LiveResourceSupport<DatabaseStage<V>, DatabaseSingleBucket<K, V, TH>> extends DatabaseResourceSupport<DatabaseStage<V>, DatabaseSingleBucket<K, V, TH>>
implements DatabaseStageEntry<V> { implements DatabaseStageEntry<V> {
private static final Logger logger = LoggerFactory.getLogger(DatabaseSingleBucket.class); private static final Logger logger = LoggerFactory.getLogger(DatabaseSingleBucket.class);

View File

@ -2,14 +2,13 @@ package it.cavallium.dbengine.database.disk;
import io.net5.buffer.api.Drop; import io.net5.buffer.api.Drop;
import io.net5.buffer.api.Owned; import io.net5.buffer.api.Owned;
import it.cavallium.dbengine.database.LiveResourceSupport; import it.cavallium.dbengine.database.DatabaseResourceSupport;
import it.cavallium.dbengine.database.collections.DatabaseMapDictionaryHashed;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.IndexSearcher;
import org.warp.commonutils.log.Logger; import org.warp.commonutils.log.Logger;
import org.warp.commonutils.log.LoggerFactory; import org.warp.commonutils.log.LoggerFactory;
public class LLIndexSearcher extends LiveResourceSupport<LLIndexSearcher, LLIndexSearcher> { public class LLIndexSearcher extends DatabaseResourceSupport<LLIndexSearcher, LLIndexSearcher> {
private static final Logger logger = LoggerFactory.getLogger(LLIndexSearcher.class); private static final Logger logger = LoggerFactory.getLogger(LLIndexSearcher.class);

View File

@ -4,24 +4,16 @@ import io.net5.buffer.api.Drop;
import io.net5.buffer.api.Owned; import io.net5.buffer.api.Owned;
import io.net5.buffer.api.Resource; import io.net5.buffer.api.Resource;
import io.net5.buffer.api.Send; import io.net5.buffer.api.Send;
import io.net5.buffer.api.internal.ResourceSupport; import it.cavallium.dbengine.database.DatabaseResourceSupport;
import it.cavallium.dbengine.database.LLEntry;
import it.cavallium.dbengine.database.LLSearchResultShard;
import it.cavallium.dbengine.database.LiveResourceSupport;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import java.io.IOException; import java.io.IOException;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap;
import java.util.List; import java.util.List;
import org.apache.lucene.index.Fields;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexReaderContext;
import org.apache.lucene.index.MultiReader; import org.apache.lucene.index.MultiReader;
import org.apache.lucene.index.StoredFieldVisitor;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.IndexSearcher;
import org.warp.commonutils.log.Logger; import org.warp.commonutils.log.Logger;
import org.warp.commonutils.log.LoggerFactory; import org.warp.commonutils.log.LoggerFactory;
@ -42,7 +34,7 @@ public interface LLIndexSearchers extends Resource<LLIndexSearchers> {
IndexReader allShards(); IndexReader allShards();
class UnshardedIndexSearchers extends LiveResourceSupport<LLIndexSearchers, UnshardedIndexSearchers> class UnshardedIndexSearchers extends DatabaseResourceSupport<LLIndexSearchers, UnshardedIndexSearchers>
implements LLIndexSearchers { implements LLIndexSearchers {
private static final Logger logger = LoggerFactory.getLogger(UnshardedIndexSearchers.class); private static final Logger logger = LoggerFactory.getLogger(UnshardedIndexSearchers.class);
@ -133,7 +125,7 @@ public interface LLIndexSearchers extends Resource<LLIndexSearchers> {
} }
} }
class ShardedIndexSearchers extends LiveResourceSupport<LLIndexSearchers, ShardedIndexSearchers> class ShardedIndexSearchers extends DatabaseResourceSupport<LLIndexSearchers, ShardedIndexSearchers>
implements LLIndexSearchers { implements LLIndexSearchers {
private static final Logger logger = LoggerFactory.getLogger(ShardedIndexSearchers.class); private static final Logger logger = LoggerFactory.getLogger(ShardedIndexSearchers.class);

View File

@ -92,7 +92,7 @@ public class LLLocalDatabaseConnection implements LLDatabaseConnection {
var env = this.env.get(); var env = this.env.get();
Objects.requireNonNull(env, "Environment not set"); Objects.requireNonNull(env, "Environment not set");
return new LLLocalMultiLuceneIndex(env, return new LLLocalMultiLuceneIndex(env,
basePath.resolve("lucene"), luceneOptions.inMemory() ? null : basePath.resolve("lucene"),
name, name,
instancesCount, instancesCount,
indicizerAnalyzers, indicizerAnalyzers,
@ -101,7 +101,7 @@ public class LLLocalDatabaseConnection implements LLDatabaseConnection {
luceneHacks luceneHacks
); );
} else { } else {
return new LLLocalLuceneIndex(basePath.resolve("lucene"), return new LLLocalLuceneIndex(luceneOptions.inMemory() ? null : basePath.resolve("lucene"),
name, name,
indicizerAnalyzers, indicizerAnalyzers,
indicizerSimilarities, indicizerSimilarities,

View File

@ -2,20 +2,15 @@ package it.cavallium.dbengine.lucene.searcher;
import io.net5.buffer.api.Drop; import io.net5.buffer.api.Drop;
import io.net5.buffer.api.Owned; import io.net5.buffer.api.Owned;
import io.net5.buffer.api.internal.ResourceSupport;
import it.cavallium.dbengine.client.query.current.data.TotalHitsCount; import it.cavallium.dbengine.client.query.current.data.TotalHitsCount;
import it.cavallium.dbengine.database.LLKeyScore; import it.cavallium.dbengine.database.LLKeyScore;
import it.cavallium.dbengine.database.LLSearchResultShard; import it.cavallium.dbengine.database.DatabaseResourceSupport;
import it.cavallium.dbengine.database.LiveResourceSupport;
import it.cavallium.dbengine.database.disk.LLLocalKeyValueDatabase;
import java.io.IOException;
import java.util.Objects; import java.util.Objects;
import org.warp.commonutils.log.Logger; import org.warp.commonutils.log.Logger;
import org.warp.commonutils.log.LoggerFactory; import org.warp.commonutils.log.LoggerFactory;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
public final class LuceneSearchResult extends LiveResourceSupport<LuceneSearchResult, LuceneSearchResult> { public final class LuceneSearchResult extends DatabaseResourceSupport<LuceneSearchResult, LuceneSearchResult> {
private static final Logger logger = LoggerFactory.getLogger(LuceneSearchResult.class); private static final Logger logger = LoggerFactory.getLogger(LuceneSearchResult.class);

View File

@ -4,16 +4,12 @@ import io.net5.buffer.api.Buffer;
import io.net5.buffer.api.Drop; import io.net5.buffer.api.Drop;
import io.net5.buffer.api.Owned; import io.net5.buffer.api.Owned;
import io.net5.buffer.api.Send; import io.net5.buffer.api.Send;
import io.net5.buffer.api.internal.ResourceSupport; import it.cavallium.dbengine.database.DatabaseResourceSupport;
import it.cavallium.dbengine.client.SearchResult;
import it.cavallium.dbengine.database.LLSearchResultShard;
import it.cavallium.dbengine.database.LiveResourceSupport;
import it.cavallium.dbengine.database.collections.DatabaseSingle;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.warp.commonutils.log.Logger; import org.warp.commonutils.log.Logger;
import org.warp.commonutils.log.LoggerFactory; import org.warp.commonutils.log.LoggerFactory;
public class NullableBuffer extends LiveResourceSupport<NullableBuffer, NullableBuffer> { public class NullableBuffer extends DatabaseResourceSupport<NullableBuffer, NullableBuffer> {
private static final Logger logger = LoggerFactory.getLogger(NullableBuffer.class); private static final Logger logger = LoggerFactory.getLogger(NullableBuffer.class);