use of org.apache.kafka.server.log.remote.storage.RemoteLogSegmentState in project kafka by apache.
the class RemoteLogMetadataCache method updateRemoteLogSegmentMetadata.
public void updateRemoteLogSegmentMetadata(RemoteLogSegmentMetadataUpdate metadataUpdate) throws RemoteResourceNotFoundException {
log.debug("Updating remote log segment metadata: [{}]", metadataUpdate);
Objects.requireNonNull(metadataUpdate, "metadataUpdate can not be null");
RemoteLogSegmentState targetState = metadataUpdate.state();
RemoteLogSegmentId remoteLogSegmentId = metadataUpdate.remoteLogSegmentId();
RemoteLogSegmentMetadata existingMetadata = idToSegmentMetadata.get(remoteLogSegmentId);
if (existingMetadata == null) {
throw new RemoteResourceNotFoundException("No remote log segment metadata found for :" + remoteLogSegmentId);
}
// Check the state transition.
checkStateTransition(existingMetadata.state(), targetState);
switch(targetState) {
case COPY_SEGMENT_STARTED:
// RemoteLogSegmentState.COPY_SEGMENT_STARTED.
throw new IllegalArgumentException("metadataUpdate: " + metadataUpdate + " with state " + RemoteLogSegmentState.COPY_SEGMENT_STARTED + " can not be updated");
case COPY_SEGMENT_FINISHED:
handleSegmentWithCopySegmentFinishedState(existingMetadata.createWithUpdates(metadataUpdate));
break;
case DELETE_SEGMENT_STARTED:
handleSegmentWithDeleteSegmentStartedState(existingMetadata.createWithUpdates(metadataUpdate));
break;
case DELETE_SEGMENT_FINISHED:
handleSegmentWithDeleteSegmentFinishedState(existingMetadata.createWithUpdates(metadataUpdate));
break;
default:
throw new IllegalArgumentException("Metadata with the state " + targetState + " is not supported");
}
}
use of org.apache.kafka.server.log.remote.storage.RemoteLogSegmentState in project kafka by apache.
the class RemoteLogMetadataCacheTest method testAPIsWithInvalidArgs.
@Test
public void testAPIsWithInvalidArgs() {
RemoteLogMetadataCache cache = new RemoteLogMetadataCache();
Assertions.assertThrows(NullPointerException.class, () -> cache.addCopyInProgressSegment(null));
Assertions.assertThrows(NullPointerException.class, () -> cache.updateRemoteLogSegmentMetadata(null));
// Check for invalid state updates to addCopyInProgressSegment method.
for (RemoteLogSegmentState state : RemoteLogSegmentState.values()) {
if (state != RemoteLogSegmentState.COPY_SEGMENT_STARTED) {
RemoteLogSegmentMetadata segmentMetadata = new RemoteLogSegmentMetadata(new RemoteLogSegmentId(TP0, Uuid.randomUuid()), 0, 100L, -1L, BROKER_ID_0, time.milliseconds(), SEG_SIZE, Collections.singletonMap(0, 0L));
RemoteLogSegmentMetadata updatedMetadata = segmentMetadata.createWithUpdates(new RemoteLogSegmentMetadataUpdate(segmentMetadata.remoteLogSegmentId(), time.milliseconds(), state, BROKER_ID_1));
Assertions.assertThrows(IllegalArgumentException.class, () -> cache.addCopyInProgressSegment(updatedMetadata));
}
}
// Check for updating non existing segment-id.
Assertions.assertThrows(RemoteResourceNotFoundException.class, () -> {
RemoteLogSegmentId nonExistingId = new RemoteLogSegmentId(TP0, Uuid.randomUuid());
cache.updateRemoteLogSegmentMetadata(new RemoteLogSegmentMetadataUpdate(nonExistingId, time.milliseconds(), RemoteLogSegmentState.DELETE_SEGMENT_STARTED, BROKER_ID_1));
});
// Check for invalid state transition.
Assertions.assertThrows(IllegalStateException.class, () -> {
RemoteLogSegmentMetadata segmentMetadata = createSegmentUpdateWithState(cache, Collections.singletonMap(0, 0L), 0, 100, RemoteLogSegmentState.COPY_SEGMENT_FINISHED);
cache.updateRemoteLogSegmentMetadata(new RemoteLogSegmentMetadataUpdate(segmentMetadata.remoteLogSegmentId(), time.milliseconds(), RemoteLogSegmentState.DELETE_SEGMENT_FINISHED, BROKER_ID_1));
});
}
Aggregations