Class StandardCacheBucket

  • All Implemented Interfaces:
    CacheBucket

    public class StandardCacheBucket
    extends java.lang.Object
    implements CacheBucket
    • Constructor Detail

      • StandardCacheBucket

        public StandardCacheBucket​(SubCache parent,
                                   long start,
                                   long end)
        Creates a new bucket that represents the time, and the parameters inherited from SubCache.
    • Method Detail

      • getLogger

        protected org.apache.log4j.Logger getLogger()
      • isDataNull

        public boolean isDataNull()
      • isValid

        public boolean isValid()
        Description copied from interface: CacheBucket
        Indicates that the bucket is still valid and hasn't been ejected. Ejected buckets can still return good data, but they shouldn't be used much and should be removed when possible.
        Specified by:
        isValid in interface CacheBucket
      • getRelevencyScore

        public double getRelevencyScore()
        Description copied from interface: CacheBucket
        The score of how "important" this bucket is, so that it can be ranked against other buckets.
        Specified by:
        getRelevencyScore in interface CacheBucket
      • calculateRelevency

        public void calculateRelevency()
        This where we look at our statistics and calculate how important this bucket is.
        The parameters we have to work with:
        • Fetch time - how long the data took to load. Each time, we calculate a deviation from a moving average, so its weight is relative to the overall performance of the system.
        • Hit Count - how many times the bucket has been hit. Important to show more frequently used buckets
        • Hit rating - how closely the hits are following a pattern.
        • Last hit time - how long ago we got a hit.
        • Data size - how much space the bucket is taking.
        Of these, hit count seems the most important. However, we don't want a case where we get a large set, use it for a long time, and then stop- and it stays in memory blocking new buckets forever, just because it was highly used once. In this case, a strong deviation from the pattern should hurt the score a lot.

        So basically, we want to assign points based on various properties, and then give a bonus- positive or negative, for the hit pattern.

        Specified by:
        calculateRelevency in interface CacheBucket
      • updateHitCount

        protected void updateHitCount()
      • getMemorySize

        public int getMemorySize()
        Returns a very rough approximation of memory requirement.
        Specified by:
        getMemorySize in interface CacheBucket
      • getData

        public Dataset getData​(TagHistoryQueryProvider backingProvider)
                        throws java.lang.Exception
        Description copied from interface: CacheBucket
        Returns the cached data, or goes to the store and retrieves it.
        Specified by:
        getData in interface CacheBucket
        Throws:
        java.lang.Exception
      • loadData

        protected Dataset loadData​(TagHistoryQueryProvider backingProvider)
                            throws java.lang.Exception
        Loads the data from
        Throws:
        java.lang.Exception
      • validateData

        protected void validateData()
        This function looks at the data that was loaded and adjusts the blocks validity and coverage size.

        This is necessary because we don't want to cache data that might change on the backend. That kind of thing can happen when the query range extends into the future, or when data is backfilled from the store and forward system.

        This seems like a tricky thing to get right, and something that could impact performance a lot. We need a fast way to detect what data should be discarded. This current implementation does a binary search to find the last row of data with all "good" quality.

      • hits

        public boolean hits​(long time)
      • isProvisional

        public boolean isProvisional()
      • eject

        public boolean eject()
        Tells the bucket that the cache would like to eject it. If the bucket cannot be ejected, because it's in use, it can return false. If it can be ejected, the bucket will release its data and will notify its subcache.
        Specified by:
        eject in interface CacheBucket
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • resetStats

        public static void resetStats()