Byte cleaner

This commit is contained in:
Andrea Cavalli 2019-04-20 22:28:57 +02:00
parent 7321795000
commit bf40dd7787

View File

@ -21,7 +21,7 @@ public class DatabaseReferencesMetadata implements IReferencesMetadata {
public static final byte ERRORED_CLEANER = (byte) -1;
public static final byte BLANK_DATA_CLEANER = (byte) -2;
public static final ReferenceInfo NONEXISTENT_REFERENCE_INFO = new ReferenceInfo(ERRORED_CLEANER, ERROR_BLOCK_ID);
private static final int REF_META_BYTES_COUNT = Long.BYTES + Integer.BYTES;
private static final int REF_META_BYTES_COUNT = Long.BYTES + Byte.BYTES;
public static final int REF_META_READS_AT_EVERY_READ = (DISK_BLOCK_SIZE - DISK_BLOCK_SIZE % REF_META_BYTES_COUNT) / REF_META_BYTES_COUNT;
private final AsynchronousFileChannel metaFileChannel;
@ -91,7 +91,7 @@ public class DatabaseReferencesMetadata implements IReferencesMetadata {
for (int delta = 0; delta < referencesCount; delta++) {
long referenceToLoad = reference + delta;
long currentBlock = buffer.getLong();
byte cleanerId = (byte) buffer.getInt();
byte cleanerId = buffer.get();
if (buffer.limit() != 0 && currentBlock != 0xFFFFFFFFFFFFFFFFL) {
allReferences[delta] = referenceToLoad;
allCleaners[delta] = cleanerId;
@ -191,7 +191,7 @@ public class DatabaseReferencesMetadata implements IReferencesMetadata {
}
ByteBuffer data = ByteBuffer.allocate(REF_META_BYTES_COUNT);
data.putLong(blockId);
data.putInt(cleanerId & 0xFF);
data.put(cleanerId);
data.flip();
try {
metaFileChannel.write(data, reference * REF_META_BYTES_COUNT).get();