Re: FDW-based dblink

From: Itagaki Takahiro <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>
To: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: FDW-based dblink
Date: 2009-08-14 01:53:11
Message-ID: 20090814104655.99DC.52131E4D@oss.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com> wrote:

> Quite aside from the requirement for on-commit trigger, how exactly
> would you use 2PC with the remote database? When would you issue PREPARE
> TRANSACTION, and when would COMMIT PREPARED? What if the local database
> crashes in between - is the remote transaction left hanging in prepared
> state?

I'm thinking prepareing remote transactions just before commit the local
transaction in CommitTransaction(). The pseudo code is something like:

1. Fire deferred triggers and do works for just-before-commit.
2. AtEOXact_dblink()
=> prepare and commit remote transactions.
3. HOLD_INTERRUPTS()
We cannot rollback the local transaction after this.
4. do works for commit

If we need more robust atomicity, we could use 2PC against the local
transaction if there some remote transactions. i.e., expand COMMIT
command into PREPARE TRANSACTION and COMMIT PREPARED internally:

1. Fire deferred triggers and do works for just-before-commit.
2. AtEOXact_dblink_prepare() -- prepare remotes
3. PrepareTransaction() -- prepare local
4. AtEOXact_dblink_commit() -- commit remotes
5. FinishPreparedTransaction(commit) -- commit local

I'm using deferrable after trigger for the purpose in my present
prototype, and it seems to work if the trigger is called at the
end of deferrable event and local backend doesn't crash in final
works for commit -- and we have some should-not-failed operations
in the final works already (flushing WAL, etc.).

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2009-08-14 03:11:39 Re: Why is vacuum_freeze_min_age 100m?
Previous Message Олег Царев 2009-08-14 00:48:48 Re: Implementation of GROUPING SETS (T431: Extended grouping capabilities)