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 @@ -1119,6 +1119,38 @@ public void testLockAllocateDayReplaceMonthAllocateAppend()
verifyIntervalHasVisibleSegments(JAN_23, segmentV10, segmentV11, segmentV12);
}

@Test
public void test_concurrentAppend_toIntervalWithUnusedSegments()
{
// Allocate and commit an APPEND segment
final SegmentIdWithShardSpec pendingSegment
= appendTask.allocateSegmentForTimestamp(FIRST_OF_JAN_23.getStart(), Granularities.DAY);
Assert.assertEquals(SEGMENT_V0, pendingSegment.getVersion());
Assert.assertEquals(0, pendingSegment.getShardSpec().getPartitionNum());

final DataSegment segmentV01 = asSegment(pendingSegment);
appendTask.commitAppendSegments(segmentV01);

verifyIntervalHasUsedSegments(FIRST_OF_JAN_23, segmentV01);
verifyIntervalHasVisibleSegments(FIRST_OF_JAN_23, segmentV01);

// Mark it as unused
getStorageCoordinator().markAllSegmentsAsUnused(appendTask.getDataSource());
verifyIntervalHasUsedSegments(FIRST_OF_JAN_23);

// Allocate and commit another APPEND segment
final SegmentIdWithShardSpec pendingSegment2
= appendTask.allocateSegmentForTimestamp(FIRST_OF_JAN_23.getStart(), Granularities.DAY);
Assert.assertEquals(SEGMENT_V0, pendingSegment2.getVersion());
Assert.assertEquals(1, pendingSegment2.getShardSpec().getPartitionNum());

final DataSegment segmentV02 = asSegment(pendingSegment2);
appendTask.commitAppendSegments(segmentV02);
Assert.assertNotEquals(segmentV01, segmentV02);

verifyIntervalHasUsedSegments(FIRST_OF_JAN_23, segmentV02);
verifyIntervalHasVisibleSegments(FIRST_OF_JAN_23, segmentV02);
}

@Nullable
private DataSegment findSegmentWith(String version, Map<String, Object> loadSpec, Set<DataSegment> segments)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,7 @@ private PendingSegmentRecord createNewPendingSegment(
version,
partialShardSpec.complete(jsonMapper, newPartitionId, 0)
);
pendingSegmentId = getTrueAllocatedId(transaction, pendingSegmentId);
return PendingSegmentRecord.create(
pendingSegmentId,
request.getSequenceName(),
Expand Down Expand Up @@ -1555,12 +1556,13 @@ private SegmentIdWithShardSpec createNewPendingSegment(
? PartitionIds.NON_ROOT_GEN_START_PARTITION_ID
: PartitionIds.ROOT_GEN_START_PARTITION_ID;
String version = newSegmentVersion == null ? existingVersion : newSegmentVersion;
return new SegmentIdWithShardSpec(
SegmentIdWithShardSpec allocatedId = new SegmentIdWithShardSpec(
dataSource,
interval,
version,
partialShardSpec.complete(jsonMapper, newPartitionId, 0)
);
return getTrueAllocatedId(transaction, allocatedId);
} else if (!overallMaxId.getInterval().equals(interval)) {
log.warn(
"Cannot allocate new segment for dataSource[%s], interval[%s], existingVersion[%s]: conflicting segment[%s].",
Expand Down
Loading