diff --git a/config-service-impl/src/main/java/org/hypertrace/config/service/ConfigServiceGrpcImpl.java b/config-service-impl/src/main/java/org/hypertrace/config/service/ConfigServiceGrpcImpl.java index 053ad6d1..9d85dc2d 100644 --- a/config-service-impl/src/main/java/org/hypertrace/config/service/ConfigServiceGrpcImpl.java +++ b/config-service-impl/src/main/java/org/hypertrace/config/service/ConfigServiceGrpcImpl.java @@ -1,6 +1,5 @@ package org.hypertrace.config.service; -import static org.hypertrace.config.service.ConfigServiceUtils.emptyValue; import static org.hypertrace.config.service.ConfigServiceUtils.filterNull; import static org.hypertrace.config.service.ConfigServiceUtils.merge; @@ -134,7 +133,7 @@ public void deleteConfig( } // write an empty config for the specified config resource. This maintains the versioning. - configStore.writeConfig(configResourceContext, getUserId(), emptyValue()); + configStore.deleteConfigs(List.of(configResourceContext)); responseObserver.onNext( DeleteConfigResponse.newBuilder().setDeletedConfig(configToDelete).build()); responseObserver.onCompleted(); @@ -155,22 +154,19 @@ public void deleteConfigs( .asException()); return; } - Map valuesByContext = + + List valuesToDelete = request.getConfigsList().stream() - .map( - requestedDelete -> - Map.entry(this.getConfigResourceContext(requestedDelete), emptyValue())) - .collect(ImmutableMap.toImmutableMap(Entry::getKey, Entry::getValue)); + .map(this::getConfigResourceContext) + .collect(Collectors.toUnmodifiableList()); - List deletedConfigs = - configStore.writeAllConfigs(valuesByContext, getUserId()); + Map configsToDelete = + configStore.getContextConfigs(valuesToDelete); + configStore.deleteConfigs(configsToDelete.keySet()); responseObserver.onNext( DeleteConfigsResponse.newBuilder() - .addAllDeletedConfigs( - deletedConfigs.stream() - .map(this::buildDeletedContextSpecificConfig) - .collect(Collectors.toUnmodifiableList())) + .addAllDeletedConfigs(configsToDelete.values()) .build()); responseObserver.onCompleted(); } catch (Exception e) { @@ -179,15 +175,6 @@ public void deleteConfigs( } } - private ContextSpecificConfig buildDeletedContextSpecificConfig(UpsertedConfig deletedConfig) { - return ContextSpecificConfig.newBuilder() - .setContext(deletedConfig.getContext()) - .setCreationTimestamp(deletedConfig.getCreationTimestamp()) - .setUpdateTimestamp(deletedConfig.getUpdateTimestamp()) - .setConfig(deletedConfig.getPrevConfig()) - .build(); - } - @Override public void upsertAllConfigs( UpsertAllConfigsRequest request, StreamObserver responseObserver) { diff --git a/config-service-impl/src/main/java/org/hypertrace/config/service/store/ConfigStore.java b/config-service-impl/src/main/java/org/hypertrace/config/service/store/ConfigStore.java index 6000431c..8c9e493a 100644 --- a/config-service-impl/src/main/java/org/hypertrace/config/service/store/ConfigStore.java +++ b/config-service-impl/src/main/java/org/hypertrace/config/service/store/ConfigStore.java @@ -3,6 +3,7 @@ import com.google.protobuf.Value; import com.typesafe.config.Config; import java.io.IOException; +import java.util.Collection; import java.util.List; import java.util.Map; import org.hypertrace.config.service.ConfigResource; @@ -34,6 +35,8 @@ public interface ConfigStore { UpsertedConfig writeConfig( ConfigResourceContext configResourceContext, String userId, Value config) throws IOException; + void deleteConfigs(Collection resourceContextCollection); + /** * Get the config with the latest version for the specified resource. * @@ -52,6 +55,9 @@ UpsertedConfig writeConfig( */ List getAllConfigs(ConfigResource configResource) throws IOException; + Map getContextConfigs( + Collection configResourceContexts) throws IOException; + /** * Write each of the provided config value associated with the specified config resource to the * store. diff --git a/config-service-impl/src/main/java/org/hypertrace/config/service/store/DocumentConfigStore.java b/config-service-impl/src/main/java/org/hypertrace/config/service/store/DocumentConfigStore.java index 9da55a64..203c136c 100644 --- a/config-service-impl/src/main/java/org/hypertrace/config/service/store/DocumentConfigStore.java +++ b/config-service-impl/src/main/java/org/hypertrace/config/service/store/DocumentConfigStore.java @@ -8,6 +8,7 @@ import static org.hypertrace.config.service.store.ConfigDocument.TENANT_ID_FIELD_NAME; import static org.hypertrace.config.service.store.ConfigDocument.VERSION_FIELD_NAME; +import com.google.common.collect.Maps; import com.google.protobuf.Value; import com.typesafe.config.Config; import io.grpc.Status; @@ -20,6 +21,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -90,6 +92,22 @@ public UpsertedConfig writeConfig( .orElseGet(() -> this.buildUpsertResult(latestConfigDocument)); } + @Override + public void deleteConfigs(java.util.Collection resourceContextCollection) { + collection.delete( + resourceContextCollection.stream().map(ConfigDocumentKey::new).collect(Collectors.toSet())); + } + + @Override + public Map getContextConfigs( + java.util.Collection configResourceContexts) throws IOException { + return Maps.filterValues( + Maps.transformValues( + getLatestVersionConfigDocs(configResourceContexts), + doc -> doc.flatMap(this::convertToContextSpecificConfig).orElse(null)), + Objects::nonNull); + } + private List writeConfigs( Map resourceContextValueMap, String userId) throws IOException { Map> previousConfigDocs = @@ -212,7 +230,7 @@ private Optional getLatestVersionConfigDoc( } private Map> getLatestVersionConfigDocs( - Set configResourceContexts) throws IOException { + java.util.Collection configResourceContexts) throws IOException { if (configResourceContexts.isEmpty()) { return Collections.emptyMap(); }