remove the wrapper class PdbDB
It did not serve any purpose and could be replaced by DataStore.
This commit is contained in:
@@ -1,60 +0,0 @@
|
||||
package org.lucares.pdb.datastore;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import org.lucares.pdb.api.Tags;
|
||||
import org.lucares.pdb.datastore.internal.DataStore;
|
||||
import org.lucares.pdb.datastore.internal.Proposer;
|
||||
import org.lucares.pdb.diskstorage.DiskStorage;
|
||||
|
||||
public class PdbDB implements AutoCloseable {
|
||||
|
||||
private final DataStore dataStore;
|
||||
private final Proposer proposer;
|
||||
|
||||
public PdbDB(final Path dataDirectory) throws IOException {
|
||||
dataStore = new DataStore(dataDirectory);
|
||||
proposer = new Proposer(dataStore);
|
||||
}
|
||||
|
||||
public List<Doc> search(final String query) {
|
||||
return dataStore.search(query);
|
||||
}
|
||||
|
||||
public long createNewFile(final Tags tags) throws IOException {
|
||||
return dataStore.createNewFile(tags);
|
||||
}
|
||||
|
||||
public List<String> getAvailableFields() {
|
||||
return dataStore.getAvailableFields();
|
||||
}
|
||||
|
||||
public SortedSet<String> getAvailableValuesForKey(final String query, final String fieldName) {
|
||||
return dataStore.getAvailableValuesForKey(query, fieldName);
|
||||
}
|
||||
|
||||
public List<Proposal> propose(final String query, final int caretIndex) {
|
||||
return proposer.propose(query, caretIndex);
|
||||
}
|
||||
|
||||
public List<Doc> getByTags(final Tags tags) {
|
||||
|
||||
return dataStore.getByTags(tags);
|
||||
}
|
||||
|
||||
public Path getStorageBasePath() {
|
||||
return dataStore.getStorageBasePath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
dataStore.close();
|
||||
}
|
||||
|
||||
public DiskStorage getDiskStorage() {
|
||||
return dataStore.getDiskStorage();
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import org.lucares.collections.IntList;
|
||||
import org.lucares.pdb.api.StringCompressor;
|
||||
import org.lucares.pdb.api.Tags;
|
||||
import org.lucares.pdb.datastore.Doc;
|
||||
import org.lucares.pdb.datastore.Proposal;
|
||||
import org.lucares.pdb.datastore.lang.Expression;
|
||||
import org.lucares.pdb.datastore.lang.ExpressionToDocIdVisitor;
|
||||
import org.lucares.pdb.datastore.lang.ExpressionToDocIdVisitor.AllDocIds;
|
||||
@@ -265,15 +266,15 @@ public class DataStore implements AutoCloseable {
|
||||
return result;
|
||||
}
|
||||
|
||||
public Path getStorageBasePath() {
|
||||
return storageBasePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
diskStorage.close();
|
||||
}
|
||||
|
||||
public List<Proposal> propose(final String query, final int caretIndex) {
|
||||
return new Proposer(this).propose(query, caretIndex);
|
||||
}
|
||||
|
||||
private void initListingFileIfNotExists() throws IOException {
|
||||
if (!Files.exists(listingFilePath)) {
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.lucares.pdb.api.Tags;
|
||||
import org.lucares.pdb.datastore.PdbDB;
|
||||
import org.lucares.pdb.datastore.Proposal;
|
||||
import org.lucares.utils.CollectionUtils;
|
||||
import org.lucares.utils.file.FileUtils;
|
||||
@@ -21,7 +20,7 @@ import org.testng.annotations.Test;
|
||||
public class ProposerTest {
|
||||
|
||||
private Path dataDirectory;
|
||||
private PdbDB db;
|
||||
private DataStore dataStore;
|
||||
|
||||
@BeforeClass
|
||||
public void beforeClass() throws Exception {
|
||||
@@ -32,13 +31,13 @@ public class ProposerTest {
|
||||
@AfterClass
|
||||
public void afterClass() throws IOException {
|
||||
FileUtils.delete(dataDirectory);
|
||||
db.close();
|
||||
db = null;
|
||||
dataStore.close();
|
||||
dataStore = null;
|
||||
Tags.STRING_COMPRESSOR = null;
|
||||
}
|
||||
|
||||
private void initDatabase() throws Exception {
|
||||
db = new PdbDB(dataDirectory);
|
||||
dataStore = new DataStore(dataDirectory);
|
||||
|
||||
final Tags eagleTim = Tags.create("bird", "eagle", "name", "Tim");
|
||||
final Tags eagleTimothy = Tags.create("bird", "eagle", "name", "Timothy");
|
||||
@@ -47,12 +46,12 @@ public class ProposerTest {
|
||||
final Tags labradorJenny = Tags.create("dog", "labrador", "name", "Jenny");
|
||||
final Tags labradorTim = Tags.create("dog", "labrador", "name", "Tim");
|
||||
|
||||
db.createNewFile(eagleTim);
|
||||
db.createNewFile(eagleTimothy);
|
||||
db.createNewFile(pigeonJennifer);
|
||||
db.createNewFile(flamingoJennifer);
|
||||
db.createNewFile(labradorJenny);
|
||||
db.createNewFile(labradorTim);
|
||||
dataStore.createNewFile(eagleTim);
|
||||
dataStore.createNewFile(eagleTimothy);
|
||||
dataStore.createNewFile(pigeonJennifer);
|
||||
dataStore.createNewFile(flamingoJennifer);
|
||||
dataStore.createNewFile(labradorJenny);
|
||||
dataStore.createNewFile(labradorTim);
|
||||
}
|
||||
|
||||
public void testEmptyQuery() throws Exception {
|
||||
@@ -142,7 +141,7 @@ public class ProposerTest {
|
||||
private void assertProposals(final String query, final int caretIndex, final Proposal... expected)
|
||||
throws InterruptedException {
|
||||
|
||||
final List<Proposal> actual = db.propose(query, caretIndex);
|
||||
final List<Proposal> actual = dataStore.propose(query, caretIndex);
|
||||
final List<Proposal> expectedList = Arrays.asList(expected);
|
||||
Collections.sort(expectedList);
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@ import org.lucares.pdb.api.Entry;
|
||||
import org.lucares.pdb.api.GroupResult;
|
||||
import org.lucares.pdb.api.Result;
|
||||
import org.lucares.pdb.api.Tags;
|
||||
import org.lucares.pdb.datastore.PdbDB;
|
||||
import org.lucares.pdb.datastore.Proposal;
|
||||
import org.lucares.pdb.datastore.internal.DataStore;
|
||||
import org.lucares.pdb.datastore.lang.SyntaxException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -28,13 +28,13 @@ public class PerformanceDb implements AutoCloseable {
|
||||
|
||||
private final TagsToFile tagsToFile;
|
||||
|
||||
private final PdbDB db;
|
||||
private final DataStore dataStore;
|
||||
|
||||
public PerformanceDb(final Path dataDirectory) throws IOException {
|
||||
|
||||
db = new PdbDB(dataDirectory);
|
||||
dataStore = new DataStore(dataDirectory);
|
||||
|
||||
tagsToFile = new TagsToFile(db);
|
||||
tagsToFile = new TagsToFile(dataStore);
|
||||
}
|
||||
|
||||
public void put(final Entry entry) throws WriteException {
|
||||
@@ -139,7 +139,7 @@ public class PerformanceDb implements AutoCloseable {
|
||||
private Result toResult(final Grouping grouping) {
|
||||
final List<GroupResult> groupResults = new ArrayList<>();
|
||||
for (final Group group : grouping.getGroups()) {
|
||||
final Stream<LongList> stream = PdbFile.toStream(group.getFiles(), db.getDiskStorage());
|
||||
final Stream<LongList> stream = PdbFile.toStream(group.getFiles(), dataStore.getDiskStorage());
|
||||
final GroupResult groupResult = new GroupResult(stream, group.getTags());
|
||||
groupResults.add(groupResult);
|
||||
}
|
||||
@@ -151,7 +151,7 @@ public class PerformanceDb implements AutoCloseable {
|
||||
public void close() {
|
||||
tagsToFile.close();
|
||||
try {
|
||||
db.close();
|
||||
dataStore.close();
|
||||
} catch (final IOException e) {
|
||||
LOGGER.error("failed to close PdbDB", e);
|
||||
}
|
||||
@@ -159,17 +159,17 @@ public class PerformanceDb implements AutoCloseable {
|
||||
|
||||
public List<Proposal> autocomplete(final String query, final int caretIndex) {
|
||||
|
||||
return db.propose(query, caretIndex);
|
||||
return dataStore.propose(query, caretIndex);
|
||||
}
|
||||
|
||||
public List<String> getFields() {
|
||||
|
||||
final List<String> fields = db.getAvailableFields();
|
||||
final List<String> fields = dataStore.getAvailableFields();
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
||||
public SortedSet<String> getFieldsValues(final String query, final String fieldName) {
|
||||
return db.getAvailableValuesForKey(query, fieldName);
|
||||
return dataStore.getAvailableValuesForKey(query, fieldName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.function.Consumer;
|
||||
|
||||
import org.lucares.pdb.api.Tags;
|
||||
import org.lucares.pdb.datastore.Doc;
|
||||
import org.lucares.pdb.datastore.PdbDB;
|
||||
import org.lucares.pdb.datastore.internal.DataStore;
|
||||
import org.lucares.performance.db.HotEntryCache.Event;
|
||||
import org.lucares.performance.db.HotEntryCache.EventListener;
|
||||
import org.lucares.performance.db.HotEntryCache.EventType;
|
||||
@@ -64,12 +64,11 @@ public class TagsToFile implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
private final PdbDB db;
|
||||
|
||||
private final HotEntryCache<CacheKey, PdbWriter> writerCache;
|
||||
private final DataStore dataStore;
|
||||
|
||||
public TagsToFile(final PdbDB db) {
|
||||
this.db = db;
|
||||
public TagsToFile(final DataStore dataStore) {
|
||||
this.dataStore = dataStore;
|
||||
|
||||
writerCache = new HotEntryCache<>(Duration.ofSeconds(10));
|
||||
writerCache.addListener(new RemovalListener(), EventType.EVICTED, EventType.REMOVED);
|
||||
@@ -78,7 +77,7 @@ public class TagsToFile implements AutoCloseable {
|
||||
|
||||
public List<PdbFile> getFilesForQuery(final String query) {
|
||||
|
||||
final List<Doc> searchResult = db.search(query);
|
||||
final List<Doc> searchResult = dataStore.search(query);
|
||||
if (searchResult.size() > 500_000) {
|
||||
throw new IllegalStateException("Too many results.");
|
||||
}
|
||||
@@ -111,12 +110,12 @@ public class TagsToFile implements AutoCloseable {
|
||||
if (writer == null) {
|
||||
|
||||
LOGGER.trace("getByTags({})", tags);
|
||||
final List<Doc> docsForTags = db.getByTags(tags);
|
||||
final List<Doc> docsForTags = dataStore.getByTags(tags);
|
||||
if (docsForTags.size() > 0) {
|
||||
try {
|
||||
final Doc doc = docsForTags.get(0);
|
||||
final PdbFile pdbFile = new PdbFile(doc.getRootBlockNumber(), tags);
|
||||
writer = new PdbWriter(pdbFile, db.getDiskStorage());
|
||||
writer = new PdbWriter(pdbFile, dataStore.getDiskStorage());
|
||||
} catch (final IOException e) {
|
||||
throw new ReadException(e);
|
||||
}
|
||||
@@ -134,7 +133,7 @@ public class TagsToFile implements AutoCloseable {
|
||||
final long start = System.nanoTime();
|
||||
try {
|
||||
final PdbFile pdbFile = createNewPdbFile(tags);
|
||||
final PdbWriter result = new PdbWriter(pdbFile, db.getDiskStorage());
|
||||
final PdbWriter result = new PdbWriter(pdbFile, dataStore.getDiskStorage());
|
||||
|
||||
METRICS_LOGGER_NEW_WRITER.debug("newPdbWriter took {}ms tags: {}",
|
||||
(System.nanoTime() - start) / 1_000_000.0, tags);
|
||||
@@ -147,7 +146,7 @@ public class TagsToFile implements AutoCloseable {
|
||||
|
||||
private PdbFile createNewPdbFile(final Tags tags) throws IOException {
|
||||
|
||||
final long rootBlockNumber = db.createNewFile(tags);
|
||||
final long rootBlockNumber = dataStore.createNewFile(tags);
|
||||
|
||||
final PdbFile result = new PdbFile(rootBlockNumber, tags);
|
||||
return result;
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.time.ZoneOffset;
|
||||
|
||||
import org.lucares.pdb.api.Entry;
|
||||
import org.lucares.pdb.api.Tags;
|
||||
import org.lucares.pdb.datastore.PdbDB;
|
||||
import org.lucares.pdb.datastore.internal.DataStore;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
@@ -31,8 +31,8 @@ public class TagsToFilesTest {
|
||||
|
||||
public void test() throws Exception {
|
||||
|
||||
try (final PdbDB db = new PdbDB(dataDirectory); //
|
||||
final TagsToFile tagsToFile = new TagsToFile(db)) {
|
||||
try (final DataStore dataStore = new DataStore(dataDirectory); //
|
||||
final TagsToFile tagsToFile = new TagsToFile(dataStore)) {
|
||||
|
||||
final OffsetDateTime date = OffsetDateTime.now(ZoneOffset.UTC);
|
||||
final Tags tags = Tags.create("myKey", "myValue");
|
||||
@@ -47,8 +47,8 @@ public class TagsToFilesTest {
|
||||
|
||||
public void testAppendingToSameFile() throws Exception {
|
||||
|
||||
try (final PdbDB db = new PdbDB(dataDirectory); //
|
||||
final TagsToFile tagsToFile = new TagsToFile(db);) {
|
||||
try (final DataStore dataStore = new DataStore(dataDirectory); //
|
||||
final TagsToFile tagsToFile = new TagsToFile(dataStore);) {
|
||||
|
||||
// dayC is before dayA and dayB
|
||||
final OffsetDateTime dayA = DateUtils.getDate(2016, 1, 2, 1, 1, 1);
|
||||
@@ -72,8 +72,8 @@ public class TagsToFilesTest {
|
||||
|
||||
public void testIdenticalDatesGoIntoSameFile() throws Exception {
|
||||
|
||||
try (final PdbDB db = new PdbDB(dataDirectory); //
|
||||
final TagsToFile tagsToFile = new TagsToFile(db)) {
|
||||
try (final DataStore dataStore = new DataStore(dataDirectory); //
|
||||
final TagsToFile tagsToFile = new TagsToFile(dataStore)) {
|
||||
|
||||
final OffsetDateTime timestamp = DateUtils.getDate(2016, 1, 1, 13, 1, 1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user