… | |
… | |
49 | CFPlus::DB::Server::req (put => @_); |
49 | CFPlus::DB::Server::req (put => @_); |
50 | } |
50 | } |
51 | |
51 | |
52 | sub unlink($$) { |
52 | sub unlink($$) { |
53 | CFPlus::DB::Server::req (unlink => @_); |
53 | CFPlus::DB::Server::req (unlink => @_); |
|
|
54 | } |
|
|
55 | |
|
|
56 | sub read_file($$) { |
|
|
57 | CFPlus::DB::Server::req (read_file => @_); |
54 | } |
58 | } |
55 | |
59 | |
56 | sub write_file($$$) { |
60 | sub write_file($$$) { |
57 | CFPlus::DB::Server::req (write_file => @_); |
61 | CFPlus::DB::Server::req (write_file => @_); |
58 | } |
62 | } |
… | |
… | |
106 | -Cachesize => 8_000_000, |
110 | -Cachesize => 8_000_000, |
107 | -ErrFile => "$DB_HOME/errorlog.txt", |
111 | -ErrFile => "$DB_HOME/errorlog.txt", |
108 | # -ErrPrefix => "DATABASE", |
112 | # -ErrPrefix => "DATABASE", |
109 | -Verbose => 1, |
113 | -Verbose => 1, |
110 | -Flags => DB_CREATE | DB_RECOVER | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN | $recover, |
114 | -Flags => DB_CREATE | DB_RECOVER | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN | $recover, |
111 | -SetFlags => DB_AUTO_COMMIT | DB_LOG_AUTOREMOVE, |
115 | -SetFlags => DB_AUTO_COMMIT | DB_LOG_AUTOREMOVE | DB_TXN_WRITE_NOSYNC, |
112 | or die "unable to create/open database home $DB_HOME: $BerkeleyDB::Error"; |
116 | or die "unable to create/open database home $DB_HOME: $BerkeleyDB::Error"; |
113 | |
117 | |
114 | 1 |
118 | 1 |
115 | } |
119 | } |
116 | |
120 | |
… | |
… | |
124 | -Env => $DB_ENV, |
128 | -Env => $DB_ENV, |
125 | -Filename => $table, |
129 | -Filename => $table, |
126 | # -Filename => "database", |
130 | # -Filename => "database", |
127 | # -Subname => $table, |
131 | # -Subname => $table, |
128 | -Property => DB_CHKSUM, |
132 | -Property => DB_CHKSUM, |
129 | -Flags => DB_CREATE | DB_UPGRADE, |
133 | -Flags => DB_AUTO_COMMIT | DB_CREATE | DB_UPGRADE, |
130 | or die "unable to create/open database table $_[0]: $BerkeleyDB::Error" |
134 | or die "unable to create/open database table $_[0]: $BerkeleyDB::Error" |
131 | } |
135 | } |
132 | } |
136 | } |
133 | |
137 | |
134 | our %CB; |
138 | our %CB; |
… | |
… | |
137 | our ($fh_r_watcher, $fh_w_watcher); |
141 | our ($fh_r_watcher, $fh_w_watcher); |
138 | our $sync_timer; |
142 | our $sync_timer; |
139 | our $write_buf; |
143 | our $write_buf; |
140 | our $read_buf; |
144 | our $read_buf; |
141 | |
145 | |
142 | our $SYNC = Event->idle (min => 5, max => 60, parked => 1, cb => sub { |
146 | our $SYNC = Event->idle (min => 120, max => 180, parked => 1, cb => sub { |
143 | CFPlus::DB::Server::req (sync => sub { }); |
147 | CFPlus::DB::Server::req (sync => sub { }); |
144 | $_[0]->w->stop; |
148 | $_[0]->w->stop; |
145 | }); |
149 | }); |
146 | |
150 | |
147 | sub fh_write { |
151 | sub fh_write { |
… | |
… | |
265 | |
269 | |
266 | return $id; |
270 | return $id; |
267 | } |
271 | } |
268 | } |
272 | } |
269 | $txn->txn_abort; |
273 | $txn->txn_abort; |
|
|
274 | select undef, undef, undef, 0.01 * rand; |
270 | } |
275 | } |
271 | |
276 | |
272 | die "maximum number of transaction retries reached - database problems?"; |
277 | die "maximum number of transaction retries reached - database problems?"; |
273 | } |
278 | } |
274 | |
279 | |
275 | sub do_unlink { |
280 | sub do_unlink { |
276 | unlink $_[0]; |
281 | unlink $_[0]; |
277 | } |
282 | } |
278 | |
283 | |
|
|
284 | sub do_read_file { |
|
|
285 | my ($path) = @_; |
|
|
286 | |
|
|
287 | utf8::downgrade $path; |
|
|
288 | open my $fh, "<:raw", $path |
|
|
289 | or return; |
|
|
290 | sysread $fh, my $buf, -s $fh; |
|
|
291 | |
|
|
292 | $buf |
|
|
293 | } |
|
|
294 | |
279 | sub do_write_file { |
295 | sub do_write_file { |
280 | my ($file, $data) = @_; |
296 | my ($path, $data) = @_; |
281 | |
297 | |
282 | utf8::downgrade $file; |
298 | utf8::downgrade $path; |
283 | utf8::downgrade $data; |
299 | utf8::downgrade $data; |
284 | open my $fh, ">:raw", $file |
300 | open my $fh, ">:raw", $path |
285 | or return; |
301 | or return; |
286 | print $fh $data; |
302 | syswrite $fh, $data; |
287 | close $fh; |
303 | close $fh; |
288 | |
304 | |
289 | 1 |
305 | 1 |
290 | } |
306 | } |
291 | |
307 | |
292 | sub do_prefetch_file { |
308 | sub do_prefetch_file { |
293 | my ($file, $size) = @_; |
309 | my ($path, $size) = @_; |
294 | |
310 | |
295 | utf8::downgrade $file; |
311 | utf8::downgrade $path; |
296 | open my $fh, "<:raw", $file |
312 | open my $fh, "<:raw", $path |
297 | or return; |
313 | or return; |
298 | sysread $fh, my $buf, $size; |
314 | sysread $fh, my $buf, $size; |
299 | |
315 | |
300 | 1 |
316 | 1 |
301 | } |
317 | } |