GigaSpaces ReadModifiers class (see Javadoc ) provides static methods and constants to decode read-type modifiers. The sets of modifiers are represented as integers with distinct bit positions representing different modifiers.
Four main types of modifiers can be used:
These should be used for backward compatibility with older versions of GigaSpaces:
You can use bitwise or the | operator to unite different modifiers.
REPEATABLE_READ, DIRTY_READ, and READ_COMMITTED are mutually exclusive (i.e. can't be used together). EXCLUSIVE_READ_LOCK can be joined with any of them.
These modifiers can be set either at the proxy level - IJSpace.setReadModifiers(int), or at the operation level (e.g. using one of IJSpace read/readIfExists/readMultiple/count methods with a modifiers parameter).
The following table describes the mapping between the Spring TransactionDefinition Mapping to GigaSpaces ReadModifiers:
REPEATABLE_READ is the default modifier, defined by the JavaSpaces specification.
The REPEATABLE_READ isolation level allows a transaction to acquire read locks on an object it returns to an application, and write locks an object it write, updates, or deletes. By using the REPEATABLE_READ isolation level, space operations issued multiple times within the same transaction always yield the same result. A transaction using the REPEATABLE_READ isolation level can retrieve and manipulate the same object as many times as needed until it completes its task. However, no other transaction can write, update, or delete an object that can affect the result being accessed, until the isolating transaction releases its locks. That is, when the isolating transaction is either committed or rolled back.
Transactions using the REPEATABLE_READ isolation level wait until the object that is write-locked by other transactions are unlocked before they acquire their own locks. This prevents them from reading "dirty" data. In addition, because other transactions cannot update or delete an object that is locked by a transaction using the REPEATABLE_READ isolation level, non-repeatable read situations are avoided.
The JavaSpaces specification defines the visibility of object for read operations as follows:
Sometimes it is desirable for non-transactional read operations to have full visibility of the objects in the space. The DIRTY_READ modifier, once set, enables read/readIfExists/readMultiple/count operations under a null transaction to have this complete visibility.
The READ_COMMITTED modifier enables a read-committed isolation level in read operations.
Read-committed is the isolation-level in which a read operation (under a transaction or a null transaction) can not see changes made by other transactions, until those transactions are committed. At this level of isolation, dirty-reads are not possible, but unrepeatable-reads and phantoms might occur.
Read-committed is the default isolation level in database systems. This isolation level means that the read operations return the space objects that are currently committed, regardless of the fact that these space objects might be updated (with a newer version) or taken under an uncommitted transaction. This is opposed to the default space isolation-level (derived from the JavaSpaces specification), which is repeatable-read.
The read-committed isolation level is useful for the local cache, local view, and GSIterators, which performs readMultiple and keep their current status by registering notify templates.
The READ_COMMITTED modifier is provided at the proxy level and the read API level. It is relevant for read, readIfExists, readMultiple, and count.
READ_COMMITTED and DIRTY_READ are mutually-exclusive. A space object under an (uncommitted) updating transaction or under a taking (unrolled) transaction returns the original (committed) value unless the operation is under the same transaction as the locking one.
If the read operation is under a transaction, there is no need to "enlist" the space object in the transaction (unless its already enlisted).
readIfExists has less space objects to wait for, unless these are new objects under an uncommitted transaction.
Refer to the Space Locking and Blocking section for GigaSpaces general locking and blocking rules.
The examples below assumes you are using IJSpace interface that is available via the GigaSpaces.getSpace(). If you are using the GigaSpaces interface and Spring automatic transaction demarcation, you will not need to specify the transaction object explicitly. Still, the blocking rules will be enforced.
The Exclusive Read Lock is similar to select for update SQL for RDBMS, or update lock with ODBMS.
In the JavaSpaces specification, a read under a transaction does not allow other users to modify the Entry, but it does allow two readers or more to read the same Entry under different transactions. To allow a user to block other users from reading an object, a read using exclusive read lock mode with a transaction should be performed.
The following methods support exclusive read lock when used with a transaction:
The exclusive read lock is supported in a clustered environment when using the Jini Transaction Manager.
The matching behavior can be changed by adding one of these modifiers.
Setting MATCH_BY_ID changes the matching algorithm, such that once a SpaceID is set the other fields' values are ignored. The matching is only done according to the SpaceID value.
Setting THROW_PARTIAL_FAILURE is only effective when readMultiple() is called. When set and a matching can be performed only on part of the partitions instead of just returning the partial result a QueryMultiplePartialFailureException is thrown including the partial result and the source of the partial failure.