Skip to content

HBASE-30340: CatalogJanitor can run concurrent scans due to incorrect alreadyRunning lock handling - #8569

Open
sercanCyberVision wants to merge 1 commit into
apache:masterfrom
sercanCyberVision:janitor-catalog-fix
Open

HBASE-30340: CatalogJanitor can run concurrent scans due to incorrect alreadyRunning lock handling#8569
sercanCyberVision wants to merge 1 commit into
apache:masterfrom
sercanCyberVision:janitor-catalog-fix

Conversation

@sercanCyberVision

@sercanCyberVision sercanCyberVision commented Aug 25, 2026

Copy link
Copy Markdown

CatalogJanitor.scan() can allow concurrent scans due to incorrect handling of the
alreadyRunning lock.

ROOT CAUSE
Currently, the lock acquisition is performed inside the try block:

    try {
      if (!alreadyRunning.compareAndSet(false, true)) {
        return -1;
      }
      ...
    } finally {
      alreadyRunning.set(false);
    }

When a scan is already running, a concurrent scan fails the compareAndSet() and
returns immediately. However, because the lock acquisition is inside the try block,
the finally block is still executed and resets alreadyRunning to false.

This allows another scan to acquire the lock while the original scan is still running.

SOLUTION
The lock acquisition should be moved before the try block:

    if (!alreadyRunning.compareAndSet(false, true)) {
      return -1;
    }
    try {
      ...
    } finally {
      alreadyRunning.set(false);
    }

This prevents another scan from starting until the current scan has completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant