-
Notifications
You must be signed in to change notification settings - Fork 0
Concept Undo Journal Rollback
Turkce Dokumantasyon | English Documentation
Category: Core Concepts & Architecture
Subsystem: Transaction Engine (AmberDB::Transact)
Entry Type: Architectural Concept
The Undo-Journal ACID Rollback and Crash Recovery Mechanism guarantees Atomicity and Consistency across multi-table operations in AmberDB.
When a transaction is started via transact_start, AmberDB creates an active disk-backed undo journal file (dbstore/txn/amberdb_processid_timestamp.txn). Before any physical record in .db or secondary index file (.inx, .fld, .src, .fac, .srt) is mutated on disk, its original unmodified state is recorded sequentially into the journal.
If any error occurs during execution, or if the Perl process crashes/aborts unexpectedly, AmberDB replays the undo journal in Last-In, First-Out (LIFO) reverse order to restore all modified tables and indexes back to their exact pre-transaction state.
Undo-Journal Pipeline
1. transact_start() > Creates .txn journal file
2. Record Mutation (Insert/Update) > Writes PREVIOUS state to .txn BEFORE modifying .db
3. Normal Completion (transact_end) > Flushes changes, unlinks .txn file
4. Failure / Crash / Abort > Replays .txn in reverse LIFO order to revert changes
If a host server loses power, encounters a kernel panic, or a worker process is terminated via kill -9, incomplete .txn journal files remain on disk under dbstore/txn/.
On subsequent AmberDB initialization (AmberDB->new), the engine automatically triggers transact_recover():
- Scans
dbstore/txn/for orphaned.txnfiles left by terminated PIDs. - Reads the journal's reverse-diff entries.
- Automatically rolls back the incomplete changes and removes the orphaned journals.
- Logs diagnostic recovery events cleanly.
# Multi-table atomic transfer with automatic journal logging
$adb->transact_start();
eval {
# Deduct from Account A
my @acc_a = $adb->read_id("accounts", 1001);
$acc_a[2] -= 500;
$adb->modify_id("accounts", @acc_a);
# Simulate failure
die "Network connection timeout\n" if $network_error;
# Add to Account B
my @acc_b = $adb->read_id("accounts", 1002);
$acc_b[2] += 500;
$adb->modify_id("accounts", @acc_b);
$adb->transact_end();
};
if ($@) {
# LIFO rollback restores Account A to pre-deduction balance
$adb->transact_rollback();
}AmberDB — High-Performance Schema-Driven NoSQL Database Engine for Perl.
Copyright 2005-2026 Maruf Cetin. Released under the Artistic License 2.0.
CPAN · GitHub Repository · Issue Tracker
- Berkeley DB (DB_File) Engine
- AmberDB Table Schema
- Global Flags
- Table Schema Flags
- Directory Structure
- File Structure (Extensions)
- Repeat Blocks
- Auto-Increment ID
- ASCII ID
- Relational Records
- Record Anatomy
- JOIN-Free Architecture
- Packed Binary Index
- Strict 2PL Locking
- Undo Journal & Rollback
- Tiered Junk Indexing
- Disjunctive Faceting
- Phonetic Accent Search
- 2-Pillar Disaster Recovery
- RAM-Disk Acceleration
- In-Memory Schema Mutation
- Simple Mode
- new
- config
- set_datadir
- insert_id
- insert_list
- modify_id
- modify_list
- delete_id
- delete_list
- read_id
- read_all
- read_list
- exist_id
- exist_list
- exist_table
- table_count
- table_keys
- table_lastid
- table_attr
- table_create
- field_fetch
- field_filter
- search_table
- facet_menu
- field_fltkeys
- field_allfltkeys
- facet_rules
- slug_read
- slug_fetch
- transact_start
- transact_end
- transact_commit
- transact_rollback
- transact_recover
- flock_open
- flock_close
- cache_setup
- cache_read
- cache_write
- cache_delete
- cache_preload
- cache_ensure
- buffer_write
- buffer_read
- buffer_delete
- recs_scan
- recs_get
- recs_put
- recs_del
- locale_uc
- locale_lc
- locale_sort
- locale_to_ascii
- locale_num2text
- locale_format_currency
- locale_format_date
- array_sort
- array_punch
- array_filter
- array_sublist
- deep_copy
- log_owner
- use_counter
- use_junk
- keep_deleted
- auto_id
- buffer_write
- simple
- no_write
- no_backup
- jnktype
- keys_only
- id_type
- language
- .db · .table · .dbase
- .inx · .fld · .src
- .fac · .srt · .slg
- .unq · .del · .aut
- .cnt · .txn · .amberdb
- .csv · .cache · .tmp