diff options
author | Eric Wong <e@80x24.org> | 2016-07-31 00:02:05 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2016-07-31 01:15:58 +0000 |
commit | 3a988efc28064954e64419bb0d368684fa7c7f20 (patch) | |
tree | 0d91879fc8b7cb197a927af9990c160c10716982 /lib/PublicInbox/Msgmap.pm | |
parent | 4f9325bd4c9a8f971ab6e37aa449ee6958ec95e9 (diff) | |
download | public-inbox-3a988efc28064954e64419bb0d368684fa7c7f20.tar.gz |
We want transactions to be the responsibility of the caller when possible; this fixes the potential for the msgmap to internally become inconsistent when using it from inside searchidx.
Diffstat (limited to 'lib/PublicInbox/Msgmap.pm')
-rw-r--r-- | lib/PublicInbox/Msgmap.pm | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/lib/PublicInbox/Msgmap.pm b/lib/PublicInbox/Msgmap.pm index 8fe17a95..2583ff47 100644 --- a/lib/PublicInbox/Msgmap.pm +++ b/lib/PublicInbox/Msgmap.pm @@ -33,7 +33,9 @@ sub new { if ($writable) { create_tables($dbh); + $dbh->begin_work; $self->created_at(time) unless $self->created_at; + $dbh->commit; } $self; } @@ -51,22 +53,14 @@ sub meta_accessor { defined $value or return $dbh->selectrow_array(meta_select, undef, $key); - $dbh->begin_work; - eval { - $prev = $dbh->selectrow_array(meta_select, undef, $key); + $prev = $dbh->selectrow_array(meta_select, undef, $key); - if (defined $prev) { - $dbh->do(meta_update, undef, $value, $key); - } else { - $dbh->do(meta_insert, undef, $key, $value); - } - $dbh->commit; - }; - my $err = $@; - return $prev unless $err; - - $dbh->rollback; - die $err; + if (defined $prev) { + $dbh->do(meta_update, undef, $value, $key); + } else { + $dbh->do(meta_insert, undef, $key, $value); + } + $prev; } sub last_commit { |