Code cleanup
This commit is contained in:
parent
af7c3dfd65
commit
1aeb0c99d3
|
@ -1,7 +1,7 @@
|
||||||
package it.cavallium.dbengine.database;
|
package it.cavallium.dbengine.database;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* https://lucene.apache.org/core/8_0_0/core/org/apache/lucene/document/Field.html
|
* <a href="https://lucene.apache.org/core/8_0_0/core/org/apache/lucene/document/Field.html">Field.html</a>
|
||||||
*/
|
*/
|
||||||
public enum LLType {
|
public enum LLType {
|
||||||
StringField,
|
StringField,
|
||||||
|
|
|
@ -357,7 +357,7 @@ public sealed abstract class AbstractRocksDBColumn<T extends RocksDB> implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mayExists(@NotNull ReadOptions readOptions, Buf key) throws RocksDBException {
|
public boolean mayExists(@NotNull ReadOptions readOptions, Buf key) {
|
||||||
var closeReadLock = closeLock.readLock();
|
var closeReadLock = closeLock.readLock();
|
||||||
try {
|
try {
|
||||||
ensureOpen();
|
ensureOpen();
|
||||||
|
@ -504,7 +504,7 @@ public sealed abstract class AbstractRocksDBColumn<T extends RocksDB> implements
|
||||||
@NotNull WriteOptions writeOptions,
|
@NotNull WriteOptions writeOptions,
|
||||||
Buf key,
|
Buf key,
|
||||||
BinarySerializationFunction updater,
|
BinarySerializationFunction updater,
|
||||||
UpdateAtomicResultMode returnMode) throws RocksDBException {
|
UpdateAtomicResultMode returnMode) {
|
||||||
var closeReadLock = closeLock.readLock();
|
var closeReadLock = closeLock.readLock();
|
||||||
try {
|
try {
|
||||||
ensureOpen();
|
ensureOpen();
|
||||||
|
@ -543,7 +543,7 @@ public sealed abstract class AbstractRocksDBColumn<T extends RocksDB> implements
|
||||||
@NotNull WriteOptions writeOptions,
|
@NotNull WriteOptions writeOptions,
|
||||||
Buf key,
|
Buf key,
|
||||||
BinarySerializationFunction updater,
|
BinarySerializationFunction updater,
|
||||||
UpdateAtomicResultMode returnMode) throws RocksDBException;
|
UpdateAtomicResultMode returnMode);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|
|
@ -40,10 +40,8 @@ public class CachedIndexSearcherManager extends SimpleResource implements IndexS
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private final SnapshotsManager snapshotsManager;
|
private final SnapshotsManager snapshotsManager;
|
||||||
private final ScheduledExecutorService luceneHeavyTasksScheduler;
|
|
||||||
private final Similarity similarity;
|
private final Similarity similarity;
|
||||||
private final SearcherManager searcherManager;
|
private final SearcherManager searcherManager;
|
||||||
private final Duration queryRefreshDebounceTime;
|
|
||||||
|
|
||||||
private final AtomicLong activeSearchers = new AtomicLong(0);
|
private final AtomicLong activeSearchers = new AtomicLong(0);
|
||||||
private final AtomicLong activeRefreshes = new AtomicLong(0);
|
private final AtomicLong activeRefreshes = new AtomicLong(0);
|
||||||
|
@ -59,9 +57,7 @@ public class CachedIndexSearcherManager extends SimpleResource implements IndexS
|
||||||
boolean writeAllDeletes,
|
boolean writeAllDeletes,
|
||||||
Duration queryRefreshDebounceTime) {
|
Duration queryRefreshDebounceTime) {
|
||||||
this.snapshotsManager = snapshotsManager;
|
this.snapshotsManager = snapshotsManager;
|
||||||
this.luceneHeavyTasksScheduler = luceneHeavyTasksScheduler;
|
|
||||||
this.similarity = similarity;
|
this.similarity = similarity;
|
||||||
this.queryRefreshDebounceTime = queryRefreshDebounceTime;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.searcherManager = new SearcherManager(indexWriter, applyAllDeletes, writeAllDeletes, SEARCHER_FACTORY);
|
this.searcherManager = new SearcherManager(indexWriter, applyAllDeletes, writeAllDeletes, SEARCHER_FACTORY);
|
||||||
|
|
|
@ -25,8 +25,4 @@ public abstract class LLIndexSearcher extends SimpleResource implements Discardi
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract IndexSearcher getIndexSearcherInternal();
|
protected abstract IndexSearcher getIndexSearcherInternal();
|
||||||
|
|
||||||
public AtomicBoolean getClosed() {
|
|
||||||
return super.getClosed();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,4 @@ public abstract class LLIndexSearcherImpl extends LLIndexSearcher {
|
||||||
public IndexSearcher getIndexSearcherInternal() {
|
public IndexSearcher getIndexSearcherInternal() {
|
||||||
return indexSearcher;
|
return indexSearcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AtomicBoolean getClosed() {
|
|
||||||
return super.getClosed();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -749,8 +749,7 @@ public class LLLocalKeyValueDatabase extends Backuppable implements LLKeyValueDa
|
||||||
return closeLock;
|
return closeLock;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void flushAndCloseDb(RocksDB db, Cache standardCache, Cache compressedCache, List<ColumnFamilyHandle> handles)
|
private void flushAndCloseDb(RocksDB db, Cache standardCache, Cache compressedCache, List<ColumnFamilyHandle> handles) {
|
||||||
throws RocksDBException {
|
|
||||||
var closeWriteLock = closeLock.writeLock();
|
var closeWriteLock = closeLock.writeLock();
|
||||||
try {
|
try {
|
||||||
if (closed) {
|
if (closed) {
|
||||||
|
@ -1536,7 +1535,7 @@ public class LLLocalKeyValueDatabase extends Backuppable implements LLKeyValueDa
|
||||||
});
|
});
|
||||||
handles.clear();
|
handles.clear();
|
||||||
deleteUnusedOldLogFiles();
|
deleteUnusedOldLogFiles();
|
||||||
} catch (RocksDBException e) {
|
} catch (Exception e) {
|
||||||
throw new DBException("Failed to close", e);
|
throw new DBException("Failed to close", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,8 @@ import org.rocksdb.RocksDBException;
|
||||||
public final class LLLocalMigrationReactiveRocksIterator {
|
public final class LLLocalMigrationReactiveRocksIterator {
|
||||||
|
|
||||||
private final RocksDBColumn db;
|
private final RocksDBColumn db;
|
||||||
private LLRange range;
|
private final LLRange range;
|
||||||
private Supplier<ReadOptions> readOptions;
|
private final Supplier<ReadOptions> readOptions;
|
||||||
|
|
||||||
public LLLocalMigrationReactiveRocksIterator(RocksDBColumn db,
|
public LLLocalMigrationReactiveRocksIterator(RocksDBColumn db,
|
||||||
LLRange range,
|
LLRange range,
|
||||||
|
@ -41,17 +41,13 @@ public final class LLLocalMigrationReactiveRocksIterator {
|
||||||
throw new DBException("Failed to open iterator", e);
|
throw new DBException("Failed to open iterator", e);
|
||||||
}
|
}
|
||||||
return streamWhileNonNull(() -> {
|
return streamWhileNonNull(() -> {
|
||||||
try {
|
if (rocksIterator.isValid()) {
|
||||||
if (rocksIterator.isValid()) {
|
var key = rocksIterator.keyBuf().copy();
|
||||||
var key = rocksIterator.keyBuf().copy();
|
var value = rocksIterator.valueBuf().copy();
|
||||||
var value = rocksIterator.valueBuf().copy();
|
rocksIterator.next(false);
|
||||||
rocksIterator.next(false);
|
return LLEntry.of(key, value);
|
||||||
return LLEntry.of(key, value);
|
} else {
|
||||||
} else {
|
return null;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} catch (RocksDBException ex) {
|
|
||||||
throw new CompletionException(new DBException("Failed to iterate", ex));
|
|
||||||
}
|
}
|
||||||
}).onClose(() -> {
|
}).onClose(() -> {
|
||||||
rocksIterator.close();
|
rocksIterator.close();
|
||||||
|
|
|
@ -102,8 +102,6 @@ public class LLLocalSingleton implements LLSingleton {
|
||||||
UpdateAtomicResult result;
|
UpdateAtomicResult result;
|
||||||
try (var readOptions = new ReadOptions(); var writeOptions = new WriteOptions()) {
|
try (var readOptions = new ReadOptions(); var writeOptions = new WriteOptions()) {
|
||||||
result = db.updateAtomic(readOptions, writeOptions, name, updater, returnMode);
|
result = db.updateAtomic(readOptions, writeOptions, name, updater, returnMode);
|
||||||
} catch (RocksDBException e) {
|
|
||||||
throw new DBException("Failed to read or write", e);
|
|
||||||
}
|
}
|
||||||
return switch (updateReturnMode) {
|
return switch (updateReturnMode) {
|
||||||
case NOTHING -> null;
|
case NOTHING -> null;
|
||||||
|
@ -120,8 +118,6 @@ public class LLLocalSingleton implements LLSingleton {
|
||||||
UpdateAtomicResult result;
|
UpdateAtomicResult result;
|
||||||
try (var readOptions = new ReadOptions(); var writeOptions = new WriteOptions()) {
|
try (var readOptions = new ReadOptions(); var writeOptions = new WriteOptions()) {
|
||||||
result = db.updateAtomic(readOptions, writeOptions, name, updater, DELTA);
|
result = db.updateAtomic(readOptions, writeOptions, name, updater, DELTA);
|
||||||
} catch (RocksDBException e) {
|
|
||||||
throw new DBException("Failed to read or write", e);
|
|
||||||
}
|
}
|
||||||
return ((UpdateAtomicResultDelta) result).delta();
|
return ((UpdateAtomicResultDelta) result).delta();
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ public sealed interface RocksDBColumn permits AbstractRocksDBColumn {
|
||||||
|
|
||||||
boolean exists(@NotNull ReadOptions readOptions, Buf key) throws RocksDBException;
|
boolean exists(@NotNull ReadOptions readOptions, Buf key) throws RocksDBException;
|
||||||
|
|
||||||
boolean mayExists(@NotNull ReadOptions readOptions, Buf key) throws RocksDBException;
|
boolean mayExists(@NotNull ReadOptions readOptions, Buf key);
|
||||||
|
|
||||||
void put(@NotNull WriteOptions writeOptions, Buf key, Buf value) throws RocksDBException;
|
void put(@NotNull WriteOptions writeOptions, Buf key, Buf value) throws RocksDBException;
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ public sealed interface RocksDBColumn permits AbstractRocksDBColumn {
|
||||||
@NotNull WriteOptions writeOptions,
|
@NotNull WriteOptions writeOptions,
|
||||||
Buf key,
|
Buf key,
|
||||||
BinarySerializationFunction updater,
|
BinarySerializationFunction updater,
|
||||||
UpdateAtomicResultMode returnMode) throws RocksDBException;
|
UpdateAtomicResultMode returnMode);
|
||||||
|
|
||||||
void delete(WriteOptions writeOptions, Buf key) throws RocksDBException;
|
void delete(WriteOptions writeOptions, Buf key) throws RocksDBException;
|
||||||
|
|
||||||
|
@ -84,5 +84,5 @@ public sealed interface RocksDBColumn permits AbstractRocksDBColumn {
|
||||||
|
|
||||||
boolean supportsTransactions();
|
boolean supportsTransactions();
|
||||||
|
|
||||||
void forceCompaction(int volumeId) throws RocksDBException;
|
void forceCompaction(int volumeId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,7 +201,7 @@ public class RocksIteratorObj extends SimpleResource {
|
||||||
next(true);
|
next(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void next(boolean traceStats) throws RocksDBException {
|
public void next(boolean traceStats) {
|
||||||
ensureOpen();
|
ensureOpen();
|
||||||
if (traceStats) {
|
if (traceStats) {
|
||||||
startedIterNext.increment();
|
startedIterNext.increment();
|
||||||
|
@ -217,7 +217,7 @@ public class RocksIteratorObj extends SimpleResource {
|
||||||
prev(true);
|
prev(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void prev(boolean traceStats) throws RocksDBException {
|
public void prev(boolean traceStats) {
|
||||||
ensureOpen();
|
ensureOpen();
|
||||||
if (traceStats) {
|
if (traceStats) {
|
||||||
startedIterNext.increment();
|
startedIterNext.increment();
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
package it.cavallium.dbengine.lucene;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.OptionalLong;
|
|
||||||
import org.apache.lucene.misc.store.DirectIODirectory;
|
|
||||||
import org.apache.lucene.store.FSDirectory;
|
|
||||||
import org.apache.lucene.store.IOContext;
|
|
||||||
|
|
||||||
public class AlwaysDirectIOFSDirectory extends DirectIODirectory {
|
|
||||||
|
|
||||||
public AlwaysDirectIOFSDirectory(Path path, int mergeBufferSize, long minBytesDirect) throws IOException {
|
|
||||||
super(FSDirectory.open(path), mergeBufferSize, minBytesDirect);
|
|
||||||
}
|
|
||||||
|
|
||||||
public AlwaysDirectIOFSDirectory(Path path) throws IOException {
|
|
||||||
super(FSDirectory.open(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean useDirectIO(String name, IOContext context, OptionalLong fileLength) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -69,7 +69,7 @@ public class BigCompositeReader<R extends IndexReader> {
|
||||||
public static <T extends IndexReader> Collection<String> getIndexedFields(BigCompositeReader<T> readers) {
|
public static <T extends IndexReader> Collection<String> getIndexedFields(BigCompositeReader<T> readers) {
|
||||||
return readers.subReadersList
|
return readers.subReadersList
|
||||||
.stream()
|
.stream()
|
||||||
.map(t -> t.getContext())
|
.map(IndexReader::getContext)
|
||||||
.flatMap(l -> l.leaves().stream())
|
.flatMap(l -> l.leaves().stream())
|
||||||
.flatMap((l) -> StreamSupport
|
.flatMap((l) -> StreamSupport
|
||||||
.stream(l.reader().getFieldInfos().spliterator(), false)
|
.stream(l.reader().getFieldInfos().spliterator(), false)
|
||||||
|
|
|
@ -86,11 +86,11 @@ import org.apache.lucene.util.PriorityQueue;
|
||||||
* <pre class="prettyprint">
|
* <pre class="prettyprint">
|
||||||
* IndexReader ir = ...
|
* IndexReader ir = ...
|
||||||
* IndexSearcher is = ...
|
* IndexSearcher is = ...
|
||||||
*
|
* <p>
|
||||||
* MoreLikeThis mlt = new MoreLikeThis(ir);
|
* MoreLikeThis mlt = new MoreLikeThis(ir);
|
||||||
* Reader target = ... // orig source of doc you want to find similarities to
|
* Reader target = ... // orig source of doc you want to find similarities to
|
||||||
* Query query = mlt.like( target);
|
* Query query = mlt.like( target);
|
||||||
*
|
* <p>
|
||||||
* Hits hits = is.search(query);
|
* Hits hits = is.search(query);
|
||||||
* // now the usual iteration thru 'hits' - the only thing to watch for is to make sure
|
* // now the usual iteration thru 'hits' - the only thing to watch for is to make sure
|
||||||
* //you ignore the doc if it matches your 'target' document, as it should be similar to itself
|
* //you ignore the doc if it matches your 'target' document, as it should be similar to itself
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class AdaptiveLocalSearcher implements LocalSearcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String toString() {
|
||||||
return "adaptivelocal";
|
return "adaptivelocal";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class AdaptiveMultiSearcher implements MultiSearcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String toString() {
|
||||||
return "adaptive local";
|
return "adaptive local";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class CountMultiSearcher implements MultiSearcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String toString() {
|
||||||
return "count";
|
return "count";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,5 +25,6 @@ public interface LocalSearcher {
|
||||||
* Get the name of this searcher type
|
* Get the name of this searcher type
|
||||||
* @return searcher type name
|
* @return searcher type name
|
||||||
*/
|
*/
|
||||||
String getName();
|
@Override
|
||||||
|
String toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class PagedLocalSearcher implements LocalSearcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String toString() {
|
||||||
return "paged local";
|
return "paged local";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -214,7 +214,7 @@ public class ScoredPagedMultiSearcher implements MultiSearcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String toString() {
|
||||||
return "scored paged multi";
|
return "scored paged multi";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -131,7 +131,7 @@ public class StandardSearcher implements MultiSearcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String toString() {
|
||||||
return "standard";
|
return "standard";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class UnsortedStreamingMultiSearcher implements MultiSearcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String toString() {
|
||||||
return "unsorted streaming multi";
|
return "unsorted streaming multi";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package it.cavallium.dbengine.tests;
|
package it.cavallium.dbengine.tests;
|
||||||
|
|
||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
import static java.util.Objects.requireNonNullElseGet;
|
|
||||||
|
|
||||||
import it.cavallium.dbengine.database.LLKeyScore;
|
import it.cavallium.dbengine.database.LLKeyScore;
|
||||||
import it.cavallium.dbengine.database.disk.LLIndexSearcher;
|
import it.cavallium.dbengine.database.disk.LLIndexSearcher;
|
||||||
|
@ -42,17 +41,17 @@ public class SwappableLuceneSearcher implements LocalSearcher, MultiSearcher, Cl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String toString() {
|
||||||
var single = this.single.get();
|
var single = this.single.get();
|
||||||
var multi = this.multi.get();
|
var multi = this.multi.get();
|
||||||
if (single == multi) {
|
if (single == multi) {
|
||||||
if (single == null) {
|
if (single == null) {
|
||||||
return "swappable";
|
return "swappable";
|
||||||
} else {
|
} else {
|
||||||
return single.getName();
|
return single.toString();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return "swappable[single=" + single.getName() + ",multi=" + multi.getName() + "]";
|
return "swappable[single=" + single.toString() + ",multi=" + multi.toString() + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -157,7 +157,7 @@ public class TestLuceneIndex {
|
||||||
if (customSearcher instanceof MultiSearcher multiSearcher) {
|
if (customSearcher instanceof MultiSearcher multiSearcher) {
|
||||||
tempDb.swappableLuceneSearcher().setMulti(multiSearcher);
|
tempDb.swappableLuceneSearcher().setMulti(multiSearcher);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Expected a LuceneMultiSearcher, got a LuceneLocalSearcher: " + customSearcher.getName());
|
throw new IllegalArgumentException("Expected a LuceneMultiSearcher, got a LuceneLocalSearcher: " + customSearcher.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -170,7 +170,7 @@ public class TestLuceneSearches {
|
||||||
throws Throwable {
|
throws Throwable {
|
||||||
var searchers = getSearchers(expectedQueryType);
|
var searchers = getSearchers(expectedQueryType);
|
||||||
for (LocalSearcher searcher : searchers) {
|
for (LocalSearcher searcher : searchers) {
|
||||||
log.info("Using searcher \"{}\"", searcher.getName());
|
log.info("Using searcher \"{}\"", searcher.toString());
|
||||||
consumer.accept(searcher);
|
consumer.accept(searcher);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@ public class TestLuceneSearches {
|
||||||
if (customSearcher instanceof MultiSearcher multiSearcher) {
|
if (customSearcher instanceof MultiSearcher multiSearcher) {
|
||||||
tempDb.swappableLuceneSearcher().setMulti(multiSearcher);
|
tempDb.swappableLuceneSearcher().setMulti(multiSearcher);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Expected a LuceneMultiSearcher, got a LuceneLocalSearcher: " + customSearcher.getName());
|
throw new IllegalArgumentException("Expected a LuceneMultiSearcher, got a LuceneLocalSearcher: " + customSearcher.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -85,7 +85,7 @@ public class UnsortedUnscoredSimpleMultiSearcher implements MultiSearcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String toString() {
|
||||||
return "unsorted unscored simple multi";
|
return "unsorted unscored simple multi";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user