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.38 by root, Fri Jul 18 22:40:51 2008 UTC vs.
Revision 1.42 by root, Sun Jan 4 10:22:19 2009 UTC

18use utf8; 18use utf8;
19 19
20use File::Path (); 20use File::Path ();
21use Carp (); 21use Carp ();
22use Storable (); 22use Storable ();
23use AnyEvent::Util ();
23use Config; 24use Config;
24use BDB; 25use BDB;
25 26
26use DC; 27use DC;
27 28
28our $ODBDIR = "cfplus-" . BDB::VERSION_MAJOR . "." . BDB::VERSION_MINOR . "-$Config{archname}"; 29our $ODBDIR = "cfplus-" . BDB::VERSION_MAJOR . "." . BDB::VERSION_MINOR . "-$Config{archname}";
29our $DBDIR = "client-" . BDB::VERSION_MAJOR . "." . BDB::VERSION_MINOR . "-$Config{archname}"; 30our $DBDIR = "client-" . BDB::VERSION_MAJOR . "." . BDB::VERSION_MINOR . "-$Config{archname}";
30our $DB_HOME = "$Deliantra::VARDIR/$DBDIR"; 31our $DB_HOME = "$Deliantra::VARDIR/$DBDIR";
32
33sub FIRST_TILE_ID () { 64 }
31 34
32unless (-d $DB_HOME) { 35unless (-d $DB_HOME) {
33 if (-d "$Deliantra::VARDIR/$ODBDIR") { 36 if (-d "$Deliantra::VARDIR/$ODBDIR") {
34 rename "$Deliantra::VARDIR/$ODBDIR", $DB_HOME; 37 rename "$Deliantra::VARDIR/$ODBDIR", $DB_HOME;
35 print STDERR "INFO: moved old database from $Deliantra::VARDIR/$ODBDIR to $DB_HOME\n"; 38 print STDERR "INFO: moved old database from $Deliantra::VARDIR/$ODBDIR to $DB_HOME\n";
57 60
58 $env->set_errfile (\*STDERR); 61 $env->set_errfile (\*STDERR);
59 $env->set_msgfile (\*STDERR); 62 $env->set_msgfile (\*STDERR);
60 $env->set_verbose (-1, 1); 63 $env->set_verbose (-1, 1);
61 64
62 $env->set_flags (BDB::AUTO_COMMIT | BDB::LOG_AUTOREMOVE | BDB::TXN_WRITE_NOSYNC); 65 $env->set_flags (BDB::AUTO_COMMIT | BDB::REGION_INIT);
66 $env->set_flags (&BDB::LOG_AUTOREMOVE ) if BDB::VERSION v0, v4.7;
67 $env->log_set_config (&BDB::LOG_AUTO_REMOVE) if BDB::VERSION v4.7;
68
69 $env->set_timeout (3, BDB::SET_TXN_TIMEOUT);
70 $env->set_timeout (3, BDB::SET_LOCK_TIMEOUT);
71
63 $env->set_cachesize (0, 2048 * 1024, 0); 72 $env->set_cachesize (0, 2048 * 1024, 0);
64 73
65 db_env_open $env, $DB_HOME, 74 db_env_open $env, $DB_HOME,
66 BDB::CREATE | BDB::REGISTER | BDB::RECOVER | BDB::INIT_MPOOL | BDB::INIT_LOCK | BDB::INIT_TXN, 75 BDB::CREATE | BDB::REGISTER | BDB::RECOVER | BDB::INIT_MPOOL | BDB::INIT_LOCK | BDB::INIT_TXN,
67 0666; 76 0666;
76sub table($) { 85sub table($) {
77 $DB_TABLE{$_[0]} ||= do { 86 $DB_TABLE{$_[0]} ||= do {
78 my ($table) = @_; 87 my ($table) = @_;
79 88
80 $table =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge; 89 $table =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge;
90
91 $DB_ENV#d#
92 or return ::clienterror ("trying to create table $_[0] with empty db_env $DB_ENV" => 1);#d#
81 93
82 my $db = db_create $DB_ENV; 94 my $db = db_create $DB_ENV;
83 $db->set_flags (BDB::CHKSUM); 95 $db->set_flags (BDB::CHKSUM);
84 96
85 db_open $db, undef, $table, undef, BDB::BTREE, 97 db_open $db, undef, $table, undef, BDB::BTREE,
150 db_get $table, undef, $name => $id, 0; 162 db_get $table, undef, $name => $id, 0;
151 $! or return $cb->($id); 163 $! or return $cb->($id);
152 164
153 unless ($TILE_SEQ) { 165 unless ($TILE_SEQ) {
154 $TILE_SEQ = $table->sequence; 166 $TILE_SEQ = $table->sequence;
155 $TILE_SEQ->initial_value (64); 167 $TILE_SEQ->initial_value (FIRST_TILE_ID);
156 $TILE_SEQ->set_cachesize (0); 168 $TILE_SEQ->set_cachesize (0);
157 db_sequence_open $TILE_SEQ, undef, "id", BDB::CREATE; 169 db_sequence_open $TILE_SEQ, undef, "id", BDB::CREATE;
158 } 170 }
159 171
160 db_sequence_get $TILE_SEQ, undef, 1, my $id; 172 db_sequence_get $TILE_SEQ, undef, 1, my $id;
344 356
345 print { $LOG_FH{$path} } "$ts $line\n" 357 print { $LOG_FH{$path} } "$ts $line\n"
346} 358}
347 359
348sub run { 360sub run {
349 ($FH, my $fh) = DC::socketpipe; 361 ($FH, my $fh) = AnyEvent::Util::portable_socketpair
362 or die "unable to create database socketpair: $!";
350 363
351 my $oldfh = select $FH; $| = 1; select $oldfh; 364 my $oldfh = select $FH; $| = 1; select $oldfh;
352 my $oldfh = select $fh; $| = 1; select $oldfh; 365 my $oldfh = select $fh; $| = 1; select $oldfh;
353 366
354 my $pid = fork; 367 my $pid = fork;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines