From 4d706a6a8f93be2d3d3621b4c8940f4968db199c Mon Sep 17 00:00:00 2001 From: ZMai <zmai@slb.com> Date: Wed, 28 Jun 2023 16:00:22 -0500 Subject: [PATCH] Implement Redis cache in Azure for two kinds of object caches that are required to be synchronized across the indexer service --- .../osdu/indexer/model/Constants.java | 4 ++-- .../cache/RecordChangeInfoRedisCache.java | 23 +++++++++++++++++++ .../azure/cache/RelatedObjectRedisCache.java | 23 +++++++++++++++++++ .../osdu/indexer/azure/di/RedisConfig.java | 9 ++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/RecordChangeInfoRedisCache.java create mode 100644 provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/RelatedObjectRedisCache.java diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/Constants.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/Constants.java index 91017c2fe..2153c214c 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/Constants.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/Constants.java @@ -21,9 +21,9 @@ public class Constants { // Specifications using kind as key is not partition safe if the specifications are per data partition public static final int SPEC_CACHE_EXPIRATION = 600; - public static final int SPEC_MAX_CACHE_SIZE = 2000; + public static final int SPEC_MAX_CACHE_SIZE = 20000; // Data id itself is partition safe public static final int DATA_CACHE_EXPIRATION = 120; - public static final int DATA_MAX_CACHE_SIZE = 2000; + public static final int DATA_MAX_CACHE_SIZE = 20000; } diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/RecordChangeInfoRedisCache.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/RecordChangeInfoRedisCache.java new file mode 100644 index 000000000..ce6467290 --- /dev/null +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/RecordChangeInfoRedisCache.java @@ -0,0 +1,23 @@ +package org.opengroup.osdu.indexer.azure.cache; + +import org.opengroup.osdu.core.common.cache.RedisCache; +import org.opengroup.osdu.indexer.cache.IRecordChangeInfoCache; +import org.opengroup.osdu.indexer.model.RecordChangeInfo; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.stereotype.Component; + +import javax.inject.Named; + +@Component +@ConditionalOnProperty(value = "runtime.env.local", havingValue = "false", matchIfMissing = true) +public class RecordChangeInfoRedisCache extends RedisCache<String, RecordChangeInfo> implements IRecordChangeInfoCache { + public RecordChangeInfoRedisCache(final @Named("REDIS_HOST") String host, + final @Named("REDIS_PORT") int port, + final @Named("REDIS_PASSWORD") String password, + final @Named("RECORDS_REDIS_TTL") int timeout, + @Qualifier("") @Value("${redis.database}") final int database) { + super(host, port, password, timeout, database, String.class, RecordChangeInfo.class); + } +} diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/RelatedObjectRedisCache.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/RelatedObjectRedisCache.java new file mode 100644 index 000000000..e36c071c5 --- /dev/null +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/RelatedObjectRedisCache.java @@ -0,0 +1,23 @@ +package org.opengroup.osdu.indexer.azure.cache; + +import org.opengroup.osdu.core.common.cache.RedisCache; +import org.opengroup.osdu.core.common.model.storage.RecordData; +import org.opengroup.osdu.indexer.cache.IRelatedObjectCache; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.stereotype.Component; + +import javax.inject.Named; + +@Component +@ConditionalOnProperty(value = "runtime.env.local", havingValue = "false", matchIfMissing = true) +public class RelatedObjectRedisCache extends RedisCache<String, RecordData> implements IRelatedObjectCache { + public RelatedObjectRedisCache(final @Named("REDIS_HOST") String host, + final @Named("REDIS_PORT") int port, + final @Named("REDIS_PASSWORD") String password, + final @Named("RECORDS_REDIS_TTL") int timeout, + @Qualifier("") @Value("${redis.database}") final int database) { + super(host, port, password, timeout, database, String.class, RecordData.class); + } +} diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/RedisConfig.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/RedisConfig.java index 6b98eb7ce..8ed9134f0 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/RedisConfig.java +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/RedisConfig.java @@ -38,6 +38,9 @@ public class RedisConfig { @Value("${redis.schema.ttl:3600}") public int schemaTtl; + @Value("${redis.records.ttl:120}") + public int recordsTtl; + @Bean @Named("REDIS_PORT") public int getRedisPort() { @@ -62,6 +65,12 @@ public class RedisConfig { return schemaTtl; } + @Bean + @Named("RECORDS_REDIS_TTL") + public int getRecordsRedisTtl() { + return recordsTtl; + } + @Bean @Named("REDIS_HOST") public String redisHost(SecretClient kv) { -- GitLab