remove the wrapper class PdbDB

It did not serve any purpose and could be replaced by DataStore.
This commit is contained in:
2018-10-04 18:43:27 +02:00
parent 01b93e32ca
commit 8939332004
6 changed files with 41 additions and 102 deletions

View File

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

View File

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

View File

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