Insert ephemeral messages in the standard cache queue

This commit is contained in:
Chris Eager
2021-08-24 18:24:42 -05:00
committed by Chris Eager
parent a7443a9ece
commit e08c5a412e
6 changed files with 75 additions and 141 deletions

View File

@@ -4,9 +4,14 @@
*/
package org.whispersystems.textsecuregcm.push;
import static com.codahale.metrics.MetricRegistry.name;
import static org.whispersystems.textsecuregcm.entities.MessageProtos.Envelope;
import io.dropwizard.lifecycle.Managed;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Tag;
import java.util.List;
import java.util.Optional;
import org.whispersystems.textsecuregcm.metrics.PushLatencyManager;
import org.whispersystems.textsecuregcm.push.ApnMessage.Type;
import org.whispersystems.textsecuregcm.redis.RedisOperation;
@@ -15,12 +20,6 @@ import org.whispersystems.textsecuregcm.storage.Device;
import org.whispersystems.textsecuregcm.storage.MessagesManager;
import org.whispersystems.textsecuregcm.util.Util;
import java.util.List;
import java.util.Optional;
import static com.codahale.metrics.MetricRegistry.name;
import static org.whispersystems.textsecuregcm.entities.MessageProtos.Envelope;
/**
* A MessageSender sends Signal messages to destination devices. Messages may be "normal" user-to-user messages,
* ephemeral ("online") messages like typing indicators, or delivery receipts.
@@ -88,7 +87,7 @@ public class MessageSender implements Managed {
clientPresent = clientPresenceManager.isPresent(account.getUuid(), device.getId());
if (clientPresent) {
messagesManager.insertEphemeral(account.getUuid(), device.getId(), message);
messagesManager.insert(account.getUuid(), device.getId(), message.toBuilder().setEphemeral(true).build());
}
} else {
messagesManager.insert(account.getUuid(), device.getId(), message);

View File

@@ -12,9 +12,10 @@ package org.whispersystems.textsecuregcm.storage;
*/
public interface MessageAvailabilityListener {
void handleNewMessagesAvailable();
void handleNewMessagesAvailable();
void handleNewEphemeralMessageAvailable();
@Deprecated
void handleNewEphemeralMessageAvailable();
void handleMessagesPersisted();
void handleMessagesPersisted();
}

View File

@@ -63,7 +63,6 @@ public class MessagesCache extends RedisClusterPubSubAdapter<String, String> imp
private final Map<MessageAvailabilityListener, String> queueNamesByMessageListener = new IdentityHashMap<>();
private final Timer insertTimer = Metrics.timer(name(MessagesCache.class, "insert"), "ephemeral", "false");
private final Timer insertEphemeralTimer = Metrics.timer(name(MessagesCache.class, "insert"), "ephemeral", "true");
private final Timer getMessagesTimer = Metrics.timer(name(MessagesCache.class, "get"));
private final Timer getQueuesToPersistTimer = Metrics.timer(name(MessagesCache.class, "getQueuesToPersist"));
private final Timer clearQueueTimer = Metrics.timer(name(MessagesCache.class, "clear"));
@@ -144,27 +143,6 @@ public class MessagesCache extends RedisClusterPubSubAdapter<String, String> imp
guid.toString().getBytes(StandardCharsets.UTF_8))));
}
public void insertEphemeral(final UUID destinationUuid, final long destinationDevice,
final MessageProtos.Envelope message) {
final MessageProtos.Envelope messageWithGuid;
if (!message.hasServerGuid()) {
messageWithGuid = message.toBuilder().setServerGuid(UUID.randomUUID().toString()).build();
} else {
messageWithGuid = message;
}
insertEphemeralTimer.record(() -> {
final byte[] ephemeralQueueKey = getEphemeralMessageQueueKey(destinationUuid, destinationDevice);
insertCluster.useBinaryCluster(connection -> {
connection.sync().rpush(ephemeralQueueKey, messageWithGuid.toByteArray());
connection.sync().expire(ephemeralQueueKey, MAX_EPHEMERAL_MESSAGE_DELAY.toSeconds());
});
});
}
public Optional<OutgoingMessageEntity> remove(final UUID destinationUuid, final long destinationDevice,
final UUID messageGuid) {
return remove(destinationUuid, destinationDevice, List.of(messageGuid)).stream().findFirst();
@@ -247,6 +225,7 @@ public class MessagesCache extends RedisClusterPubSubAdapter<String, String> imp
});
}
@Deprecated
public Optional<MessageProtos.Envelope> takeEphemeralMessage(final UUID destinationUuid,
final long destinationDevice) {
return takeEphemeralMessage(destinationUuid, destinationDevice, System.currentTimeMillis());

View File

@@ -59,10 +59,7 @@ public class MessagesManager {
}
}
public void insertEphemeral(final UUID destinationUuid, final long destinationDevice, final Envelope message) {
messagesCache.insertEphemeral(destinationUuid, destinationDevice, message);
}
@Deprecated
public Optional<Envelope> takeEphemeralMessage(final UUID destinationUuid, final long destinationDevice) {
return messagesCache.takeEphemeralMessage(destinationUuid, destinationDevice);
}