Skip to content

Commit f4f094b

Browse files
timwtglman
authored andcommitted
Correct records size after update and delete.
Correctly calculate records size for a cluster on update and delete, adjusting for cluster and chunk entry overheads, and allowing multi-chunk records. Add checks for record size to all cluster ITs, implemented for V2 and left as a TODO for V0/V1 (which are either incorrect or have a different interpretation of records size).
1 parent e1887b8 commit f4f094b

File tree

4 files changed

+204
-29
lines changed

4 files changed

+204
-29
lines changed

core/src/main/java/com/orientechnologies/orient/core/storage/cluster/v2/OPaginatedClusterV2.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,21 @@ private static int calculateChunkSize(final int entrySize) {
611611
return entrySize + OByteSerializer.BYTE_SIZE + OLongSerializer.LONG_SIZE;
612612
}
613613

614+
private static int calculateContentSizeDeltaFromChunk(final byte[] chunk) {
615+
final byte firstChunk =
616+
OByteSerializer.INSTANCE.deserialize(
617+
chunk, chunk.length - OLongSerializer.LONG_SIZE - OByteSerializer.BYTE_SIZE);
618+
if (firstChunk == 0) {
619+
// Subsequent chunk, no cluster entry header
620+
// entry content - first entry flag - next entry pointer
621+
return chunk.length - OLongSerializer.LONG_SIZE - OByteSerializer.BYTE_SIZE;
622+
}
623+
// entry content - record type - record length - first entry flag - next entry pointer
624+
return calculateContentSizeFromClusterEntrySize(chunk.length)
625+
- OByteSerializer.BYTE_SIZE
626+
- OLongSerializer.LONG_SIZE;
627+
}
628+
614629
private static int getEntryContentLength(final int grownContentSize) {
615630

616631
return grownContentSize
@@ -831,7 +846,7 @@ public boolean deleteRecord(OAtomicOperation atomicOperation, final long cluster
831846
atomicOperation.addDeletedRecordPosition(
832847
id, cacheEntry.getPageIndex(), recordPosition);
833848
assert content != null;
834-
removeRecordSize = calculateContentSizeFromClusterEntrySize(content.length);
849+
removeRecordSize += calculateContentSizeDeltaFromChunk(content);
835850

836851
maxRecordSize = localPage.getMaxRecordSize();
837852
removedContentSize += localPage.getFreeSpace() - initialFreeSpace;
@@ -892,7 +907,7 @@ public void updateRecord(
892907
final OClusterPage page = new OClusterPage(cacheEntry);
893908
final byte[] deletedRecord = page.deleteRecord(nextRecordPosition, true);
894909
assert deletedRecord != null;
895-
oldContentSize = calculateContentSizeFromClusterEntrySize(deletedRecord.length);
910+
oldContentSize += calculateContentSizeDeltaFromChunk(deletedRecord);
896911
nextPagePointer =
897912
OLongSerializer.INSTANCE.deserializeNative(
898913
deletedRecord, deletedRecord.length - OLongSerializer.LONG_SIZE);

0 commit comments

Comments
 (0)