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.18 by root, Mon Aug 13 06:47:07 2007 UTC vs.
Revision 1.20 by root, Tue Aug 28 20:07:18 2007 UTC

70} 70}
71 71
72our $tilemap; 72our $tilemap;
73 73
74sub get_tile_id_sync($) { 74sub get_tile_id_sync($) {
75 my ($hash) = @_; 75 my ($name) = @_;
76 76
77 # fetch the full face table first 77 # fetch the full face table first
78 unless ($tilemap) { 78 unless ($tilemap) {
79 CFPlus::DB::Server::req (table => facemap => sub { $tilemap = $_[0] }); 79 CFPlus::DB::Server::req (table => facemap => sub {
80 $tilemap = $_[0];
81 delete $tilemap->{id};
82 my %maptile = reverse %$tilemap;#d#
83 if ((scalar keys %$tilemap) != (scalar keys %maptile)) {#d#
84 $tilemap = { };#d#
85 CFPlus::error "FATAL: facemap is not a 1:1 mapping, please report this and delete your $DB_HOME directory!\n";#d#
86 }#d#
87 });
80 sync; 88 sync;
81 } 89 }
82 90
83 $tilemap->{$hash} ||= do { 91 $tilemap->{$name} ||= do {
84 my $id; 92 my $id;
85 CFPlus::DB::Server::req (get_tile_id => $hash, sub { $id = $_[0] }); 93 CFPlus::DB::Server::req (get_tile_id => $name, sub { $id = $_[0] });
86 sync; 94 sync;
87 $id 95 $id
88 } 96 }
89} 97}
90 98
110 -Cachesize => 8_000_000, 118 -Cachesize => 8_000_000,
111 -ErrFile => "$DB_HOME/errorlog.txt", 119 -ErrFile => "$DB_HOME/errorlog.txt",
112# -ErrPrefix => "DATABASE", 120# -ErrPrefix => "DATABASE",
113 -Verbose => 1, 121 -Verbose => 1,
114 -Flags => DB_CREATE | DB_RECOVER | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN | $recover, 122 -Flags => DB_CREATE | DB_RECOVER | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN | $recover,
115 -SetFlags => DB_AUTO_COMMIT | DB_LOG_AUTOREMOVE, 123 -SetFlags => DB_AUTO_COMMIT | DB_LOG_AUTOREMOVE | DB_TXN_WRITE_NOSYNC,
116 or die "unable to create/open database home $DB_HOME: $BerkeleyDB::Error"; 124 or die "unable to create/open database home $DB_HOME: $BerkeleyDB::Error";
117 125
118 1 126 1
119} 127}
120 128
128 -Env => $DB_ENV, 136 -Env => $DB_ENV,
129 -Filename => $table, 137 -Filename => $table,
130# -Filename => "database", 138# -Filename => "database",
131# -Subname => $table, 139# -Subname => $table,
132 -Property => DB_CHKSUM, 140 -Property => DB_CHKSUM,
133 -Flags => DB_CREATE | DB_UPGRADE, 141 -Flags => DB_AUTO_COMMIT | DB_CREATE | DB_UPGRADE,
134 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error" 142 or die "unable to create/open database table $_[0]: $BerkeleyDB::Error"
135 } 143 }
136} 144}
137 145
138our %CB; 146our %CB;
248 256
249 \%kv 257 \%kv
250} 258}
251 259
252sub do_get_tile_id { 260sub do_get_tile_id {
253 my ($hash) = @_; 261 my ($name) = @_;
254 262
255 my $id; 263 my $id;
256 my $table = table "facemap"; 264 my $table = table "facemap";
257 265
258 return $id 266 return $id
259 if $table->db_get ($hash, $id) == 0; 267 if $table->db_get ($name, $id) == 0;
260 268
261 for (1..100) { 269 for (1..100) {
262 my $txn = $DB_ENV->txn_begin; 270 my $txn = $DB_ENV->txn_begin;
263 my $status = $table->db_get (id => $id); 271 my $status = $table->db_get (id => $id);
264 if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { 272 if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) {
265 $id = ($id || 64) + 1; 273 $id = ($id || 64) + 1;
266 if ($table->db_put (id => $id) == 0 274 if ($table->db_put (id => $id) == 0
267 && $table->db_put ($hash => $id) == 0) { 275 && $table->db_put ($name => $id) == 0) {
268 $txn->txn_commit; 276 $txn->txn_commit;
269 277
270 return $id; 278 return $id;
271 } 279 }
272 } 280 }
273 $txn->txn_abort; 281 $txn->txn_abort;
282 select undef, undef, undef, 0.01 * rand;
274 } 283 }
275 284
276 die "maximum number of transaction retries reached - database problems?"; 285 die "maximum number of transaction retries reached - database problems?";
277} 286}
278 287

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines