mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-12-02 11:46:53 +00:00
Retire batched acknowledgement system in favor of point deletions
This commit is contained in:
1 parent
55fa60dd4e
commit
3f3aa89b0f
10 files changed
+71
-414
No files matched your search
+14
-8
@@ -6,9 +6,10 @@
|
||||
package org.whispersystems.textsecuregcm.storage;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -20,11 +21,11 @@ import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.whispersystems.textsecuregcm.experiment.ExperimentEnrollmentManager;
|
||||
import org.whispersystems.textsecuregcm.identity.AciServiceIdentifier;
|
||||
import org.whispersystems.textsecuregcm.storage.foundationdb.FoundationDbMessageStore;
|
||||
import org.whispersystems.textsecuregcm.storage.foundationdb.FoundationDbMessageStream;
|
||||
|
||||
class MirroringMessageStreamTest {
|
||||
|
||||
private FoundationDbMessageStore foundationDbMessageStore;
|
||||
private FoundationDbMessageStream foundationDbMessageStream;
|
||||
private ExperimentEnrollmentManager experimentEnrollmentManager;
|
||||
|
||||
private MirroringMessageStream mirroringMessageStream;
|
||||
@@ -34,12 +35,12 @@ class MirroringMessageStreamTest {
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
foundationDbMessageStore = mock(FoundationDbMessageStore.class);
|
||||
foundationDbMessageStream = mock(FoundationDbMessageStream.class);
|
||||
experimentEnrollmentManager = mock(ExperimentEnrollmentManager.class);
|
||||
|
||||
mirroringMessageStream = new MirroringMessageStream(
|
||||
mock(RedisDynamoDbMessageStream.class),
|
||||
foundationDbMessageStore,
|
||||
foundationDbMessageStream,
|
||||
experimentEnrollmentManager,
|
||||
ACCOUNT_IDENTIFIER.uuid(),
|
||||
DEVICE_ID);
|
||||
@@ -51,10 +52,15 @@ class MirroringMessageStreamTest {
|
||||
when(experimentEnrollmentManager.isEnrolled(any(UUID.class), eq(MessagesManager.MIRROR_DELETIONS_EXPERIMENT_NAME)))
|
||||
.thenReturn(enrolled);
|
||||
|
||||
mirroringMessageStream.acknowledgeMessage(messageGuid, System.currentTimeMillis());
|
||||
final long serverTimestamp = System.currentTimeMillis();
|
||||
|
||||
verify(foundationDbMessageStore, times(expectFoundationDbDeletion ? 1 : 0))
|
||||
.delete(ACCOUNT_IDENTIFIER, DEVICE_ID, messageGuid);
|
||||
mirroringMessageStream.acknowledgeMessage(messageGuid, serverTimestamp);
|
||||
|
||||
if (expectFoundationDbDeletion) {
|
||||
verify(foundationDbMessageStream).acknowledgeMessage(messageGuid, serverTimestamp);
|
||||
} else {
|
||||
verify(foundationDbMessageStream, never()).acknowledgeMessage(any(), anyLong());
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Arguments> acknowledgeMessage() {
|
||||
|
||||
-95
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright 2026 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.textsecuregcm.storage.foundationdb;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import com.apple.foundationdb.tuple.Versionstamp;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.whispersystems.textsecuregcm.util.Pair;
|
||||
|
||||
class AcknowledgedMessageBufferTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void computeFlushableRanges(final List<Integer> versionstampsSent,
|
||||
final List<Integer> versionstampsAcknowledged,
|
||||
final List<Pair<Integer, Integer>> expectedRanges) {
|
||||
|
||||
final AcknowledgedMessageBuffer acknowledgedMessageBuffer =
|
||||
new AcknowledgedMessageBuffer(FoundationDbMessageStream.DEFAULT_MAX_UNACKNOWLEDGED_MESSAGES);
|
||||
|
||||
versionstampsSent.forEach(versionstamp -> assertDoesNotThrow(() ->
|
||||
acknowledgedMessageBuffer.addUnacknowledgedMessage(versionstampFromInt(versionstamp))));
|
||||
|
||||
versionstampsAcknowledged.forEach(versionstamp ->
|
||||
acknowledgedMessageBuffer.acknowledgeMessage(versionstampFromInt(versionstamp)));
|
||||
|
||||
final List<Pair<Versionstamp, Versionstamp>> flushableRanges = acknowledgedMessageBuffer.computeFlushableRanges();
|
||||
|
||||
assertEquals(expectedRanges
|
||||
.stream()
|
||||
.map(range -> new Pair<>(versionstampFromInt(range.first()), versionstampFromInt(range.second())))
|
||||
.toList(),
|
||||
flushableRanges);
|
||||
}
|
||||
|
||||
@Test
|
||||
void takeFlushableRanges() {
|
||||
final AcknowledgedMessageBuffer acknowledgedMessageBuffer =
|
||||
new AcknowledgedMessageBuffer(FoundationDbMessageStream.DEFAULT_MAX_UNACKNOWLEDGED_MESSAGES);
|
||||
|
||||
IntStream.range(0, 10)
|
||||
.mapToObj(AcknowledgedMessageBufferTest::versionstampFromInt)
|
||||
.forEach(versionstamp -> assertDoesNotThrow(
|
||||
() -> acknowledgedMessageBuffer.addUnacknowledgedMessage(versionstamp)));
|
||||
|
||||
assertEquals(10, acknowledgedMessageBuffer.getUnacknowledgedMessageCount());
|
||||
|
||||
IntStream.range(2, 8)
|
||||
.mapToObj(AcknowledgedMessageBufferTest::versionstampFromInt)
|
||||
.forEach(acknowledgedMessageBuffer::acknowledgeMessage);
|
||||
|
||||
assertEquals(List.of(new Pair<>(versionstampFromInt(2), versionstampFromInt(7))),
|
||||
acknowledgedMessageBuffer.takeFlushableRanges());
|
||||
|
||||
assertEquals(4, acknowledgedMessageBuffer.getUnacknowledgedMessageCount());
|
||||
}
|
||||
|
||||
static Stream<Arguments> computeFlushableRanges() {
|
||||
return Stream.of(
|
||||
Arguments.argumentSet("Single acknowledged message range", List.of(1, 2, 3), List.of(1),
|
||||
List.of(new Pair<>(1, 1))),
|
||||
Arguments.argumentSet("No acknowledged messages", List.of(1, 2, 3), Collections.emptyList(),
|
||||
Collections.emptyList()),
|
||||
Arguments.argumentSet("Fully acknowledged message range", List.of(1, 2, 3, 4),
|
||||
List.of(1, 2, 3, 4), List.of(new Pair<>(1, 4))),
|
||||
Arguments.argumentSet("Not all messages acknowledged", List.of(1, 2, 3, 4),
|
||||
List.of(1, 2, 3), List.of(new Pair<>(1, 3))),
|
||||
Arguments.argumentSet("Out-of-order acknowledged ranges", List.of(1, 2, 3, 4, 5, 6, 7, 8),
|
||||
List.of(1, 3, 4, 5, 7, 8), List.of(new Pair<>(1, 1), new Pair<>(3, 5), new Pair<>(7, 8))),
|
||||
Arguments.argumentSet("Out-of-order acknowledged single messages", List.of(1, 2, 3, 4, 5, 6, 7, 8),
|
||||
List.of(1, 3, 5), List.of(new Pair<>(1, 1), new Pair<>(3, 3), new Pair<>(5, 5)))
|
||||
);
|
||||
}
|
||||
|
||||
private static Versionstamp versionstampFromInt(final int version) {
|
||||
final ByteBuffer buf = ByteBuffer.allocate(10).order(ByteOrder.BIG_ENDIAN);
|
||||
buf.putLong(version); // 8 bytes: transaction version
|
||||
buf.putShort((short) 2); // 2 bytes: batch order within transaction
|
||||
return Versionstamp.complete(buf.array());
|
||||
}
|
||||
}
|
||||
+6
-16
@@ -35,9 +35,7 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -66,8 +64,6 @@ class FoundationDbMessagePublisherTest {
|
||||
private static final byte[] MESSAGES_AVAILABLE_WATCH_KEY =
|
||||
FoundationDbMessageStore.getMessagesAvailableWatchKey(SERVICE_IDENTIFIER);
|
||||
|
||||
private static final Supplier<Consumer<Transaction>> NOOP_ON_PAGE_FETCH = () -> _ -> {};
|
||||
|
||||
private static final Clock CLOCK = Clock.systemUTC();
|
||||
|
||||
private static final int STREAM_ID = ThreadLocalRandom.current().nextInt();
|
||||
@@ -131,8 +127,7 @@ class FoundationDbMessagePublisherTest {
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
(_, newState) -> stateTransitions.add(newState),
|
||||
NOOP_ON_PAGE_FETCH
|
||||
(_, newState) -> stateTransitions.add(newState)
|
||||
);
|
||||
|
||||
StepVerifier.create(finitePublisher.getMessages())
|
||||
@@ -219,8 +214,7 @@ class FoundationDbMessagePublisherTest {
|
||||
watchFuture2.complete(null);
|
||||
}
|
||||
}
|
||||
},
|
||||
NOOP_ON_PAGE_FETCH
|
||||
}
|
||||
);
|
||||
|
||||
StepVerifier.create(infinitePublisher.getMessages())
|
||||
@@ -302,8 +296,7 @@ class FoundationDbMessagePublisherTest {
|
||||
.count() == 1) {
|
||||
watchFuture1.complete(null);
|
||||
}
|
||||
},
|
||||
NOOP_ON_PAGE_FETCH
|
||||
}
|
||||
);
|
||||
|
||||
StepVerifier.create(infinitePublisher.getMessages())
|
||||
@@ -338,8 +331,7 @@ class FoundationDbMessagePublisherTest {
|
||||
100,
|
||||
FoundationDbMessageStore.getPresenceKey(SERVICE_IDENTIFIER, Device.PRIMARY_ID),
|
||||
presenceRenewalExecutorService,
|
||||
MESSAGES_AVAILABLE_WATCH_KEY,
|
||||
() -> _ -> {});
|
||||
MESSAGES_AVAILABLE_WATCH_KEY);
|
||||
final MessageProtos.Envelope message = FoundationDbMessageStoreTest.generateRandomMessage(false);
|
||||
final Transaction transaction = mock(Transaction.class);
|
||||
final KeyValue keyValue = mockKeyValue((byte) 5, message);
|
||||
@@ -399,8 +391,7 @@ class FoundationDbMessagePublisherTest {
|
||||
FoundationDbMessageStore.getPresenceKey(SERVICE_IDENTIFIER, Device.PRIMARY_ID),
|
||||
presenceRenewalExecutorService,
|
||||
MESSAGES_AVAILABLE_WATCH_KEY,
|
||||
(_, newState) -> stateTransitions.add(newState),
|
||||
NOOP_ON_PAGE_FETCH
|
||||
(_, newState) -> stateTransitions.add(newState)
|
||||
);
|
||||
|
||||
final RuntimeException streamTerminationException = new RuntimeException("Stream terminated");
|
||||
@@ -464,8 +455,7 @@ class FoundationDbMessagePublisherTest {
|
||||
&& newState == FoundationDbMessagePublisher.State.MESSAGES_AVAILABLE) {
|
||||
latch.countDown();
|
||||
}
|
||||
},
|
||||
NOOP_ON_PAGE_FETCH
|
||||
}
|
||||
);
|
||||
|
||||
// Request two messages one at a time and verify that we only fetch a single batch (batch size = 2) and not two batches
|
||||
|
||||
+1
-26
@@ -594,7 +594,7 @@ class FoundationDbMessageStoreTest {
|
||||
.toList();
|
||||
|
||||
final MessageStream messageStream =
|
||||
foundationDbMessageStore.getMessages(aci, Device.PRIMARY_ID, batchSize, numMessages, Util.NOOP);
|
||||
foundationDbMessageStore.getMessages(aci, Device.PRIMARY_ID, batchSize, Util.NOOP);
|
||||
|
||||
final List<MessageStreamEntry> retrievedEntries = new ArrayList<>();
|
||||
StepVerifier.create(JdkFlowAdapter.flowPublisherToFlux(messageStream.getMessages()))
|
||||
@@ -908,7 +908,6 @@ class FoundationDbMessageStoreTest {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
final MessageStream messageStream = foundationDbMessageStore.getMessages(aci, Device.PRIMARY_ID,
|
||||
FoundationDbMessageStream.DEFAULT_MAX_MESSAGES_PER_SCAN,
|
||||
FoundationDbMessageStream.DEFAULT_MAX_UNACKNOWLEDGED_MESSAGES,
|
||||
latch::countDown);
|
||||
final List<CompletableFuture<Void>> acknowledgeFutures = new ArrayList<>();
|
||||
final AtomicInteger messageCounter = new AtomicInteger(0);
|
||||
@@ -979,7 +978,6 @@ class FoundationDbMessageStoreTest {
|
||||
final MessageStream messageStream = foundationDbMessageStore.getMessages(aci,
|
||||
deviceId,
|
||||
FoundationDbMessageStream.DEFAULT_MAX_MESSAGES_PER_SCAN,
|
||||
FoundationDbMessageStream.DEFAULT_MAX_UNACKNOWLEDGED_MESSAGES,
|
||||
cleanupLatch::countDown);
|
||||
|
||||
final List<MessageStreamEntry> retrievedEntries = new ArrayList<>();
|
||||
@@ -1020,28 +1018,6 @@ class FoundationDbMessageStoreTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void outstandingUnacknowledgedMessages() {
|
||||
final int numMessages = 5;
|
||||
final int maxUnacknowledgedMessages = 3;
|
||||
|
||||
final AciServiceIdentifier aci = new AciServiceIdentifier(UUID.randomUUID());
|
||||
|
||||
for (int i = 0; i < numMessages; i++) {
|
||||
foundationDbMessageStore.insert(aci, Map.of(Device.PRIMARY_ID, generateRandomMessage(false))).join();
|
||||
}
|
||||
|
||||
final MessageStream messageStream = foundationDbMessageStore.getMessages(aci, Device.PRIMARY_ID,
|
||||
FoundationDbMessageStream.DEFAULT_MAX_MESSAGES_PER_SCAN,
|
||||
maxUnacknowledgedMessages,
|
||||
Util.NOOP);
|
||||
|
||||
StepVerifier.create(JdkFlowAdapter.flowPublisherToFlux(messageStream.getMessages()), numMessages)
|
||||
.expectNextCount(maxUnacknowledgedMessages)
|
||||
.expectError(TooManyUnacknowledgedMessagesException.class)
|
||||
.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
void discardStaleEphemeralMessages() throws InterruptedException {
|
||||
final AciServiceIdentifier aci = new AciServiceIdentifier(UUID.randomUUID());
|
||||
@@ -1078,7 +1054,6 @@ class FoundationDbMessageStoreTest {
|
||||
|
||||
final MessageStream messageStream = foundationDbMessageStore.getMessages(aci, Device.PRIMARY_ID,
|
||||
FoundationDbMessageStream.DEFAULT_MAX_MESSAGES_PER_SCAN,
|
||||
FoundationDbMessageStream.DEFAULT_MAX_UNACKNOWLEDGED_MESSAGES,
|
||||
cleanUpLatch::countDown);
|
||||
StepVerifier.create(JdkFlowAdapter.flowPublisherToFlux(messageStream.getMessages()))
|
||||
// We should have discarded the already-inserted ephemeral message
|
||||
|
||||
Reference in new issue
Block a user