ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/DB.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/DB.pm (file contents):
Revision 1.29 by root, Wed Dec 26 21:03:21 2007 UTC vs.
Revision 1.31 by root, Thu Jan 10 23:02:19 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines