Use a lock to ensure transaction isolation. #272

This commit is contained in:
akwizgran
2016-03-24 17:18:54 +00:00
parent 9714713d73
commit 1855dbbd2d
22 changed files with 248 additions and 189 deletions

View File

@@ -57,7 +57,7 @@ class ClientHelperImpl implements ClientHelper {
@Override
public void addLocalMessage(Message m, ClientId c, BdfDictionary metadata,
boolean shared) throws DbException, FormatException {
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
addLocalMessage(txn, m, c, metadata, shared);
txn.setComplete();
@@ -89,7 +89,7 @@ class ClientHelperImpl implements ClientHelper {
public BdfDictionary getMessageAsDictionary(MessageId m) throws DbException,
FormatException {
BdfDictionary dictionary;
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(true);
try {
dictionary = getMessageAsDictionary(txn, m);
txn.setComplete();
@@ -112,7 +112,7 @@ class ClientHelperImpl implements ClientHelper {
public BdfList getMessageAsList(MessageId m) throws DbException,
FormatException {
BdfList list;
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(true);
try {
list = getMessageAsList(txn, m);
txn.setComplete();
@@ -135,7 +135,7 @@ class ClientHelperImpl implements ClientHelper {
public BdfDictionary getGroupMetadataAsDictionary(GroupId g)
throws DbException, FormatException {
BdfDictionary dictionary;
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(true);
try {
dictionary = getGroupMetadataAsDictionary(txn, g);
txn.setComplete();
@@ -156,7 +156,7 @@ class ClientHelperImpl implements ClientHelper {
public BdfDictionary getMessageMetadataAsDictionary(MessageId m)
throws DbException, FormatException {
BdfDictionary dictionary;
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(true);
try {
dictionary = getMessageMetadataAsDictionary(txn, m);
txn.setComplete();
@@ -177,7 +177,7 @@ class ClientHelperImpl implements ClientHelper {
public Map<MessageId, BdfDictionary> getMessageMetatataAsDictionary(
GroupId g) throws DbException, FormatException {
Map<MessageId, BdfDictionary> map;
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(true);
try {
map = getMessageMetadataAsDictionary(txn, g);
txn.setComplete();
@@ -201,7 +201,7 @@ class ClientHelperImpl implements ClientHelper {
@Override
public void mergeGroupMetadata(GroupId g, BdfDictionary metadata)
throws DbException, FormatException {
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
mergeGroupMetadata(txn, g, metadata);
txn.setComplete();
@@ -219,7 +219,7 @@ class ClientHelperImpl implements ClientHelper {
@Override
public void mergeMessageMetadata(MessageId m, BdfDictionary metadata)
throws DbException, FormatException {
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
mergeMessageMetadata(txn, m, metadata);
txn.setComplete();

View File

@@ -51,7 +51,7 @@ class ContactManagerImpl implements ContactManager, RemoveIdentityHook {
long timestamp, boolean alice, boolean active)
throws DbException {
ContactId c;
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
c = db.addContact(txn, remote, local, active);
keyManager.addContact(txn, c, master, timestamp, alice);
@@ -68,7 +68,7 @@ class ContactManagerImpl implements ContactManager, RemoveIdentityHook {
@Override
public Contact getContact(ContactId c) throws DbException {
Contact contact;
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(true);
try {
contact = db.getContact(txn, c);
txn.setComplete();
@@ -81,7 +81,7 @@ class ContactManagerImpl implements ContactManager, RemoveIdentityHook {
@Override
public Collection<Contact> getActiveContacts() throws DbException {
Collection<Contact> contacts;
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(true);
try {
contacts = db.getContacts(txn);
txn.setComplete();
@@ -95,7 +95,7 @@ class ContactManagerImpl implements ContactManager, RemoveIdentityHook {
@Override
public void removeContact(ContactId c) throws DbException {
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
removeContact(txn, c);
txn.setComplete();
@@ -107,7 +107,7 @@ class ContactManagerImpl implements ContactManager, RemoveIdentityHook {
@Override
public void setContactActive(ContactId c, boolean active)
throws DbException {
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
db.setContactActive(txn, c, active);
txn.setComplete();

View File

@@ -59,6 +59,8 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Logger;
import javax.inject.Inject;
@@ -78,6 +80,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
private final EventBus eventBus;
private final ShutdownManager shutdown;
private final AtomicBoolean closed = new AtomicBoolean(false);
private final ReadWriteLock lock = new ReentrantReadWriteLock(true);
private volatile int shutdownHandle = -1;
@@ -115,18 +118,33 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
db.close();
}
public Transaction startTransaction() throws DbException {
return new Transaction(db.startTransaction());
public Transaction startTransaction(boolean readOnly) throws DbException {
if (readOnly) lock.readLock().lock();
else lock.writeLock().lock();
try {
return new Transaction(db.startTransaction(), readOnly);
} catch (DbException e) {
if (readOnly) lock.readLock().unlock();
else lock.writeLock().unlock();
throw e;
} catch (RuntimeException e) {
if (readOnly) lock.readLock().unlock();
else lock.writeLock().unlock();
throw e;
}
}
public void endTransaction(Transaction transaction) throws DbException {
T txn = txnClass.cast(transaction.unbox());
if (transaction.isComplete()) {
db.commitTransaction(txn);
for (Event e : transaction.getEvents()) eventBus.broadcast(e);
} else {
db.abortTransaction(txn);
try {
T txn = txnClass.cast(transaction.unbox());
if (transaction.isComplete()) db.commitTransaction(txn);
else db.abortTransaction(txn);
} finally {
if (transaction.isReadOnly()) lock.readLock().unlock();
else lock.writeLock().unlock();
}
if (transaction.isComplete())
for (Event e : transaction.getEvents()) eventBus.broadcast(e);
}
private T unbox(Transaction transaction) {
@@ -136,6 +154,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public ContactId addContact(Transaction transaction, Author remote,
AuthorId local, boolean active) throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsLocalAuthor(txn, local))
throw new NoSuchLocalAuthorException();
@@ -148,6 +167,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
}
public void addGroup(Transaction transaction, Group g) throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsGroup(txn, g.getId())) {
db.addGroup(txn, g);
@@ -157,6 +177,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public void addLocalAuthor(Transaction transaction, LocalAuthor a)
throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsLocalAuthor(txn, a.getId())) {
db.addLocalAuthor(txn, a);
@@ -166,6 +187,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public void addLocalMessage(Transaction transaction, Message m, ClientId c,
Metadata meta, boolean shared) throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsGroup(txn, m.getGroupId()))
throw new NoSuchGroupException();
@@ -189,6 +211,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public void addTransport(Transaction transaction, TransportId t,
int maxLatency) throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsTransport(txn, t))
db.addTransport(txn, t, maxLatency);
@@ -196,6 +219,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public void addTransportKeys(Transaction transaction, ContactId c,
TransportKeys k) throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsContact(txn, c))
throw new NoSuchContactException();
@@ -206,6 +230,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public void deleteMessage(Transaction transaction, MessageId m)
throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsMessage(txn, m))
throw new NoSuchMessageException();
@@ -214,6 +239,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public void deleteMessageMetadata(Transaction transaction, MessageId m)
throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsMessage(txn, m))
throw new NoSuchMessageException();
@@ -222,6 +248,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public Ack generateAck(Transaction transaction, ContactId c,
int maxMessages) throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsContact(txn, c))
throw new NoSuchContactException();
@@ -233,6 +260,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public Collection<byte[]> generateBatch(Transaction transaction,
ContactId c, int maxLength, int maxLatency) throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsContact(txn, c))
throw new NoSuchContactException();
@@ -250,6 +278,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public Offer generateOffer(Transaction transaction, ContactId c,
int maxMessages, int maxLatency) throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsContact(txn, c))
throw new NoSuchContactException();
@@ -261,6 +290,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public Request generateRequest(Transaction transaction, ContactId c,
int maxMessages) throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsContact(txn, c))
throw new NoSuchContactException();
@@ -273,6 +303,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public Collection<byte[]> generateRequestedBatch(Transaction transaction,
ContactId c, int maxLength, int maxLatency) throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsContact(txn, c))
throw new NoSuchContactException();
@@ -418,6 +449,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public void incrementStreamCounter(Transaction transaction, ContactId c,
TransportId t, long rotationPeriod) throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsContact(txn, c))
throw new NoSuchContactException();
@@ -438,6 +470,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public void mergeGroupMetadata(Transaction transaction, GroupId g,
Metadata meta) throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsGroup(txn, g))
throw new NoSuchGroupException();
@@ -446,6 +479,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public void mergeMessageMetadata(Transaction transaction, MessageId m,
Metadata meta) throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsMessage(txn, m))
throw new NoSuchMessageException();
@@ -454,6 +488,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public void mergeSettings(Transaction transaction, Settings s,
String namespace) throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
Settings old = db.getSettings(txn, namespace);
Settings merged = new Settings();
@@ -467,6 +502,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public void receiveAck(Transaction transaction, ContactId c, Ack a)
throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsContact(txn, c))
throw new NoSuchContactException();
@@ -482,6 +518,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public void receiveMessage(Transaction transaction, ContactId c, Message m)
throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsContact(txn, c))
throw new NoSuchContactException();
@@ -497,6 +534,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public void receiveOffer(Transaction transaction, ContactId c, Offer o)
throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsContact(txn, c))
throw new NoSuchContactException();
@@ -519,6 +557,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public void receiveRequest(Transaction transaction, ContactId c, Request r)
throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsContact(txn, c))
throw new NoSuchContactException();
@@ -535,6 +574,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public void removeContact(Transaction transaction, ContactId c)
throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsContact(txn, c))
throw new NoSuchContactException();
@@ -544,6 +584,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public void removeGroup(Transaction transaction, Group g)
throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
GroupId id = g.getId();
if (!db.containsGroup(txn, id))
@@ -556,6 +597,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public void removeLocalAuthor(Transaction transaction, AuthorId a)
throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsLocalAuthor(txn, a))
throw new NoSuchLocalAuthorException();
@@ -565,6 +607,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public void removeTransport(Transaction transaction, TransportId t)
throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsTransport(txn, t))
throw new NoSuchTransportException();
@@ -573,6 +616,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public void setContactActive(Transaction transaction, ContactId c,
boolean active) throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsContact(txn, c))
throw new NoSuchContactException();
@@ -582,6 +626,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public void setMessageShared(Transaction transaction, Message m,
boolean shared) throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsMessage(txn, m.getId()))
throw new NoSuchMessageException();
@@ -591,6 +636,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public void setMessageValid(Transaction transaction, Message m, ClientId c,
boolean valid) throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsMessage(txn, m.getId()))
throw new NoSuchMessageException();
@@ -601,6 +647,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public void setReorderingWindow(Transaction transaction, ContactId c,
TransportId t, long rotationPeriod, long base, byte[] bitmap)
throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsContact(txn, c))
throw new NoSuchContactException();
@@ -611,6 +658,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public void setVisibleToContact(Transaction transaction, ContactId c,
GroupId g, boolean visible) throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsContact(txn, c))
throw new NoSuchContactException();
@@ -636,6 +684,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public void updateTransportKeys(Transaction transaction,
Map<ContactId, TransportKeys> keys) throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
Map<ContactId, TransportKeys> filtered =
new HashMap<ContactId, TransportKeys>();

View File

@@ -83,7 +83,7 @@ class ForumManagerImpl implements ForumManager {
public Forum getForum(GroupId g) throws DbException {
try {
Group group;
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(true);
try {
group = db.getGroup(txn, g);
txn.setComplete();
@@ -100,7 +100,7 @@ class ForumManagerImpl implements ForumManager {
public Collection<Forum> getForums() throws DbException {
try {
Collection<Group> groups;
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(true);
try {
groups = db.getGroups(txn, CLIENT_ID);
txn.setComplete();
@@ -132,7 +132,7 @@ class ForumManagerImpl implements ForumManager {
Set<AuthorId> localAuthorIds = new HashSet<AuthorId>();
Set<AuthorId> contactAuthorIds = new HashSet<AuthorId>();
Map<MessageId, BdfDictionary> metadata;
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(true);
try {
// Load the IDs of the user's identities
for (LocalAuthor a : db.getLocalAuthors(txn))

View File

@@ -131,7 +131,7 @@ class ForumSharingManagerImpl implements ForumSharingManager, AddContactHook,
@Override
public void addForum(Forum f) throws DbException {
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
db.addGroup(txn, f.getGroup());
txn.setComplete();
@@ -144,7 +144,7 @@ class ForumSharingManagerImpl implements ForumSharingManager, AddContactHook,
public void removeForum(Forum f) throws DbException {
try {
// Update the list shared with each contact
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
for (Contact c : db.getContacts(txn))
removeFromList(txn, getContactGroup(c).getId(), f);
@@ -162,7 +162,7 @@ class ForumSharingManagerImpl implements ForumSharingManager, AddContactHook,
public Collection<Forum> getAvailableForums() throws DbException {
try {
Set<Forum> available = new HashSet<Forum>();
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(true);
try {
// Get any forums we subscribe to
Set<Group> subscribed = new HashSet<Group>(db.getGroups(txn,
@@ -196,7 +196,7 @@ class ForumSharingManagerImpl implements ForumSharingManager, AddContactHook,
public Collection<Contact> getSharedBy(GroupId g) throws DbException {
try {
List<Contact> subscribers = new ArrayList<Contact>();
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(true);
try {
for (Contact c : db.getContacts(txn)) {
if (listContains(txn, getContactGroup(c).getId(), g, false))
@@ -216,7 +216,7 @@ class ForumSharingManagerImpl implements ForumSharingManager, AddContactHook,
public Collection<ContactId> getSharedWith(GroupId g) throws DbException {
try {
List<ContactId> shared = new ArrayList<ContactId>();
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(true);
try {
for (Contact c : db.getContacts(txn)) {
if (listContains(txn, getContactGroup(c).getId(), g, true))
@@ -236,7 +236,7 @@ class ForumSharingManagerImpl implements ForumSharingManager, AddContactHook,
public void setSharedWith(GroupId g, Collection<ContactId> shared)
throws DbException {
try {
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
// Retrieve the forum
Forum f = parseForum(db.getGroup(txn, g));
@@ -268,7 +268,7 @@ class ForumSharingManagerImpl implements ForumSharingManager, AddContactHook,
@Override
public void setSharedWithAll(GroupId g) throws DbException {
try {
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
// Retrieve the forum
Forum f = parseForum(db.getGroup(txn, g));

View File

@@ -37,7 +37,7 @@ class IdentityManagerImpl implements IdentityManager {
@Override
public void addLocalAuthor(LocalAuthor localAuthor) throws DbException {
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
db.addLocalAuthor(txn, localAuthor);
for (AddIdentityHook hook : addHooks)
@@ -51,7 +51,7 @@ class IdentityManagerImpl implements IdentityManager {
@Override
public LocalAuthor getLocalAuthor(AuthorId a) throws DbException {
LocalAuthor author;
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(true);
try {
author = db.getLocalAuthor(txn, a);
txn.setComplete();
@@ -64,7 +64,7 @@ class IdentityManagerImpl implements IdentityManager {
@Override
public Collection<LocalAuthor> getLocalAuthors() throws DbException {
Collection<LocalAuthor> authors;
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(true);
try {
authors = db.getLocalAuthors(txn);
txn.setComplete();
@@ -76,7 +76,7 @@ class IdentityManagerImpl implements IdentityManager {
@Override
public void removeLocalAuthor(AuthorId a) throws DbException {
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
LocalAuthor localAuthor = db.getLocalAuthor(txn, a);
for (RemoveIdentityHook hook : removeHooks)

View File

@@ -106,7 +106,7 @@ class MessagingManagerImpl implements MessagingManager, AddContactHook,
@Override
public GroupId getConversationId(ContactId c) throws DbException {
Contact contact;
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(true);
try {
contact = db.getContact(txn, c);
txn.setComplete();
@@ -121,7 +121,7 @@ class MessagingManagerImpl implements MessagingManager, AddContactHook,
throws DbException {
Map<MessageId, BdfDictionary> metadata;
Collection<MessageStatus> statuses;
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(true);
try {
GroupId g = getContactGroup(db.getContact(txn, c)).getId();
metadata = clientHelper.getMessageMetadataAsDictionary(txn, g);

View File

@@ -84,7 +84,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
@Override
public void addRemoteProperties(ContactId c, DeviceId dev,
Map<TransportId, TransportProperties> props) throws DbException {
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
Group g = getContactGroup(db.getContact(txn, c));
for (Entry<TransportId, TransportProperties> e : props.entrySet()) {
@@ -101,7 +101,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
public Map<TransportId, TransportProperties> getLocalProperties()
throws DbException {
Map<TransportId, TransportProperties> local;
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(true);
try {
local = getLocalProperties(txn);
txn.setComplete();
@@ -116,7 +116,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
throws DbException {
try {
TransportProperties p = null;
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(true);
try {
// Find the latest local update
LatestUpdate latest = findLatest(txn, localGroup.getId(), t,
@@ -146,7 +146,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
try {
Map<ContactId, TransportProperties> remote =
new HashMap<ContactId, TransportProperties>();
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(true);
try {
for (Contact c : db.getContacts(txn)) {
Group g = getContactGroup(c);
@@ -173,7 +173,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
public void mergeLocalProperties(TransportId t, TransportProperties p)
throws DbException {
try {
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
// Create the local group if necessary
db.addGroup(txn, localGroup);

View File

@@ -21,7 +21,7 @@ class SettingsManagerImpl implements SettingsManager {
@Override
public Settings getSettings(String namespace) throws DbException {
Settings s;
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(true);
try {
s = db.getSettings(txn, namespace);
txn.setComplete();
@@ -33,7 +33,7 @@ class SettingsManagerImpl implements SettingsManager {
@Override
public void mergeSettings(Settings s, String namespace) throws DbException {
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
db.mergeSettings(txn, s, namespace);
txn.setComplete();

View File

@@ -172,7 +172,7 @@ class DuplexOutgoingSession implements SyncSession, EventListener {
if (interrupted) return;
try {
Ack a;
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
a = db.generateAck(txn, contactId, MAX_MESSAGE_IDS);
txn.setComplete();
@@ -213,7 +213,7 @@ class DuplexOutgoingSession implements SyncSession, EventListener {
if (interrupted) return;
try {
Collection<byte[]> b;
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
b = db.generateRequestedBatch(txn, contactId,
MAX_PACKET_PAYLOAD_LENGTH, maxLatency);
@@ -255,7 +255,7 @@ class DuplexOutgoingSession implements SyncSession, EventListener {
if (interrupted) return;
try {
Offer o;
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
o = db.generateOffer(txn, contactId, MAX_MESSAGE_IDS,
maxLatency);
@@ -297,7 +297,7 @@ class DuplexOutgoingSession implements SyncSession, EventListener {
if (interrupted) return;
try {
Request r;
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
r = db.generateRequest(txn, contactId, MAX_MESSAGE_IDS);
txn.setComplete();

View File

@@ -99,7 +99,7 @@ class IncomingSession implements SyncSession, EventListener {
public void run() {
try {
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
db.receiveAck(txn, contactId, ack);
txn.setComplete();
@@ -123,7 +123,7 @@ class IncomingSession implements SyncSession, EventListener {
public void run() {
try {
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
db.receiveMessage(txn, contactId, message);
txn.setComplete();
@@ -147,7 +147,7 @@ class IncomingSession implements SyncSession, EventListener {
public void run() {
try {
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
db.receiveOffer(txn, contactId, offer);
txn.setComplete();
@@ -171,7 +171,7 @@ class IncomingSession implements SyncSession, EventListener {
public void run() {
try {
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
db.receiveRequest(txn, contactId, request);
txn.setComplete();

View File

@@ -114,7 +114,7 @@ class SimplexOutgoingSession implements SyncSession, EventListener {
if (interrupted) return;
try {
Ack a;
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
a = db.generateAck(txn, contactId, MAX_MESSAGE_IDS);
txn.setComplete();
@@ -156,7 +156,7 @@ class SimplexOutgoingSession implements SyncSession, EventListener {
if (interrupted) return;
try {
Collection<byte[]> b;
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
b = db.generateBatch(txn, contactId,
MAX_PACKET_PAYLOAD_LENGTH, maxLatency);

View File

@@ -83,7 +83,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
public void run() {
try {
Queue<MessageId> unvalidated = new LinkedList<MessageId>();
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(true);
try {
unvalidated.addAll(db.getMessagesToValidate(txn, c));
txn.setComplete();
@@ -106,7 +106,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
try {
Message m = null;
Group g = null;
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(true);
try {
MessageId id = unvalidated.poll();
byte[] raw = db.getRawMessage(txn, id);
@@ -160,7 +160,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
dbExecutor.execute(new Runnable() {
public void run() {
try {
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
if (meta == null) {
db.setMessageValid(txn, m, c, false);
@@ -198,7 +198,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
public void run() {
try {
Group g;
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(true);
try {
g = db.getGroup(txn, m.getGroupId());
txn.setComplete();

View File

@@ -73,7 +73,7 @@ class KeyManagerImpl implements KeyManager, Service, EventListener {
latencies.put(f.getId(), f.getMaxLatency());
try {
Collection<Contact> contacts;
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
contacts = db.getContacts(txn);
for (Entry<TransportId, Integer> e : latencies.entrySet())
@@ -123,7 +123,7 @@ class KeyManagerImpl implements KeyManager, Service, EventListener {
// Activate the contact if not already active
if (!activeContacts.containsKey(ctx.getContactId())) {
try {
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
db.setContactActive(txn, ctx.getContactId(), true);
txn.setComplete();

View File

@@ -67,7 +67,7 @@ class TransportKeyManager {
// Load the transport keys from the DB
Map<ContactId, TransportKeys> loaded;
try {
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(true);
try {
loaded = db.getTransportKeys(txn, transportId);
txn.setComplete();
@@ -129,7 +129,7 @@ class TransportKeyManager {
private void updateTransportKeys(Map<ContactId, TransportKeys> rotated)
throws DbException {
if (!rotated.isEmpty()) {
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
db.updateTransportKeys(txn, rotated);
txn.setComplete();
@@ -198,7 +198,7 @@ class TransportKeyManager {
outKeys.getStreamCounter());
// Increment the stream counter and write it back to the DB
outKeys.incrementStreamCounter();
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
db.incrementStreamCounter(txn, c, transportId,
outKeys.getRotationPeriod());
@@ -244,7 +244,7 @@ class TransportKeyManager {
inContexts.remove(new Bytes(removeTag));
}
// Write the window back to the DB
Transaction txn = db.startTransaction();
Transaction txn = db.startTransaction(false);
try {
db.setReorderingWindow(txn, tagCtx.contactId, transportId,
inKeys.getRotationPeriod(), window.getBase(),