… | |
… | |
268 | unless ($id) { |
268 | unless ($id) { |
269 | # create new id for face |
269 | # create new id for face |
270 | # I love transactions |
270 | # I love transactions |
271 | for (1..100) { |
271 | for (1..100) { |
272 | my $txn = $CFClient::DB_ENV->txn_begin; |
272 | my $txn = $CFClient::DB_ENV->txn_begin; |
273 | my $status = $self->{facemap}->db_get (id => $id, BerkeleyDB::DB_RMW); |
273 | my $status = $self->{facemap}->db_get (id => $id); |
274 | if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { |
274 | if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { |
275 | $id = ($id || 16) + 1; |
275 | $id = ($id || 16) + 1; |
276 | if ($self->{facemap}->put (id => $id) == 0 |
276 | if ($self->{facemap}->put (id => $id) == 0 |
277 | && $self->{facemap}->put ($hash => $id) == 0) { |
277 | && $self->{facemap}->put ($hash => $id) == 0) { |
278 | $txn->txn_commit; |
278 | $txn->txn_commit; |
279 | |
279 | |
280 | goto gotid; |
280 | goto gotid; |
281 | } |
281 | } |
282 | } |
282 | } |
283 | $txn->abort; |
283 | $txn->txn_abort; |
284 | } |
284 | } |
285 | |
285 | |
286 | CFClient::fatal "maximum number of transaction retries reached - database problems?"; |
286 | CFClient::fatal "maximum number of transaction retries reached - database problems?"; |
287 | } |
287 | } |
288 | |
288 | |