You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cassandra.apache.org by "Ghosh, Mainak" <mg...@illinois.edu> on 2014/09/04 18:50:04 UTC

Pointers on writing your own Compaction Strategy

Hello,

I am planning to write a new compaction strategy and I was hoping if anyone can point me to the relevant functions and how they are related in the call hierarchy.

Thanks for the help.

Regards,
Mainak.

Re: Pointers on writing your own Compaction Strategy

Posted by Tupshin Harper <tu...@tupshin.com>.
In addition to what Markus said, take a look at the latest patch in
https://issues.apache.org/jira/browse/CASSANDRA-6602 for a relevant
example.

-Tupshin
On Sep 4, 2014 2:28 PM, "Marcus Eriksson" <kr...@gmail.com> wrote:

> 1. create a class that extends AbstractCompactionStrategy (i would keep it
> in-tree while developing to avoid having classpath issues etc)
> 2. Implement the abstract methods
>    - getNextBackgroundTask - called when cassandra wants to do a new minor
> (background) compaction - return a CompactionTask with the sstables you
> want compacted
>    - getMaximalTask - called when a user triggers a major compaction
>    - getUserDefinedTask - when a user triggers a user defined compaction
> from JMX
>    - getEstimatedRemainingTasks - return the guessed number of tasks before
> we are "done"
>    - getMaxSSTableBytes - if your compaction strategy puts a limit on the
> size of sstables
> 3. Execute this in cqlsh to enable your compaction strategy: ALTER TABLE
> foo WITH compaction = { class: ‘Bar’ }
> 4. Things to think about:
>     - make sure you mark sstables as compacting before returning them from
> the compaction strategy (and check the return value!):
>
> https://github.com/apache/cassandra/blob/trunk/src/java/org/apache/cassandra/db/compaction/SizeTieredCompactionStrategy.java#L271
>     - if you do this on 2.1 - dont mix repaired and unrepaired sstables
> (SSTableReader#isRepaired)
>
> Let me know if you need any more information
>
> /Marcus
>
>
>
> On Thu, Sep 4, 2014 at 6:50 PM, Ghosh, Mainak <mg...@illinois.edu>
> wrote:
>
> > Hello,
> >
> > I am planning to write a new compaction strategy and I was hoping if
> > anyone can point me to the relevant functions and how they are related in
> > the call hierarchy.
> >
> > Thanks for the help.
> >
> > Regards,
> > Mainak.
> >
>

Re: Pointers on writing your own Compaction Strategy

Posted by Marcus Eriksson <kr...@gmail.com>.
1. create a class that extends AbstractCompactionStrategy (i would keep it
in-tree while developing to avoid having classpath issues etc)
2. Implement the abstract methods
   - getNextBackgroundTask - called when cassandra wants to do a new minor
(background) compaction - return a CompactionTask with the sstables you
want compacted
   - getMaximalTask - called when a user triggers a major compaction
   - getUserDefinedTask - when a user triggers a user defined compaction
from JMX
   - getEstimatedRemainingTasks - return the guessed number of tasks before
we are "done"
   - getMaxSSTableBytes - if your compaction strategy puts a limit on the
size of sstables
3. Execute this in cqlsh to enable your compaction strategy: ALTER TABLE
foo WITH compaction = { class: ‘Bar’ }
4. Things to think about:
    - make sure you mark sstables as compacting before returning them from
the compaction strategy (and check the return value!):
https://github.com/apache/cassandra/blob/trunk/src/java/org/apache/cassandra/db/compaction/SizeTieredCompactionStrategy.java#L271
    - if you do this on 2.1 - dont mix repaired and unrepaired sstables
(SSTableReader#isRepaired)

Let me know if you need any more information

/Marcus



On Thu, Sep 4, 2014 at 6:50 PM, Ghosh, Mainak <mg...@illinois.edu> wrote:

> Hello,
>
> I am planning to write a new compaction strategy and I was hoping if
> anyone can point me to the relevant functions and how they are related in
> the call hierarchy.
>
> Thanks for the help.
>
> Regards,
> Mainak.
>