Avoid use of checking and casting to LLRealtimeSegmentDataManager in SegmentOfflineStateModelFactory
- Dominant language
- Java
- Stars
- 6.1k
- Forks
- 1.5k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 189
Description
As example take a look at this code in SegmentOnlineOfflineStateModelFactory.java::onBecomeOnlineFromConsuming()
```
try {
if (!(acquiredSegment instanceof LLRealtimeSegmentDataManager)) {
// We found an LLC segment that is not consuming right now, must be that we already swapped it with a
// segment that has been built. Nothing to do for this state transition.
_logger
.info("Segment {} not an instance of LLRealtimeSegmentDataManager. Reporting success for the transition",
acquiredSegment.getSegmentName());
return;
}
LLRealtimeSegmentDataManager segmentDataManager = (LLRealtimeSegmentDataManager) acquiredSegment;
SegmentZKMetadata segmentZKMetadata = ZKMetadataProvider
.getSegmentZKMetadata(_instanceDataManager.getPropertyStore(), realtimeTableName, segmentNameStr);
segmentDataManager.goOnlineFromConsuming(segmentZKMetadata);
} catch (InterruptedException e) {
String errorMessage = String.format("State transition interrupted for segment %s.", segmentNameStr);
_logger.warn(errorMessage, e);
tableDataManager
.addSegmentError(segmentNameStr, new SegmentErrorInfo(System.currentTimeMillis(), errorMessage, e));
throw new RuntimeException(e);
} finally {
tableDataManager.releaseSegment(acquiredSegment);
}
```
The details of realtime segment data manger should be handled in that class on a method called when this transitions for all types of segment data managers. Default NOP implementation can be used for other types of segement data managers
Contributor guide
Research direction
Start with SegmentOnlineOfflineStateModelFactory.java::onBecomeOnlineFromConsuming(), then compare the corresponding transition in SegmentOfflineStateModelFactory. Trace how segment data managers handle this transition; done when the factory no longer checks or casts to LLRealtimeSegmentDataManager and other manager types have a default no-op path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100