SlideShare una empresa de Scribd logo
1 de 20
Descargar para leer sin conexión
© 2013 EDB All rights reserved. 1
Atomicity for transactions involving
foreign servers
•
Ashutosh Bapat | 19th
June 2015
@PGCon 2015, Ottawa, Canada
© 2013 EDB All rights reserved. 2
•
Atomic commit for transactions involving foreign
servers
– Current status
– Solution – two-phase commit protocol
– Overview of implementation
– Foreign servers without 2PC support
•
Atomic visibility
Agenda
© 2013 EDB All rights reserved. 3
Atomicity
val
1
2
tab1
val
1
2
tab2
BEGIN;
UPDATE tab1 SET val = val + 1;
UPDATE tab2 SET val = val + 2;
COMMIT;
val
1
2
tab1
val
1
2
tab2
val
2
3
tab1
val
3
4
tab2
success
val
2
3
tab1
val
1
2
tab2
failure
© 2013 EDB All rights reserved. 4
Distributed Atomicity
val
1
2
tab1
val
1
2
tab2
BEGIN;
UPDATE tab1 SET val = val + 1;
UPDATE tab2 SET val = val + 2;
COMMIT;
val
1
2
tab1
val
1
2
tab2
val
2
3
tab1
val
3
4
tab2
val
2
3
tab1
val
1
2
tab2
Coordinator
FS 1 FS 2
FDW FDW
failure
success
© 2013 EDB All rights reserved. 5
Atomicity - foreign table inheritance
val
1
2
chld1
val
1
2
chld2
UPDATE parent SET val = val + 1;
val
1
2
tab1
val
1
2
tab2
val
2
3
tab1
val
2
3
tab2
val
2
3
tab1
val
1
2
tab2
Coordinator
FS 1 FS 2
FDW FDW
failure
success
parent
© 2013 EDB All rights reserved. 6
•
Transaction management is entirely implemented by
FDW
– postgres_fdw uses one-phase commit
– any failure (including connectivity) during commit
processing can cause changes to some foreign
servers committed and others aborted
•
Atomicity is not guaranteed
Current status
© 2013 EDB All rights reserved. 7
Two-phase commit
Prepare transaction
on foreign server
Prepare
succeeded?
Next foreign
server?
yes
yes
Commit all prepared
transactions.
No
Abort all prepared
transactions
Abort any
unprepared
transactions
No
Phase 1
Phase 2
failure
Commit processing,
record commit locally
Local pre-commit
processing
© 2013 EDB All rights reserved. 8
Two-phase commit
Prepare transaction on foreign server
Prepare succeeded?
Next foreign server?
yes
yes
Commit all prepared
transactions.
No
Abort all prepared
transactions
Abort any unprepared transactions
No
Phase 1
Phase 2
Connectivity failure, coordinator/foreign server crash
•
all the foreign transactions and local transaction may not commit at the
same time
– Atomic commit – guaranteed
– Atomic visibility – not guaranteed
•
Unresolved prepared transactions – prepared transactions waiting to be
committed/aborted
– Blocked resources, degraded performance
© 2013 EDB All rights reserved. 9
Remembering foreign transactions
Log about prepared
transactions
Persist prepared
transaction information
to disk
Prepare transaction on
foreign server
Get prepared
transaction information
pg_fdw_xact/
XLOG
In-memory array
Crash
recovery,
replication
Server restarts
Prepare transaction on
foreign server
© 2013 EDB All rights reserved. 10
Resolving foreign transactions
Log the removal of
foreign transaction
information
Remove foreign
transaction from the
disk
Commit/Abort foreign
transaction
pg_fdw_xact/
XLOG
In-memory array
Crash
recovery,
replication
Commit/abort foreign
transaction
Successful?
Yes
No
Retried by
resolver till
resolved
© 2013 EDB All rights reserved. 11
•
Transaction id: decides the fate of foreign transaction
•
Database id: where to look for foreign server and user
mapping
•
Foreign server and user: where and who prepared the
foreign transaction
•
Foreign transaction id: identifies the prepared
transaction on the foreign server
– e.g. GID on PostgreSQL
Foreign transaction information
© 2013 EDB All rights reserved. 12
Foreign servers without 2PC support
Commit
transaction on
foreign server
Successful?
Next
foreign
server?
No
No
Yes
Yes
Transaction
aborted on
foreign
server
Local
commit
successful?
Yes
Abort transaction
on all foreign
servers
No
Commit
transaction on
foreign server
Successful?
Next
foreign
server?
No
No
Yes
Yes
Precommit
processing
successful?
Yes
Abort transaction
on all remaining
foreign servers
No
Vs
© 2013 EDB All rights reserved. 13
•
GetPrepareId
– function to obtain prepared transaction id for a
given foreign server
– Each FDW might have different rules for identifier
– Persisted and WAL logged
FDW hooks for transaction management
© 2013 EDB All rights reserved. 14
•
HandleForeignTransaction - function to end foreign
transaction in following ways
– Commit/Rollback running transaction
– Prepare running transaction
– Commit/Rollback prepared transaction with given
identifier
FDW hooks for transaction management
© 2013 EDB All rights reserved. 15
•
atomic_foreign_transaction – when ON, two phase
commit is used for transactions involving foreign
servers.
– When ON requires all participating servers to
support 2PC
– Can be set any time during the transaction.Value
at the time of commit is used.
•
max_foreign_xacts – maximum number of transactions
prepared on foreign servers at a given time
GUCs
© 2013 EDB All rights reserved. 16
•
Builtin function (pg_fdw_resolve())– resolves all the
unresolved foreign transactions in the database where
it's run
•
Background worker process – fires the built-in function
by connecting to various databases
– Available at contrib/pg_fdw_xact_resolver
– Install and add to 'shared_preload_libraries' (and
restart)
Foreign transaction resolver
© 2013 EDB All rights reserved. 17
Atomic visibility
© 2013 EDB All rights reserved. 18
•
Problem: MVCC allows older versions to be read
– Older version of data is read while transaction
modifying it is prepared but not committed/resolved
•
Solution: Wait for prepared transactions to get
committed/resolved
– Stronger locking – FOR SHARE, SERIALISABLE
ISOLATION – performance affected
– Resolve prepared transactions before data is
accessed
●
You have connectivity now, right?
●
How to detect this situation?
Atomic visibility – rough ideas
© 2013 EDB All rights reserved. 19
•
Hackers discussion thread with subject “Transactions
involving multiple postgres foreign servers”
•
First WIP patch on 17th
Feb.
– 2015-06 commitfest
– Had several TODOs
•
Improved patch to be submitted soon
– Takes care of many TODOs
– Addresses atomic commit
– Does not address atomic visibility
Current status
Atomicity for transactions involving foreign server in PostgreSQL

Más contenido relacionado

Similar a Atomicity for transactions involving foreign server in PostgreSQL

Enhanced Live Migration for Intensive Memory Loads
Enhanced Live Migration for Intensive Memory LoadsEnhanced Live Migration for Intensive Memory Loads
Enhanced Live Migration for Intensive Memory LoadsSamsung Open Source Group
 
Application High Availability and Upgrades Using Oracle GoldenGate
Application High Availability and Upgrades Using Oracle GoldenGateApplication High Availability and Upgrades Using Oracle GoldenGate
Application High Availability and Upgrades Using Oracle GoldenGateShane Borden
 
GeeCon- 'www.NoSQL.com' by Mark Addy
GeeCon- 'www.NoSQL.com' by Mark Addy GeeCon- 'www.NoSQL.com' by Mark Addy
GeeCon- 'www.NoSQL.com' by Mark Addy C2B2 Consulting
 
Migrating to XtraDB Cluster
Migrating to XtraDB ClusterMigrating to XtraDB Cluster
Migrating to XtraDB Clusterpercona2013
 
2007-05-23 Cecchet_PGCon2007.ppt
2007-05-23 Cecchet_PGCon2007.ppt2007-05-23 Cecchet_PGCon2007.ppt
2007-05-23 Cecchet_PGCon2007.pptnadirpervez2
 
Taming the Tiger: Tips and Tricks for Using Telegraf
Taming the Tiger: Tips and Tricks for Using TelegrafTaming the Tiger: Tips and Tricks for Using Telegraf
Taming the Tiger: Tips and Tricks for Using TelegrafInfluxData
 
Migrating to XtraDB Cluster
Migrating to XtraDB ClusterMigrating to XtraDB Cluster
Migrating to XtraDB Clusterpercona2013
 
Gdb basics for my sql db as (percona live europe 2019)
Gdb basics for my sql db as (percona live europe 2019)Gdb basics for my sql db as (percona live europe 2019)
Gdb basics for my sql db as (percona live europe 2019)Valerii Kravchuk
 
Percona Xtradb Cluster (pxc) 101 percona university 2019
Percona Xtradb Cluster (pxc) 101 percona university 2019Percona Xtradb Cluster (pxc) 101 percona university 2019
Percona Xtradb Cluster (pxc) 101 percona university 2019Marcelo Henrique Gonçalves
 
XPDS16: Live Migration of vGPU - Xiao Zheng, Intel Asia-Pacific Research & De...
XPDS16: Live Migration of vGPU - Xiao Zheng, Intel Asia-Pacific Research & De...XPDS16: Live Migration of vGPU - Xiao Zheng, Intel Asia-Pacific Research & De...
XPDS16: Live Migration of vGPU - Xiao Zheng, Intel Asia-Pacific Research & De...The Linux Foundation
 
7 concurrency controltwo
7 concurrency controltwo7 concurrency controltwo
7 concurrency controltwoashish61_scs
 
7 concurrency controltwo
7 concurrency controltwo7 concurrency controltwo
7 concurrency controltwoashish61_scs
 
IOUG Data Integration SIG w/ Oracle GoldenGate Solutions and Configuration
IOUG Data Integration SIG w/ Oracle GoldenGate Solutions and ConfigurationIOUG Data Integration SIG w/ Oracle GoldenGate Solutions and Configuration
IOUG Data Integration SIG w/ Oracle GoldenGate Solutions and ConfigurationBobby Curtis
 
Database , 13 Replication
Database , 13 ReplicationDatabase , 13 Replication
Database , 13 ReplicationAli Usman
 
Kapacitor Stream Processing
Kapacitor Stream ProcessingKapacitor Stream Processing
Kapacitor Stream ProcessingInfluxData
 
OpenZFS send and receive
OpenZFS send and receiveOpenZFS send and receive
OpenZFS send and receiveMatthew Ahrens
 
Ganeti Hands-on Walk-thru (part 2) -- LinuxCon 2012
Ganeti Hands-on Walk-thru (part 2) -- LinuxCon 2012Ganeti Hands-on Walk-thru (part 2) -- LinuxCon 2012
Ganeti Hands-on Walk-thru (part 2) -- LinuxCon 2012Lance Albertson
 
High-availability with Galera Cluster for MySQL
High-availability with Galera Cluster for MySQLHigh-availability with Galera Cluster for MySQL
High-availability with Galera Cluster for MySQLFromDual GmbH
 

Similar a Atomicity for transactions involving foreign server in PostgreSQL (20)

Enhanced Live Migration for Intensive Memory Loads
Enhanced Live Migration for Intensive Memory LoadsEnhanced Live Migration for Intensive Memory Loads
Enhanced Live Migration for Intensive Memory Loads
 
Application High Availability and Upgrades Using Oracle GoldenGate
Application High Availability and Upgrades Using Oracle GoldenGateApplication High Availability and Upgrades Using Oracle GoldenGate
Application High Availability and Upgrades Using Oracle GoldenGate
 
GeeCon- 'www.NoSQL.com' by Mark Addy
GeeCon- 'www.NoSQL.com' by Mark Addy GeeCon- 'www.NoSQL.com' by Mark Addy
GeeCon- 'www.NoSQL.com' by Mark Addy
 
Migrating to XtraDB Cluster
Migrating to XtraDB ClusterMigrating to XtraDB Cluster
Migrating to XtraDB Cluster
 
2007-05-23 Cecchet_PGCon2007.ppt
2007-05-23 Cecchet_PGCon2007.ppt2007-05-23 Cecchet_PGCon2007.ppt
2007-05-23 Cecchet_PGCon2007.ppt
 
Taming the Tiger: Tips and Tricks for Using Telegraf
Taming the Tiger: Tips and Tricks for Using TelegrafTaming the Tiger: Tips and Tricks for Using Telegraf
Taming the Tiger: Tips and Tricks for Using Telegraf
 
Migrating to XtraDB Cluster
Migrating to XtraDB ClusterMigrating to XtraDB Cluster
Migrating to XtraDB Cluster
 
Gdb basics for my sql db as (percona live europe 2019)
Gdb basics for my sql db as (percona live europe 2019)Gdb basics for my sql db as (percona live europe 2019)
Gdb basics for my sql db as (percona live europe 2019)
 
Percona Xtradb Cluster (pxc) 101 percona university 2019
Percona Xtradb Cluster (pxc) 101 percona university 2019Percona Xtradb Cluster (pxc) 101 percona university 2019
Percona Xtradb Cluster (pxc) 101 percona university 2019
 
XPDS16: Live Migration of vGPU - Xiao Zheng, Intel Asia-Pacific Research & De...
XPDS16: Live Migration of vGPU - Xiao Zheng, Intel Asia-Pacific Research & De...XPDS16: Live Migration of vGPU - Xiao Zheng, Intel Asia-Pacific Research & De...
XPDS16: Live Migration of vGPU - Xiao Zheng, Intel Asia-Pacific Research & De...
 
7 concurrency controltwo
7 concurrency controltwo7 concurrency controltwo
7 concurrency controltwo
 
7 concurrency controltwo
7 concurrency controltwo7 concurrency controltwo
7 concurrency controltwo
 
IOUG Data Integration SIG w/ Oracle GoldenGate Solutions and Configuration
IOUG Data Integration SIG w/ Oracle GoldenGate Solutions and ConfigurationIOUG Data Integration SIG w/ Oracle GoldenGate Solutions and Configuration
IOUG Data Integration SIG w/ Oracle GoldenGate Solutions and Configuration
 
Database , 13 Replication
Database , 13 ReplicationDatabase , 13 Replication
Database , 13 Replication
 
OpenDataPlane Project
OpenDataPlane ProjectOpenDataPlane Project
OpenDataPlane Project
 
Kapacitor Stream Processing
Kapacitor Stream ProcessingKapacitor Stream Processing
Kapacitor Stream Processing
 
OpenZFS send and receive
OpenZFS send and receiveOpenZFS send and receive
OpenZFS send and receive
 
Ganeti Hands-on Walk-thru (part 2) -- LinuxCon 2012
Ganeti Hands-on Walk-thru (part 2) -- LinuxCon 2012Ganeti Hands-on Walk-thru (part 2) -- LinuxCon 2012
Ganeti Hands-on Walk-thru (part 2) -- LinuxCon 2012
 
Distributed fun with etcd
Distributed fun with etcdDistributed fun with etcd
Distributed fun with etcd
 
High-availability with Galera Cluster for MySQL
High-availability with Galera Cluster for MySQLHigh-availability with Galera Cluster for MySQL
High-availability with Galera Cluster for MySQL
 

Último

Role of Consumer Insights in business transformation
Role of Consumer Insights in business transformationRole of Consumer Insights in business transformation
Role of Consumer Insights in business transformationAnnie Melnic
 
Digital Indonesia Report 2024 by We Are Social .pdf
Digital Indonesia Report 2024 by We Are Social .pdfDigital Indonesia Report 2024 by We Are Social .pdf
Digital Indonesia Report 2024 by We Are Social .pdfNicoChristianSunaryo
 
IBEF report on the Insurance market in India
IBEF report on the Insurance market in IndiaIBEF report on the Insurance market in India
IBEF report on the Insurance market in IndiaManalVerma4
 
Presentation of project of business person who are success
Presentation of project of business person who are successPresentation of project of business person who are success
Presentation of project of business person who are successPratikSingh115843
 
Non Text Magic Studio Magic Design for Presentations L&P.pdf
Non Text Magic Studio Magic Design for Presentations L&P.pdfNon Text Magic Studio Magic Design for Presentations L&P.pdf
Non Text Magic Studio Magic Design for Presentations L&P.pdfPratikPatil591646
 
English-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdf
English-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdfEnglish-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdf
English-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdfblazblazml
 
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...Dr Arash Najmaei ( Phd., MBA, BSc)
 
Decoding Movie Sentiments: Analyzing Reviews with Data Analysis model
Decoding Movie Sentiments: Analyzing Reviews with Data Analysis modelDecoding Movie Sentiments: Analyzing Reviews with Data Analysis model
Decoding Movie Sentiments: Analyzing Reviews with Data Analysis modelBoston Institute of Analytics
 
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...Boston Institute of Analytics
 
DATA ANALYSIS using various data sets like shoping data set etc
DATA ANALYSIS using various data sets like shoping data set etcDATA ANALYSIS using various data sets like shoping data set etc
DATA ANALYSIS using various data sets like shoping data set etclalithasri22
 
Digital Marketing Plan, how digital marketing works
Digital Marketing Plan, how digital marketing worksDigital Marketing Plan, how digital marketing works
Digital Marketing Plan, how digital marketing worksdeepakthakur548787
 
why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...
why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...
why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...Jack Cole
 
Statistics For Management by Richard I. Levin 8ed.pdf
Statistics For Management by Richard I. Levin 8ed.pdfStatistics For Management by Richard I. Levin 8ed.pdf
Statistics For Management by Richard I. Levin 8ed.pdfnikeshsingh56
 
Bank Loan Approval Analysis: A Comprehensive Data Analysis Project
Bank Loan Approval Analysis: A Comprehensive Data Analysis ProjectBank Loan Approval Analysis: A Comprehensive Data Analysis Project
Bank Loan Approval Analysis: A Comprehensive Data Analysis ProjectBoston Institute of Analytics
 

Último (17)

Role of Consumer Insights in business transformation
Role of Consumer Insights in business transformationRole of Consumer Insights in business transformation
Role of Consumer Insights in business transformation
 
2023 Survey Shows Dip in High School E-Cigarette Use
2023 Survey Shows Dip in High School E-Cigarette Use2023 Survey Shows Dip in High School E-Cigarette Use
2023 Survey Shows Dip in High School E-Cigarette Use
 
Digital Indonesia Report 2024 by We Are Social .pdf
Digital Indonesia Report 2024 by We Are Social .pdfDigital Indonesia Report 2024 by We Are Social .pdf
Digital Indonesia Report 2024 by We Are Social .pdf
 
IBEF report on the Insurance market in India
IBEF report on the Insurance market in IndiaIBEF report on the Insurance market in India
IBEF report on the Insurance market in India
 
Presentation of project of business person who are success
Presentation of project of business person who are successPresentation of project of business person who are success
Presentation of project of business person who are success
 
Non Text Magic Studio Magic Design for Presentations L&P.pdf
Non Text Magic Studio Magic Design for Presentations L&P.pdfNon Text Magic Studio Magic Design for Presentations L&P.pdf
Non Text Magic Studio Magic Design for Presentations L&P.pdf
 
English-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdf
English-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdfEnglish-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdf
English-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdf
 
Data Analysis Project: Stroke Prediction
Data Analysis Project: Stroke PredictionData Analysis Project: Stroke Prediction
Data Analysis Project: Stroke Prediction
 
Insurance Churn Prediction Data Analysis Project
Insurance Churn Prediction Data Analysis ProjectInsurance Churn Prediction Data Analysis Project
Insurance Churn Prediction Data Analysis Project
 
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...
 
Decoding Movie Sentiments: Analyzing Reviews with Data Analysis model
Decoding Movie Sentiments: Analyzing Reviews with Data Analysis modelDecoding Movie Sentiments: Analyzing Reviews with Data Analysis model
Decoding Movie Sentiments: Analyzing Reviews with Data Analysis model
 
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
 
DATA ANALYSIS using various data sets like shoping data set etc
DATA ANALYSIS using various data sets like shoping data set etcDATA ANALYSIS using various data sets like shoping data set etc
DATA ANALYSIS using various data sets like shoping data set etc
 
Digital Marketing Plan, how digital marketing works
Digital Marketing Plan, how digital marketing worksDigital Marketing Plan, how digital marketing works
Digital Marketing Plan, how digital marketing works
 
why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...
why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...
why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...
 
Statistics For Management by Richard I. Levin 8ed.pdf
Statistics For Management by Richard I. Levin 8ed.pdfStatistics For Management by Richard I. Levin 8ed.pdf
Statistics For Management by Richard I. Levin 8ed.pdf
 
Bank Loan Approval Analysis: A Comprehensive Data Analysis Project
Bank Loan Approval Analysis: A Comprehensive Data Analysis ProjectBank Loan Approval Analysis: A Comprehensive Data Analysis Project
Bank Loan Approval Analysis: A Comprehensive Data Analysis Project
 

Atomicity for transactions involving foreign server in PostgreSQL

  • 1. © 2013 EDB All rights reserved. 1 Atomicity for transactions involving foreign servers • Ashutosh Bapat | 19th June 2015 @PGCon 2015, Ottawa, Canada
  • 2. © 2013 EDB All rights reserved. 2 • Atomic commit for transactions involving foreign servers – Current status – Solution – two-phase commit protocol – Overview of implementation – Foreign servers without 2PC support • Atomic visibility Agenda
  • 3. © 2013 EDB All rights reserved. 3 Atomicity val 1 2 tab1 val 1 2 tab2 BEGIN; UPDATE tab1 SET val = val + 1; UPDATE tab2 SET val = val + 2; COMMIT; val 1 2 tab1 val 1 2 tab2 val 2 3 tab1 val 3 4 tab2 success val 2 3 tab1 val 1 2 tab2 failure
  • 4. © 2013 EDB All rights reserved. 4 Distributed Atomicity val 1 2 tab1 val 1 2 tab2 BEGIN; UPDATE tab1 SET val = val + 1; UPDATE tab2 SET val = val + 2; COMMIT; val 1 2 tab1 val 1 2 tab2 val 2 3 tab1 val 3 4 tab2 val 2 3 tab1 val 1 2 tab2 Coordinator FS 1 FS 2 FDW FDW failure success
  • 5. © 2013 EDB All rights reserved. 5 Atomicity - foreign table inheritance val 1 2 chld1 val 1 2 chld2 UPDATE parent SET val = val + 1; val 1 2 tab1 val 1 2 tab2 val 2 3 tab1 val 2 3 tab2 val 2 3 tab1 val 1 2 tab2 Coordinator FS 1 FS 2 FDW FDW failure success parent
  • 6. © 2013 EDB All rights reserved. 6 • Transaction management is entirely implemented by FDW – postgres_fdw uses one-phase commit – any failure (including connectivity) during commit processing can cause changes to some foreign servers committed and others aborted • Atomicity is not guaranteed Current status
  • 7. © 2013 EDB All rights reserved. 7 Two-phase commit Prepare transaction on foreign server Prepare succeeded? Next foreign server? yes yes Commit all prepared transactions. No Abort all prepared transactions Abort any unprepared transactions No Phase 1 Phase 2 failure Commit processing, record commit locally Local pre-commit processing
  • 8. © 2013 EDB All rights reserved. 8 Two-phase commit Prepare transaction on foreign server Prepare succeeded? Next foreign server? yes yes Commit all prepared transactions. No Abort all prepared transactions Abort any unprepared transactions No Phase 1 Phase 2 Connectivity failure, coordinator/foreign server crash • all the foreign transactions and local transaction may not commit at the same time – Atomic commit – guaranteed – Atomic visibility – not guaranteed • Unresolved prepared transactions – prepared transactions waiting to be committed/aborted – Blocked resources, degraded performance
  • 9. © 2013 EDB All rights reserved. 9 Remembering foreign transactions Log about prepared transactions Persist prepared transaction information to disk Prepare transaction on foreign server Get prepared transaction information pg_fdw_xact/ XLOG In-memory array Crash recovery, replication Server restarts Prepare transaction on foreign server
  • 10. © 2013 EDB All rights reserved. 10 Resolving foreign transactions Log the removal of foreign transaction information Remove foreign transaction from the disk Commit/Abort foreign transaction pg_fdw_xact/ XLOG In-memory array Crash recovery, replication Commit/abort foreign transaction Successful? Yes No Retried by resolver till resolved
  • 11. © 2013 EDB All rights reserved. 11 • Transaction id: decides the fate of foreign transaction • Database id: where to look for foreign server and user mapping • Foreign server and user: where and who prepared the foreign transaction • Foreign transaction id: identifies the prepared transaction on the foreign server – e.g. GID on PostgreSQL Foreign transaction information
  • 12. © 2013 EDB All rights reserved. 12 Foreign servers without 2PC support Commit transaction on foreign server Successful? Next foreign server? No No Yes Yes Transaction aborted on foreign server Local commit successful? Yes Abort transaction on all foreign servers No Commit transaction on foreign server Successful? Next foreign server? No No Yes Yes Precommit processing successful? Yes Abort transaction on all remaining foreign servers No Vs
  • 13. © 2013 EDB All rights reserved. 13 • GetPrepareId – function to obtain prepared transaction id for a given foreign server – Each FDW might have different rules for identifier – Persisted and WAL logged FDW hooks for transaction management
  • 14. © 2013 EDB All rights reserved. 14 • HandleForeignTransaction - function to end foreign transaction in following ways – Commit/Rollback running transaction – Prepare running transaction – Commit/Rollback prepared transaction with given identifier FDW hooks for transaction management
  • 15. © 2013 EDB All rights reserved. 15 • atomic_foreign_transaction – when ON, two phase commit is used for transactions involving foreign servers. – When ON requires all participating servers to support 2PC – Can be set any time during the transaction.Value at the time of commit is used. • max_foreign_xacts – maximum number of transactions prepared on foreign servers at a given time GUCs
  • 16. © 2013 EDB All rights reserved. 16 • Builtin function (pg_fdw_resolve())– resolves all the unresolved foreign transactions in the database where it's run • Background worker process – fires the built-in function by connecting to various databases – Available at contrib/pg_fdw_xact_resolver – Install and add to 'shared_preload_libraries' (and restart) Foreign transaction resolver
  • 17. © 2013 EDB All rights reserved. 17 Atomic visibility
  • 18. © 2013 EDB All rights reserved. 18 • Problem: MVCC allows older versions to be read – Older version of data is read while transaction modifying it is prepared but not committed/resolved • Solution: Wait for prepared transactions to get committed/resolved – Stronger locking – FOR SHARE, SERIALISABLE ISOLATION – performance affected – Resolve prepared transactions before data is accessed ● You have connectivity now, right? ● How to detect this situation? Atomic visibility – rough ideas
  • 19. © 2013 EDB All rights reserved. 19 • Hackers discussion thread with subject “Transactions involving multiple postgres foreign servers” • First WIP patch on 17th Feb. – 2015-06 commitfest – Had several TODOs • Improved patch to be submitted soon – Takes care of many TODOs – Addresses atomic commit – Does not address atomic visibility Current status