Source:
<code>private SegmentIdentifier tryAllocate( TaskActionToolbox toolbox, Task task, Interval tryInterval, Interval rowInterval, boolean logOnFail ) { log.debug( "Trying to allocate pending segment for rowInterval[%s], segmentInterval[%s].", rowInterval, tryInterval ); final LockResult lockResult = toolbox.getTaskLockbox().tryLock(TaskLockType.EXCLUSIVE, task, tryInterval); if (lockResult.isRevoked()) { throw new ISE("The lock for interval[%s] is preempted and no longer valid", tryInterval); } if (lockResult.isOk()) { SegmentIdentifier identifier; <START> synchronized (lockResult.getTaskLock()) { <END> identifier = toolbox.getIndexerMetadataStorageCoordinator().allocatePendingSegment( dataSource, sequenceName, previousSegmentId, tryInterval, lockResult.getTaskLock().getVersion(), skipSegmentLineageCheck ); } if (identifier != null) { return identifier; } else { final String msg = StringUtils.format( "Could not allocate pending segment for rowInterval[%s], segmentInterval[%s].", rowInterval, tryInterval ); if (logOnFail) { log.error(msg); } else { log.debug(msg); } return null; } } else { final String msg = StringUtils.format( "Could not acquire lock for rowInterval[%s], segmentInterval[%s].", rowInterval, tryInterval ); if (logOnFail) { log.error(msg); } else { log.debug(msg); } return null; } }</code><technical_language>TaskLock is shared tasks if groupId (see TaskLockPosse). this works for kafka indexing service kafkaIndexTasks for dataSource groupId, true for other task types. I sense call toolbox.getIndexerMetadataStorageCoordinator().allocatePendingSegment() of TaskLockBox.doInCriticalSection(). designed perform some action in a critical section, other tasks revoke lock of current task. Also, guarantees task perform action time. Please check SegmentTransactionalInsertAction example. do think</technical_language>

Target:
private SegmentIdentifier tryAllocate( TaskActionToolbox toolbox, Task task, Interval tryInterval, Interval rowInterval, boolean logOnFail ) { log.debug( "Trying to allocate pending segment for rowInterval[%s], segmentInterval[%s].", rowInterval, tryInterval ); final LockResult lockResult = toolbox.getTaskLockbox().tryLock(TaskLockType.EXCLUSIVE, task, tryInterval); if (lockResult.isRevoked()) { throw new ISE("The lock for interval[%s] is preempted and no longer valid", tryInterval); } if (lockResult.isOk()) { final SegmentIdentifier identifier; try { identifier = toolbox.getTaskLockbox().doInCriticalSection( task, ImmutableList.of(tryInterval), CriticalAction.<SegmentIdentifier>builder() .onValidLocks( () -> toolbox.getIndexerMetadataStorageCoordinator().allocatePendingSegment( dataSource, sequenceName, previousSegmentId, tryInterval, lockResult.getTaskLock().getVersion(), skipSegmentLineageCheck ) ).onInvalidLocks( () -> null ) .build() ); } catch (Exception e) { throw new RuntimeException(e); } if (identifier != null) { return identifier; } else { final String msg = StringUtils.format( "Could not allocate pending segment for rowInterval[%s], segmentInterval[%s].", rowInterval, tryInterval ); if (logOnFail) { log.error(msg); } else { log.debug(msg); } return null; } } else { final String msg = StringUtils.format( "Could not acquire lock for rowInterval[%s], segmentInterval[%s].", rowInterval, tryInterval ); if (logOnFail) { log.error(msg); } else { log.debug(msg); } return null; } }