improve trace logging

- Add filename for trace logs for read/write operations.
This commit is contained in:
2019-08-18 09:25:49 +02:00
parent 16bf0933e7
commit 3252fcf42d
15 changed files with 102 additions and 39 deletions

View File

@@ -159,7 +159,7 @@ public class BSFile implements AutoCloseable {
public void flush() {
LOGGER.trace("flush bsFile={} dirty={}", rootBlockOffset, dirty);
LOGGER.trace("flush bsFile={} dirty={} file={}", rootBlockOffset, dirty, diskStorage.getRelativeDatabaseFileForLogging());
if (dirty) {
buffer.writeAsync();
}

View File

@@ -25,7 +25,11 @@ public class DiskStorage implements AutoCloseable {
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 {
Files.createDirectories(databaseFile.getParent());
@@ -47,7 +51,7 @@ public class DiskStorage implements AutoCloseable {
public DiskBlock getDiskBlock(final long blockOffset, final int blockSize) {
try {
LOGGER.trace("read block={}", blockOffset);
LOGGER.trace("read block={} file={}", blockOffset, relativeDatabaseFileForLogging);
final var byteBuffer = fileChannel.map(MapMode.READ_WRITE, blockOffset, blockSize);
@@ -56,6 +60,10 @@ public class DiskStorage implements AutoCloseable {
throw new DiskStorageException(e);
}
}
public Path getRelativeDatabaseFileForLogging() {
return relativeDatabaseFileForLogging;
}
@Override
public void close() {

View File

@@ -48,6 +48,8 @@ public class PersistentMap<K, V> implements AutoCloseable {
public default Function<O,byte[]> asEncoder() {
return plain -> this.encode(plain);
}
public byte[] getEmptyValue();
}
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) {
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> {
@@ -74,6 +80,10 @@ public class PersistentMap<K, V> implements AutoCloseable {
public Long decode(final byte[] bytes) {
return bytes == null ? null : VariableByteEncoder.decodeFirstValue(bytes);
}
public byte[] getEmptyValue() {
return new byte[] {0};
}
}
private static final class UUIDCoder implements EncoderDecoder<UUID> {
@@ -94,6 +104,10 @@ public class PersistentMap<K, V> implements AutoCloseable {
return new UUID(mostSignificantBits, leastSignificantBits);
}
public byte[] getEmptyValue() {
return new byte[] {0};
}
}
private static final class EmptyCoder implements EncoderDecoder<Empty> {
@@ -112,6 +126,10 @@ public class PersistentMap<K, V> implements AutoCloseable {
return Empty.INSTANCE;
}
public byte[] getEmptyValue() {
return new byte[] {};
}
}
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);
public PersistentMap(final Path path, final EncoderDecoder<K> keyEncoder, final EncoderDecoder<V> valueEncoder) {
this.diskStore = new DiskStorage(path);
public PersistentMap(final Path path, final Path storageBasePath, final EncoderDecoder<K> keyEncoder, final EncoderDecoder<V> valueEncoder) {
this.diskStore = new DiskStorage(path, storageBasePath);
this.keyEncoder = keyEncoder;
this.valueEncoder = valueEncoder;
initIfNew();
@@ -169,7 +187,7 @@ public class PersistentMap<K, V> implements AutoCloseable {
writeNodeOffsetOfRootNode(blockOffset);
// 5. insert a dummy entry with a 'maximum' key
putValue(MAX_KEY, new byte[] { });
putValue(MAX_KEY, valueEncoder.getEmptyValue());
}
}