MLDBM::Sync

Safe concurrent access to MLDBM databases
Download

MLDBM::Sync Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Joshua Chamas
  • Publisher web site:
  • http://search.cpan.org/~chamas/

MLDBM::Sync Tags


MLDBM::Sync Description

Safe concurrent access to MLDBM databases MLDBM::Sync is a Perl module wraps around the MLDBM interface, by handling concurrent access to MLDBM databases with file locking, and flushes i/o explicity per lock/unlock. The new Lock()/UnLock() API can be used to serialize requests logically and improve performance for bundled reads & writes. my $sync_dbm_obj = tie che, 'MLDBM::Sync', '/tmp/syncdbm', O_CREAT|O_RDWR, 0640; # Write locked critical section $sync_dbm_obj->Lock; ... all accesses to DBM LOCK_EX protected, and go to same tied file handles $cache{'KEY'} = 'VALUE'; $sync_dbm_obj->UnLock; # Read locked critical section $sync_dbm_obj->ReadLock; ... all read accesses to DBM LOCK_SH protected, and go to same tied files ... WARNING, cannot write to DBM in ReadLock() section, will die() ... WARNING, my $v = $cache{'KEY'}{'SUBKEY'} will trigger a write so not safe ... to use in ReadLock() section my $value = $cache{'KEY'}; $sync_dbm_obj->UnLock; # Normal access OK too, without explicity locking $cache{'KEY'} = 'VALUE'; my $value = $cache{'KEY'};MLDBM continues to serve as the underlying OO layer that serializes complex data structures to be stored in the databases. See the MLDBM BUGS section for important limitations.MLDBM::Sync also provides built in RAM caching with Tie::Cache md5 key checksum functionality.SYNOPSIS use MLDBM::Sync; # this gets the default, SDBM_File use MLDBM qw(DB_File Storable); # use Storable for serializing use MLDBM qw(MLDBM::Sync::SDBM_File); # use extended SDBM_File, handles values > 1024 bytes use Fcntl qw(:DEFAULT); # import symbols O_CREAT & O_RDWR for use with DBMs # NORMAL PROTECTED read/write with implicit locks per i/o request my $sync_dbm_obj = tie che, 'MLDBM::Sync' or die $!; $cache{"AAAA"} = "BBBB"; my $value = $cache{"AAAA"}; # SERIALIZED PROTECTED read/write with explicit lock for both i/o requests my $sync_dbm_obj = tie che, 'MLDBM::Sync', '/tmp/syncdbm', O_CREAT|O_RDWR, 0640; $sync_dbm_obj->Lock; $cache{"AAAA"} = "BBBB"; my $value = $cache{"AAAA"}; $sync_dbm_obj->UnLock; # SERIALIZED PROTECTED READ access with explicit read lock for both reads $sync_dbm_obj->ReadLock; my @keys = keys che; my $value = $cache{'AAAA'}; $sync_dbm_obj->UnLock; # MEMORY CACHE LAYER with Tie::Cache $sync_dbm_obj->SyncCacheSize('100K'); # KEY CHECKSUMS, for lookups on MD5 checksums on large keys my $sync_dbm_obj = tie che, 'MLDBM::Sync', '/tmp/syncdbm', O_CREAT|O_RDWR, 0640; $sync_dbm_obj->SyncKeysChecksum(1); my $large_key = "KEY" x 10000; $sync{$large_key} = "LARGE"; my $value = $sync{$large_key}; Requirements: · Perl


MLDBM::Sync Related Software