From afa910bbd7ff5ea69ed6bfe3bcd46b7301ec4373 Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Wed, 24 Nov 2021 17:04:05 -0500 Subject: [PATCH] Drop relational profiles store --- .../textsecuregcm/WhisperServerService.java | 4 +- .../textsecuregcm/storage/Profiles.java | 104 ------------------ .../storage/ProfilesManager.java | 51 ++------- .../mappers/VersionedProfileMapper.java | 28 ----- .../workers/DeleteUserCommand.java | 5 +- .../SetUserDiscoverabilityCommand.java | 5 +- .../storage/ProfilesPostgresTest.java | 39 ------- .../tests/storage/ProfilesManagerTest.java | 23 +--- 8 files changed, 14 insertions(+), 245 deletions(-) delete mode 100644 service/src/main/java/org/whispersystems/textsecuregcm/storage/Profiles.java delete mode 100644 service/src/main/java/org/whispersystems/textsecuregcm/storage/mappers/VersionedProfileMapper.java delete mode 100644 service/src/test/java/org/whispersystems/textsecuregcm/storage/ProfilesPostgresTest.java diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java index 766f04d2c..031f23024 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java @@ -188,7 +188,6 @@ import org.whispersystems.textsecuregcm.storage.MessagesDynamoDb; import org.whispersystems.textsecuregcm.storage.MessagesManager; import org.whispersystems.textsecuregcm.storage.NonNormalizedAccountCrawlerListener; import org.whispersystems.textsecuregcm.storage.PhoneNumberIdentifiers; -import org.whispersystems.textsecuregcm.storage.Profiles; import org.whispersystems.textsecuregcm.storage.ProfilesDynamoDb; import org.whispersystems.textsecuregcm.storage.ProfilesManager; import org.whispersystems.textsecuregcm.storage.PubSubManager; @@ -386,7 +385,6 @@ public class WhisperServerService extends Application jdbi.useHandle(handle -> { - try (Timer.Context ignored = setTimer.time()) { - handle.createUpdate( - "INSERT INTO profiles (" - + UID + ", " - + VERSION + ", " - + NAME + ", " - + AVATAR + ", " - + ABOUT_EMOJI + ", " - + ABOUT + ", " - + PAYMENT_ADDRESS + ", " - + COMMITMENT + ") " - + "VALUES (:uuid, :version, :name, :avatar, :about_emoji, :about, :payment_address, :commitment) " - + "ON CONFLICT (" + UID + ", " + VERSION + ") " - + "DO UPDATE SET " - + NAME + " = EXCLUDED." + NAME + ", " - + AVATAR + " = EXCLUDED." + AVATAR + ", " - + ABOUT + " = EXCLUDED." + ABOUT + ", " - + ABOUT_EMOJI + " = EXCLUDED." + ABOUT_EMOJI + ", " - + PAYMENT_ADDRESS + " = EXCLUDED." + PAYMENT_ADDRESS + ", " - + DELETED + " = FALSE, " - + COMMITMENT + " = CASE WHEN profiles." + DELETED + " = TRUE THEN EXCLUDED." + COMMITMENT + " ELSE profiles." + COMMITMENT + " END") - .bind("uuid", uuid) - .bind("version", profile.getVersion()) - .bind("name", profile.getName()) - .bind("avatar", profile.getAvatar()) - .bind("about_emoji", profile.getAboutEmoji()) - .bind("about", profile.getAbout()) - .bind("payment_address", profile.getPaymentAddress()) - .bind("commitment", profile.getCommitment()) - .execute(); - } - })); - } - - @Override - public Optional get(UUID uuid, String version) { - return database.with(jdbi -> jdbi.withHandle(handle -> { - try (Timer.Context ignored = getTimer.time()) { - return handle.createQuery("SELECT * FROM profiles WHERE " + UID + " = :uuid AND " + VERSION + " = :version AND " + DELETED + "= FALSE") - .bind("uuid", uuid) - .bind("version", version) - .mapTo(VersionedProfile.class) - .findFirst(); - } - })); - } - - @Override - public void deleteAll(UUID uuid) { - database.use(jdbi -> jdbi.useHandle(handle -> { - try (Timer.Context ignored = deleteTimer.time()) { - handle.createUpdate("UPDATE profiles SET " + DELETED + " = TRUE WHERE " + UID + " = :uuid") - .bind("uuid", uuid) - .execute(); - } - })); - } -} diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/ProfilesManager.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/ProfilesManager.java index 5f48be7c0..4fac73405 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/ProfilesManager.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/storage/ProfilesManager.java @@ -8,16 +8,13 @@ package org.whispersystems.textsecuregcm.storage; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import io.lettuce.core.RedisException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicConfiguration; -import org.whispersystems.textsecuregcm.experiment.Experiment; -import org.whispersystems.textsecuregcm.redis.FaultTolerantRedisCluster; -import org.whispersystems.textsecuregcm.util.SystemMapper; - import java.io.IOException; import java.util.Optional; import java.util.UUID; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.whispersystems.textsecuregcm.redis.FaultTolerantRedisCluster; +import org.whispersystems.textsecuregcm.util.SystemMapper; public class ProfilesManager { @@ -25,63 +22,31 @@ public class ProfilesManager { private static final String CACHE_PREFIX = "profiles::"; - private final Profiles profiles; private final ProfilesDynamoDb profilesDynamoDb; private final FaultTolerantRedisCluster cacheCluster; - private final DynamicConfigurationManager dynamicConfigurationManager; private final ObjectMapper mapper; - private final Experiment migrationExperiment = new Experiment("profileMigration"); - - public ProfilesManager(final Profiles profiles, - final ProfilesDynamoDb profilesDynamoDb, - final FaultTolerantRedisCluster cacheCluster, - final DynamicConfigurationManager dynamicConfigurationManager) { - this.profiles = profiles; + public ProfilesManager(final ProfilesDynamoDb profilesDynamoDb, final FaultTolerantRedisCluster cacheCluster) { this.profilesDynamoDb = profilesDynamoDb; this.cacheCluster = cacheCluster; - this.dynamicConfigurationManager = dynamicConfigurationManager; this.mapper = SystemMapper.getMapper(); } public void set(UUID uuid, VersionedProfile versionedProfile) { memcacheSet(uuid, versionedProfile); - profiles.set(uuid, versionedProfile); - - if (dynamicConfigurationManager.getConfiguration().getProfileMigrationConfiguration().isDynamoDbWriteEnabled()) { - profilesDynamoDb.set(uuid, versionedProfile); - } + profilesDynamoDb.set(uuid, versionedProfile); } public void deleteAll(UUID uuid) { memcacheDelete(uuid); - profiles.deleteAll(uuid); - - if (dynamicConfigurationManager.getConfiguration().getProfileMigrationConfiguration().isDynamoDbDeleteEnabled()) { - profilesDynamoDb.deleteAll(uuid); - } + profilesDynamoDb.deleteAll(uuid); } public Optional get(UUID uuid, String version) { Optional profile = memcacheGet(uuid, version); if (profile.isEmpty()) { - if (dynamicConfigurationManager.getConfiguration().getProfileMigrationConfiguration().isDynamoDbReadPrimary()) { - profile = profilesDynamoDb.get(uuid, version); - } else { - profile = profiles.get(uuid, version); - - if (dynamicConfigurationManager.getConfiguration().getProfileMigrationConfiguration().isDynamoDbReadForComparisonEnabled()) { - final Optional dynamoProfile = profilesDynamoDb.get(uuid, version); - migrationExperiment.compareSupplierResult(profile, () -> dynamoProfile); - - if (profile.isEmpty() && dynamoProfile.isPresent() && - dynamicConfigurationManager.getConfiguration().getProfileMigrationConfiguration().isLogMismatches()) { - logger.info("Profile {}/{} absent from relational database, but present in DynamoDB", uuid, version); - } - } - } - + profile = profilesDynamoDb.get(uuid, version); profile.ifPresent(versionedProfile -> memcacheSet(uuid, versionedProfile)); } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/mappers/VersionedProfileMapper.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/mappers/VersionedProfileMapper.java deleted file mode 100644 index 53f740b96..000000000 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/mappers/VersionedProfileMapper.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2013-2020 Signal Messenger, LLC - * SPDX-License-Identifier: AGPL-3.0-only - */ - -package org.whispersystems.textsecuregcm.storage.mappers; - -import java.sql.ResultSet; -import java.sql.SQLException; -import org.jdbi.v3.core.mapper.RowMapper; -import org.jdbi.v3.core.statement.StatementContext; -import org.whispersystems.textsecuregcm.storage.Profiles; -import org.whispersystems.textsecuregcm.storage.VersionedProfile; - -public class VersionedProfileMapper implements RowMapper { - - @Override - public VersionedProfile map(ResultSet resultSet, StatementContext ctx) throws SQLException { - return new VersionedProfile( - resultSet.getString(Profiles.VERSION), - resultSet.getString(Profiles.NAME), - resultSet.getString(Profiles.AVATAR), - resultSet.getString(Profiles.ABOUT_EMOJI), - resultSet.getString(Profiles.ABOUT), - resultSet.getString(Profiles.PAYMENT_ADDRESS), - resultSet.getBytes(Profiles.COMMITMENT)); - } -} diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/workers/DeleteUserCommand.java b/service/src/main/java/org/whispersystems/textsecuregcm/workers/DeleteUserCommand.java index 8f86a6e48..0fbf896d1 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/workers/DeleteUserCommand.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/workers/DeleteUserCommand.java @@ -49,7 +49,6 @@ import org.whispersystems.textsecuregcm.storage.MessagesCache; import org.whispersystems.textsecuregcm.storage.MessagesDynamoDb; import org.whispersystems.textsecuregcm.storage.MessagesManager; import org.whispersystems.textsecuregcm.storage.PhoneNumberIdentifiers; -import org.whispersystems.textsecuregcm.storage.Profiles; import org.whispersystems.textsecuregcm.storage.ProfilesDynamoDb; import org.whispersystems.textsecuregcm.storage.ProfilesManager; import org.whispersystems.textsecuregcm.storage.ReportMessageDynamoDb; @@ -177,7 +176,6 @@ public class DeleteUserCommand extends EnvironmentCommand jdbi.useHandle(handle -> handle.createUpdate("DELETE FROM profiles").execute())); - } - - @Override - protected ProfilesStore getProfilesStore() { - return profiles; - } -} diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/ProfilesManagerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/ProfilesManagerTest.java index b6b1a6d5a..aed7518e8 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/ProfilesManagerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/tests/storage/ProfilesManagerTest.java @@ -24,11 +24,7 @@ import java.util.Optional; import java.util.UUID; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicConfiguration; -import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicProfileMigrationConfiguration; import org.whispersystems.textsecuregcm.redis.FaultTolerantRedisCluster; -import org.whispersystems.textsecuregcm.storage.DynamicConfigurationManager; -import org.whispersystems.textsecuregcm.storage.Profiles; import org.whispersystems.textsecuregcm.storage.ProfilesDynamoDb; import org.whispersystems.textsecuregcm.storage.ProfilesManager; import org.whispersystems.textsecuregcm.storage.VersionedProfile; @@ -36,7 +32,7 @@ import org.whispersystems.textsecuregcm.tests.util.RedisClusterHelper; public class ProfilesManagerTest { - private Profiles profiles; + private ProfilesDynamoDb profiles; private RedisAdvancedClusterCommands commands; private ProfilesManager profilesManager; @@ -47,22 +43,9 @@ public class ProfilesManagerTest { commands = mock(RedisAdvancedClusterCommands.class); final FaultTolerantRedisCluster cacheCluster = RedisClusterHelper.buildMockRedisCluster(commands); - profiles = mock(Profiles.class); + profiles = mock(ProfilesDynamoDb.class); - @SuppressWarnings("unchecked") final DynamicConfigurationManager dynamicConfigurationManager = - mock(DynamicConfigurationManager.class); - - final DynamicConfiguration dynamicConfiguration = mock(DynamicConfiguration.class); - final DynamicProfileMigrationConfiguration profileMigrationConfiguration = - mock(DynamicProfileMigrationConfiguration.class); - - when(dynamicConfigurationManager.getConfiguration()).thenReturn(dynamicConfiguration); - when(dynamicConfiguration.getProfileMigrationConfiguration()).thenReturn(profileMigrationConfiguration); - - profilesManager = new ProfilesManager(profiles, - mock(ProfilesDynamoDb.class), - cacheCluster, - dynamicConfigurationManager); + profilesManager = new ProfilesManager(profiles, cacheCluster); } @Test