geode transactions

20
Transactions Swapnil Bawaskar (Incubating)

Upload: swapnil-bawaskar

Post on 15-Apr-2017

216 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Geode transactions

Transactions

Swapnil Bawaskar

(Incubating)

Page 2: Geode transactions

2

Agenda

• Semantics• Implementation– Replicated Regions– Partitioned Region– From Client

• Failure Handling• Road Map

Page 3: Geode transactions

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

Page 4: Geode transactions

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());

Page 5: Geode transactions

5

Implementation

• Isolation through ThreadLocal– Copy existing reference in ThreadLocal– Perform conflict check under lock at commit time

Region

Thread

TXState

Entry

Reference

Page 6: Geode transactions

6

At Commit

Page 7: Geode transactions

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

Page 8: Geode transactions

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

Page 9: Geode transactions

9

PR HostPR Host

Thread

TX State

Partitioned Region

PR Host

Page 10: Geode transactions

10

PR HostPR Host

Thread

TX State

PR Host

Partitioned Region

Page 11: Geode transactions

11

PR HostPR Host

Thread

TX State

PR Host

Partitioned Region

TXData

NotColocated

Page 12: Geode transactions

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

Page 13: Geode transactions

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

Page 14: Geode transactions

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

Page 15: Geode transactions

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

Page 16: Geode transactions

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

Page 17: Geode transactions

17

Handling Failure

• Types of Exception– CommitConflictException– TransactionDataNodeHasDepartedException– TransactionDataNotColocatedException– TransactionDataRebalancedException– TransactionInDoubtException

• Catch TransactionException and retry in loop

Page 18: Geode transactions

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

Page 19: Geode transactions

19

Road Map

• Distributed Transactions (GEODE-16)• XA Data Source• Persistent Transactions• OQL/Query Engine support

Page 20: Geode transactions

Questions?

http://geode.incubator.apache.org/

(sbawaskar at apache dot org)