Skip to content

Commit

Permalink
ADAPT-1433 Adjust cache mechanism within applications
Browse files Browse the repository at this point in the history
*added a redis ssl config parameter
  • Loading branch information
Mykola Nikulesko committed Sep 6, 2023
1 parent 350e7ae commit 1ec670d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ object RedisSchemaRegistryClient {
.getOrElse(throw new IllegalArgumentException(s"A $path is required."))
}

private def readSslConfigParameter(config: Config, path: String): Boolean = {
config.getBooleanOpt(path).getOrElse(true)
}

def registryUrl(config: Config): String =
readStringConfigParameter(config, "schema.registry.url")

Expand All @@ -145,14 +149,15 @@ object RedisSchemaRegistryClient {
val redisIdCacheTtl = readIntConfigParameter(config, "schema.registry.redis.id-cache-ttl")
val redisSchemaCacheTtl = readIntConfigParameter(config, "schema.registry.redis.schema-cache-ttl")
val redisVersionCacheTtl = readIntConfigParameter(config, "schema.registry.redis.version-cache-ttl")
val useSSL = readSslConfigParameter(config, "schema.registry.redis.ssl")

val client = new RedisSchemaRegistryClient(
baseUrl,
redisHost,
redisPort,
schemaRegistrySecurityConfig.toConfigMap,
CacheConfigs(redisIdCacheTtl, redisSchemaCacheTtl, redisVersionCacheTtl),
true
useSSL
)

new SchemaRegistryComponent {
Expand Down Expand Up @@ -564,13 +569,12 @@ class RedisSchemaRegistryClient(restService: RestService,
}

override def register(s: String, schema: Schema, i: Int, i1: Int): Int = synchronized {
def register(): Int = Try {
def register(): Int =
if (i >= 0) {
restService.registerSchema(schema.toString(), s, i, i1)
} else {
restService.registerSchema(schema.toString(), s)
}
}.getOrElse(-1)

if(DO_NOT_CACHE_LIST.exists(s.startsWith)) {
register()
Expand Down
3 changes: 2 additions & 1 deletion avro/src/main/scala/hydra/avro/registry/SchemaRegistry.scala
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ object SchemaRegistry {
securityConfig: SchemaRegistrySecurityConfig,
redisUrl: String,
redisPort: Int,
ssl: Boolean,
idCacheTtl: Int,
schemaCacheTtl: Int,
versionCacheTtl: Int,
Expand All @@ -168,7 +169,7 @@ object SchemaRegistry {
redisPort,
securityConfig.toConfigMap,
CacheConfigs(idCacheTtl, schemaCacheTtl, versionCacheTtl),
true
ssl
),
schemaRegistryClientRetries,
schemaRegistryClientRetriesDelay
Expand Down
4 changes: 4 additions & 0 deletions ingest/src/main/scala/hydra.ingest/app/AppConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ object AppConfig {
final case class SchemaRegistryRedisConfig(
redisUrl: String,
redisPort: Int,
ssl: Boolean,
idCacheTtl: Int = 1,
schemaCacheTtl: Int = 1,
versionCacheTtl: Int = 1,
Expand All @@ -48,6 +49,9 @@ object AppConfig {
env("HYDRA_SCHEMA_REGISTRY_REDIS_PORT")
.as[Int]
.default(6379),
env("HYDRA_SCHEMA_REGISTRY_USE_SSL")
.as[Boolean]
.default(true),
env("HYDRA_SCHEMA_REGISTRY_REDIS_ID_CACHE_TTL")
.as[Int]
.default(1),
Expand Down
1 change: 1 addition & 0 deletions ingest/src/main/scala/hydra.ingest/modules/Algebras.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ object Algebras {
config.schemaRegistrySecurityConfig,
config.schemaRegistryRedisConfig.redisUrl,
config.schemaRegistryRedisConfig.redisPort,
config.schemaRegistryRedisConfig.ssl,
config.schemaRegistryRedisConfig.idCacheTtl,
config.schemaRegistryRedisConfig.schemaCacheTtl,
config.schemaRegistryRedisConfig.versionCacheTtl,
Expand Down

0 comments on commit 1ec670d

Please sign in to comment.