[
https://issues.apache.org/jira/browse/CASSANDRA-11258?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15237138#comment-15237138
]
Marcus Olsson commented on CASSANDRA-11258:
-------------------------------------------
[~pauloricardomg] Sorry for the delay in getting back to this ticket.
--
I've pushed a rebased branch
[here|https://github.com/emolsson/cassandra/commits/CASSANDRA-11258]. The lock
factory implementation is creating locks in a try-with-resources fashion:
{code}
interface DistributedLock extends Closeable
{
}
interface LockFactory
{
DistributedLock tryLock(String resource, int priority, Map<String, String>
metadata);
}
...
try (DistributedLock lock = lockFactory.tryLock("RepairResource-DC1-1", 1, new
HashMap<>()))
{
// Do repair
}
catch (LockException e)
{
// Unable to lock the resource
}
{code}
Which would keep the lock updated with a scheduled task until {{lock.close()}}
is called.
--
Another alternative would be to go for the java
[Lock|https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/locks/Lock.html]
style of implementation and perhaps only implement {{tryLock()}} and
{{unlock()}} on the locks and have the lock factory return a lockable object
instead:
{code}
interface LockFactory
{
Lock getLock(String resource, int parallelism, int priority,
Map<String,String> metadata);
}
...
Lock lock = lockFactory.getLock("RepairResource-DC1", 1, 1, new HashMap<>());
if (lock.tryLock())
{
try
{
// Do repair
}
finally
{
lock.unlock();
}
}
else
{
// Unable to lock the resource
}
{code}
WDYT?
> Repair scheduling - Resource locking API
> ----------------------------------------
>
> Key: CASSANDRA-11258
> URL: https://issues.apache.org/jira/browse/CASSANDRA-11258
> Project: Cassandra
> Issue Type: Sub-task
> Reporter: Marcus Olsson
> Assignee: Marcus Olsson
> Priority: Minor
>
> Create a resource locking API & implementation that is able to lock a
> resource in a specified data center. It should handle priorities to avoid
> node starvation.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)