[ 
https://issues.apache.org/jira/browse/HBASE-30340?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Sercan Tekin updated HBASE-30340:
---------------------------------
    Description: 
{{CatalogJanitor.scan()}} can allow concurrent scans due to incorrect handling 
of the
{{alreadyRunning}} lock.

Currently, the lock acquisition is performed inside the {{try}} block:
{code:java}
    try {
      if (!alreadyRunning.compareAndSet(false, true)) {
        return -1;
      }
      ...
    } finally {
      alreadyRunning.set(false);
    }
{code}

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.

The lock acquisition should be moved before the {{try}} block:
{code:java}
    if (!alreadyRunning.compareAndSet(false, true)) {
      return -1;
    }
    try {
      ...
    } finally {
      alreadyRunning.set(false);
    }
{code}

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

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

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.

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.


> CatalogJanitor can run concurrent scans due to incorrect alreadyRunning lock 
> handling
> -------------------------------------------------------------------------------------
>
>                 Key: HBASE-30340
>                 URL: https://issues.apache.org/jira/browse/HBASE-30340
>             Project: HBase
>          Issue Type: Bug
>          Components: master
>    Affects Versions: 0.90.5
>            Reporter: Sercan Tekin
>            Priority: Critical
>
> {{CatalogJanitor.scan()}} can allow concurrent scans due to incorrect 
> handling of the
> {{alreadyRunning}} lock.
> Currently, the lock acquisition is performed inside the {{try}} block:
> {code:java}
>     try {
>       if (!alreadyRunning.compareAndSet(false, true)) {
>         return -1;
>       }
>       ...
>     } finally {
>       alreadyRunning.set(false);
>     }
> {code}
> 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.
> The lock acquisition should be moved before the {{try}} block:
> {code:java}
>     if (!alreadyRunning.compareAndSet(false, true)) {
>       return -1;
>     }
>     try {
>       ...
>     } finally {
>       alreadyRunning.set(false);
>     }
> {code}
> This prevents another scan from starting until the current scan has completed.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to