Class SegmentCacheIndexImpl
- java.lang.Object
-
- mondrian.rolap.cache.SegmentCacheIndexImpl
-
- All Implemented Interfaces:
SegmentCacheIndex
public class SegmentCacheIndexImpl extends Object implements SegmentCacheIndex
Data structure that identifies which segments contain cells.Not thread safe.
- Author:
- Julian Hyde
-
-
Constructor Summary
Constructors Constructor Description SegmentCacheIndexImpl(Thread thread)Creates a SegmentCacheIndexImpl.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(SegmentHeader header, SegmentBuilder.SegmentConverter converter, boolean loading)Adds a header to the index.voidcancel(Execution exec)This method must remove all registrations as a client for the given execution.booleancontains(SegmentHeader header)Tells whether or not a given segment is known to this index.List<List<SegmentHeader>>findRollupCandidates(String schemaName, ByteString schemaChecksum, String cubeName, String measureName, String rolapStarFactTableName, BitKey constrainedColsBitKey, Map<String,Comparable> coordinates, List<String> compoundPredicates)Returns a list of segments that can be rolled up to satisfy a given cell request.SegmentBuilder.SegmentConvertergetConverter(String schemaName, ByteString schemaChecksum, String cubeName, String rolapStarFactTableName, String measureName, List<String> compoundPredicates)Returns a converter that can convert the given header to internal format.Future<SegmentBody>getFuture(Execution exec, SegmentHeader header)Returns a future slot for a segment body, if a segment is currently loading, otherwise null.List<SegmentHeader>intersectRegion(String schemaName, ByteString schemaChecksum, String cubeName, String measureName, String rolapStarFactTableName, SegmentColumn[] region)Finds a list of headers that intersect a given region.voidlinkSqlStatement(SegmentHeader header, Statement stmt)Allows to link aStatementto a segment.voidloadFailed(SegmentHeader header, Throwable throwable)Notifies the segment index that a segment failed to load, and removes the segment from the index.voidloadSucceeded(SegmentHeader header, SegmentBody body)Changes the state of a header from loading to loaded.List<SegmentHeader>locate(String schemaName, ByteString schemaChecksum, String cubeName, String measureName, String rolapStarFactTableName, BitKey constrainedColsBitKey, Map<String,Comparable> coordinates, List<String> compoundPredicates)Identifies the segment headers that contain a given cell.static ListmakeConverterKey(CellRequest request, AggregationKey key)static ListmakeConverterKey(SegmentHeader header)static booleanmatches(SegmentHeader header, Map<String,Comparable> coords, List<String> compoundPredicates)voidprintCacheState(PrintWriter pw)Prints the state of the cache to the given writer.voidremove(SegmentHeader header)Removes a header from the index.voidsetConverter(String schemaName, ByteString schemaChecksum, String cubeName, String rolapStarFactTableName, String measureName, List<String> compoundPredicates, SegmentBuilder.SegmentConverter converter)Sets a converter that can convert headers in for a given measure to internal format.voidupdate(SegmentHeader oldHeader, SegmentHeader newHeader)Updates a header in the index.
-
-
-
Constructor Detail
-
SegmentCacheIndexImpl
public SegmentCacheIndexImpl(Thread thread)
Creates a SegmentCacheIndexImpl.- Parameters:
thread- Thread that must be used to execute commands.
-
-
Method Detail
-
makeConverterKey
public static List makeConverterKey(SegmentHeader header)
-
makeConverterKey
public static List makeConverterKey(CellRequest request, AggregationKey key)
-
locate
public List<SegmentHeader> locate(String schemaName, ByteString schemaChecksum, String cubeName, String measureName, String rolapStarFactTableName, BitKey constrainedColsBitKey, Map<String,Comparable> coordinates, List<String> compoundPredicates)
Description copied from interface:SegmentCacheIndexIdentifies the segment headers that contain a given cell.- Specified by:
locatein interfaceSegmentCacheIndex- Parameters:
schemaName- Schema nameschemaChecksum- Schema checksumcubeName- Cube namemeasureName- Measure namerolapStarFactTableName- Fact table tableconstrainedColsBitKey- Bit keycoordinates- CoordinatescompoundPredicates- Compound predicates- Returns:
- Empty list if not found; never null
-
add
public void add(SegmentHeader header, SegmentBuilder.SegmentConverter converter, boolean loading)
Description copied from interface:SegmentCacheIndexAdds a header to the index.- Specified by:
addin interfaceSegmentCacheIndex- Parameters:
header- Segment headerconverter- Segment converterloading- Whether segment is pending a load from SQL
-
update
public void update(SegmentHeader oldHeader, SegmentHeader newHeader)
Description copied from interface:SegmentCacheIndexUpdates a header in the index. This is required when some of the excluded regions have changed.- Specified by:
updatein interfaceSegmentCacheIndex- Parameters:
oldHeader- The old header to replace.newHeader- The new header to use instead.
-
loadSucceeded
public void loadSucceeded(SegmentHeader header, SegmentBody body)
Description copied from interface:SegmentCacheIndexChanges the state of a header from loading to loaded.The segment must have previously been added by calling
SegmentCacheIndex.add(mondrian.spi.SegmentHeader, mondrian.rolap.agg.SegmentBuilder.SegmentConverter, boolean)with a not-null value of thebodyFutureparameter; neitherloadSucceedednorSegmentCacheIndex.loadFailed(mondrian.spi.SegmentHeader, java.lang.Throwable)must have been called.Informs anyone waiting on the future supplied with
SegmentCacheIndex.add(mondrian.spi.SegmentHeader, mondrian.rolap.agg.SegmentBuilder.SegmentConverter, boolean).- Specified by:
loadSucceededin interfaceSegmentCacheIndex- Parameters:
header- Segment headerbody- Segment body
-
loadFailed
public void loadFailed(SegmentHeader header, Throwable throwable)
Description copied from interface:SegmentCacheIndexNotifies the segment index that a segment failed to load, and removes the segment from the index.The segment must have previously been added using
SegmentCacheIndex.add(mondrian.spi.SegmentHeader, mondrian.rolap.agg.SegmentBuilder.SegmentConverter, boolean)with a not-null value of thebodyFutureparameter; neitherSegmentCacheIndex.loadSucceeded(mondrian.spi.SegmentHeader, mondrian.spi.SegmentBody)norloadFailedmust have been called.Informs anyone waiting on the future supplied with
SegmentCacheIndex.add(mondrian.spi.SegmentHeader, mondrian.rolap.agg.SegmentBuilder.SegmentConverter, boolean).- Specified by:
loadFailedin interfaceSegmentCacheIndex- Parameters:
header- Headerthrowable- Error message
-
remove
public void remove(SegmentHeader header)
Description copied from interface:SegmentCacheIndexRemoves a header from the index.- Specified by:
removein interfaceSegmentCacheIndex- Parameters:
header- Segment header
-
matches
public static boolean matches(SegmentHeader header, Map<String,Comparable> coords, List<String> compoundPredicates)
-
intersectRegion
public List<SegmentHeader> intersectRegion(String schemaName, ByteString schemaChecksum, String cubeName, String measureName, String rolapStarFactTableName, SegmentColumn[] region)
Description copied from interface:SegmentCacheIndexFinds a list of headers that intersect a given region.This method is used to find out which headers need to be trimmed or removed during a flush.
- Specified by:
intersectRegionin interfaceSegmentCacheIndex- Parameters:
schemaName- Schema nameschemaChecksum- Schema checksumcubeName- Cube namemeasureName- Measure namerolapStarFactTableName- Fact table tableregion- Region- Returns:
- List of intersecting headers
-
printCacheState
public void printCacheState(PrintWriter pw)
Description copied from interface:SegmentCacheIndexPrints the state of the cache to the given writer.- Specified by:
printCacheStatein interfaceSegmentCacheIndex- Parameters:
pw- Print writer
-
getFuture
public Future<SegmentBody> getFuture(Execution exec, SegmentHeader header)
Description copied from interface:SegmentCacheIndexReturns a future slot for a segment body, if a segment is currently loading, otherwise null. This is the method to use to get segments 'hot out of the oven'.When this method is invoked, the execution instance of the thread is automatically added to the list of clients for the given segment. The calling code is responsible for calling
SegmentCacheIndex.cancel(Execution)when it is done with the segments, or else this registration will prevent others from canceling the running SQL statements associated to this segment.- Specified by:
getFuturein interfaceSegmentCacheIndexheader- Segment header- Returns:
- Slot, or null
-
linkSqlStatement
public void linkSqlStatement(SegmentHeader header, Statement stmt)
Description copied from interface:SegmentCacheIndexAllows to link aStatementto a segment. This allows the index to cleanup whenSegmentCacheIndex.cancel(Execution)is invoked and orphaned segments are left.- Specified by:
linkSqlStatementin interfaceSegmentCacheIndex- Parameters:
header- The segment.stmt- The SQL statement.
-
contains
public boolean contains(SegmentHeader header)
Description copied from interface:SegmentCacheIndexTells whether or not a given segment is known to this index.- Specified by:
containsin interfaceSegmentCacheIndex
-
cancel
public void cancel(Execution exec)
Description copied from interface:SegmentCacheIndexThis method must remove all registrations as a client for the given execution. This must terminate all SQL activity for any orphaned segments.- Specified by:
cancelin interfaceSegmentCacheIndex- Parameters:
exec- The execution to unregister.
-
getConverter
public SegmentBuilder.SegmentConverter getConverter(String schemaName, ByteString schemaChecksum, String cubeName, String rolapStarFactTableName, String measureName, List<String> compoundPredicates)
Description copied from interface:SegmentCacheIndexReturns a converter that can convert the given header to internal format.- Specified by:
getConverterin interfaceSegmentCacheIndex- Parameters:
schemaName- Schema nameschemaChecksum- Schema checksumcubeName- Cube namerolapStarFactTableName- Fact tablemeasureName- Measure namecompoundPredicates- Compound predicates- Returns:
- Converter
-
setConverter
public void setConverter(String schemaName, ByteString schemaChecksum, String cubeName, String rolapStarFactTableName, String measureName, List<String> compoundPredicates, SegmentBuilder.SegmentConverter converter)
Description copied from interface:SegmentCacheIndexSets a converter that can convert headers in for a given measure to internal format.- Specified by:
setConverterin interfaceSegmentCacheIndex- Parameters:
schemaName- Schema nameschemaChecksum- Schema checksumcubeName- Cube namerolapStarFactTableName- Fact tablemeasureName- Measure namecompoundPredicates- Compound predicatesconverter- Converter to store
-
findRollupCandidates
public List<List<SegmentHeader>> findRollupCandidates(String schemaName, ByteString schemaChecksum, String cubeName, String measureName, String rolapStarFactTableName, BitKey constrainedColsBitKey, Map<String,Comparable> coordinates, List<String> compoundPredicates)
Description copied from interface:SegmentCacheIndexReturns a list of segments that can be rolled up to satisfy a given cell request.- Specified by:
findRollupCandidatesin interfaceSegmentCacheIndex- Parameters:
schemaName- Schema nameschemaChecksum- Schema checksumcubeName- Cube namemeasureName- Measure namerolapStarFactTableName- Fact table tableconstrainedColsBitKey- Bit keycoordinates- CoordinatescompoundPredicates- Compound predicates- Returns:
- List of candidates; each element is a list of headers that, when combined using union, are sufficient to answer the given cell request
-
-