pgcopydb icon indicating copy to clipboard operation
pgcopydb copied to clipboard

Recover from crash using undo log

Open arajkumar opened this issue 1 year ago • 3 comments

This commit remembers the file write position of a last successful transaction in a undo file. If there's a crash and we need to restart, we use this undo file to get rid of any partial work from the last transaction that wasn't finished.

TODO: Can we use the undo log mechanism to even for graceful exit? This would simplify the code and make it uniform for both graceful and ungraceful exits/crashes. The idea is to undo the changes made by the last incomplete transaction by reading the undo log file and write other messages like ENDPOS.

arajkumar avatar Nov 21 '23 15:11 arajkumar

I think implementing a proper undo log will become tricky to unless we resort to a transactional file write. Maybe opening the latest file and appending a ROLLBACK(if last txn is incomplete) will be much easier to implement.

arajkumar avatar Nov 22 '23 15:11 arajkumar

I think implementing a proper undo log will become tricky to unless we resort to a transactional file write. Maybe opening the latest file and appending a ROLLBACK(if last txn is incomplete) will be much easier to implement.

What if the latest/current transaction is incomplete and started several JSON files ago?

dimitri avatar Nov 22 '23 17:11 dimitri

I think implementing a proper undo log will become tricky to unless we resort to a transactional file write. Maybe opening the latest file and appending a ROLLBACK(if last txn is incomplete) will be much easier to implement.

What if the latest/current transaction is incomplete and started several JSON files ago?

It doesn't matter, all we do is appending a rollback message to latest file if we find the last statement is part of the incomplete txn. It is same as what we do for graceful exit.

arajkumar avatar Nov 23 '23 04:11 arajkumar