Code cleanup

This commit is contained in:
Andrea Cavalli 2023-03-20 00:36:27 +01:00
parent af7c3dfd65
commit 1aeb0c99d3
25 changed files with 39 additions and 84 deletions

View File

@ -1,7 +1,7 @@
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 {
StringField,

View File

@ -357,7 +357,7 @@ public sealed abstract class AbstractRocksDBColumn<T extends RocksDB> implements
}
@Override
public boolean mayExists(@NotNull ReadOptions readOptions, Buf key) throws RocksDBException {
public boolean mayExists(@NotNull ReadOptions readOptions, Buf key) {
var closeReadLock = closeLock.readLock();
try {
ensureOpen();
@ -504,7 +504,7 @@ public sealed abstract class AbstractRocksDBColumn<T extends RocksDB> implements
@NotNull WriteOptions writeOptions,
Buf key,
BinarySerializationFunction updater,
UpdateAtomicResultMode returnMode) throws RocksDBException {
UpdateAtomicResultMode returnMode) {
var closeReadLock = closeLock.readLock();
try {
ensureOpen();
@ -543,7 +543,7 @@ public sealed abstract class AbstractRocksDBColumn<T extends RocksDB> implements
@NotNull WriteOptions writeOptions,
Buf key,
BinarySerializationFunction updater,
UpdateAtomicResultMode returnMode) throws RocksDBException;
UpdateAtomicResultMode returnMode);
@Override
@NotNull

View File

@ -40,10 +40,8 @@ public class CachedIndexSearcherManager extends SimpleResource implements IndexS
@Nullable
private final SnapshotsManager snapshotsManager;
private final ScheduledExecutorService luceneHeavyTasksScheduler;
private final Similarity similarity;
private final SearcherManager searcherManager;
private final Duration queryRefreshDebounceTime;
private final AtomicLong activeSearchers = new AtomicLong(0);
private final AtomicLong activeRefreshes = new AtomicLong(0);
@ -59,9 +57,7 @@ public class CachedIndexSearcherManager extends SimpleResource implements IndexS
boolean writeAllDeletes,
Duration queryRefreshDebounceTime) {
this.snapshotsManager = snapshotsManager;
this.luceneHeavyTasksScheduler = luceneHeavyTasksScheduler;
this.similarity = similarity;
this.queryRefreshDebounceTime = queryRefreshDebounceTime;
try {
this.searcherManager = new SearcherManager(indexWriter, applyAllDeletes, writeAllDeletes, SEARCHER_FACTORY);

View File

@ -25,8 +25,4 @@ public abstract class LLIndexSearcher extends SimpleResource implements Discardi
}
protected abstract IndexSearcher getIndexSearcherInternal();
public AtomicBoolean getClosed() {
return super.getClosed();
}
}

View File

@ -24,8 +24,4 @@ public abstract class LLIndexSearcherImpl extends LLIndexSearcher {
public IndexSearcher getIndexSearcherInternal() {
return indexSearcher;
}
public AtomicBoolean getClosed() {
return super.getClosed();
}
}

View File

@ -749,8 +749,7 @@ public class LLLocalKeyValueDatabase extends Backuppable implements LLKeyValueDa
return closeLock;
}
private void flushAndCloseDb(RocksDB db, Cache standardCache, Cache compressedCache, List<ColumnFamilyHandle> handles)
throws RocksDBException {
private void flushAndCloseDb(RocksDB db, Cache standardCache, Cache compressedCache, List<ColumnFamilyHandle> handles) {
var closeWriteLock = closeLock.writeLock();
try {
if (closed) {
@ -1536,7 +1535,7 @@ public class LLLocalKeyValueDatabase extends Backuppable implements LLKeyValueDa
});
handles.clear();
deleteUnusedOldLogFiles();
} catch (RocksDBException e) {
} catch (Exception e) {
throw new DBException("Failed to close", e);
}
}

View File

@ -21,8 +21,8 @@ import org.rocksdb.RocksDBException;
public final class LLLocalMigrationReactiveRocksIterator {
private final RocksDBColumn db;
private LLRange range;
private Supplier<ReadOptions> readOptions;
private final LLRange range;
private final Supplier<ReadOptions> readOptions;
public LLLocalMigrationReactiveRocksIterator(RocksDBColumn db,
LLRange range,
@ -41,17 +41,13 @@ public final class LLLocalMigrationReactiveRocksIterator {
throw new DBException("Failed to open iterator", e);
}
return streamWhileNonNull(() -> {
try {
if (rocksIterator.isValid()) {
var key = rocksIterator.keyBuf().copy();
var value = rocksIterator.valueBuf().copy();
rocksIterator.next(false);
return LLEntry.of(key, value);
} else {
return null;
}
} catch (RocksDBException ex) {
throw new CompletionException(new DBException("Failed to iterate", ex));
if (rocksIterator.isValid()) {
var key = rocksIterator.keyBuf().copy();
var value = rocksIterator.valueBuf().copy();
rocksIterator.next(false);
return LLEntry.of(key, value);
} else {
return null;
}
}).onClose(() -> {
rocksIterator.close();

View File

@ -102,8 +102,6 @@ public class LLLocalSingleton implements LLSingleton {
UpdateAtomicResult result;
try (var readOptions = new ReadOptions(); var writeOptions = new WriteOptions()) {
result = db.updateAtomic(readOptions, writeOptions, name, updater, returnMode);
} catch (RocksDBException e) {
throw new DBException("Failed to read or write", e);
}
return switch (updateReturnMode) {
case NOTHING -> null;
@ -120,8 +118,6 @@ public class LLLocalSingleton implements LLSingleton {
UpdateAtomicResult result;
try (var readOptions = new ReadOptions(); var writeOptions = new WriteOptions()) {
result = db.updateAtomic(readOptions, writeOptions, name, updater, DELTA);
} catch (RocksDBException e) {
throw new DBException("Failed to read or write", e);
}
return ((UpdateAtomicResultDelta) result).delta();
}

View File

@ -42,7 +42,7 @@ public sealed interface RocksDBColumn permits AbstractRocksDBColumn {
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;
@ -56,7 +56,7 @@ public sealed interface RocksDBColumn permits AbstractRocksDBColumn {
@NotNull WriteOptions writeOptions,
Buf key,
BinarySerializationFunction updater,
UpdateAtomicResultMode returnMode) throws RocksDBException;
UpdateAtomicResultMode returnMode);
void delete(WriteOptions writeOptions, Buf key) throws RocksDBException;
@ -84,5 +84,5 @@ public sealed interface RocksDBColumn permits AbstractRocksDBColumn {
boolean supportsTransactions();
void forceCompaction(int volumeId) throws RocksDBException;
void forceCompaction(int volumeId);
}

View File

@ -201,7 +201,7 @@ public class RocksIteratorObj extends SimpleResource {
next(true);
}
public void next(boolean traceStats) throws RocksDBException {
public void next(boolean traceStats) {
ensureOpen();
if (traceStats) {
startedIterNext.increment();
@ -217,7 +217,7 @@ public class RocksIteratorObj extends SimpleResource {
prev(true);
}
public void prev(boolean traceStats) throws RocksDBException {
public void prev(boolean traceStats) {
ensureOpen();
if (traceStats) {
startedIterNext.increment();

View File

@ -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;
}
}

View File

@ -69,7 +69,7 @@ public class BigCompositeReader<R extends IndexReader> {
public static <T extends IndexReader> Collection<String> getIndexedFields(BigCompositeReader<T> readers) {
return readers.subReadersList
.stream()
.map(t -> t.getContext())
.map(IndexReader::getContext)
.flatMap(l -> l.leaves().stream())
.flatMap((l) -> StreamSupport
.stream(l.reader().getFieldInfos().spliterator(), false)

View File

@ -86,11 +86,11 @@ import org.apache.lucene.util.PriorityQueue;
* <pre class="prettyprint">
* IndexReader ir = ...
* IndexSearcher is = ...
*
* <p>
* MoreLikeThis mlt = new MoreLikeThis(ir);
* Reader target = ... // orig source of doc you want to find similarities to
* Query query = mlt.like( target);
*
* <p>
* Hits hits = is.search(query);
* // 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

View File

@ -42,7 +42,7 @@ public class AdaptiveLocalSearcher implements LocalSearcher {
}
@Override
public String getName() {
public String toString() {
return "adaptivelocal";
}

View File

@ -78,7 +78,7 @@ public class AdaptiveMultiSearcher implements MultiSearcher {
}
@Override
public String getName() {
public String toString() {
return "adaptive local";
}
}

View File

@ -76,7 +76,7 @@ public class CountMultiSearcher implements MultiSearcher {
}
@Override
public String getName() {
public String toString() {
return "count";
}
}

View File

@ -25,5 +25,6 @@ public interface LocalSearcher {
* Get the name of this searcher type
* @return searcher type name
*/
String getName();
@Override
String toString();
}

View File

@ -56,7 +56,7 @@ public class PagedLocalSearcher implements LocalSearcher {
}
@Override
public String getName() {
public String toString() {
return "paged local";
}

View File

@ -214,7 +214,7 @@ public class ScoredPagedMultiSearcher implements MultiSearcher {
}
@Override
public String getName() {
public String toString() {
return "scored paged multi";
}

View File

@ -131,7 +131,7 @@ public class StandardSearcher implements MultiSearcher {
}
@Override
public String getName() {
public String toString() {
return "standard";
}
}

View File

@ -67,7 +67,7 @@ public class UnsortedStreamingMultiSearcher implements MultiSearcher {
}
@Override
public String getName() {
public String toString() {
return "unsorted streaming multi";
}
}

View File

@ -1,7 +1,6 @@
package it.cavallium.dbengine.tests;
import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNullElseGet;
import it.cavallium.dbengine.database.LLKeyScore;
import it.cavallium.dbengine.database.disk.LLIndexSearcher;
@ -42,17 +41,17 @@ public class SwappableLuceneSearcher implements LocalSearcher, MultiSearcher, Cl
}
@Override
public String getName() {
public String toString() {
var single = this.single.get();
var multi = this.multi.get();
if (single == multi) {
if (single == null) {
return "swappable";
} else {
return single.getName();
return single.toString();
}
} else {
return "swappable[single=" + single.getName() + ",multi=" + multi.getName() + "]";
return "swappable[single=" + single.toString() + ",multi=" + multi.toString() + "]";
}
}

View File

@ -157,7 +157,7 @@ public class TestLuceneIndex {
if (customSearcher instanceof MultiSearcher multiSearcher) {
tempDb.swappableLuceneSearcher().setMulti(multiSearcher);
} else {
throw new IllegalArgumentException("Expected a LuceneMultiSearcher, got a LuceneLocalSearcher: " + customSearcher.getName());
throw new IllegalArgumentException("Expected a LuceneMultiSearcher, got a LuceneLocalSearcher: " + customSearcher.toString());
}
}
} else {

View File

@ -170,7 +170,7 @@ public class TestLuceneSearches {
throws Throwable {
var searchers = getSearchers(expectedQueryType);
for (LocalSearcher searcher : searchers) {
log.info("Using searcher \"{}\"", searcher.getName());
log.info("Using searcher \"{}\"", searcher.toString());
consumer.accept(searcher);
}
}
@ -196,7 +196,7 @@ public class TestLuceneSearches {
if (customSearcher instanceof MultiSearcher multiSearcher) {
tempDb.swappableLuceneSearcher().setMulti(multiSearcher);
} else {
throw new IllegalArgumentException("Expected a LuceneMultiSearcher, got a LuceneLocalSearcher: " + customSearcher.getName());
throw new IllegalArgumentException("Expected a LuceneMultiSearcher, got a LuceneLocalSearcher: " + customSearcher.toString());
}
}
} else {

View File

@ -85,7 +85,7 @@ public class UnsortedUnscoredSimpleMultiSearcher implements MultiSearcher {
}
@Override
public String getName() {
public String toString() {
return "unsorted unscored simple multi";
}
}