-
Notifications
You must be signed in to change notification settings - Fork 0
Concept Auto ID
Turkce Dokumantasyon | English Documentation
Category: Core Concepts & Architecture
Subsystem: Primary Key Architecture (AmberDB::Base&AmberDB::Index)
Entry Type: Primary Key Management Guide
AmberDB features an atomic 64-Bit Auto-Incrementing Primary Key ID engine.
When a table is configured with auto_id => 1 (the default) and id_type => "num", passing 0, undef, or "" at index 0 during insert_id instructs the engine to allocate the next monotonic 64-bit integer ID for that table.
Auto-Increment ID Allocation Pipeline
Application: $adb->insert_id("table", 0, "Product A", ...)
|
v
┌─────────────────────────────────────────────────────────────┐
│ .inx File Header Lock (POSIX flock) │
│ - Highest Allocated ID: 1045 │
│ - Total Active Record Count: 820 │
└─────────────────────────────────────────────────────────────┘
|
v
New ID Computed: 1045 + 1 = 1046
.inx Header Updated ──> 1046
Appended to .inx Binary Body (8-byte Q* pack)
Master .db Document Written: [1046, "Product A", ...]
|
v
Returns: 1046 (Application assigns to $record[0])
When multiple independent processes (Starman workers, Forked workers, Plack pipelines) execute insert_id or insert_list simultaneously:
- AmberDB acquires an exclusive kernel-level POSIX
flockon the table's.inxfile. - The current highest ID is retrieved from the binary header, incremented, and saved atomically.
- The lock is released.
- This mechanism guarantees zero ID collisions across highly concurrent environments.
use AmberDB;
my $adb = AmberDB->new(path => { dbase_dir => "./dbstore" });
# Pass 0 at index 0
my @record = ( 0, "Laptop Stand", "Accessories", 49.99 );
my $new_id = $record[0] = $adb->insert_id("products", @record);
print "Allocated ID: $new_id\n"; # Output: 1001# Retrieve highest generated ID ($O(1) header read)
my $last_id = $adb->table_lastid("products");
print "Last Generated ID: $last_id\n";
# Retrieve total active record count ($O(1) header read)
my $count = $adb->table_count("products");
print "Total Active Records: $count\n";If your dataset utilizes pre-existing external identifiers (e.g. from an external ERP or migration stream):
- Configure
auto_id => 0in the table schema, or - Explicitly supply the target integer (e.g.
15004) at index 0 duringinsert_id. The engine stores the specified ID and updates.inxindexes accordingly.
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