From 7a48740b659712274d65a6459f7d8c4231630367 Mon Sep 17 00:00:00 2001 From: Robert Stupp Date: Tue, 15 Oct 2024 14:19:04 +0200 Subject: [PATCH] Persist: Enable reference-cache by default Default cache TTL is 5 minutes. --- CHANGELOG.md | 10 +++++++ .../providers/storage/PersistProvider.java | 13 +++++----- .../quarkus/config/QuarkusStoreConfig.java | 3 ++- .../src/main/resources/application.properties | 5 ++++ .../storage/common/config/StoreConfig.java | 26 ++++++++----------- 5 files changed, 34 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b1ba0df82c..c1ada5de8dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,11 @@ as necessary. Empty sections will not end in the release notes. Furthermore, Sentry integration can also be enabled and configured. And finally, it is now possible to configure the log level for specific loggers, not just the root logger. The old `logLevel` field is still supported, but will be removed in a future release. +- If you are not using k8s and you are running Nessie with multiple nodes, you must either + * configure `nessie.version.store.persist.cache-invalidations.service-names`, see + [docs reference](https://projectnessie.org/nessie-latest/configuration/#version-store-advanced-settings), + or + * disable the reference cache by setting `nessie.version.store.persist.reference-cache-ttl` to `PT0S`. ### Breaking changes @@ -35,6 +40,11 @@ as necessary. Empty sections will not end in the release notes. * `py-io-impl=pyiceberg.io.fsspec.FsspecFileIO` * `s3.signer=S3V4RestSigner` when S3 signing is being used - Iceberg REST: No longer return `*FileIO` options from the Iceberg REST config endpoint +- The reference-cache is now enabled by default with a TTL of 5 minutes for both cached entries + and negative entries. Updated references are invalidated across all Nessie nodes, which works + out of the box in k8s setups. Other multi-node Nessie setups need to configure + `nessie.version.store.persist.cache-invalidations.service-names`, see + [docs reference](https://projectnessie.org/nessie-latest/configuration/#version-store-advanced-settings). ### Deprecations diff --git a/servers/quarkus-common/src/main/java/org/projectnessie/quarkus/providers/storage/PersistProvider.java b/servers/quarkus-common/src/main/java/org/projectnessie/quarkus/providers/storage/PersistProvider.java index d1a0609cb7a..16c67806381 100644 --- a/servers/quarkus-common/src/main/java/org/projectnessie/quarkus/providers/storage/PersistProvider.java +++ b/servers/quarkus-common/src/main/java/org/projectnessie/quarkus/providers/storage/PersistProvider.java @@ -149,15 +149,14 @@ public CacheBackend produceCacheBackend( cacheConfig.meterRegistry(meterRegistry.get()); } - Optional referenceCacheTtl = storeConfig.referenceCacheTtl(); + Duration referenceCacheTtl = storeConfig.referenceCacheTtl(); Optional referenceCacheNegativeTtl = storeConfig.referenceCacheNegativeTtl(); - if (referenceCacheTtl.isPresent()) { - Duration refTtl = referenceCacheTtl.get(); - LOGGER.warn( - "Reference caching is an experimental feature but enabled with a TTL of {}", refTtl); - cacheConfig.referenceTtl(refTtl); - cacheConfig.referenceNegativeTtl(referenceCacheNegativeTtl.orElse(refTtl)); + if (referenceCacheTtl + .isPositive()) { // allow disabling the reference-cache by setting the TTL to 0 + LOGGER.info("Reference caching is enabled with a TTL of {}", referenceCacheTtl); + cacheConfig.referenceTtl(referenceCacheTtl); + cacheConfig.referenceNegativeTtl(referenceCacheNegativeTtl.orElse(referenceCacheTtl)); } String info = format("Using objects cache with %d MB", effectiveCacheSizeMB); diff --git a/servers/quarkus-config/src/main/java/org/projectnessie/quarkus/config/QuarkusStoreConfig.java b/servers/quarkus-config/src/main/java/org/projectnessie/quarkus/config/QuarkusStoreConfig.java index 6d3bef2973d..6fc79042671 100644 --- a/servers/quarkus-config/src/main/java/org/projectnessie/quarkus/config/QuarkusStoreConfig.java +++ b/servers/quarkus-config/src/main/java/org/projectnessie/quarkus/config/QuarkusStoreConfig.java @@ -150,8 +150,9 @@ public interface QuarkusStoreConfig extends StoreConfig { OptionalInt cacheCapacityFractionAdjustMB(); @WithName(CONFIG_REFERENCE_CACHE_TTL) + @WithDefault(DEFAULT_REFERENCE_CACHE_TTL) @Override - Optional referenceCacheTtl(); + Duration referenceCacheTtl(); @WithName(CONFIG_REFERENCE_NEGATIVE_CACHE_TTL) @Override diff --git a/servers/quarkus-server/src/main/resources/application.properties b/servers/quarkus-server/src/main/resources/application.properties index 3aff878ec44..878d0c43c20 100644 --- a/servers/quarkus-server/src/main/resources/application.properties +++ b/servers/quarkus-server/src/main/resources/application.properties @@ -194,6 +194,11 @@ nessie.version.store.type=IN_MEMORY # Settings this value to 0 disables the fixed size object cache. # Entirely disabling the cache is not recommended and will negatively affect performance. #nessie.version.store.persist.cache-capacity-mb=0 +# +# Reference cache default TTL is 5 minutes. +nessie.version.store.persist.reference-cache-ttl=PT5M +# negative cache TTL defaults to nessie.version.store.persist.reference-cache-ttl +# nessie.version.store.persist.reference-cache-negative-ttl=PT5M ## Transactional database configuration diff --git a/versioned/storage/common/src/main/java/org/projectnessie/versioned/storage/common/config/StoreConfig.java b/versioned/storage/common/src/main/java/org/projectnessie/versioned/storage/common/config/StoreConfig.java index ad83572ff37..3f1b8142fb9 100644 --- a/versioned/storage/common/src/main/java/org/projectnessie/versioned/storage/common/config/StoreConfig.java +++ b/versioned/storage/common/src/main/java/org/projectnessie/versioned/storage/common/config/StoreConfig.java @@ -70,6 +70,7 @@ public interface StoreConfig { long DEFAULT_PREVIOUS_HEAD_TIME_SPAN_SECONDS = 5 * 60; String CONFIG_REFERENCE_CACHE_TTL = "reference-cache-ttl"; + String DEFAULT_REFERENCE_CACHE_TTL = "PT5M"; String CONFIG_REFERENCE_NEGATIVE_CACHE_TTL = "reference-cache-negative-ttl"; @@ -258,35 +259,30 @@ default long referencePreviousHeadTimeSpanSeconds() { } /** - * Defines the duration how long references shall be kept in the cache. Defaults to not cache - * references. If reference caching is enabled, it is highly recommended to also enable negative - * reference caching. - * - *

It is safe to enable this for single node Nessie deployments. + * Defines the duration how long references shall be kept in the cache. Defaults is {@value + * #DEFAULT_REFERENCE_CACHE_TTL}, set to {@code PT0M} to disable. If reference caching is enabled, + * it is highly recommended to also enable negative reference caching. * *

Recommended value is currently {@code PT5M} for distributed and high values like {@code * PT1H} for single node Nessie deployments. - * - *

This feature is experimental except for single Nessie node deployments! If in doubt, - * leave this un-configured! */ - Optional referenceCacheTtl(); + @Value.Default + default Duration referenceCacheTtl() { + return Duration.parse(DEFAULT_REFERENCE_CACHE_TTL); + } /** * Defines the duration how long sentinels for non-existing references shall be kept in the cache * (negative reference caching). * *

Defaults to {@code reference-cache-ttl}. Has no effect, if {@code reference-cache-ttl} is - * not configured. Default is not enabled. If reference caching is enabled, it is highly - * recommended to also enable negative reference caching. + * not a positive value. If reference caching is enabled, it is highly recommended to also enable + * negative reference caching. * *

It is safe to enable this for single node Nessie deployments. * *

Recommended value is currently {@code PT5M} for distributed and high values like {@code * PT1H} for single node Nessie deployments. - * - *

This feature is experimental except for single Nessie node deployments! If in doubt, - * leave this un-configured! */ Optional referenceCacheNegativeTtl(); @@ -432,6 +428,6 @@ default Adjustable fromFunction(Function configFunction) { Adjustable withReferenceCacheTtl(Duration referenceCacheTtl); /** See {@link StoreConfig#referenceCacheNegativeTtl()}. */ - Adjustable withReferenceCacheNegativeTtl(Duration referencecacheNegativeTtl); + Adjustable withReferenceCacheNegativeTtl(Duration referenceCacheNegativeTtl); } }