src/java/org/apache/cassandra/db/CounterColumn.java
/**
     * There is two phase to the removal of old shards.
     * First phase: we merge the old shard value to the current shard and
     * 'nulify' the old one. We then send the counter context with the old
     * shard nulified to all other replica.
     * Second phase: once an old shard has been nulified for longer than
     * gc_grace (to be sure all other replica had been aware of the merge), we
     * simply remove that old shard from the context (it's value is 0).
     * This method does both phases.
     * (Note that the sendToOtherReplica flag is here only to facilitate
     * testing. It should be true in real code so use the method above
     * preferably)
     */
There is two phase to the removal of old shards.
First phase: we merge the old shard value to the current shard and
'nulify' the old one. We then send the counter context with the old
shard nulified to all other replica.
Second phase: once an old shard has been nulified for longer than
gc_grace (to be sure all other replica had been aware of the merge), we
simply remove that old shard from the context (it's value is 0).
This method does both phases.
(Note that the sendToOtherReplica flag is here only to facilitate
testing. It should be true in real code so use the method above
preferably)
There is two phase to the removal of old shards . First phase : we merge the old shard value to the current shard and ' nulify ' the old one . We then send the counter context with the old shard nulified to all other replica . Second phase : once an old shard has been nulified for longer than gc_grace ( to be sure all other replica had been aware of the merge ) we simply remove that old shard from the context ( it ' s value is 0 ) . This method does both phases . ( Note that the sendToOtherReplica flag is here only to facilitate testing . It should be true in real code so use the method above preferably )
public static void mergeAndRemoveOldShards(DecoratedKey key, ColumnFamily cf, int gcBefore, int mergeBefore, boolean sendToOtherReplica)
    {
        ColumnFamily remoteMerger = null;
        if (!cf.isSuper())
        {
            for (IColumn c : cf)
            {
                if (!(c instanceof CounterColumn))
                    continue;
                CounterColumn cc = (CounterColumn) c;
                CounterColumn shardMerger = cc.computeOldShardMerger(mergeBefore);
                CounterColumn merged = cc;
                if (shardMerger != null)
                {
                    merged = (CounterColumn) cc.reconcile(shardMerger);
                    if (remoteMerger == null)
                        remoteMerger = cf.cloneMeShallow();
                    remoteMerger.addColumn(merged);
                }
                CounterColumn cleaned = merged.removeOldShards(gcBefore);
                if (cleaned != cc)
                {
                    cf.replace(cc, cleaned);
                }
            }
        }
        else
        {
            for (IColumn col : cf)
            {
                SuperColumn c = (SuperColumn)col;
                for (IColumn subColumn : c.getSubColumns())
                {
                    if (!(subColumn instanceof CounterColumn))
                        continue;
                    CounterColumn cc = (CounterColumn) subColumn;
                    CounterColumn shardMerger = cc.computeOldShardMerger(mergeBefore);
                    CounterColumn merged = cc;
                    if (shardMerger != null)
                    {
                        merged = (CounterColumn) cc.reconcile(shardMerger);
                        if (remoteMerger == null)
                            remoteMerger = cf.cloneMeShallow();
                        remoteMerger.addColumn(c.name(), merged);
                    }
                    CounterColumn cleaned = merged.removeOldShards(gcBefore);
                    if (cleaned != subColumn)
                        c.replace(subColumn, cleaned);
                }
            }
        }
        if (remoteMerger != null && sendToOtherReplica)
        {
            try
            {
                sendToOtherReplica(key, remoteMerger);
            }
            catch (Exception e)
            {
                logger.error("Error while sending shard merger mutation to remote endpoints", e);
            }
        }
    }
public static void mergeAndRemoveOldShards ( DecoratedKey key , ColumnFamily cf , int gcBefore , int mergeBefore , boolean sendToOtherReplica ) { ColumnFamily remoteMerger = null ; if ( ! cf . isSuper ( ) ) { for ( IColumn c : cf ) { if ( ! ( c instanceof CounterColumn ) ) continue ; CounterColumn cc = ( CounterColumn ) c ; CounterColumn shardMerger = cc . computeOldShardMerger ( mergeBefore ) ; CounterColumn merged = cc ; if ( shardMerger != null ) { merged = ( CounterColumn ) cc . reconcile ( shardMerger ) ; if ( remoteMerger == null ) remoteMerger = cf . cloneMeShallow ( ) ; remoteMerger . addColumn ( merged ) ; } CounterColumn cleaned = merged . removeOldShards ( gcBefore ) ; if ( cleaned != cc ) { cf . replace ( cc , cleaned ) ; } } } else { for ( IColumn col : cf ) { SuperColumn c = ( SuperColumn ) col ; for ( IColumn subColumn : c . getSubColumns ( ) ) { if ( ! ( subColumn instanceof CounterColumn ) ) continue ; CounterColumn cc = ( CounterColumn ) subColumn ; CounterColumn shardMerger = cc . computeOldShardMerger ( mergeBefore ) ; CounterColumn merged = cc ; if ( shardMerger != null ) { merged = ( CounterColumn ) cc . reconcile ( shardMerger ) ; if ( remoteMerger == null ) remoteMerger = cf . cloneMeShallow ( ) ; remoteMerger . addColumn ( c . name ( ) , merged ) ; } CounterColumn cleaned = merged . removeOldShards ( gcBefore ) ; if ( cleaned != subColumn ) c . replace ( subColumn , cleaned ) ; } } } if ( remoteMerger != null && sendToOtherReplica ) { try { sendToOtherReplica ( key , remoteMerger ) ; } catch ( Exception e ) { logger . error ( "Error while sending shard merger mutation to remote endpoints" , e ) ; } } }
There is two phase to the removal of old shards.
There is two phase to the removal of old shards .