improve trace logging
- Add filename for trace logs for read/write operations.
This commit is contained in:
@@ -159,7 +159,7 @@ public class BSFile implements AutoCloseable {
|
|||||||
|
|
||||||
public void flush() {
|
public void flush() {
|
||||||
|
|
||||||
LOGGER.trace("flush bsFile={} dirty={}", rootBlockOffset, dirty);
|
LOGGER.trace("flush bsFile={} dirty={} file={}", rootBlockOffset, dirty, diskStorage.getRelativeDatabaseFileForLogging());
|
||||||
if (dirty) {
|
if (dirty) {
|
||||||
buffer.writeAsync();
|
buffer.writeAsync();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,11 @@ public class DiskStorage implements AutoCloseable {
|
|||||||
|
|
||||||
private final FileChannel fileChannel;
|
private final FileChannel fileChannel;
|
||||||
|
|
||||||
public DiskStorage(final Path databaseFile) {
|
private Path relativeDatabaseFileForLogging;
|
||||||
|
|
||||||
|
|
||||||
|
public DiskStorage(final Path databaseFile, Path storageBasePath) {
|
||||||
|
this.relativeDatabaseFileForLogging = storageBasePath != null ? storageBasePath.relativize(databaseFile): databaseFile;
|
||||||
try {
|
try {
|
||||||
Files.createDirectories(databaseFile.getParent());
|
Files.createDirectories(databaseFile.getParent());
|
||||||
|
|
||||||
@@ -47,7 +51,7 @@ public class DiskStorage implements AutoCloseable {
|
|||||||
|
|
||||||
public DiskBlock getDiskBlock(final long blockOffset, final int blockSize) {
|
public DiskBlock getDiskBlock(final long blockOffset, final int blockSize) {
|
||||||
try {
|
try {
|
||||||
LOGGER.trace("read block={}", blockOffset);
|
LOGGER.trace("read block={} file={}", blockOffset, relativeDatabaseFileForLogging);
|
||||||
|
|
||||||
final var byteBuffer = fileChannel.map(MapMode.READ_WRITE, blockOffset, blockSize);
|
final var byteBuffer = fileChannel.map(MapMode.READ_WRITE, blockOffset, blockSize);
|
||||||
|
|
||||||
@@ -57,6 +61,10 @@ public class DiskStorage implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Path getRelativeDatabaseFileForLogging() {
|
||||||
|
return relativeDatabaseFileForLogging;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ public class PersistentMap<K, V> implements AutoCloseable {
|
|||||||
public default Function<O,byte[]> asEncoder() {
|
public default Function<O,byte[]> asEncoder() {
|
||||||
return plain -> this.encode(plain);
|
return plain -> this.encode(plain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte[] getEmptyValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class StringCoder implements EncoderDecoder<String> {
|
private static final class StringCoder implements EncoderDecoder<String> {
|
||||||
@@ -61,6 +63,10 @@ public class PersistentMap<K, V> implements AutoCloseable {
|
|||||||
public String decode(final byte[] bytes) {
|
public String decode(final byte[] bytes) {
|
||||||
return bytes == null ? null : new String(bytes, StandardCharsets.UTF_8);
|
return bytes == null ? null : new String(bytes, StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte[] getEmptyValue() {
|
||||||
|
return new byte[] {0};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class LongCoder implements EncoderDecoder<Long> {
|
private static final class LongCoder implements EncoderDecoder<Long> {
|
||||||
@@ -74,6 +80,10 @@ public class PersistentMap<K, V> implements AutoCloseable {
|
|||||||
public Long decode(final byte[] bytes) {
|
public Long decode(final byte[] bytes) {
|
||||||
return bytes == null ? null : VariableByteEncoder.decodeFirstValue(bytes);
|
return bytes == null ? null : VariableByteEncoder.decodeFirstValue(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte[] getEmptyValue() {
|
||||||
|
return new byte[] {0};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class UUIDCoder implements EncoderDecoder<UUID> {
|
private static final class UUIDCoder implements EncoderDecoder<UUID> {
|
||||||
@@ -94,6 +104,10 @@ public class PersistentMap<K, V> implements AutoCloseable {
|
|||||||
|
|
||||||
return new UUID(mostSignificantBits, leastSignificantBits);
|
return new UUID(mostSignificantBits, leastSignificantBits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte[] getEmptyValue() {
|
||||||
|
return new byte[] {0};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class EmptyCoder implements EncoderDecoder<Empty> {
|
private static final class EmptyCoder implements EncoderDecoder<Empty> {
|
||||||
@@ -112,6 +126,10 @@ public class PersistentMap<K, V> implements AutoCloseable {
|
|||||||
|
|
||||||
return Empty.INSTANCE;
|
return Empty.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte[] getEmptyValue() {
|
||||||
|
return new byte[] {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final EncoderDecoder<Long> LONG_CODER = new LongCoder();
|
public static final EncoderDecoder<Long> LONG_CODER = new LongCoder();
|
||||||
@@ -134,8 +152,8 @@ public class PersistentMap<K, V> implements AutoCloseable {
|
|||||||
|
|
||||||
private final LRUCache<K, V> valueCache = new LRUCache<>(1_000);
|
private final LRUCache<K, V> valueCache = new LRUCache<>(1_000);
|
||||||
|
|
||||||
public PersistentMap(final Path path, final EncoderDecoder<K> keyEncoder, final EncoderDecoder<V> valueEncoder) {
|
public PersistentMap(final Path path, final Path storageBasePath, final EncoderDecoder<K> keyEncoder, final EncoderDecoder<V> valueEncoder) {
|
||||||
this.diskStore = new DiskStorage(path);
|
this.diskStore = new DiskStorage(path, storageBasePath);
|
||||||
this.keyEncoder = keyEncoder;
|
this.keyEncoder = keyEncoder;
|
||||||
this.valueEncoder = valueEncoder;
|
this.valueEncoder = valueEncoder;
|
||||||
initIfNew();
|
initIfNew();
|
||||||
@@ -169,7 +187,7 @@ public class PersistentMap<K, V> implements AutoCloseable {
|
|||||||
writeNodeOffsetOfRootNode(blockOffset);
|
writeNodeOffsetOfRootNode(blockOffset);
|
||||||
|
|
||||||
// 5. insert a dummy entry with a 'maximum' key
|
// 5. insert a dummy entry with a 'maximum' key
|
||||||
putValue(MAX_KEY, new byte[] { });
|
putValue(MAX_KEY, valueEncoder.getEmptyValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,8 +43,8 @@ public class BSFileTest {
|
|||||||
long blockOffset = -1;
|
long blockOffset = -1;
|
||||||
|
|
||||||
long start = System.nanoTime();
|
long start = System.nanoTime();
|
||||||
//
|
|
||||||
try (final DiskStorage ds = new DiskStorage(file)) {
|
try (final DiskStorage ds = new DiskStorage(file, dataDirectory)) {
|
||||||
|
|
||||||
try (final BSFile bsFile = BSFile.newFile(ds, NullCustomizer.INSTANCE)) {
|
try (final BSFile bsFile = BSFile.newFile(ds, NullCustomizer.INSTANCE)) {
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ public class BSFileTest {
|
|||||||
System.out.println("duration write: " + (System.nanoTime() - start) / 1_000_000.0 + "ms");
|
System.out.println("duration write: " + (System.nanoTime() - start) / 1_000_000.0 + "ms");
|
||||||
|
|
||||||
start = System.nanoTime();
|
start = System.nanoTime();
|
||||||
try (final DiskStorage ds = new DiskStorage(file)) {
|
try (final DiskStorage ds = new DiskStorage(file, dataDirectory)) {
|
||||||
final BSFile bsFile = BSFile.existingFile(blockOffset, ds, NullCustomizer.INSTANCE);
|
final BSFile bsFile = BSFile.existingFile(blockOffset, ds, NullCustomizer.INSTANCE);
|
||||||
final LongList actualLongs = bsFile.asLongList();
|
final LongList actualLongs = bsFile.asLongList();
|
||||||
final LongList expectedLongs = LongList.rangeClosed(0, numLongs - 1);
|
final LongList expectedLongs = LongList.rangeClosed(0, numLongs - 1);
|
||||||
@@ -83,7 +83,7 @@ public class BSFileTest {
|
|||||||
final Map<Long, LongList> expected = new HashMap<>();
|
final Map<Long, LongList> expected = new HashMap<>();
|
||||||
final List<Future<Void>> futures = new ArrayList<>();
|
final List<Future<Void>> futures = new ArrayList<>();
|
||||||
final long start = System.nanoTime();
|
final long start = System.nanoTime();
|
||||||
try (final DiskStorage ds = new DiskStorage(file)) {
|
try (final DiskStorage ds = new DiskStorage(file, dataDirectory)) {
|
||||||
|
|
||||||
for (int i = 0; i < threads; i++) {
|
for (int i = 0; i < threads; i++) {
|
||||||
final Future<Void> future = pool.submit(() -> {
|
final Future<Void> future = pool.submit(() -> {
|
||||||
@@ -117,7 +117,7 @@ public class BSFileTest {
|
|||||||
System.out.println("duration write: " + (System.nanoTime() - start) / 1_000_000.0 + "ms");
|
System.out.println("duration write: " + (System.nanoTime() - start) / 1_000_000.0 + "ms");
|
||||||
|
|
||||||
// verification
|
// verification
|
||||||
try (final DiskStorage ds = new DiskStorage(file)) {
|
try (final DiskStorage ds = new DiskStorage(file, dataDirectory)) {
|
||||||
for (final Entry<Long, LongList> entry : expected.entrySet()) {
|
for (final Entry<Long, LongList> entry : expected.entrySet()) {
|
||||||
final long rootBlockNumber = entry.getKey();
|
final long rootBlockNumber = entry.getKey();
|
||||||
final LongList expectedValues = entry.getValue();
|
final LongList expectedValues = entry.getValue();
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class TimeSeriesFileTest {
|
|||||||
long start = System.nanoTime();
|
long start = System.nanoTime();
|
||||||
long lastEpochMilli = 0;
|
long lastEpochMilli = 0;
|
||||||
//
|
//
|
||||||
try (final DiskStorage ds = new DiskStorage(file)) {
|
try (final DiskStorage ds = new DiskStorage(file, dataDirectory)) {
|
||||||
|
|
||||||
try (final TimeSeriesFile bsFile = TimeSeriesFile.newFile(ds)) {
|
try (final TimeSeriesFile bsFile = TimeSeriesFile.newFile(ds)) {
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ public class TimeSeriesFileTest {
|
|||||||
System.out.println("duration write: " + (System.nanoTime() - start) / 1_000_000.0 + "ms");
|
System.out.println("duration write: " + (System.nanoTime() - start) / 1_000_000.0 + "ms");
|
||||||
|
|
||||||
start = System.nanoTime();
|
start = System.nanoTime();
|
||||||
try (final DiskStorage ds = new DiskStorage(file)) {
|
try (final DiskStorage ds = new DiskStorage(file, dataDirectory)) {
|
||||||
final TimeSeriesFile bsFile = TimeSeriesFile.existingFile(blockNumber, ds);
|
final TimeSeriesFile bsFile = TimeSeriesFile.existingFile(blockNumber, ds);
|
||||||
final LongList actualLongs = bsFile.asTimeValueLongList();
|
final LongList actualLongs = bsFile.asTimeValueLongList();
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public class DiskStorageTest {
|
|||||||
final Path databaseFile = dataDirectory.resolve("db.ds");
|
final Path databaseFile = dataDirectory.resolve("db.ds");
|
||||||
Files.deleteIfExists(databaseFile);
|
Files.deleteIfExists(databaseFile);
|
||||||
|
|
||||||
try (DiskStorage ds = new DiskStorage(databaseFile)) {
|
try (DiskStorage ds = new DiskStorage(databaseFile, dataDirectory)) {
|
||||||
final int numBlocks = 10;
|
final int numBlocks = 10;
|
||||||
|
|
||||||
allocateBlocks(ds, numBlocks, BLOCK_SIZE);
|
allocateBlocks(ds, numBlocks, BLOCK_SIZE);
|
||||||
@@ -81,7 +81,7 @@ public class DiskStorageTest {
|
|||||||
//
|
//
|
||||||
// But it does see the changes. Most likely, because both channels
|
// But it does see the changes. Most likely, because both channels
|
||||||
// use the same buffers from the operating system.
|
// use the same buffers from the operating system.
|
||||||
try (DiskStorage ds2 = new DiskStorage(databaseFile)) {
|
try (DiskStorage ds2 = new DiskStorage(databaseFile, dataDirectory)) {
|
||||||
for (int i = 0; i < numBlocks; i++) {
|
for (int i = 0; i < numBlocks; i++) {
|
||||||
final DiskBlock diskBlock = ds2.getDiskBlock(i, BLOCK_SIZE);
|
final DiskBlock diskBlock = ds2.getDiskBlock(i, BLOCK_SIZE);
|
||||||
assertAllValuesAreEqual(diskBlock, (byte) i);
|
assertAllValuesAreEqual(diskBlock, (byte) i);
|
||||||
@@ -98,7 +98,7 @@ public class DiskStorageTest {
|
|||||||
|
|
||||||
final ExecutorService pool = Executors.newCachedThreadPool();
|
final ExecutorService pool = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
try (DiskStorage ds = new DiskStorage(databaseFile)) {
|
try (DiskStorage ds = new DiskStorage(databaseFile, dataDirectory)) {
|
||||||
final int numBlocks = 10;
|
final int numBlocks = 10;
|
||||||
|
|
||||||
final long[] blockOffsets = allocateBlocks(ds, numBlocks, BLOCK_SIZE);
|
final long[] blockOffsets = allocateBlocks(ds, numBlocks, BLOCK_SIZE);
|
||||||
@@ -140,7 +140,7 @@ public class DiskStorageTest {
|
|||||||
public void testAllocationSmallerThanMinimalBlockSize() throws Exception {
|
public void testAllocationSmallerThanMinimalBlockSize() throws Exception {
|
||||||
final Path databaseFile = dataDirectory.resolve("db.ds");
|
final Path databaseFile = dataDirectory.resolve("db.ds");
|
||||||
|
|
||||||
try (DiskStorage ds = new DiskStorage(databaseFile)) {
|
try (DiskStorage ds = new DiskStorage(databaseFile, dataDirectory)) {
|
||||||
|
|
||||||
final int blockSize = 31; // minimal block size is 32
|
final int blockSize = 31; // minimal block size is 32
|
||||||
ds.allocateBlock(blockSize);
|
ds.allocateBlock(blockSize);
|
||||||
@@ -151,7 +151,7 @@ public class DiskStorageTest {
|
|||||||
public void testAllocateAndFreeSingleBlockInFreeList() throws Exception {
|
public void testAllocateAndFreeSingleBlockInFreeList() throws Exception {
|
||||||
final Path databaseFile = dataDirectory.resolve("db.ds");
|
final Path databaseFile = dataDirectory.resolve("db.ds");
|
||||||
|
|
||||||
try (DiskStorage ds = new DiskStorage(databaseFile)) {
|
try (DiskStorage ds = new DiskStorage(databaseFile, dataDirectory)) {
|
||||||
|
|
||||||
final int blockSize = 32;
|
final int blockSize = 32;
|
||||||
final long block_8_39 = ds.allocateBlock(blockSize);
|
final long block_8_39 = ds.allocateBlock(blockSize);
|
||||||
@@ -175,7 +175,7 @@ public class DiskStorageTest {
|
|||||||
public void testAllocateAndFreeMultipleBlocksInFreeList() throws Exception {
|
public void testAllocateAndFreeMultipleBlocksInFreeList() throws Exception {
|
||||||
final Path databaseFile = dataDirectory.resolve("db.ds");
|
final Path databaseFile = dataDirectory.resolve("db.ds");
|
||||||
|
|
||||||
try (DiskStorage ds = new DiskStorage(databaseFile)) {
|
try (DiskStorage ds = new DiskStorage(databaseFile, dataDirectory)) {
|
||||||
|
|
||||||
final int blockSize = 32;
|
final int blockSize = 32;
|
||||||
ds.allocateBlock(blockSize);
|
ds.allocateBlock(blockSize);
|
||||||
@@ -212,7 +212,7 @@ public class DiskStorageTest {
|
|||||||
public void testAllocateAndFreeInsertFreeNodeInTheMiddleOfTheFreeList() throws Exception {
|
public void testAllocateAndFreeInsertFreeNodeInTheMiddleOfTheFreeList() throws Exception {
|
||||||
final Path databaseFile = dataDirectory.resolve("db.ds");
|
final Path databaseFile = dataDirectory.resolve("db.ds");
|
||||||
|
|
||||||
try (DiskStorage ds = new DiskStorage(databaseFile)) {
|
try (DiskStorage ds = new DiskStorage(databaseFile, dataDirectory)) {
|
||||||
|
|
||||||
final int blockSize = 32;
|
final int blockSize = 32;
|
||||||
ds.allocateBlock(blockSize);
|
ds.allocateBlock(blockSize);
|
||||||
@@ -242,7 +242,7 @@ public class DiskStorageTest {
|
|||||||
public void testAllocateAndFreeMultipleBlocksWithDifferentSizes() throws Exception {
|
public void testAllocateAndFreeMultipleBlocksWithDifferentSizes() throws Exception {
|
||||||
final Path databaseFile = dataDirectory.resolve("db.ds");
|
final Path databaseFile = dataDirectory.resolve("db.ds");
|
||||||
|
|
||||||
try (DiskStorage ds = new DiskStorage(databaseFile)) {
|
try (DiskStorage ds = new DiskStorage(databaseFile, dataDirectory)) {
|
||||||
|
|
||||||
final int blockSizeSmall = 32;
|
final int blockSizeSmall = 32;
|
||||||
final int blockSizeBig = 64;
|
final int blockSizeBig = 64;
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class PersistentMapTest {
|
|||||||
final String value = "value1";
|
final String value = "value1";
|
||||||
final String key = "key1";
|
final String key = "key1";
|
||||||
|
|
||||||
try (final PersistentMap<String, String> map = new PersistentMap<>(file, PersistentMap.STRING_CODER,
|
try (final PersistentMap<String, String> map = new PersistentMap<>(file, dataDirectory, PersistentMap.STRING_CODER,
|
||||||
PersistentMap.STRING_CODER)) {
|
PersistentMap.STRING_CODER)) {
|
||||||
|
|
||||||
Assert.assertNull(map.getValue(key));
|
Assert.assertNull(map.getValue(key));
|
||||||
@@ -50,7 +50,7 @@ public class PersistentMapTest {
|
|||||||
|
|
||||||
Assert.assertEquals(map.getValue(key), value);
|
Assert.assertEquals(map.getValue(key), value);
|
||||||
}
|
}
|
||||||
try (final PersistentMap<String, String> map = new PersistentMap<>(file, PersistentMap.STRING_CODER,
|
try (final PersistentMap<String, String> map = new PersistentMap<>(file, dataDirectory,PersistentMap.STRING_CODER,
|
||||||
PersistentMap.STRING_CODER)) {
|
PersistentMap.STRING_CODER)) {
|
||||||
|
|
||||||
Assert.assertEquals(map.getValue(key), value);
|
Assert.assertEquals(map.getValue(key), value);
|
||||||
@@ -64,7 +64,7 @@ public class PersistentMapTest {
|
|||||||
|
|
||||||
final Random rnd = new Random(1);
|
final Random rnd = new Random(1);
|
||||||
|
|
||||||
try (final PersistentMap<String, String> map = new PersistentMap<>(file, PersistentMap.STRING_CODER,
|
try (final PersistentMap<String, String> map = new PersistentMap<>(file,dataDirectory, PersistentMap.STRING_CODER,
|
||||||
PersistentMap.STRING_CODER)) {
|
PersistentMap.STRING_CODER)) {
|
||||||
map.setMaxEntriesInNode(2);
|
map.setMaxEntriesInNode(2);
|
||||||
|
|
||||||
@@ -98,7 +98,7 @@ public class PersistentMapTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try (final PersistentMap<String, String> map = new PersistentMap<>(file, PersistentMap.STRING_CODER,
|
try (final PersistentMap<String, String> map = new PersistentMap<>(file,dataDirectory, PersistentMap.STRING_CODER,
|
||||||
PersistentMap.STRING_CODER)) {
|
PersistentMap.STRING_CODER)) {
|
||||||
// map.print(PersistentMap.STRING_DECODER, PersistentMap.STRING_DECODER);
|
// map.print(PersistentMap.STRING_DECODER, PersistentMap.STRING_DECODER);
|
||||||
final AtomicInteger maxDepth = new AtomicInteger();
|
final AtomicInteger maxDepth = new AtomicInteger();
|
||||||
@@ -127,7 +127,7 @@ public class PersistentMapTest {
|
|||||||
final SecureRandom rnd = new SecureRandom();
|
final SecureRandom rnd = new SecureRandom();
|
||||||
rnd.setSeed(1);
|
rnd.setSeed(1);
|
||||||
|
|
||||||
try (final PersistentMap<Long, Long> map = new PersistentMap<>(file, PersistentMap.LONG_CODER,
|
try (final PersistentMap<Long, Long> map = new PersistentMap<>(file,dataDirectory, PersistentMap.LONG_CODER,
|
||||||
PersistentMap.LONG_CODER)) {
|
PersistentMap.LONG_CODER)) {
|
||||||
|
|
||||||
for (int i = 0; i < 1000; i++) {
|
for (int i = 0; i < 1000; i++) {
|
||||||
@@ -159,7 +159,7 @@ public class PersistentMapTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try (final PersistentMap<Long, Long> map = new PersistentMap<>(file, PersistentMap.LONG_CODER,
|
try (final PersistentMap<Long, Long> map = new PersistentMap<>(file,dataDirectory, PersistentMap.LONG_CODER,
|
||||||
PersistentMap.LONG_CODER)) {
|
PersistentMap.LONG_CODER)) {
|
||||||
// map.print(PersistentMap.LONG_DECODER, PersistentMap.LONG_DECODER);
|
// map.print(PersistentMap.LONG_DECODER, PersistentMap.LONG_DECODER);
|
||||||
final AtomicInteger counter = new AtomicInteger();
|
final AtomicInteger counter = new AtomicInteger();
|
||||||
@@ -187,7 +187,7 @@ public class PersistentMapTest {
|
|||||||
final SecureRandom rnd = new SecureRandom();
|
final SecureRandom rnd = new SecureRandom();
|
||||||
rnd.setSeed(1);
|
rnd.setSeed(1);
|
||||||
|
|
||||||
try (final PersistentMap<Long, Empty> map = new PersistentMap<>(file, PersistentMap.LONG_CODER,
|
try (final PersistentMap<Long, Empty> map = new PersistentMap<>(file,dataDirectory, PersistentMap.LONG_CODER,
|
||||||
PersistentMap.EMPTY_ENCODER)) {
|
PersistentMap.EMPTY_ENCODER)) {
|
||||||
|
|
||||||
for (int i = 0; i < 1500; i++) {
|
for (int i = 0; i < 1500; i++) {
|
||||||
@@ -219,7 +219,7 @@ public class PersistentMapTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try (final PersistentMap<Long, Empty> map = new PersistentMap<>(file, PersistentMap.LONG_CODER,
|
try (final PersistentMap<Long, Empty> map = new PersistentMap<>(file,dataDirectory, PersistentMap.LONG_CODER,
|
||||||
PersistentMap.EMPTY_ENCODER)) {
|
PersistentMap.EMPTY_ENCODER)) {
|
||||||
map.print();
|
map.print();
|
||||||
final AtomicInteger counter = new AtomicInteger();
|
final AtomicInteger counter = new AtomicInteger();
|
||||||
@@ -247,7 +247,7 @@ public class PersistentMapTest {
|
|||||||
|
|
||||||
final Queue<Integer> numbers = new LinkedList<>(Arrays.asList(1, 15, 11, 4, 16, 3, 13));
|
final Queue<Integer> numbers = new LinkedList<>(Arrays.asList(1, 15, 11, 4, 16, 3, 13));
|
||||||
|
|
||||||
try (final PersistentMap<String, String> map = new PersistentMap<>(file, PersistentMap.STRING_CODER,
|
try (final PersistentMap<String, String> map = new PersistentMap<>(file,dataDirectory, PersistentMap.STRING_CODER,
|
||||||
PersistentMap.STRING_CODER)) {
|
PersistentMap.STRING_CODER)) {
|
||||||
|
|
||||||
final int numbersSize = numbers.size();
|
final int numbersSize = numbers.size();
|
||||||
@@ -275,7 +275,7 @@ public class PersistentMapTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try (final PersistentMap<String, String> map = new PersistentMap<>(file, PersistentMap.STRING_CODER,
|
try (final PersistentMap<String, String> map = new PersistentMap<>(file,dataDirectory, PersistentMap.STRING_CODER,
|
||||||
PersistentMap.STRING_CODER)) {
|
PersistentMap.STRING_CODER)) {
|
||||||
// map.print(PersistentMap.STRING_DECODER, PersistentMap.STRING_DECODER);
|
// map.print(PersistentMap.STRING_DECODER, PersistentMap.STRING_DECODER);
|
||||||
|
|
||||||
@@ -309,13 +309,13 @@ public class PersistentMapTest {
|
|||||||
input.put(UUID.randomUUID().toString(), UUID.randomUUID().toString());
|
input.put(UUID.randomUUID().toString(), UUID.randomUUID().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
try (final PersistentMap<String, String> map = new PersistentMap<>(file, PersistentMap.STRING_CODER,
|
try (final PersistentMap<String, String> map = new PersistentMap<>(file,dataDirectory, PersistentMap.STRING_CODER,
|
||||||
PersistentMap.STRING_CODER)) {
|
PersistentMap.STRING_CODER)) {
|
||||||
|
|
||||||
map.putAllValues(input);
|
map.putAllValues(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
try (final PersistentMap<String, String> map = new PersistentMap<>(file, PersistentMap.STRING_CODER,
|
try (final PersistentMap<String, String> map = new PersistentMap<>(file,dataDirectory, PersistentMap.STRING_CODER,
|
||||||
PersistentMap.STRING_CODER)) {
|
PersistentMap.STRING_CODER)) {
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -336,7 +336,7 @@ public class PersistentMapTest {
|
|||||||
final SecureRandom rnd = new SecureRandom();
|
final SecureRandom rnd = new SecureRandom();
|
||||||
rnd.setSeed(1);
|
rnd.setSeed(1);
|
||||||
|
|
||||||
try (final PersistentMap<Long, Long> map = new PersistentMap<>(file, PersistentMap.LONG_CODER,
|
try (final PersistentMap<Long, Long> map = new PersistentMap<>(file,dataDirectory, PersistentMap.LONG_CODER,
|
||||||
PersistentMap.LONG_CODER)) {
|
PersistentMap.LONG_CODER)) {
|
||||||
|
|
||||||
for (int i = 0; i < 1_000; i++) {
|
for (int i = 0; i < 1_000; i++) {
|
||||||
@@ -368,7 +368,7 @@ public class PersistentMapTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try (final PersistentMap<Long, Long> map = new PersistentMap<>(file, PersistentMap.LONG_CODER,
|
try (final PersistentMap<Long, Long> map = new PersistentMap<>(file,dataDirectory, PersistentMap.LONG_CODER,
|
||||||
PersistentMap.LONG_CODER)) {
|
PersistentMap.LONG_CODER)) {
|
||||||
final AtomicInteger counter = new AtomicInteger();
|
final AtomicInteger counter = new AtomicInteger();
|
||||||
final AtomicInteger maxDepth = new AtomicInteger();
|
final AtomicInteger maxDepth = new AtomicInteger();
|
||||||
|
|||||||
@@ -43,4 +43,8 @@ class DocEncoderDecoder implements PartitionAwareEncoderDecoder<Doc, Doc> {
|
|||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte[] getEmptyValue() {
|
||||||
|
return new byte[] {0};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,4 +33,8 @@ public final class PartitionAwareWrapper<O> implements PartitionAwareEncoderDeco
|
|||||||
public static <O> PartitionAwareEncoderDecoder<O, O> wrap(final EncoderDecoder<O> encoder) {
|
public static <O> PartitionAwareEncoderDecoder<O, O> wrap(final EncoderDecoder<O> encoder) {
|
||||||
return new PartitionAwareWrapper<>(encoder);
|
return new PartitionAwareWrapper<>(encoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte[] getEmptyValue() {
|
||||||
|
return delegate.getEmptyValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,7 @@ public class PartitionDiskStore {
|
|||||||
creator = partitionId -> {
|
creator = partitionId -> {
|
||||||
final Path file = storageBasePath.resolve(partitionId.getPartitionId()).resolve(filename);
|
final Path file = storageBasePath.resolve(partitionId.getPartitionId()).resolve(filename);
|
||||||
final boolean isNew = !Files.exists(file);
|
final boolean isNew = !Files.exists(file);
|
||||||
final DiskStorage diskStorage = new DiskStorage(file);
|
final DiskStorage diskStorage = new DiskStorage(file, storageBasePath);
|
||||||
if (isNew) {
|
if (isNew) {
|
||||||
diskStorage.ensureAlignmentForNewBlocks(BSFile.BLOCK_SIZE);
|
diskStorage.ensureAlignmentForNewBlocks(BSFile.BLOCK_SIZE);
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,7 @@ public class PartitionDiskStore {
|
|||||||
supplier = partitionId -> {
|
supplier = partitionId -> {
|
||||||
final Path file = storageBasePath.resolve(partitionId.getPartitionId()).resolve(filename);
|
final Path file = storageBasePath.resolve(partitionId.getPartitionId()).resolve(filename);
|
||||||
if (Files.exists(file)) {
|
if (Files.exists(file)) {
|
||||||
return new DiskStorage(file);
|
return new DiskStorage(file, storageBasePath);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -38,12 +38,12 @@ public class PartitionPersistentMap<K, V, P> implements AutoCloseable {
|
|||||||
this.valueEncoder = valueEncoder;
|
this.valueEncoder = valueEncoder;
|
||||||
creator = partitionId -> {
|
creator = partitionId -> {
|
||||||
final Path file = storageBasePath.resolve(partitionId.getPartitionId()).resolve(filename);
|
final Path file = storageBasePath.resolve(partitionId.getPartitionId()).resolve(filename);
|
||||||
return new PersistentMap<>(file, keyEncoder, valueEncoder);
|
return new PersistentMap<>(file, storageBasePath, keyEncoder, valueEncoder);
|
||||||
};
|
};
|
||||||
supplier = partitionId -> {
|
supplier = partitionId -> {
|
||||||
final Path file = storageBasePath.resolve(partitionId.getPartitionId()).resolve(filename);
|
final Path file = storageBasePath.resolve(partitionId.getPartitionId()).resolve(filename);
|
||||||
if (Files.exists(file)) {
|
if (Files.exists(file)) {
|
||||||
return new PersistentMap<>(file, keyEncoder, valueEncoder);
|
return new PersistentMap<>(file, storageBasePath, keyEncoder, valueEncoder);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -164,6 +164,11 @@ public class QueryCompletionIndex implements AutoCloseable {
|
|||||||
|
|
||||||
return new TwoTags(tagA, tagB);
|
return new TwoTags(tagA, tagB);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] getEmptyValue() {
|
||||||
|
return new byte[] {0,0,0,0};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class EncoderTag implements EncoderDecoder<Tag> {
|
private static final class EncoderTag implements EncoderDecoder<Tag> {
|
||||||
@@ -188,6 +193,11 @@ public class QueryCompletionIndex implements AutoCloseable {
|
|||||||
return new Tag(key, value);
|
return new Tag(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] getEmptyValue() {
|
||||||
|
return new byte[] {0};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class EncoderField implements EncoderDecoder<String> {
|
private static final class EncoderField implements EncoderDecoder<String> {
|
||||||
@@ -207,6 +217,11 @@ public class QueryCompletionIndex implements AutoCloseable {
|
|||||||
final long compressedString = VariableByteEncoder.decodeFirstValue(bytes);
|
final long compressedString = VariableByteEncoder.decodeFirstValue(bytes);
|
||||||
return Tags.STRING_COMPRESSOR.get((int) compressedString);
|
return Tags.STRING_COMPRESSOR.get((int) compressedString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] getEmptyValue() {
|
||||||
|
return new byte[] {0};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final PartitionPersistentMap<TwoTags, Empty, Empty> tagToTagIndex;
|
private final PartitionPersistentMap<TwoTags, Empty, Empty> tagToTagIndex;
|
||||||
|
|||||||
@@ -56,4 +56,9 @@ class TagEncoderDecoder implements EncoderDecoder<Tag> {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] getEmptyValue() {
|
||||||
|
return new byte[] {0};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,4 +13,9 @@ class TagsEncoderDecoder implements EncoderDecoder<Tags> {
|
|||||||
public Tags decode(final byte[] bytes) {
|
public Tags decode(final byte[] bytes) {
|
||||||
return Tags.fromBytes(bytes);
|
return Tags.fromBytes(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] getEmptyValue() {
|
||||||
|
return new byte[] {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -323,6 +323,10 @@ public class TcpIngestor implements Ingestor, AutoCloseable, DisposableBean {
|
|||||||
this.db = db;
|
this.db = db;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PerformanceDb getDb() {
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
|
||||||
@Async
|
@Async
|
||||||
@Override
|
@Override
|
||||||
public void start() throws Exception {
|
public void start() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user