Class StandardCacheBucket
- java.lang.Object
-
- com.inductiveautomation.ignition.common.sqltags.history.cache.StandardCacheBucket
-
- All Implemented Interfaces:
CacheBucket
public class StandardCacheBucket extends java.lang.Object implements CacheBucket
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
StandardCacheBucket.HitStatistics
-
Constructor Summary
Constructors Constructor Description StandardCacheBucket(SubCache parent, long start, long end)
Creates a new bucket that represents the time, and the parameters inherited from SubCache.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.boolean
eject()
Tells the bucket that the cache would like to eject it.Dataset
getData(TagHistoryQueryProvider backingProvider)
Returns the cached data, or goes to the store and retrieves it.long
getEndTime()
StandardCacheBucket.HitStatistics
getHitStatistics()
protected org.apache.log4j.Logger
getLogger()
int
getMemorySize()
Returns a very rough approximation of memory requirement.double
getRelevencyScore()
The score of how "important" this bucket is, so that it can be ranked against other buckets.long
getStartTime()
boolean
hits(long time)
boolean
isDataNull()
boolean
isProvisional()
boolean
isValid()
Indicates that the bucket is still valid and hasn't been ejected.protected Dataset
loadData(TagHistoryQueryProvider backingProvider)
Loads the data fromstatic void
resetStats()
java.lang.String
toString()
protected void
updateHitCount()
protected void
validateData()
This function looks at the data that was loaded and adjusts the blocks validity and coverage size.
-
-
-
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()
-
getHitStatistics
public StandardCacheBucket.HitStatistics getHitStatistics()
-
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 interfaceCacheBucket
-
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 interfaceCacheBucket
-
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.
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 interfaceCacheBucket
-
updateHitCount
protected void updateHitCount()
-
getMemorySize
public int getMemorySize()
Returns a very rough approximation of memory requirement.- Specified by:
getMemorySize
in interfaceCacheBucket
-
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 interfaceCacheBucket
- 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.
-
getStartTime
public long getStartTime()
- Specified by:
getStartTime
in interfaceCacheBucket
-
getEndTime
public long getEndTime()
- Specified by:
getEndTime
in interfaceCacheBucket
-
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 interfaceCacheBucket
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
resetStats
public static void resetStats()
-
-