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.32 by root, Sat Jan 19 04:49:37 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;
42BDB::max_parallel 1;
34 43
35our $DB_ENV; 44our $DB_ENV;
36our $DB_STATE; 45our $DB_STATE;
37our %DB_TABLE; 46our %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
169sub get_tile_id_sync($) { 178sub 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
225sub logprint($$$) { 220sub 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
227unless ($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
229package DC::DB::Server; 239package DC::DB::Server;
230 240
231use strict; 241use strict;
232 242
233use EV (); 243use 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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines