mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 14:19:53 +01:00
Collapsed ack handling into a single transaction.
The locks were being held across all transactions anyway, so there was no granularity advantage to using multiple transactions.
This commit is contained in:
@@ -851,7 +851,6 @@ DatabaseCleaner.Callback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void receiveAck(ContactId c, Ack a) throws DbException {
|
public void receiveAck(ContactId c, Ack a) throws DbException {
|
||||||
// Mark all messages in acked batches as seen
|
|
||||||
contactLock.readLock().lock();
|
contactLock.readLock().lock();
|
||||||
try {
|
try {
|
||||||
if(!containsContact(c)) throw new NoSuchContactException();
|
if(!containsContact(c)) throw new NoSuchContactException();
|
||||||
@@ -859,42 +858,23 @@ DatabaseCleaner.Callback {
|
|||||||
try {
|
try {
|
||||||
messageStatusLock.writeLock().lock();
|
messageStatusLock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
// Remove the acked batches' outstanding batch records
|
|
||||||
Collection<BatchId> acks = a.getBatchIds();
|
Collection<BatchId> acks = a.getBatchIds();
|
||||||
for(BatchId ack : acks) {
|
|
||||||
T txn = db.startTransaction();
|
|
||||||
try {
|
|
||||||
db.removeAckedBatch(txn, c, ack);
|
|
||||||
db.commitTransaction(txn);
|
|
||||||
} catch(DbException e) {
|
|
||||||
db.abortTransaction(txn);
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(LOG.isLoggable(Level.FINE))
|
|
||||||
LOG.fine("Received " + acks.size() + " acks");
|
|
||||||
// Find any lost batches that need to be retransmitted
|
|
||||||
Collection<BatchId> lost;
|
|
||||||
T txn = db.startTransaction();
|
T txn = db.startTransaction();
|
||||||
try {
|
try {
|
||||||
lost = db.getLostBatches(txn, c);
|
// Mark all messages in acked batches as seen
|
||||||
|
if(LOG.isLoggable(Level.FINE))
|
||||||
|
LOG.fine("Received " + acks.size() + " acks");
|
||||||
|
for(BatchId b : acks) db.removeAckedBatch(txn, c, b);
|
||||||
|
// Find any lost batches that need to be retransmitted
|
||||||
|
Collection<BatchId> lost = db.getLostBatches(txn, c);
|
||||||
|
if(LOG.isLoggable(Level.FINE))
|
||||||
|
LOG.fine(lost.size() + " lost batches");
|
||||||
|
for(BatchId b : lost) db.removeLostBatch(txn, c, b);
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
} catch(DbException e) {
|
} catch(DbException e) {
|
||||||
db.abortTransaction(txn);
|
db.abortTransaction(txn);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
for(BatchId batch : lost) {
|
|
||||||
txn = db.startTransaction();
|
|
||||||
try {
|
|
||||||
db.removeLostBatch(txn, c, batch);
|
|
||||||
db.commitTransaction(txn);
|
|
||||||
} catch(DbException e) {
|
|
||||||
db.abortTransaction(txn);
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(LOG.isLoggable(Level.FINE))
|
|
||||||
LOG.fine("Removed " + lost.size() + " lost batches");
|
|
||||||
} finally {
|
} finally {
|
||||||
messageStatusLock.writeLock().unlock();
|
messageStatusLock.writeLock().unlock();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user