Updated
This commit is contained in:
parent
4901f2fd4c
commit
dc56da3bbb
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user