Reserve SQLite writer before reading subscription event receipts
This commit is contained in:
@@ -7,6 +7,10 @@ import org.apache.ibatis.annotations.*;
|
||||
|
||||
@Mapper
|
||||
public interface SubscriptionEventMapper {
|
||||
/** Reserve SQLite's writer before the receipt read; a deferred read-to-write upgrade can fail immediately. */
|
||||
@Update("update subscription_event_receipt set ingested_at=ingested_at where 0")
|
||||
void reserveWriter();
|
||||
|
||||
@Select("select fingerprint from subscription_event_receipt where event_id=#{eventId}")
|
||||
String fingerprint(String eventId);
|
||||
|
||||
|
||||
@@ -123,6 +123,7 @@ public class SubscriptionEventService {
|
||||
try {
|
||||
// Return acknowledgements only after execute has returned and the entire transaction committed.
|
||||
List<String> acknowledged = transactions.execute(status -> {
|
||||
events.reserveWriter();
|
||||
List<String> ids = new ArrayList<>();
|
||||
for (SubscriptionEvent event : batch) if (persist(event, "standby", null)) ids.add(event.getEventId());
|
||||
return ids;
|
||||
@@ -133,6 +134,7 @@ public class SubscriptionEventService {
|
||||
|
||||
public void recordPrimary(SubscriptionEvent event, SubBind binding) {
|
||||
transactions.executeWithoutResult(status -> {
|
||||
events.reserveWriter();
|
||||
if (!persist(event, "primary", binding)) throw new IllegalStateException("subscription user unavailable");
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user