Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,16 @@ public long write(short segIdx, String key, ByteBuffer buffer) throws MetadataEx
ISegment<ByteBuffer, IMNode> tarSeg = getSegment(segIdx);

if (tarSeg.insertRecord(key, buffer) < 0) {
// relocate inside page, if not enough space for new size segment, throw exception
// relocate inside page, if not enough space for new size segment, throw SchemaPageOverflow
// exception
// increment of segment includes: buffer, key, length of the key(4 bytes), offset of the
// buffer(2 bytes)
tarSeg =
relocateSegment(
tarSeg, segIdx, SchemaFile.reEstimateSegSize(tarSeg.size() + buffer.capacity()));
tarSeg,
segIdx,
SchemaFile.reEstimateSegSize(
tarSeg.size() + buffer.capacity() + key.getBytes().length + 4 + 2));
} else {
return 0L;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,55 @@ public void testUpdateOnFullPageSegment() throws MetadataException, IOException
sf.close();
}

/**
* This test case is designed to examine a scenario in which, every time a SegmentedPage inserts a
* record, the process of checking whether there is enough space in the segment takes into account
* not only the size of the record's buffer, but also the size of the key and related pointers.
*
* @throws Exception
*/
@Test
public void testEstimateSegSizeWithBigName() throws Exception {
IMNode sgNode = new StorageGroupMNode(null, "mma", 111111111L);
IMNode d1 =
fillChildren(
sgNode,
300,
"deviceabcdabcdefahiklmnoparstuwwxyz1ABCDEFGHUKLMNOPORSTUVWXYZ",
this::supplyEntity);
ISchemaFile sf = SchemaFile.initSchemaFile("root.sg", TEST_SCHEMA_REGION_ID);

try {
fillChildren(d1, 19, "ss1", this::supplyMeasurement);

sf.writeMNode(sgNode);

fillChildren(
d1,
2,
"sensor2abcdabcdefahiklmnoparstuwwxyz1ABCDEFGHUKLMNOPORSTUVWXYZPORSTUVWXYZ",
this::supplyMeasurementWithoutAlias);

sf.writeMNode(d1);

moveAllToBuffer(d1);
moveAllToBuffer(sgNode);

fillChildren(d1, 20, "ss", this::supplyMeasurement);
sf.writeMNode(d1);

Iterator<IMNode> verifyChildren = sf.getChildren(d1);
int cnt = 0;
while (verifyChildren.hasNext()) {
cnt++;
verifyChildren.next();
}
Assert.assertEquals(41, cnt);
} finally {
sf.close();
}
}

@Test
public void testEstimateSegSize() throws Exception {
// to test whether estimation of segment size works on edge cases
Expand Down Expand Up @@ -922,6 +971,10 @@ private IMNode supplyMeasurement(IMNode par, String name) {
return getMeasurementNode(par, name, name + "_als");
}

private IMNode supplyMeasurementWithoutAlias(IMNode par, String name) {
return getMeasurementNode(par, name, null);
}

private IMNode supplyInternal(IMNode par, String name) {
return new InternalMNode(par, name);
}
Expand Down