This commit is contained in:
Andrea Cavalli 2019-04-21 02:14:50 +02:00
parent 4901f2fd4c
commit dc56da3bbb
3 changed files with 7 additions and 1 deletions

View File

@ -43,6 +43,9 @@ public class DatabaseBlocksMetadata implements IBlocksMetadata {
long position = blockId * BLOCK_META_BYTES_COUNT;
int size = BLOCK_META_READS_AT_EVERY_READ * BLOCK_META_BYTES_COUNT;
long currentFirstFreeBlock = this.firstFreeBlock.get();
if (blockId > currentFirstFreeBlock) {
return EMPTY_BLOCK_INFO;
}
if (blockId + (size - 1) / BLOCK_META_BYTES_COUNT >= currentFirstFreeBlock) {
size = (int) ((currentFirstFreeBlock - blockId) * BLOCK_META_BYTES_COUNT);
}

View File

@ -33,9 +33,9 @@ public class DatabaseReferencesIO implements IReferencesIO {
@Override
public void writeToReference(long reference, byte cleanerId, int size, ByteBuffer data) throws IOException {
long blockId = (size == 0) ? EMPTY_BLOCK_ID : blocksIO.newBlock(size, data);
lock.writeLock().lock();
try {
long blockId = (size == 0) ? EMPTY_BLOCK_ID : blocksIO.newBlock(size, data);
referencesMetadata.editReference(reference, cleanerId, blockId);
} finally {
lock.writeLock().unlock();

View File

@ -58,6 +58,9 @@ public class DatabaseReferencesMetadata implements IReferencesMetadata {
}
long position = reference * REF_META_BYTES_COUNT;
int size = REF_META_READS_AT_EVERY_READ * REF_META_BYTES_COUNT;
if (reference > firstFreeReference) {
return EMPTY_BLOCK_ID;
}
if (reference + (size - 1) / REF_META_BYTES_COUNT >= firstFreeReference) {
size = (int) ((firstFreeReference - reference) * REF_META_BYTES_COUNT);
}