{"record":{"id":"832ceeb4327d083d","repo":"apache/druid","slug":"the-lock-for-interval-s-is-preempted-and-no-long","errorCode":null,"errorMessage":"The lock for interval[%s] is preempted and no longer valid","messagePattern":"The lock for interval\\[(.+?)\\] is preempted and no longer valid","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"indexing-service/src/main/java/org/apache/druid/indexing/common/actions/SegmentAllocateAction.java","lineNumber":353,"sourceCode":"    final LockResult lockResult = toolbox.getTaskLockbox().tryLock(\n        task,\n        new LockRequestForNewSegment(\n            lockGranularity,\n            taskLockType,\n            task.getGroupId(),\n            dataSource,\n            tryInterval,\n            partialShardSpec,\n            task.getPriority(),\n            sequenceName,\n            previousSegmentId,\n            skipSegmentLineageCheck\n        )\n    );\n\n    if (lockResult.isRevoked()) {\n      // We had acquired a lock but it was preempted by other locks\n      throw new ISE(\"The lock for interval[%s] is preempted and no longer valid\", tryInterval);\n    }\n\n    if (lockResult.isOk()) {\n      final SegmentIdWithShardSpec identifier = lockResult.getNewSegmentId();\n      if (identifier != null) {\n        return identifier;\n      } else {\n        final String msg = StringUtils.format(\n            \"Could not allocate pending segment for rowInterval[%s], segmentInterval[%s].\",\n            rowInterval,\n            tryInterval\n        );\n        if (logOnFail) {\n          log.error(msg);\n        } else {\n          log.debug(msg);\n        }\n        return null;","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/indexing-service/src/main/java/org/apache/druid/indexing/common/actions/SegmentAllocateAction.java#L335-L371","documentation":"During tryAllocate, SegmentAllocateAction acquires a time-sharing/task lock for the candidate interval and then submits the allocation. If the returned lock result is marked revoked, another (higher-priority) lock preempted it between acquisition and use, making the lock invalid; Druid throws rather than allocate under a stolen lock. Allocation must be retried by the task at a higher level.","triggerScenarios":"A higher-priority task (e.g. an overwrite/compaction task with a REVOKED-capable priority) took an overlapping interval lock while this task's allocation was in flight; concurrent allocation under contention on the same interval.","commonSituations":"Compaction or manual overwrite tasks launched while streaming ingestion is running; lock priority changes mid-run; two tasks racing for the same time chunk.","solutions":["Retry the task or the allocation step; Druid tasks usually retry automatically on this error.","Pause or reschedule the conflicting higher-priority (overwrite/compaction) task so it does not overlap the streaming task's intervals.","Increase the streaming task's lock priority or configure lock priorities so low-priority tasks are preempted cleanly and restart.","Reduce interval overlap by aligning segment granularity/partitions of competing tasks."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Cannot be pre-validated: preemption is inherently racy. Optionally check current locks before allocating:\n// if (toolbox.getTaskLockbox().isRevoked(task, tryInterval)) skip/retry;","typeGuard":null,"tryCatchPattern":"try { id = tryAllocate(...); } catch (ISE e) { if (e.getMessage().contains(\"is preempted\")) { /* backoff and retry allocation; task framework retries automatically */ } else throw e; }","preventionTips":["Avoid running compaction/overwrite tasks concurrently with streaming ingestion over the same intervals.","Set deliberate lock priorities per task type.","Monitor task logs for revoked-lock warnings and tune priorities.","Keep allocation windows short after lock acquisition."],"tags":["druid","locking","segment-allocation","preemption"],"backgroundTag":"segment-lock-revoked","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}