1 | =head1 NAME |
1 | =head1 NAME |
2 | |
2 | |
3 | DC::DB - async. database and filesystem access for cfplus |
3 | DC::DB - async. database and filesystem access for deliantra |
4 | |
4 | |
5 | =head1 SYNOPSIS |
5 | =head1 SYNOPSIS |
6 | |
6 | |
7 | use DC::DB; |
7 | use DC::DB; |
8 | |
8 | |
… | |
… | |
22 | use Config; |
22 | use Config; |
23 | use BDB; |
23 | use BDB; |
24 | |
24 | |
25 | use DC; |
25 | use DC; |
26 | |
26 | |
27 | our $DBDIR = "cfplus-" . BDB::VERSION . "-$Config{archname}"; |
27 | our $ODBDIR = "cfplus-" . BDB::VERSION . "-$Config{archname}"; |
|
|
28 | our $DBDIR = "client-" . BDB::VERSION . "-$Config{archname}"; |
28 | our $DB_HOME = "$Deliantra::VARDIR/$DBDIR"; |
29 | our $DB_HOME = "$Deliantra::VARDIR/$DBDIR"; |
29 | |
30 | |
|
|
31 | if (!-e $DB_HOME and -e "$Deliantra::VARDIR/$ODBDIR") { |
|
|
32 | rename "$Deliantra::VARDIR/$ODBDIR", $DB_HOME; |
|
|
33 | print STDERR "INFO: moved old database from $Deliantra::VARDIR/$ODBDIR to $DB_HOME\n"; |
|
|
34 | } |
|
|
35 | |
30 | if (!-e $DB_HOME and -e "$Deliantra::OLDDIR/$DBDIR") { |
36 | if (!-e $DB_HOME and -e "$Deliantra::OLDDIR/$ODBDIR") { |
31 | rename "$Deliantra::OLDDIR/$DBDIR", $DB_HOME; |
37 | rename "$Deliantra::OLDDIR/$DBDIR", $DB_HOME; |
32 | print STDERR "INFO: moved old database from $Deliantra::OLDDIR/$DBDIR to $DB_HOME\n"; |
38 | print STDERR "INFO: moved old database from $Deliantra::OLDDIR/$ODBDIR to $DB_HOME\n"; |
33 | } |
39 | } |
|
|
40 | |
|
|
41 | BDB::max_poll_time 0.03; |
|
|
42 | BDB::max_parallel 1; |
34 | |
43 | |
35 | our $DB_ENV; |
44 | our $DB_ENV; |
36 | our $DB_STATE; |
45 | our $DB_STATE; |
37 | our %DB_TABLE; |
46 | our %DB_TABLE; |
38 | |
47 | |
… | |
… | |
166 | die "maximum number of transaction retries reached - database problems?"; |
175 | die "maximum number of transaction retries reached - database problems?"; |
167 | } |
176 | } |
168 | |
177 | |
169 | sub get_tile_id_sync($) { |
178 | sub get_tile_id_sync($) { |
170 | my ($name) = @_; |
179 | my ($name) = @_; |
171 | |
|
|
172 | # fetch the full face table first |
|
|
173 | unless ($tilemap) { |
|
|
174 | do_table facemap => sub { |
|
|
175 | $tilemap = $_[0]; |
|
|
176 | delete $tilemap->{id}; |
|
|
177 | my %maptile = reverse %$tilemap;#d# |
|
|
178 | if ((scalar keys %$tilemap) != (scalar keys %maptile)) {#d# |
|
|
179 | $tilemap = { };#d# |
|
|
180 | DC::error "FATAL: facemap is not a 1:1 mapping, please report this and delete your $DB_HOME directory!\n";#d# |
|
|
181 | }#d# |
|
|
182 | }; |
|
|
183 | BDB::flush; |
|
|
184 | } |
|
|
185 | |
180 | |
186 | $tilemap->{$name} ||= do { |
181 | $tilemap->{$name} ||= do { |
187 | my $id; |
182 | my $id; |
188 | do_get_tile_id $name, sub { |
183 | do_get_tile_id $name, sub { |
189 | $id = $_[0]; |
184 | $id = $_[0]; |
… | |
… | |
224 | |
219 | |
225 | sub logprint($$$) { |
220 | sub logprint($$$) { |
226 | DC::DB::Server::req (logprint => @_); |
221 | DC::DB::Server::req (logprint => @_); |
227 | } |
222 | } |
228 | |
223 | |
|
|
224 | ############################################################################# |
|
|
225 | |
|
|
226 | # fetch the full face table first |
|
|
227 | unless ($tilemap) { |
|
|
228 | do_table facemap => sub { |
|
|
229 | $tilemap = $_[0]; |
|
|
230 | delete $tilemap->{id}; |
|
|
231 | my %maptile = reverse %$tilemap;#d# |
|
|
232 | if ((scalar keys %$tilemap) != (scalar keys %maptile)) {#d# |
|
|
233 | $tilemap = { };#d# |
|
|
234 | DC::error "FATAL: facemap is not a 1:1 mapping, please report this and delete your $DB_HOME directory!\n";#d# |
|
|
235 | }#d# |
|
|
236 | }; |
|
|
237 | } |
|
|
238 | |
229 | package DC::DB::Server; |
239 | package DC::DB::Server; |
230 | |
240 | |
231 | use strict; |
241 | use strict; |
232 | |
242 | |
233 | use EV (); |
243 | use EV (); |
… | |
… | |
363 | my $oldfh = select $fh; $| = 1; select $oldfh; |
373 | my $oldfh = select $fh; $| = 1; select $oldfh; |
364 | |
374 | |
365 | my $pid = fork; |
375 | my $pid = fork; |
366 | |
376 | |
367 | if (defined $pid && !$pid) { |
377 | if (defined $pid && !$pid) { |
368 | local $SIG{QUIT}; |
378 | local $SIG{QUIT} = "IGNORE"; |
369 | local $SIG{__DIE__}; |
379 | local $SIG{__DIE__}; |
370 | local $SIG{__WARN__}; |
380 | local $SIG{__WARN__}; |
371 | eval { |
381 | eval { |
372 | close $FH; |
382 | close $FH; |
373 | |
383 | |