Subject: | Not clear at all how to use ->renew |
I've been poking at trying to get ->renew to do something, but it doesn't like me at all :(
->renew seems to want an active transaction, and I don't know how to exactly construct such a thing without it already being a usable transaction.
Attached attempt
Subject: | reuse_txn.pl |
use strict;
use warnings;
use LMDB_File qw( :all );
use Path::Tiny;
my $tdir = Path::Tiny->tempdir;
my $dbi;
my $env = LMDB::Env->new( "$tdir", { mapsize => ( 10 * 1024 * 1024 ), maxdbs => 1024, });
sub initial_setup {
my $txn = $env->BeginTxn;
$dbi = $txn->open( 'test', MDB_CREATE );
my $db = LMDB_File->new( $txn, $dbi );
$txn->commit;
}
sub reuse_dbi {
my $txn = $env->BeginTxn;
my $db = LMDB_File->new( $txn, $dbi );
$txn->commit;
}
sub write_action {
my $txn = $env->BeginTxn;
my $db = LMDB_File->new( $txn, $dbi );
$db->put('Chunky' => 'Bacon');
$txn->commit;
}
my $read_txn;
sub readonly_action {
if ( $read_txn ) {
$read_txn->renew;
} else {
$read_txn = $env->BeginTxn(MDB_RDONLY);
}
my $db = LMDB_File->new( $read_txn, $dbi );
print "Got value\n" if $db->get( 'Chunky' ) eq 'Bacon';
$read_txn->commit;
}
initial_setup;
write_action;
readonly_action;
readonly_action;