geode transactions
TRANSCRIPT
Transactions
Swapnil Bawaskar
(Incubating)
2
Agenda
• Semantics• Implementation– Replicated Regions– Partitioned Region– From Client
• Failure Handling• Road Map
3
Semantics
• Repeatable Read– Thread sees own changes– Other threads do not until commit is called
• Optimistic– No Entry level locks, Readers not blocked– Conflict Detection
• NOT Persistent (yet)– Not a problem if you have at-least one member up
4
APIBASIC
CacheTransactionManager mgr = cache.getCacheTransactionManager();mgr.begin();region1.put("K1", "V1");region1.put("K2", "V2");region2.put("K2", "V2");mgr.commit();
SUSPEND/RESUMETransactionId txId = mgr.suspend();
… other non-transactional workmgr.resume(txId);mgr.tryResume(…);
SINGLE ENTRYregion.putIfAbsent(K, V);region.replace(K, V, V);region.remove(K, V);
OTHERmgr.addListener(new MyTransactionListener());mgr.setWriter(new TransactionWriter());
5
Implementation
• Isolation through ThreadLocal– Copy existing reference in ThreadLocal– Perform conflict check under lock at commit time
Region
Thread
TXState
Entry
Reference
6
At Commit
7
Notes
• copy-on-read must be set to true• D-lock grantor single point of contention• Non-transactional threads may see
intermediate state (non atomic)– Reads should be done within a transaction– Set system property Dgemfire.detectReadConflicts=true
• Prone to ABA problem• Faster than doing individual operations
8
Failure Scenarios
• Replica Fails– No problem, It will do a GII from other members
• Coordinator Fails– Replicas gossip to arrive at the outcome of the
transaction• If no member has “Apply Commit” message, some
members missing commit set, Abort transaction• If at-least one member has “Apply Commit” message,
all members have commit set, apply transaction
9
PR HostPR Host
Thread
TX State
Partitioned Region
PR Host
10
PR HostPR Host
Thread
TX State
PR Host
Partitioned Region
11
PR HostPR Host
Thread
TX State
PR Host
Partitioned Region
TXData
NotColocated
12
Partitioned Region
• TX State on member with Primary copy (TX HOST)• Only one TX Host per transaction– First operation in TX establishes the host– All subsequent operations (even for Replicate Regions)
sent to the same host– Throws TransactionDataNotColocatedException if TX Host is
not primary• D-lock service is striped– TX Locks are local, no messaging– No single point of contention in the system
13
Data Colocation
• Inspiration“For scalability, applications should manipulate single collection of data that lives on one JVM”- Pat Helland (Life Beyond Distributed Transactions)
- Custom Partitioning- Within one Partitioned Region- E.g. All trades in January
- Data Colocation- Between Two or more Partitioned Regions- All Orders of a Customer
14
Failure Scenarios
• Failures before Commit– TX Host Crashes (TransactionDataNodeHasDeparted)– On Re-balance (TransactionDataRebalanced)• Entire transaction should be re-tried
• Failures after Commit– TX Host Crashes» Replicas would have applied all or none changes» Consistent but Outcome unknown TransactionInDoubt
– Replica Crashes, Succeeds
15
• All operations sent to the server• If necessary, server delegates to primary• HA supported when delegate fails
Client
Delegate TX HostTX State
Client Initiated
16
Feature Interaction• Eviction/Expiration
– Entry is reference counted– Entry kept around if reference count > 0
• OQL– Does not honor Repeatable Read
• Persistence– gemfire.ALLOW_PERSISTENT_TRANSACTIONS=true– No delineation on Disk– Works as long as one replica survives
• Functions– Can begin, commit, suspend/resume transactions
17
Handling Failure
• Types of Exception– CommitConflictException– TransactionDataNodeHasDepartedException– TransactionDataNotColocatedException– TransactionDataRebalancedException– TransactionInDoubtException
• Catch TransactionException and retry in loop
18
JTA
• Enlists as a Synchronization with external JTA Managers– Last to prepare, first to Commit
• Has a JCA adapter for Last Resource Commit with Weblogic.
• Has an implementation of JTA Manager– not production grade
19
Road Map
• Distributed Transactions (GEODE-16)• XA Data Source• Persistent Transactions• OQL/Query Engine support
Questions?
http://geode.incubator.apache.org/
(sbawaskar at apache dot org)