Fix task bootstrapping & simplify segment load/drop flows#16475
Fix task bootstrapping & simplify segment load/drop flows#16475abhishekrb19 merged 48 commits intoapache:masterfrom
Conversation
- The load drop handler code talks to the local cache manager via SegmentManager.
| public void storeInfoFile(DataSegment segment) throws IOException | ||
| { | ||
| final File segmentInfoCacheFile = new File(getInfoDir(), segment.getId().toString()); | ||
| if (!segmentInfoCacheFile.exists()) { |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression
| final File factoryJson = new File(segmentFiles, "factory.json"); | ||
| final SegmentizerFactory factory; | ||
|
|
||
| if (factoryJson.exists()) { |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression
|
|
||
| if (factoryJson.exists()) { | ||
| try { | ||
| factory = jsonMapper.readValue(factoryJson, SegmentizerFactory.class); |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression
be28082 to
aece4e6
Compare
aece4e6 to
6e563aa
Compare
| try { | ||
| byte[] bytes = new byte[size]; | ||
| ThreadLocalRandom.current().nextBytes(bytes); | ||
| Files.write(bytes, segmentFile); |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression
| byte[] bytes = new byte[size]; | ||
| ThreadLocalRandom.current().nextBytes(bytes); | ||
| Files.write(bytes, segmentFile); | ||
| Files.write("{\"type\":\"testSegmentFactory\"}".getBytes(StandardCharsets.UTF_8), factoryJson); |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression
|
@abhishekrb19 , thanks for the detailed description. IIUC, this PR is basically doing the following:
Is there any other bug fix or feature included in this PR too? |
That's about right, except that we're not injecting storage locations into
There's no other bug fix or feature in this PR. I do have another related change that touches some of this code, but given the size of this PR, I will add it separately to make reviewing easier. 🙂 |
|
Makes sense. Thanks for the clarification, @abhishekrb19 ! |
19c00e4 to
16658e1
Compare
1e028cb to
e02f5cb
Compare
The intellij-inspect tool doesn't seem to correctly inspect lambda usages. See ScheduledExecutors.
d2d1c2d to
f11da12
Compare
…/incubator-druid into fixup_task_bootstrap_inject
c262ed4 to
f97d10f
Compare
Problems
The segment bootstrapping logic relies on the presence of configured storage locations. That is, only servers that have storage location configured will act like a "segment data server". Tasks on the other hand don't have this static configuration because tasks can dynamically run on any slot. The
CliPeoninjects a list of dynamicStorageLocations. ThisList<StorageLocation>is not currently present inSegmentLoadDropHandler, which does the bootstrapping of segments as part of itsstart()lifecycle. Instead, this class directly usesconfig.getLocations(), which isn't set by theTaskToolboxFactorywhen it instantiatesSegmentCacheManager.One of the overloaded constructors marked
@VisibleForTestinginSegmentLocalCacheManageris also being used by tasks viaSegmentCacheManagerFactory. This "test constructor" also does not initialize the thread pool executors, so segments won't be loaded into the page cache even if loader config has the appropriate settings.Core changes
The core part of the fix in
SegmentLoadDropHandleris to rely on the source of truth for the caching layer:SegmentCacheManager. Currently, the various interactions of the classes are complex and have abstraction leaks in its implementation:SegmentManager->SegmentCacheLoader->SegmentCacheManagerSegmentLoadDropHandler->SegmentManager->SegmentCacheLoader->SegmentCacheManagerSegmentLoadDropHandler->SegmentCacheManagerThe
SegmentLoadDropHandlerdirectly handles the segment info file creation and deletion. These low-level file operations should really be owned and handled by theSegmentCacheManagerand the classes that interact with should just operate at the granularity ofSegmentobjects.With this patch, the updated interactions are as follows:
SegmentManager->SegmentCacheManagerSegmentLoadDropHandler->SegmentManager->SegmentCacheManagerThe addition and deletion of segment info files are handled by the
SegmentLocalCacheManagerclass itself. TheSegmentLoadDropHandlergets the set of cached segments from theSegmentManager. To that effect, the dependencies inSegmentLoadDropHandlerhave been cleaned up, and this class doesn't fiddle with the segment files directly.In order to simplify this, we did the following:
Removed the
SegmentLoaderinterface and its concrete implementationSegmentLocalCacheLoader. The implementation was acting as a simple factory of Segment objects from the underlying segment files, which has now been moved toSegmentLocalCacheManager, still providing convenience for any test overrides for the factory.Added the following methods to
SegmentCacheManagerfor callers to interact with:SegmentManageris now responsible for callingstoreInfoFile(segment)once the segment bookkeeping stuff is successful as part of the load segment flow.SegmentLoadDropHandler, which is now moved to theSegmentLocalCacheManager., along with the initialization of the segment download executor.SegmentManagerandSegmentLocalCacheManagerhave bene broken down intoloadSegment()andloadBootstrapSegment()variants, because segment lazy loading and the fail callback are only applicable for the bootstrap segment flow. This cleanup ensures that callers don't pass unnecessary null arguments anymore and makes the intent clearer.VisibleForTestinghooks, including the problematic "test constructor" inSegmentLocalCacheManagernoted in the problems section. Where possible, the test code uses the same initialization logic as the core code.Test changes
SegmentLocalCacheManagerTestandSegmentManagerTest.SegmentLoaderTesttoSegmentLocalCacheManagerTest.TestSegmentUtilsfor commonly used test utilities that has test implementation support for loadingDataSegment,Segmentfactory, etc.Future work
SegmentLoadDropHandlertoSegmentManagersuch that the announcements moves to the manager layer itself. That'll entail a slightly larger refactor.SegmentLocalCacheManagerTestBoth of these require moderate to large refactoring changes, which can be tackled separately.
Release note
Fixed an issue in task bootstrapping that prevented tasks from accepting any segment assignments, including broadcast segments.
This PR has: