Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Update metrics and cache configurations

...

NameTypeUnitDescription
numCachedRecordGaugeRecordsThe number of records in cache.
numCachedBytesGaugeBytesThe number of bytes used by cache.
hitCountCounter
The number of cache hits
missCountCounter
The number of cache misses, which might leads to loading operations
numBytesLoadedTotalloadCountCounterBytes

The number of

bytes totally loaded to the cache
numRecordsLoadedTotalCounterRecords

times to load data into cache from external system.

For LRU cache the load count should be equal to miss count, but for all cache this would be different.

The number of records totally loaded to the cache

numLoadFailureCounter
The number of load failures
latestLoadTimeGaugemsThe time spent for the latest load operation

...

Code Block
languagejava
titleCacheMetricGroup
/** Pre-defined metrics for {@code Cache}. */
public interface CacheMetricGroup {

    /** The number of cache hits. */
    Counter getHitCounter();

    /** The number of cache misses. */
    Counter getMissCounter();

    /** The number of recordstimes totallyto loadedload todata theinto cache. */
from    Counter getNumRecordsLoadedTotalCounter();

    /** The number of bytes totally loaded to the cacheexternal system. */
    Counter getNumBytesLoadedTotalCountergetLoadCounter();

    /** The time spent for the latest load operation. */
    Gauge<Long> getLatestLoadTimeGauge();

    /** The number of load failures. */
    Counter getNumLoadFailureCounter();

    /** The number of records in cache. */
    void setNumCachedRecordsGauge(Gauge<Long> numCachedRecordsGauge);

    /** The number of bytes used by cache. */
    void setNumCachedBytesGauge(Gauge<Long> numCachedBytesGauge);
}

...

Code Block
languagejava
titleCacheConfig
@PublicEvolving
/**
 * Configuration for building caches.
 */
public class CacheConfig {

	// Type of the cachepublic class CacheConfig implements ReadableConfig, WritableConfig {

    private final Configuration configuration = new Configuration();

    public CacheConfig setCacheStrategy(CacheConfigOptions.CacheStrategy strategy) {
    private CacheType cacheType;

	// Time-to-live (TTL) of entries in cache
    private Duration ttl;

	// Maximum number of entries that the cache could contain
    private long maxSize; 

    // Whether to allow empty values associated with a key in the cache
    private boolean allowEmptyValues;

	/**
     * Type of the cache.
     *
     * <ul>
     *   <li>ALL: Load all entries when initializing the cache.
     *   <li>LRU: A capacity limited cache with least-recent-use(LRU) evicting strategy.
     *   <li>NONE: A cache storing nothing.
     * </ul>
     */
	public enum CacheType configuration.set(CacheConfigOptions.CACHE_STRATEGY, strategy);
        return this;
    }

    public CacheConfig setTTL(Duration ttl) {
        configuration.set(CacheConfigOptions.CACHE_TTL, ttl);
        return this;
    }

    public CacheConfig setMaxEntries(long maxEntries) {
        configuration.set(CacheConfigOptions.CACHE_MAX_ENTRIES, maxEntries);
        return this;
    }

    public CacheConfig setAllowEmptyValues(boolean allowEmptyValues) {
        configuration.set(CacheConfigOptions.CACHE_ALLOW_EMPTY_VALUES, allowEmptyValues);
        return this;
    }

    @Override
    public <T> T get(ConfigOption<T> option) {
        return configuration.get(option);
    }

    @Override
    public <T> Optional<T> getOptional(ConfigOption<T> option) {
        return configuration.getOptional(option);
    }

    @Override
    public <T> WritableConfig set(ConfigOption<T> option, T value) {
        return configuration.set(option, value);
    }
}  

Cache Options

Code Block
languagejava
titleCacheConfigOptions
public class CacheConfigOptions {

    public static final ConfigOption<CacheStrategy> CACHE_STRATEGY =
            ConfigOptions.key("lookup.cache.strategy")
                    .enumType(CacheStrategy.class)
                    .noDefaultValue()
                    .withDescription(
                            "Strategy of the cache to load and evict entries, including ALL, LRU and NONE");

    public static final ConfigOption<Duration> CACHE_TTL =
            ConfigOptions.key("lookup.cache.ttl")
                    .durationType()
                    .noDefaultValue()
                    .withDescription("Time-to-live (TTL) of entries in cache");

    public static final ConfigOption<Long> CACHE_MAX_ENTRIES =
            ConfigOptions.key("lookup.cache.max-entries")
                    .longType()
                    .noDefaultValue()
                    .withDescription("The maximum number of entries that the cache could contain");

    public static final ConfigOption<Boolean> CACHE_ALLOW_EMPTY_VALUES =
            ConfigOptions.key("lookup.cache.allow-empty-values")
                    .booleanType()
                    .noDefaultValue()
                    .withDescription(
                            "Whether to allow empty values associated with a key in the cache");

    public enum CacheStrategy {
        ALL,
        LRU,
        NONE
    }
}

CachingTableFunction

A helper TableFunction with a default or a custom cache implementation.

...