Fix badblocks memory leak

This commit is contained in:
Andrea Cavalli 2021-06-26 23:57:24 +02:00
parent bd8755c180
commit 63cdb43644
2 changed files with 15 additions and 1 deletions

View File

@ -13,6 +13,7 @@ import it.cavallium.dbengine.database.LLSnapshot;
import it.cavallium.dbengine.database.LLUtils; import it.cavallium.dbengine.database.LLUtils;
import it.cavallium.dbengine.database.UpdateMode; import it.cavallium.dbengine.database.UpdateMode;
import it.cavallium.dbengine.database.disk.LLLocalDictionary; import it.cavallium.dbengine.database.disk.LLLocalDictionary;
import it.cavallium.dbengine.database.disk.ReleasableSlice;
import it.cavallium.dbengine.database.serialization.SerializerFixedBinaryLength; import it.cavallium.dbengine.database.serialization.SerializerFixedBinaryLength;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -427,7 +428,15 @@ public class DatabaseMapDictionaryDeep<T, U, US extends DatabaseStage<U>> implem
public Flux<BadBlock> badBlocks() { public Flux<BadBlock> badBlocks() {
return this return this
.getAllValues(null) .getAllValues(null)
.flatMap(result -> Mono.<BadBlock>empty()) .doOnNext(entry -> {
if (entry.getKey() instanceof ReferenceCounted referenceCounted) {
referenceCounted.release();
}
if (entry.getValue() instanceof ReferenceCounted referenceCounted) {
referenceCounted.release();
}
})
.concatMap(entry -> Mono.<BadBlock>empty())
.onErrorResume(ex -> Mono.just(new BadBlock(dictionary.getDatabaseName(), .onErrorResume(ex -> Mono.just(new BadBlock(dictionary.getDatabaseName(),
Column.special(dictionary.getColumnName()), null, ex))); Column.special(dictionary.getColumnName()), null, ex)));
} }

View File

@ -153,6 +153,11 @@ public class DatabaseSingle<U> implements DatabaseStageEntry<U> {
public Flux<BadBlock> badBlocks() { public Flux<BadBlock> badBlocks() {
return this return this
.get(null, true) .get(null, true)
.doOnNext(entry -> {
if (entry instanceof ReferenceCounted referenceCounted) {
referenceCounted.release();
}
})
.then(Mono.<BadBlock>empty()) .then(Mono.<BadBlock>empty())
.onErrorResume(ex -> Mono.just(new BadBlock(dictionary.getDatabaseName(), .onErrorResume(ex -> Mono.just(new BadBlock(dictionary.getDatabaseName(),
Column.special(dictionary.getDatabaseName()), Column.special(dictionary.getDatabaseName()),