Use a single read-write lock for the DB - don't optimise prematurely.

This commit is contained in:
akwizgran
2014-07-04 11:35:44 +01:00
parent 14c5b4e4ff
commit 96a9178b0b
3 changed files with 712 additions and 1147 deletions

View File

@@ -38,29 +38,22 @@ import org.briarproject.api.transport.TemporarySecret;
* terminated by calling either {@link #abortTransaction(T)} or
* {@link #commitTransaction(T)}, even if an exception is thrown.
* <p>
* Locking is provided by the DatabaseComponent implementation. To prevent
* deadlock, locks must be acquired in the following (alphabetical) order:
* <ul>
* <li> contact
* <li> identity
* <li> message
* <li> retention
* <li> setting
* <li> subscription
* <li> transport
* <li> window
* </ul>
* If table A has a foreign key pointing to table B, we get a read lock on A to
* read A, a write lock on A to write A, and write locks on A and B to write B.
* Read-write locking is provided by the DatabaseComponent implementation.
*/
interface Database<T> {
/** Opens the database and returns true if the database already existed. */
/**
* Opens the database and returns true if the database already existed.
* <p>
* Locking: write.
*/
boolean open() throws DbException, IOException;
/**
* Prevents new transactions from starting, waits for all current
* transactions to finish, and closes the database.
* <p>
* Locking: write.
*/
void close() throws DbException, IOException;
@@ -92,8 +85,7 @@ interface Database<T> {
* Stores a contact associated with the given local and remote pseudonyms,
* and returns an ID for the contact.
* <p>
* Locking: contact write, message write, retention write,
* subscription write, transport write, window write.
* Locking: write.
*/
ContactId addContact(T txn, Author remote, AuthorId local)
throws DbException;
@@ -101,7 +93,7 @@ interface Database<T> {
/**
* Stores an endpoint.
* <p>
* Locking: window write.
* Locking: write.
*/
void addEndpoint(T txn, Endpoint ep) throws DbException;
@@ -109,29 +101,28 @@ interface Database<T> {
* Subscribes to a group, or returns false if the user already has the
* maximum number of subscriptions.
* <p>
* Locking: message write, subscription write.
* Locking: write.
*/
boolean addGroup(T txn, Group g) throws DbException;
/**
* Stores a local pseudonym.
* <p>
* Locking: contact write, identity write, message write, retention write,
* subscription write, transport write, window write.
* Locking: write.
*/
void addLocalAuthor(T txn, LocalAuthor a) throws DbException;
/**
* Stores a message.
* <p>
* Locking: message write.
* Locking: write.
*/
void addMessage(T txn, Message m, boolean local) throws DbException;
/**
* Records that a message has been offered by the given contact.
* <p>
* Locking: message write.
* Locking: write.
*/
void addOfferedMessage(T txn, ContactId c, MessageId m) throws DbException;
@@ -139,7 +130,7 @@ interface Database<T> {
* Stores the given temporary secrets and deletes any secrets that have
* been made obsolete.
* <p>
* Locking: window write.
* Locking: write.
*/
void addSecrets(T txn, Collection<TemporarySecret> secrets)
throws DbException;
@@ -147,10 +138,10 @@ interface Database<T> {
/**
* Initialises the status of the given message with respect to the given
* contact.
* <p>
* Locking: write.
* @param ack whether the message needs to be acknowledged.
* @param seen whether the contact has seen the message.
* <p>
* Locking: message write.
*/
void addStatus(T txn, ContactId c, MessageId m, boolean ack, boolean seen)
throws DbException;
@@ -159,7 +150,7 @@ interface Database<T> {
* Stores a transport and returns true if the transport was not previously
* in the database.
* <p>
* Locking: transport write, window write.
* Locking: write.
*/
boolean addTransport(T txn, TransportId t, long maxLatency)
throws DbException;
@@ -167,49 +158,49 @@ interface Database<T> {
/**
* Makes a group visible to the given contact.
* <p>
* Locking: subscription write.
* Locking: write.
*/
void addVisibility(T txn, ContactId c, GroupId g) throws DbException;
/**
* Returns true if the database contains the given contact.
* <p>
* Locking: contact read.
* Locking: read.
*/
boolean containsContact(T txn, AuthorId a) throws DbException;
/**
* Returns true if the database contains the given contact.
* <p>
* Locking: contact read.
* Locking: read.
*/
boolean containsContact(T txn, ContactId c) throws DbException;
/**
* Returns true if the user subscribes to the given group.
* <p>
* Locking: subscription read.
* Locking: read.
*/
boolean containsGroup(T txn, GroupId g) throws DbException;
/**
* Returns true if the database contains the given local pseudonym.
* <p>
* Locking: identity read.
* Locking: read.
*/
boolean containsLocalAuthor(T txn, AuthorId a) throws DbException;
/**
* Returns true if the database contains the given message.
* <p>
* Locking: message read.
* Locking: read.
*/
boolean containsMessage(T txn, MessageId m) throws DbException;
/**
* Returns true if the database contains the given transport.
* <p>
* Locking: transport read.
* Locking: read.
*/
boolean containsTransport(T txn, TransportId t) throws DbException;
@@ -217,7 +208,7 @@ interface Database<T> {
* Returns true if the user subscribes to the given group and the group is
* visible to the given contact.
* <p>
* Locking: subscription read.
* Locking: read.
*/
boolean containsVisibleGroup(T txn, ContactId c, GroupId g)
throws DbException;
@@ -226,7 +217,7 @@ interface Database<T> {
* Returns true if the database contains the given message and the message
* is visible to the given contact.
* <p>
* Locking: message read, subscription read.
* Locking: read.
*/
boolean containsVisibleMessage(T txn, ContactId c, MessageId m)
throws DbException;
@@ -234,7 +225,7 @@ interface Database<T> {
/**
* Returns the number of messages offered by the given contact.
* <p>
* Locking: message read.
* Locking: read.
*/
int countOfferedMessages(T txn, ContactId c) throws DbException;
@@ -242,49 +233,49 @@ interface Database<T> {
* Returns the status of all groups to which the user subscribes or can
* subscribe, excluding inbox groups.
* <p>
* Locking: subscription read.
* Locking: read.
*/
Collection<GroupStatus> getAvailableGroups(T txn) throws DbException;
/**
* Returns the configuration for the given transport.
* <p>
* Locking: transport read.
* Locking: read.
*/
TransportConfig getConfig(T txn, TransportId t) throws DbException;
/**
* Returns the contact with the given ID.
* <p>
* Locking: contact read.
* Locking: read.
*/
Contact getContact(T txn, ContactId c) throws DbException;
/**
* Returns the IDs of all contacts.
* <p>
* Locking: contact read.
* Locking: read.
*/
Collection<ContactId> getContactIds(T txn) throws DbException;
/**
* Returns all contacts.
* <p>
* Locking: contact read, window read.
* Locking: read.
*/
Collection<Contact> getContacts(T txn) throws DbException;
/**
* Returns all contacts associated with the given local pseudonym.
* <p>
* Locking: contact read.
* Locking: read.
*/
Collection<ContactId> getContacts(T txn, AuthorId a) throws DbException;
/**
* Returns all endpoints.
* <p>
* Locking: window read.
* Locking: read.
*/
Collection<Endpoint> getEndpoints(T txn) throws DbException;
@@ -298,14 +289,14 @@ interface Database<T> {
/**
* Returns the group with the given ID, if the user subscribes to it.
* <p>
* Locking: subscription read.
* Locking: read.
*/
Group getGroup(T txn, GroupId g) throws DbException;
/**
* Returns all groups to which the user subscribes.
* <p>
* Locking: subscription read.
* Locking: read.
*/
Collection<Group> getGroups(T txn) throws DbException;
@@ -313,7 +304,7 @@ interface Database<T> {
* Returns the ID of the inbox group for the given contact, or null if no
* inbox group has been set.
* <p>
* Locking: contact read, subscription read.
* Locking: read.
*/
GroupId getInboxGroupId(T txn, ContactId c) throws DbException;
@@ -321,7 +312,7 @@ interface Database<T> {
* Returns the headers of all messages in the inbox group for the given
* contact, or null if no inbox group has been set.
* <p>
* Locking: contact read, identity read, message read, subscription read.
* Locking: read.
*/
Collection<MessageHeader> getInboxMessageHeaders(T txn, ContactId c)
throws DbException;
@@ -329,21 +320,21 @@ interface Database<T> {
/**
* Returns the local pseudonym with the given ID.
* <p>
* Locking: identity read.
* Locking: read.
*/
LocalAuthor getLocalAuthor(T txn, AuthorId a) throws DbException;
/**
* Returns all local pseudonyms.
* <p>
* Locking: identity read.
* Locking: read.
*/
Collection<LocalAuthor> getLocalAuthors(T txn) throws DbException;
/**
* Returns the local transport properties for all transports.
* <p>
* Locking: transport read.
* Locking: read.
*/
Map<TransportId, TransportProperties> getLocalProperties(T txn)
throws DbException;
@@ -351,7 +342,7 @@ interface Database<T> {
/**
* Returns the local transport properties for the given transport.
* <p>
* Locking: transport read.
* Locking: read.
*/
TransportProperties getLocalProperties(T txn, TransportId t)
throws DbException;
@@ -359,14 +350,14 @@ interface Database<T> {
/**
* Returns the body of the message identified by the given ID.
* <p>
* Locking: message read.
* Locking: read.
*/
byte[] getMessageBody(T txn, MessageId m) throws DbException;
/**
* Returns the headers of all messages in the given group.
* <p>
* Locking: message read.
* Locking: read.
*/
Collection<MessageHeader> getMessageHeaders(T txn, GroupId g)
throws DbException;
@@ -375,7 +366,7 @@ interface Database<T> {
* Returns the IDs of some messages received from the given contact that
* need to be acknowledged, up to the given number of messages.
* <p>
* Locking: message read.
* Locking: read.
*/
Collection<MessageId> getMessagesToAck(T txn, ContactId c, int maxMessages)
throws DbException;
@@ -384,7 +375,7 @@ interface Database<T> {
* Returns the IDs of some messages that are eligible to be offered to the
* given contact, up to the given number of messages.
* <p>
* Locking: message read, subscription read.
* Locking: read.
*/
Collection<MessageId> getMessagesToOffer(T txn, ContactId c,
int maxMessages) throws DbException;
@@ -393,7 +384,7 @@ interface Database<T> {
* Returns the IDs of some messages that are eligible to be sent to the
* given contact, up to the given total length.
* <p>
* Locking: message read, subscription read.
* Locking: read.
*/
Collection<MessageId> getMessagesToSend(T txn, ContactId c, int maxLength)
throws DbException;
@@ -402,7 +393,7 @@ interface Database<T> {
* Returns the IDs of some messages that are eligible to be requested from
* the given contact, up to the given number of messages.
* <p>
* Locking: message read.
* Locking: read.
*/
Collection<MessageId> getMessagesToRequest(T txn, ContactId c,
int maxMessages) throws DbException;
@@ -411,7 +402,7 @@ interface Database<T> {
* Returns the IDs of the oldest messages in the database, with a total
* size less than or equal to the given size.
* <p>
* Locking: message read.
* Locking: read.
*/
Collection<MessageId> getOldMessages(T txn, int size) throws DbException;
@@ -420,28 +411,28 @@ interface Database<T> {
* has no parent, or the parent is absent from the database, or the parent
* belongs to a different group.
* <p>
* Locking: message read.
* Locking: read.
*/
MessageId getParent(T txn, MessageId m) throws DbException;
/**
* Returns the message identified by the given ID, in serialised form.
* <p>
* Locking: message read.
* Locking: read.
*/
byte[] getRawMessage(T txn, MessageId m) throws DbException;
/**
* Returns true if the given message is marked as read.
* <p>
* Locking: message read.
* Locking: read.
*/
boolean getReadFlag(T txn, MessageId m) throws DbException;
/**
* Returns all remote properties for the given transport.
* <p>
* Locking: transport read.
* Locking: read.
*/
Map<ContactId, TransportProperties> getRemoteProperties(T txn,
TransportId t) throws DbException;
@@ -451,7 +442,7 @@ interface Database<T> {
* given contact and have been requested by the contact, up to the given
* total length.
* <p>
* Locking: message read, subscription read.
* Locking: read.
*/
Collection<MessageId> getRequestedMessagesToSend(T txn, ContactId c,
int maxLength) throws DbException;
@@ -459,7 +450,7 @@ interface Database<T> {
/**
* Returns a retention ack for the given contact, or null if no ack is due.
* <p>
* Locking: retention write.
* Locking: write.
*/
RetentionAck getRetentionAck(T txn, ContactId c) throws DbException;
@@ -467,7 +458,7 @@ interface Database<T> {
* Returns a retention update for the given contact and updates its expiry
* time using the given latency, or returns null if no update is due.
* <p>
* Locking: message read, retention write.
* Locking: write.
*/
RetentionUpdate getRetentionUpdate(T txn, ContactId c, long maxLatency)
throws DbException;
@@ -475,21 +466,21 @@ interface Database<T> {
/**
* Returns all temporary secrets.
* <p>
* Locking: window read.
* Locking: read.
*/
Collection<TemporarySecret> getSecrets(T txn) throws DbException;
/**
* Returns all settings.
* <p>
* Locking: setting read.
* Locking: read.
*/
Settings getSettings(T txn) throws DbException;
/**
* Returns all contacts who subscribe to the given group.
* <p>
* Locking: subscription read.
* Locking: read.
*/
Collection<Contact> getSubscribers(T txn, GroupId g) throws DbException;
@@ -497,7 +488,7 @@ interface Database<T> {
* Returns a subscription ack for the given contact, or null if no ack is
* due.
* <p>
* Locking: subscription write.
* Locking: write.
*/
SubscriptionAck getSubscriptionAck(T txn, ContactId c) throws DbException;
@@ -505,7 +496,7 @@ interface Database<T> {
* Returns a subscription update for the given contact and updates its
* expiry time using the given latency, or returns null if no update is due.
* <p>
* Locking: subscription write.
* Locking: write.
*/
SubscriptionUpdate getSubscriptionUpdate(T txn, ContactId c,
long maxLatency) throws DbException;
@@ -514,7 +505,7 @@ interface Database<T> {
* Returns a collection of transport acks for the given contact, or null if
* no acks are due.
* <p>
* Locking: transport write.
* Locking: write.
*/
Collection<TransportAck> getTransportAcks(T txn, ContactId c)
throws DbException;
@@ -522,7 +513,7 @@ interface Database<T> {
/**
* Returns the maximum latencies of all local transports.
* <p>
* Locking: transport read.
* Locking: read.
*/
Map<TransportId, Long> getTransportLatencies(T txn) throws DbException;
@@ -531,7 +522,7 @@ interface Database<T> {
* updates their expiry times using the given latency, or returns null if
* no updates are due.
* <p>
* Locking: transport write.
* Locking: write.
*/
Collection<TransportUpdate> getTransportUpdates(T txn, ContactId c,
long maxLatency) throws DbException;
@@ -539,14 +530,14 @@ interface Database<T> {
/**
* Returns the number of unread messages in each subscribed group.
* <p>
* Locking: message read.
* Locking: read.
*/
Map<GroupId, Integer> getUnreadMessageCounts(T txn) throws DbException;
/**
* Returns the IDs of all contacts to which the given group is visible.
* <p>
* Locking: subscription read.
* Locking: read.
*/
Collection<ContactId> getVisibility(T txn, GroupId g) throws DbException;
@@ -555,7 +546,7 @@ interface Database<T> {
* in the given rotation period and returns the old value, or -1 if the
* counter does not exist.
* <p>
* Locking: window write.
* Locking: write.
*/
long incrementConnectionCounter(T txn, ContactId c, TransportId t,
long period) throws DbException;
@@ -564,7 +555,7 @@ interface Database<T> {
* Increments the retention time versions for all contacts to indicate that
* the database's retention time has changed and updates should be sent.
* <p>
* Locking: retention write.
* Locking: write.
*/
void incrementRetentionVersions(T txn) throws DbException;
@@ -572,7 +563,7 @@ interface Database<T> {
* Marks the given messages as not needing to be acknowledged to the
* given contact.
* <p>
* Locking: message write.
* Locking: write.
*/
void lowerAckFlag(T txn, ContactId c, Collection<MessageId> acked)
throws DbException;
@@ -581,7 +572,7 @@ interface Database<T> {
* Marks the given messages as not having been requested by the given
* contact.
* <p>
* Locking: message write.
* Locking: write.
*/
void lowerRequestedFlag(T txn, ContactId c, Collection<MessageId> requested)
throws DbException;
@@ -590,7 +581,7 @@ interface Database<T> {
* Merges the given configuration with the existing configuration for the
* given transport.
* <p>
* Locking: transport write.
* Locking: write.
*/
void mergeConfig(T txn, TransportId t, TransportConfig config)
throws DbException;
@@ -599,7 +590,7 @@ interface Database<T> {
* Merges the given properties with the existing local properties for the
* given transport.
* <p>
* Locking: transport write.
* Locking: write.
*/
void mergeLocalProperties(T txn, TransportId t, TransportProperties p)
throws DbException;
@@ -607,36 +598,35 @@ interface Database<T> {
/**
* Merges the given settings with the existing settings.
* <p>
* Locking: setting write.
* Locking: write.
*/
void mergeSettings(T txn, Settings s) throws DbException;
/**
* Marks a message as needing to be acknowledged to the given contact.
* <p>
* Locking: message write.
* Locking: write.
*/
void raiseAckFlag(T txn, ContactId c, MessageId m) throws DbException;
/**
* Marks a message as having been requested by the given contact.
* <p>
* Locking: message write.
* Locking: write.
*/
void raiseRequestedFlag(T txn, ContactId c, MessageId m) throws DbException;
/**
* Marks a message as having been seen by the given contact.
* <p>
* Locking: message write.
* Locking: write.
*/
void raiseSeenFlag(T txn, ContactId c, MessageId m) throws DbException;
/**
* Removes a contact from the database.
* <p>
* Locking: contact write, message write, retention write,
* subscription write, transport write, window write.
* Locking: write.
*/
void removeContact(T txn, ContactId c) throws DbException;
@@ -644,7 +634,7 @@ interface Database<T> {
* Unsubscribes from a group. Any messages belonging to the group are
* deleted from the database.
* <p>
* Locking: message write, subscription write.
* Locking: write.
*/
void removeGroup(T txn, GroupId g) throws DbException;
@@ -652,15 +642,14 @@ interface Database<T> {
* Removes a local pseudonym (and all associated contacts) from the
* database.
* <p>
* Locking: contact write, identity write, message write, retention write,
* subscription write, transport write, window write.
* Locking: write.
*/
void removeLocalAuthor(T txn, AuthorId a) throws DbException;
/**
* Removes a message (and all associated state) from the database.
* <p>
* Locking: message write.
* Locking: write.
*/
void removeMessage(T txn, MessageId m) throws DbException;
@@ -668,7 +657,7 @@ interface Database<T> {
* Removes an offered message that was offered by the given contact, or
* returns false if there is no such message.
* <p>
* Locking: message write.
* Locking: write.
*/
boolean removeOfferedMessage(T txn, ContactId c, MessageId m)
throws DbException;
@@ -677,7 +666,7 @@ interface Database<T> {
* Removes the given offered messages that were offered by the given
* contact.
* <p>
* Locking: message write.
* Locking: write.
*/
void removeOfferedMessages(T txn, ContactId c,
Collection<MessageId> requested) throws DbException;
@@ -685,14 +674,14 @@ interface Database<T> {
/**
* Removes a transport (and all associated state) from the database.
* <p>
* Locking: transport write, window write.
* Locking: write.
*/
void removeTransport(T txn, TransportId t) throws DbException;
/**
* Makes a group invisible to the given contact.
* <p>
* Locking: subscription write.
* Locking: write.
*/
void removeVisibility(T txn, ContactId c, GroupId g) throws DbException;
@@ -700,7 +689,7 @@ interface Database<T> {
* Resets the transmission count and expiry time of the given message with
* respect to the given contact.
* <p>
* Locking: message write.
* Locking: write.
*/
void resetExpiryTime(T txn, ContactId c, MessageId m) throws DbException;
@@ -708,7 +697,7 @@ interface Database<T> {
* Sets the connection reordering window for the given endpoint in the
* given rotation period.
* <p>
* Locking: window write.
* Locking: write.
*/
void setConnectionWindow(T txn, ContactId c, TransportId t, long period,
long centre, byte[] bitmap) throws DbException;
@@ -718,7 +707,7 @@ interface Database<T> {
* true, unless an update with an equal or higher version number has
* already been received from the contact.
* <p>
* Locking: message write, subscription write.
* Locking: write.
*/
boolean setGroups(T txn, ContactId c, Collection<Group> groups,
long version) throws DbException;
@@ -727,14 +716,14 @@ interface Database<T> {
* Makes a group visible to the given contact, adds it to the contact's
* subscriptions, and sets it as the inbox group for the contact.
* <p>
* Locking: subscription write.
* Locking: write.
*/
public void setInboxGroup(T txn, ContactId c, Group g) throws DbException;
/**
* Marks a message as read or unread.
* <p>
* Locking: message write.
* Locking: write.
*/
void setReadFlag(T txn, MessageId m, boolean read) throws DbException;
@@ -742,7 +731,7 @@ interface Database<T> {
* Sets the remote transport properties for the given contact, replacing
* any existing properties.
* <p>
* Locking: transport write.
* Locking: write.
*/
void setRemoteProperties(T txn, ContactId c,
Map<TransportId, TransportProperties> p) throws DbException;
@@ -753,7 +742,7 @@ interface Database<T> {
* unless an update with an equal or higher version number has already been
* received from the contact.
* <p>
* Locking: transport write.
* Locking: write.
*/
boolean setRemoteProperties(T txn, ContactId c, TransportId t,
TransportProperties p, long version) throws DbException;
@@ -763,7 +752,7 @@ interface Database<T> {
* true, unless an update with an equal or higher version number has
* already been received from the contact.
* <p>
* Locking: retention write.
* Locking: write.
*/
boolean setRetentionTime(T txn, ContactId c, long retention, long version)
throws DbException;
@@ -772,7 +761,7 @@ interface Database<T> {
* Records a retention ack from the given contact for the given version,
* unless the contact has already acked an equal or higher version.
* <p>
* Locking: retention write.
* Locking: write.
*/
void setRetentionUpdateAcked(T txn, ContactId c, long version)
throws DbException;
@@ -781,7 +770,7 @@ interface Database<T> {
* Records a subscription ack from the given contact for the given version,
* unless the contact has already acked an equal or higher version.
* <p>
* Locking: subscription write.
* Locking: write.
*/
void setSubscriptionUpdateAcked(T txn, ContactId c, long version)
throws DbException;
@@ -790,7 +779,7 @@ interface Database<T> {
* Records a transport ack from the give contact for the given version,
* unless the contact has already acked an equal or higher version.
* <p>
* Locking: transport write.
* Locking: write.
*/
void setTransportUpdateAcked(T txn, ContactId c, TransportId t,
long version) throws DbException;
@@ -798,7 +787,7 @@ interface Database<T> {
/**
* Makes a group visible or invisible to future contacts by default.
* <p>
* Locking: subscription write.
* Locking: write.
*/
void setVisibleToAll(T txn, GroupId g, boolean all) throws DbException;
@@ -807,7 +796,7 @@ interface Database<T> {
* with respect to the given contact, using the latency of the transport
* over which it was sent.
* <p>
* Locking: message write.
* Locking: write.
*/
void updateExpiryTime(T txn, ContactId c, MessageId m, long maxLatency)
throws DbException;

File diff suppressed because it is too large Load Diff

View File

@@ -71,8 +71,6 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " value VARCHAR NOT NULL,"
+ " PRIMARY KEY (key))";
// Locking: identity
// Dependents: contact, message, retention, subscription, transport, window
private static final String CREATE_LOCAL_AUTHORS =
"CREATE TABLE localAuthors"
+ " (authorId HASH NOT NULL,"
@@ -82,8 +80,6 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " created BIGINT NOT NULL,"
+ " PRIMARY KEY (authorId))";
// Locking: contact
// Dependents: message, retention, subscription, transport, window
private static final String CREATE_CONTACTS =
"CREATE TABLE contacts"
+ " (contactId COUNTER,"
@@ -97,8 +93,6 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " REFERENCES localAuthors (authorId)"
+ " ON DELETE CASCADE)";
// Locking: subscription
// Dependents: message
private static final String CREATE_GROUPS =
"CREATE TABLE groups"
+ " (groupId HASH NOT NULL,"
@@ -107,7 +101,6 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " visibleToAll BOOLEAN NOT NULL,"
+ " PRIMARY KEY (groupId))";
// Locking: subscription
private static final String CREATE_GROUP_VISIBILITIES =
"CREATE TABLE groupVisibilities"
+ " (contactId INT NOT NULL,"
@@ -121,7 +114,6 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " REFERENCES groups (groupId)"
+ " ON DELETE CASCADE)";
// Locking: subscription
private static final String CREATE_CONTACT_GROUPS =
"CREATE TABLE contactGroups"
+ " (contactId INT NOT NULL,"
@@ -133,7 +125,6 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " REFERENCES contacts (contactId)"
+ " ON DELETE CASCADE)";
// Locking: subscription
private static final String CREATE_GROUP_VERSIONS =
"CREATE TABLE groupVersions"
+ " (contactId INT NOT NULL,"
@@ -148,7 +139,6 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " REFERENCES contacts (contactId)"
+ " ON DELETE CASCADE)";
// Locking: message
private static final String CREATE_MESSAGES =
"CREATE TABLE messages"
+ " (messageId HASH NOT NULL,"
@@ -182,7 +172,6 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " REFERENCES contacts (contactId)"
+ " ON DELETE CASCADE)";
// Locking: message
private static final String CREATE_STATUSES =
"CREATE TABLE statuses"
+ " (messageId HASH NOT NULL,"
@@ -206,7 +195,6 @@ abstract class JdbcDatabase implements Database<Connection> {
private static final String INDEX_STATUSES_BY_CONTACT =
"CREATE INDEX statusesByContact ON statuses (contactId)";
// Locking: retention
private static final String CREATE_RETENTION_VERSIONS =
"CREATE TABLE retentionVersions"
+ " (contactId INT NOT NULL,"
@@ -222,15 +210,12 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " REFERENCES contacts (contactId)"
+ " ON DELETE CASCADE)";
// Locking: transport
// Dependents: window
private static final String CREATE_TRANSPORTS =
"CREATE TABLE transports"
+ " (transportId VARCHAR NOT NULL,"
+ " maxLatency BIGINT NOT NULL,"
+ " PRIMARY KEY (transportId))";
// Locking: transport
private static final String CREATE_TRANSPORT_CONFIGS =
"CREATE TABLE transportConfigs"
+ " (transportId VARCHAR NOT NULL,"
@@ -241,7 +226,6 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " REFERENCES transports (transportId)"
+ " ON DELETE CASCADE)";
// Locking: transport
private static final String CREATE_TRANSPORT_PROPS =
"CREATE TABLE transportProperties"
+ " (transportId VARCHAR NOT NULL,"
@@ -252,7 +236,6 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " REFERENCES transports (transportId)"
+ " ON DELETE CASCADE)";
// Locking: transport
private static final String CREATE_TRANSPORT_VERSIONS =
"CREATE TABLE transportVersions"
+ " (contactId INT NOT NULL,"
@@ -269,7 +252,6 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " REFERENCES transports (transportId)"
+ " ON DELETE CASCADE)";
// Locking: transport
private static final String CREATE_CONTACT_TRANSPORT_PROPS =
"CREATE TABLE contactTransportProperties"
+ " (contactId INT NOT NULL,"
@@ -281,7 +263,6 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " REFERENCES contacts (contactId)"
+ " ON DELETE CASCADE)";
// Locking: transport
private static final String CREATE_CONTACT_TRANSPORT_VERSIONS =
"CREATE TABLE contactTransportVersions"
+ " (contactId INT NOT NULL,"
@@ -293,7 +274,6 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " REFERENCES contacts (contactId)"
+ " ON DELETE CASCADE)";
// Locking: window
private static final String CREATE_ENDPOINTS =
"CREATE TABLE endpoints"
+ " (contactId INT NOT NULL,"
@@ -308,7 +288,6 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " REFERENCES transports (transportId)"
+ " ON DELETE CASCADE)";
// Locking: window
private static final String CREATE_SECRETS =
"CREATE TABLE secrets"
+ " (contactId INT NOT NULL,"