Class SegmentCacheIndexImpl

  • All Implemented Interfaces:
    SegmentCacheIndex

    public class SegmentCacheIndexImpl
    extends java.lang.Object
    implements SegmentCacheIndex
    Data structure that identifies which segments contain cells.

    Not thread safe.

    Author:
    Julian Hyde
    • Constructor Summary

      Constructors 
      Constructor Description
      SegmentCacheIndexImpl​(java.lang.Thread thread)
      Creates a SegmentCacheIndexImpl.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(SegmentHeader header, SegmentBuilder.SegmentConverter converter, boolean loading)
      Adds a header to the index.
      void cancel​(Execution exec)
      This method must remove all registrations as a client for the given execution.
      boolean contains​(SegmentHeader header)
      Tells whether or not a given segment is known to this index.
      java.util.List<java.util.List<SegmentHeader>> findRollupCandidates​(java.lang.String schemaName, ByteString schemaChecksum, java.lang.String cubeName, java.lang.String measureName, java.lang.String rolapStarFactTableName, BitKey constrainedColsBitKey, java.util.Map<java.lang.String,​java.lang.Comparable> coordinates, java.util.List<java.lang.String> compoundPredicates)
      Returns a list of segments that can be rolled up to satisfy a given cell request.
      SegmentBuilder.SegmentConverter getConverter​(java.lang.String schemaName, ByteString schemaChecksum, java.lang.String cubeName, java.lang.String rolapStarFactTableName, java.lang.String measureName, java.util.List<java.lang.String> compoundPredicates)
      Returns a converter that can convert the given header to internal format.
      java.util.concurrent.Future<SegmentBody> getFuture​(Execution exec, SegmentHeader header)
      Returns a future slot for a segment body, if a segment is currently loading, otherwise null.
      java.util.List<SegmentHeader> intersectRegion​(java.lang.String schemaName, ByteString schemaChecksum, java.lang.String cubeName, java.lang.String measureName, java.lang.String rolapStarFactTableName, SegmentColumn[] region)
      Finds a list of headers that intersect a given region.
      void linkSqlStatement​(SegmentHeader header, java.sql.Statement stmt)
      Allows to link a Statement to a segment.
      void loadFailed​(SegmentHeader header, java.lang.Throwable throwable)
      Notifies the segment index that a segment failed to load, and removes the segment from the index.
      void loadSucceeded​(SegmentHeader header, SegmentBody body)
      Changes the state of a header from loading to loaded.
      java.util.List<SegmentHeader> locate​(java.lang.String schemaName, ByteString schemaChecksum, java.lang.String cubeName, java.lang.String measureName, java.lang.String rolapStarFactTableName, BitKey constrainedColsBitKey, java.util.Map<java.lang.String,​java.lang.Comparable> coordinates, java.util.List<java.lang.String> compoundPredicates)
      Identifies the segment headers that contain a given cell.
      static java.util.List makeConverterKey​(CellRequest request, AggregationKey key)  
      static java.util.List makeConverterKey​(SegmentHeader header)  
      static boolean matches​(SegmentHeader header, java.util.Map<java.lang.String,​java.lang.Comparable> coords, java.util.List<java.lang.String> compoundPredicates)  
      void printCacheState​(java.io.PrintWriter pw)
      Prints the state of the cache to the given writer.
      void remove​(SegmentHeader header)
      Removes a header from the index.
      void setConverter​(java.lang.String schemaName, ByteString schemaChecksum, java.lang.String cubeName, java.lang.String rolapStarFactTableName, java.lang.String measureName, java.util.List<java.lang.String> compoundPredicates, SegmentBuilder.SegmentConverter converter)
      Sets a converter that can convert headers in for a given measure to internal format.
      void update​(SegmentHeader oldHeader, SegmentHeader newHeader)
      Updates a header in the index.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SegmentCacheIndexImpl

        public SegmentCacheIndexImpl​(java.lang.Thread thread)
        Creates a SegmentCacheIndexImpl.
        Parameters:
        thread - Thread that must be used to execute commands.
    • Method Detail

      • makeConverterKey

        public static java.util.List makeConverterKey​(SegmentHeader header)
      • locate

        public java.util.List<SegmentHeader> locate​(java.lang.String schemaName,
                                                    ByteString schemaChecksum,
                                                    java.lang.String cubeName,
                                                    java.lang.String measureName,
                                                    java.lang.String rolapStarFactTableName,
                                                    BitKey constrainedColsBitKey,
                                                    java.util.Map<java.lang.String,​java.lang.Comparable> coordinates,
                                                    java.util.List<java.lang.String> compoundPredicates)
        Description copied from interface: SegmentCacheIndex
        Identifies the segment headers that contain a given cell.
        Specified by:
        locate in interface SegmentCacheIndex
        Parameters:
        schemaName - Schema name
        schemaChecksum - Schema checksum
        cubeName - Cube name
        measureName - Measure name
        rolapStarFactTableName - Fact table table
        constrainedColsBitKey - Bit key
        coordinates - Coordinates
        compoundPredicates - Compound predicates
        Returns:
        Empty list if not found; never null
      • update

        public void update​(SegmentHeader oldHeader,
                           SegmentHeader newHeader)
        Description copied from interface: SegmentCacheIndex
        Updates a header in the index. This is required when some of the excluded regions have changed.
        Specified by:
        update in interface SegmentCacheIndex
        Parameters:
        oldHeader - The old header to replace.
        newHeader - The new header to use instead.
      • matches

        public static boolean matches​(SegmentHeader header,
                                      java.util.Map<java.lang.String,​java.lang.Comparable> coords,
                                      java.util.List<java.lang.String> compoundPredicates)
      • intersectRegion

        public java.util.List<SegmentHeader> intersectRegion​(java.lang.String schemaName,
                                                             ByteString schemaChecksum,
                                                             java.lang.String cubeName,
                                                             java.lang.String measureName,
                                                             java.lang.String rolapStarFactTableName,
                                                             SegmentColumn[] region)
        Description copied from interface: SegmentCacheIndex
        Finds 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:
        intersectRegion in interface SegmentCacheIndex
        Parameters:
        schemaName - Schema name
        schemaChecksum - Schema checksum
        cubeName - Cube name
        measureName - Measure name
        rolapStarFactTableName - Fact table table
        region - Region
        Returns:
        List of intersecting headers
      • printCacheState

        public void printCacheState​(java.io.PrintWriter pw)
        Description copied from interface: SegmentCacheIndex
        Prints the state of the cache to the given writer.
        Specified by:
        printCacheState in interface SegmentCacheIndex
        Parameters:
        pw - Print writer
      • getFuture

        public java.util.concurrent.Future<SegmentBody> getFuture​(Execution exec,
                                                                  SegmentHeader header)
        Description copied from interface: SegmentCacheIndex
        Returns 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:
        getFuture in interface SegmentCacheIndex
        header - Segment header
        Returns:
        Slot, or null
      • cancel

        public void cancel​(Execution exec)
        Description copied from interface: SegmentCacheIndex
        This method must remove all registrations as a client for the given execution. This must terminate all SQL activity for any orphaned segments.
        Specified by:
        cancel in interface SegmentCacheIndex
        Parameters:
        exec - The execution to unregister.
      • getConverter

        public SegmentBuilder.SegmentConverter getConverter​(java.lang.String schemaName,
                                                            ByteString schemaChecksum,
                                                            java.lang.String cubeName,
                                                            java.lang.String rolapStarFactTableName,
                                                            java.lang.String measureName,
                                                            java.util.List<java.lang.String> compoundPredicates)
        Description copied from interface: SegmentCacheIndex
        Returns a converter that can convert the given header to internal format.
        Specified by:
        getConverter in interface SegmentCacheIndex
        Parameters:
        schemaName - Schema name
        schemaChecksum - Schema checksum
        cubeName - Cube name
        rolapStarFactTableName - Fact table
        measureName - Measure name
        compoundPredicates - Compound predicates
        Returns:
        Converter
      • setConverter

        public void setConverter​(java.lang.String schemaName,
                                 ByteString schemaChecksum,
                                 java.lang.String cubeName,
                                 java.lang.String rolapStarFactTableName,
                                 java.lang.String measureName,
                                 java.util.List<java.lang.String> compoundPredicates,
                                 SegmentBuilder.SegmentConverter converter)
        Description copied from interface: SegmentCacheIndex
        Sets a converter that can convert headers in for a given measure to internal format.
        Specified by:
        setConverter in interface SegmentCacheIndex
        Parameters:
        schemaName - Schema name
        schemaChecksum - Schema checksum
        cubeName - Cube name
        rolapStarFactTableName - Fact table
        measureName - Measure name
        compoundPredicates - Compound predicates
        converter - Converter to store
      • findRollupCandidates

        public java.util.List<java.util.List<SegmentHeader>> findRollupCandidates​(java.lang.String schemaName,
                                                                                  ByteString schemaChecksum,
                                                                                  java.lang.String cubeName,
                                                                                  java.lang.String measureName,
                                                                                  java.lang.String rolapStarFactTableName,
                                                                                  BitKey constrainedColsBitKey,
                                                                                  java.util.Map<java.lang.String,​java.lang.Comparable> coordinates,
                                                                                  java.util.List<java.lang.String> compoundPredicates)
        Description copied from interface: SegmentCacheIndex
        Returns a list of segments that can be rolled up to satisfy a given cell request.
        Specified by:
        findRollupCandidates in interface SegmentCacheIndex
        Parameters:
        schemaName - Schema name
        schemaChecksum - Schema checksum
        cubeName - Cube name
        measureName - Measure name
        rolapStarFactTableName - Fact table table
        constrainedColsBitKey - Bit key
        coordinates - Coordinates
        compoundPredicates - 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