Skip to content

Commit

Permalink
Renamed Lock->TxnLock to prevent name clash with java.util.concurrent…
Browse files Browse the repository at this point in the history
….locks.Lock
  • Loading branch information
pveentjer committed Apr 8, 2012
1 parent a461100 commit 0dc8e65
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 64 deletions.
Expand Up @@ -7,15 +7,15 @@
*
* <p>Normally transactions are very optimistic (e.g. fail during execution or at the end because some read or
* write conflict was detected), but in some cases a more pessimistic approach is better. For more information
* see {@link Lock}.
* see {@link TxnLock}.
*
* @author Peter Veentjer.
* @see TxnFactoryBuilder#setReadLockMode(LockMode)
* @see TxnFactoryBuilder#setWriteLockMode(LockMode)
* @see TxnConfig#getReadLockMode()
* @see TxnConfig#getWriteLockMode()
* @see TxnObject#getLock()
* @see Lock
* @see TxnLock
*/
public enum LockMode implements MultiverseConstants {

Expand Down Expand Up @@ -43,7 +43,7 @@ public enum LockMode implements MultiverseConstants {
* no other transaction can acquire any lock or can do any reading/writing (unless the transaction previously has read the
* transactional object).
*
* <p>The ExclusiveLock is the Lock acquired by the STM once a Txn is prepared for writing changes to a TxnObject.
* <p>The ExclusiveLock is the TxnLock acquired by the STM once a Txn is prepared for writing changes to a TxnObject.
*/
Exclusive(LOCKMODE_EXCLUSIVE);

Expand Down
@@ -1,7 +1,7 @@
package org.multiverse.api;

/**
* The Lock provides access to pessimistic behavior of a {@link TxnObject}. STM normally is very optimistic, but
* The TxnLock provides access to pessimistic behavior of a {@link TxnObject}. STM normally is very optimistic, but
* in some cases a more pessimistic approach (one with less retries) could be a better fitting solution.
* <p/>
* There are 4 different types of lockmodes:
Expand All @@ -16,15 +16,15 @@
* write-lock, reads still are allowed. Normally this would not be acceptable because once the write-lock
* is acquired, the internals could be modified. But in case of STM, the STM can still provide a consistent view
* even though the locking transaction has made changes. This essentially is the same behavior you get with the
* 'select for update' from Oracle. Once the write lock is acquired, other transactions can't acquire the Lock.
* 'select for update' from Oracle. Once the write lock is acquired, other transactions can't acquire the TxnLock.
* </li>
* <li><b>LockMode.Exclusive:</b> it allows only one transaction to acquire the commit lock, and readers are not
* allowed to read anymore. From an isolation perspective, the exclusive lock looks a lot like the synchronized
* statement (or a {@link java.util.concurrent.locks.ReentrantLock}} where only mutually exclusive access is
* possible. The exclusive lock normally is used by the STM when it commits.</li>
* </ul>
*
* <h3>Lock duration and release</h3>
* <h3>TxnLock duration and release</h3>
*
* <p>Locks atm are acquired for the remaining duration of the transaction and only will always be automatically
* released once the transaction commits/aborts. This is essentially the same behavior you get with Oracle once
Expand All @@ -47,19 +47,19 @@
* the lock again. This is a topic that needs more research and probably will be integrated in the contention
* management.
*
* <h3>Lock upgrade</h3>
* <h3>TxnLock upgrade</h3>
*
* <p>It is possible to upgrade a lock to more strict version, e.g. to upgrade a read-lock to a write-lock.
* The following upgrades are possible:
* <ol>
* <li>LockMode.Read->LockMode.Write: as long as no other transaction has acquired the Lock in LockMode.Read</li>
* <li>LockMode.Read->LockMode.Exclusive: as long as no other transaction has acquired the Lock in LockMode.Read</li>
* <li>LockMode.Read->LockMode.Write: as long as no other transaction has acquired the TxnLock in LockMode.Read</li>
* <li>LockMode.Read->LockMode.Exclusive: as long as no other transaction has acquired the TxnLock in LockMode.Read</li>
* <li>LockMode.Write->LockMode.Exclusive: will always succeed</li>
* </ol>
* <p>
* The Txn is allowed to apply a more strict LockMode than the one specified.
*
* <h3>Lock downgrade</h3>
* <h3>TxnLock downgrade</h3>
*
* <p>Downgrading locks currently is not possible and downgrade calls are ignored.
*
Expand All @@ -70,10 +70,10 @@
* is needed) are locked automatically. It can also be done on the reference level using
* getAndLock/setAndLock/getAndSetAndLock methods or by accessing the {@link TxnObject#getLock()}.
*
* <h3>Lock escalation</h3>
* <h3>TxnLock escalation</h3>
*
* <p>In traditional lock based databases, managing locks in memory can be quite expensive. That is one of the reason why
* different Lock granularities are used (record level, page level, table level for example). To prevent managing too many
* different TxnLock granularities are used (record level, page level, table level for example). To prevent managing too many
* locks, some databases apply lock escalation so that multiple low granularity locks are upgraded to a single higher granular
* lock. The problem with lock escalations is that the system could be subject to lock contention and to deadlocks.
*
Expand All @@ -95,21 +95,21 @@
* @see TxnFactoryBuilder#setReadLockMode(LockMode)
* @see TxnFactoryBuilder#setWriteLockMode(LockMode)
*/
public interface Lock {
public interface TxnLock {

/**
* Returns the current LockMode. This call doesn't look at any running transaction, it shows the actual
* state of the Lock. The value could be stale as soon as it is received. To retrieve the LockMode a
* a Txn has on a Lock, the {@link #getLockMode()} or {@link #getLockMode(Txn)} need
* state of the TxnLock. The value could be stale as soon as it is received. To retrieve the LockMode a
* a Txn has on a TxnLock, the {@link #getLockMode()} or {@link #getLockMode(Txn)} need
* to be used.
*
* @return the current LockMode.
*/
LockMode atomicGetLockMode();

/**
* Gets the LockMode the transaction stored in the the {@link TxnThreadLocal} has on this Lock.
* To retrieve the actual LockMode of the Lock, you need to use the {@link #atomicGetLockMode()}.
* Gets the LockMode the transaction stored in the the {@link TxnThreadLocal} has on this TxnLock.
* To retrieve the actual LockMode of the TxnLock, you need to use the {@link #atomicGetLockMode()}.
*
* @return the LockMode.
* @throws org.multiverse.api.exceptions.TxnExecutionException
Expand All @@ -123,11 +123,11 @@ public interface Lock {
LockMode getLockMode();

/**
* Gets the LockMode the transaction has on the Lock. This call makes use of the tx. To retrieve the actual
* LockMode of the Lock, you need to use the {@link #atomicGetLockMode()}
* Gets the LockMode the transaction has on the TxnLock. This call makes use of the tx. To retrieve the actual
* LockMode of the TxnLock, you need to use the {@link #atomicGetLockMode()}
*
* @param txn the Lock
* @return the LockMode the transaction has on the Lock.
* @param txn the TxnLock
* @return the LockMode the transaction has on the TxnLock.
* @throws org.multiverse.api.exceptions.TxnExecutionException
* if something failed while using the transaction. The transaction is guaranteed to have been aborted.
* @throws org.multiverse.api.exceptions.ControlFlowError
Expand All @@ -139,14 +139,14 @@ public interface Lock {
LockMode getLockMode(Txn txn);

/**
* Acquires a Lock with the provided LockMode. This call doesn't block if the Lock can't be upgraded, but throws
* a {@link org.multiverse.api.exceptions.ReadWriteConflict}. It could also be that the Lock is acquired, but the
* Acquires a TxnLock with the provided LockMode. This call doesn't block if the TxnLock can't be upgraded, but throws
* a {@link org.multiverse.api.exceptions.ReadWriteConflict}. It could also be that the TxnLock is acquired, but the
* Txn sees that it isn't consistent anymore. In that case also a
* {@link org.multiverse.api.exceptions.ReadWriteConflict} is thrown.
*
* <p>This call makes use of the Txn stored in the {@link TxnThreadLocal}.
*
* <p>If the lockMode is lower than the LockMode the transaction already has on this Lock, the call is ignored.
* <p>If the lockMode is lower than the LockMode the transaction already has on this TxnLock, the call is ignored.
*
* @param desiredLockMode the desired lockMode.
* @throws org.multiverse.api.exceptions.TxnExecutionException
Expand All @@ -160,12 +160,12 @@ public interface Lock {
void acquire(LockMode desiredLockMode);

/**
* Acquires a Lock with the provided LockMode using the provided transaction. This call doesn't block if the Lock can't be
* upgraded but throws a {@link org.multiverse.api.exceptions.ReadWriteConflict}. It could also be that the Lock is acquired,
* Acquires a TxnLock with the provided LockMode using the provided transaction. This call doesn't block if the TxnLock can't be
* upgraded but throws a {@link org.multiverse.api.exceptions.ReadWriteConflict}. It could also be that the TxnLock is acquired,
* but the Txn sees that it isn't consistent anymore. In that case also a
* {@link org.multiverse.api.exceptions.ReadWriteConflict} is thrown.
*
* <p>If the lockMode is lower than the LockMode the transaction already has on this Lock, the call is ignored.
* <p>If the lockMode is lower than the LockMode the transaction already has on this TxnLock, the call is ignored.
*
* @param txn the Txn used for this operation.
* @param desiredLockMode the desired lockMode.
Expand Down
10 changes: 5 additions & 5 deletions multiverse-core/src/main/java/org/multiverse/api/TxnObject.java
Expand Up @@ -23,15 +23,15 @@ public interface TxnObject {
Stm getStm();

/**
* Gets the {@link Lock} that belongs to this TxnObject. This call doesn't cause any locking, it
* Gets the {@link TxnLock} that belongs to this TxnObject. This call doesn't cause any locking, it
* only provides access to the object that is able to lock. The returned value will never be null.
*
* <p>This call also doesn't rely on a {@link Txn}.
*
* @return the Lock
* @return the TxnLock
* @throws UnsupportedOperationException if this operation is not supported.
*/
Lock getLock();
TxnLock getLock();

/**
* Returns the current version of the transactional object. Each time an update happens, the value is increased. It depends
Expand All @@ -52,7 +52,7 @@ public interface TxnObject {
* <p>This can safely be called on an TxnObject that already is locked, although it doesn't provide much value
* since with a locked TxnObject, since the writeskew problem can't occur anymore because it can't be changed.
*
* <p>Unlike the {@link Lock#acquire(LockMode)} which is pessimistic, ensure is optimistic. This means that a conflict
* <p>Unlike the {@link TxnLock#acquire(LockMode)} which is pessimistic, ensure is optimistic. This means that a conflict
* can be detected once the transaction commits.
*
* <p>This method has no effect if the {@link Txn} is readonly, because a writeskew is not possible with a
Expand All @@ -76,7 +76,7 @@ public interface TxnObject {
* <p>This can safely be called on an TxnObject that already is locked, although it doesn't provide much value
* since with a locked TxnObject, since the writeskew problem can't occur anymore because it can't be changed.
*
* <p>Unlike the {@link Lock#acquire(LockMode)} which is pessimistic, ensure is optimistic. This means that a conflict
* <p>Unlike the {@link TxnLock#acquire(LockMode)} which is pessimistic, ensure is optimistic. This means that a conflict
* can be detected once the transaction commits.
*
* <p>This method has no effect if the {@link Txn} is readonly, because a writeskew is not possible with a
Expand Down
Expand Up @@ -19,7 +19,7 @@
public final class VetoCommitBarrier extends CommitBarrier {

/**
* Creates a new VetoCommitBarrier that uses an unfair Lock.
* Creates a new VetoCommitBarrier that uses an unfair TxnLock.
*/
public VetoCommitBarrier() {
this(false);
Expand Down
Expand Up @@ -20,18 +20,6 @@
public final class FatGammaTxnExecutor extends AbstractGammaTxnExecutor{
private static final Logger logger = Logger.getLogger(FatGammaTxnExecutor.class.getName());

public void execute(Runnable runnable){
throw new UnsupportedOperationException();
}

public <E> E execute(Callable<E> callable){
throw new UnsupportedOperationException();
}

public <E> E executeChecked(Callable<E> callable)throws Exception{
throw new UnsupportedOperationException();
}

private final PropagationLevel propagationLevel;

public FatGammaTxnExecutor(final GammaTxnFactory txnFactory) {
Expand Down
Expand Up @@ -20,18 +20,6 @@
public final class LeanGammaTxnExecutor extends AbstractGammaTxnExecutor{
private static final Logger logger = Logger.getLogger(LeanGammaTxnExecutor.class.getName());

public void execute(Runnable runnable){
throw new UnsupportedOperationException();
}

public <E> E execute(Callable<E> callable){
throw new UnsupportedOperationException();
}

public <E> E executeChecked(Callable<E> callable)throws Exception{
throw new UnsupportedOperationException();
}


public LeanGammaTxnExecutor(final GammaTxnFactory txnFactory) {
super(txnFactory);
Expand Down
@@ -1,6 +1,6 @@
package org.multiverse.stms.gamma.transactionalobjects;

import org.multiverse.api.Lock;
import org.multiverse.api.TxnLock;
import org.multiverse.api.LockMode;
import org.multiverse.api.Txn;
import org.multiverse.api.exceptions.PanicError;
Expand All @@ -15,7 +15,7 @@
import static org.multiverse.api.TxnThreadLocal.getThreadLocalTxn;

@SuppressWarnings({"OverlyComplexClass"})
public abstract class AbstractGammaObject implements GammaObject, Lock {
public abstract class AbstractGammaObject implements GammaObject, TxnLock {

public static final long MASK_OREC_EXCLUSIVELOCK = 0x8000000000000000L;
public static final long MASK_OREC_UPDATELOCK = 0x4000000000000000L;
Expand Down Expand Up @@ -73,7 +73,7 @@ public final GammaStm getStm() {
}

@Override
public final Lock getLock() {
public final TxnLock getLock() {
return this;
}

Expand Down Expand Up @@ -570,7 +570,7 @@ public final void departAfterReadingAndUnlock() {
int readLockCount = getReadLockCount(current);

if (readLockCount == 0 && !hasWriteOrExclusiveLock(current)) {
throw new PanicError("No Lock acquired " + toOrecString(current));
throw new PanicError("No TxnLock acquired " + toOrecString(current));
}

boolean isReadBiased = isReadBiased(current);
Expand Down Expand Up @@ -748,7 +748,7 @@ public final void unlockByUnregistered() {
}

if (lockMode == 0) {
throw new PanicError("No Lock " + toOrecString(current));
throw new PanicError("No TxnLock " + toOrecString(current));
}

if (getSurplus(current) > 1) {
Expand Down
@@ -1,6 +1,6 @@
package org.multiverse.stms.gamma.transactionalobjects;

import org.multiverse.api.Lock;
import org.multiverse.api.TxnLock;
import org.multiverse.stms.gamma.GammaConstants;
import org.multiverse.stms.gamma.GammaStm;

Expand All @@ -10,7 +10,7 @@ public interface GammaObject extends GammaConstants {

GammaStm getStm();

Lock getLock();
TxnLock getLock();

int identityHashCode();
}

0 comments on commit 0dc8e65

Please sign in to comment.