src/java/org/apache/cassandra/db/index/SecondaryIndexManager.java
/**
     * Removes obsolete index entries and creates new ones for the given row key
     * and mutated columns.
     * 
     * For columns whos underlying index type has the isRowLevelIndex() flag set to true this function will
     * call the 
     * 
     * @param rowKey the row key
     * @param cf the current rows data
     * @param mutatedIndexedColumns the set of columns that were changed or added
     * @param oldIndexedColumns the columns what were deleted
     * @throws IOException 
     */
Removes obsolete index entries and creates new ones for the given row key
and mutated columns.

For columns whos underlying index type has the isRowLevelIndex() flag set to true this function will
call the


Removes obsolete index entries and creates new ones for the given row key and mutated columns . For columns whos underlying index type has the isRowLevelIndex () flag set to true this function will call the
public void applyIndexUpdates(ByteBuffer rowKey,
                                  ColumnFamily cf,
                                  SortedSet<ByteBuffer> mutatedIndexedColumns,
                                  ColumnFamily oldIndexedColumns) throws IOException
    {
        Set<Class<? extends SecondaryIndex>> appliedRowLevelIndexes = null;       
        if (oldIndexedColumns != null)
        {
            for (ByteBuffer columnName : oldIndexedColumns.getColumnNames())
            {
                IColumn column = oldIndexedColumns.getColumn(columnName);
                if (column == null)
                    continue;
                if (column.isMarkedForDelete())
                    continue;              
                SecondaryIndex index = getIndexForColumn(columnName);
                if (index == null)
                {
                    logger.debug("Looks like index got dropped mid-update.  Skipping");
                    continue;
                }
                if (index instanceof PerRowSecondaryIndex)
                {
                    if (appliedRowLevelIndexes == null)
                        appliedRowLevelIndexes = new HashSet<Class<? extends SecondaryIndex>>();
                    if (appliedRowLevelIndexes.add(index.getClass()))
                        ((PerRowSecondaryIndex)index).applyIndexUpdates(rowKey, cf, mutatedIndexedColumns, oldIndexedColumns);
                }
                else
                {
                    DecoratedKey<LocalToken> valueKey = getIndexKeyFor(columnName, column.value());
                    ((PerColumnSecondaryIndex)index).deleteColumn(valueKey, rowKey, column);
                }
            }
        }
        for (ByteBuffer columnName : mutatedIndexedColumns)
        {
            IColumn column = cf.getColumn(columnName);
            if (column == null || column.isMarkedForDelete())
                continue; 
            SecondaryIndex index = getIndexForColumn(columnName);
            if (index == null)
            {
                logger.debug("index on {} removed; skipping remove-old for {}", columnName, ByteBufferUtil.bytesToHex(rowKey));
                continue;
            }
            if (index instanceof PerRowSecondaryIndex)
            {
                if (appliedRowLevelIndexes == null)
                    appliedRowLevelIndexes = new HashSet<Class<? extends SecondaryIndex>>();
                if (appliedRowLevelIndexes.add(index.getClass()))
                    ((PerRowSecondaryIndex)index).applyIndexUpdates(rowKey, cf, mutatedIndexedColumns, oldIndexedColumns);
            }
            else
            {
                DecoratedKey<LocalToken> valueKey = getIndexKeyFor(columnName, column.value());
                ((PerColumnSecondaryIndex)index).insertColumn(valueKey, rowKey, column);         
            }
        }
    }
public void applyIndexUpdates ( ByteBuffer rowKey , ColumnFamily cf , SortedSet < ByteBuffer > mutatedIndexedColumns , ColumnFamily oldIndexedColumns ) throws IOException { Set < Class < ? extends SecondaryIndex > > appliedRowLevelIndexes = null ; if ( oldIndexedColumns != null ) { for ( ByteBuffer columnName : oldIndexedColumns . getColumnNames ( ) ) { IColumn column = oldIndexedColumns . getColumn ( columnName ) ; if ( column == null ) continue ; if ( column . isMarkedForDelete ( ) ) continue ; SecondaryIndex index = getIndexForColumn ( columnName ) ; if ( index == null ) { logger . debug ( "Looks like index got dropped mid-update.  Skipping" ) ; continue ; } if ( index instanceof PerRowSecondaryIndex ) { if ( appliedRowLevelIndexes == null ) appliedRowLevelIndexes = new HashSet < Class < ? extends SecondaryIndex > > ( ) ; if ( appliedRowLevelIndexes . add ( index . getClass ( ) ) ) ( ( PerRowSecondaryIndex ) index ) . applyIndexUpdates ( rowKey , cf , mutatedIndexedColumns , oldIndexedColumns ) ; } else { DecoratedKey < LocalToken > valueKey = getIndexKeyFor ( columnName , column . value ( ) ) ; ( ( PerColumnSecondaryIndex ) index ) . deleteColumn ( valueKey , rowKey , column ) ; } } } for ( ByteBuffer columnName : mutatedIndexedColumns ) { IColumn column = cf . getColumn ( columnName ) ; if ( column == null || column . isMarkedForDelete ( ) ) continue ; SecondaryIndex index = getIndexForColumn ( columnName ) ; if ( index == null ) { logger . debug ( "index on {} removed; skipping remove-old for {}" , columnName , ByteBufferUtil . bytesToHex ( rowKey ) ) ; continue ; } if ( index instanceof PerRowSecondaryIndex ) { if ( appliedRowLevelIndexes == null ) appliedRowLevelIndexes = new HashSet < Class < ? extends SecondaryIndex > > ( ) ; if ( appliedRowLevelIndexes . add ( index . getClass ( ) ) ) ( ( PerRowSecondaryIndex ) index ) . applyIndexUpdates ( rowKey , cf , mutatedIndexedColumns , oldIndexedColumns ) ; } else { DecoratedKey < LocalToken > valueKey = getIndexKeyFor ( columnName , column . value ( ) ) ; ( ( PerColumnSecondaryIndex ) index ) . insertColumn ( valueKey , rowKey , column ) ; } } }
Removes obsolete index entries and creates new ones for the given row key
 and mutated columns.
Removes obsolete index entries and creates new ones for the given row key and mutated columns .
// Identify the columns with PerRowSecondaryIndexes // we need to make sure this is only called once // remove the old index entries //this was previously deleted so should not be in index // Update entire row if we encounter a row level index //insert new columns // null column == row deletion // Update entire row if we encounter a row level index