1616
1717package org .polypheny .db .transaction .locking ;
1818
19- import lombok .extern .slf4j .Slf4j ;
20- import org .polypheny .db .catalog .exceptions .GenericRuntimeException ;
21- import org .polypheny .db .transaction .Transaction ;
22- import org .polypheny .db .transaction .locking .Lockable .LockType ;
23- import org .polypheny .db .util .DeadlockException ;
2419import java .util .HashSet ;
2520import java .util .Map ;
2621import java .util .Set ;
3126import java .util .concurrent .locks .Lock ;
3227import java .util .concurrent .locks .ReentrantLock ;
3328import java .util .stream .Collectors ;
29+ import lombok .extern .slf4j .Slf4j ;
30+ import org .polypheny .db .catalog .exceptions .GenericRuntimeException ;
31+ import org .polypheny .db .transaction .Transaction ;
32+ import org .polypheny .db .transaction .locking .Lockable .LockType ;
33+ import org .polypheny .db .util .DeadlockException ;
3434
3535@ Slf4j
3636public class LockManager {
@@ -46,7 +46,7 @@ public class LockManager {
4646 private final Map <Transaction , Lockable > waitFor = new ConcurrentHashMap <>();
4747
4848
49- record LockEntry ( Transaction transaction , Lockable lockable , LockType lockType ) {
49+ public record LockEntry ( Transaction transaction , Lockable lockable , LockType lockType ) {
5050
5151 }
5252
@@ -135,12 +135,16 @@ private boolean acquireLock( Transaction transaction, Lockable lockable, LockTyp
135135
136136 Set <LockEntry > newLocks = tryAcquireLock ( locks , entry );
137137
138- if ( newLocks != null && (locks == newLocks || entries .compareAndSet ( locks , newLocks )) ) {// TODO: Use equal
139- Lockable l = waitFor .remove ( transaction ); // No longer waiting
140- if ( l != null && l != lockable ) {
141- throw new AssertionError ( "Wrong lockable" );
138+ if ( newLocks != null ) {
139+ if ( entries .compareAndSet ( locks , newLocks ) ) {
140+ Lockable l = waitFor .remove ( transaction ); // No longer waiting
141+ if ( l != null && l != lockable ) {
142+ throw new AssertionError ( "Wrong lockable" );
143+ }
144+ return true ;
145+ } else {
146+ return false ; // Try again, someone else has acquired a lock
142147 }
143- return true ;
144148 } else {
145149 waitFor .put ( transaction , lockable ); // TODO: Two transactions could abort at the same time
146150 // If there is a Deadlock, this means that other Transactions are already waiting for us, so the relevant parts won't change
0 commit comments