curator-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phil Mikhailov (JIRA)" <j...@apache.org>
Subject [jira] [Created] (CURATOR-43) Acquire gets stuck in InterProcessMutex if there are sub-nodes in lock path
Date Wed, 26 Jun 2013 15:34:19 GMT
Phil Mikhailov created CURATOR-43:
-------------------------------------

             Summary: Acquire gets stuck in InterProcessMutex if there are sub-nodes in lock
path
                 Key: CURATOR-43
                 URL: https://issues.apache.org/jira/browse/CURATOR-43
             Project: Apache Curator
          Issue Type: Bug
          Components: Recipes
    Affects Versions: 2.0.1-incubating
            Reporter: Phil Mikhailov


If lock path has sub-node, this sub-node is also treated as try to acquire this lock.
I created small test method in TestInterProcessMutex that reproduces this issue:

{noformat}
@Test
public void testWithSubNode() throws Exception {
    final CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(),
new RetryOneTime(1));
    try {
        client.start();
        final InterProcessMutex lock = new InterProcessMutex(client, LOCK_PATH);
        final InterProcessMutex lock0 = new InterProcessMutex(client, LOCK_PATH + "/0");
        boolean acquired0 = lock0.acquire(5, TimeUnit.SECONDS);
        Assert.assertTrue(acquired0);
        lock0.release();
        boolean acquired = lock.acquire(5, TimeUnit.SECONDS);
        Assert.assertTrue(acquired);
        lock.release();
    } finally {
        client.close();
    }
}
{noformat}

I also patched our curator build in LockInternals with this temporary patch before you found
better solution.

{noformat}
static final String             PROTECTED_PREFIX = "_c_";

public static List<String> getSortedChildren(CuratorFramework client, String basePath,
final String lockName, final LockInternalsSorter sorter) throws Exception
{
    List<String> children = Lists.newArrayList(Collections2.filter(client.getChildren().forPath(basePath),
            new Predicate<String>()
            {
                @Override
                public boolean apply(String s)
                {
                    return s.startsWith(PROTECTED_PREFIX);
                }
            }));
    return getSortedChildren(lockName, sorter, children);
}
 {noformat}



--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message