Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Optimize compaction #364

Open
wants to merge 1 commit into
base: branch-3.11.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,9 @@ All options take a value enclosed in single quotes:
The cost of this optimization is an extra comparison performed each time a row must be indexed.
This flag helps in reducing lucene calls when the row is updated partially, and the columns
that affect the index are updated less frequently then the rest of the row.
- **use_ttl**: If false, deletion of data using `USING TTL` will not be performed automatically.
This reduces reading of data during compaction.
In some cases, the speed of compaction is greatly improved.
- **schema**: see below

.. code-block:: sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ class IndexOptions(tableMetadata: CFMetaData, indexMetadata: IndexMetadata) {
val path = parsePath(options, tableMetadata, Some(indexMetadata))

/** If the index is sparse or not */
val sparse = parseSparse(options, tableMetadata)
val sparse = parseBool(options, SPARSE_OPTION, DEFAULT_SPARSE)

val useTtl = parseBool(options, USE_TTL, DEFAULT_USE_TTL)
}

/** Companion object for [[IndexOptions]]. */
Expand Down Expand Up @@ -107,6 +109,9 @@ object IndexOptions {
val SPARSE_OPTION = "sparse"
val DEFAULT_SPARSE = false

val USE_TTL = "use_ttl"
val DEFAULT_USE_TTL = true

/** Validates the specified index options.
*
* @param options the options to be validated
Expand Down Expand Up @@ -192,12 +197,12 @@ object IndexOptions {
}).getOrElse(DEFAULT_PARTITIONER)
}

def parseSparse(options: Map[String, String], table: CFMetaData): Boolean = {
options.get(SPARSE_OPTION).map(
def parseBool(options: Map[String, String], name: String, default: Boolean): Boolean = {
options.get(name).map(
value => try value.toBoolean catch {
case e: Exception => throw new IndexException(e,
s"'$SPARSE_OPTION' is invalid : ${e.getMessage}")
}).getOrElse(DEFAULT_SPARSE)
s"'$name' is invalid : ${e.getMessage}")
}).getOrElse(default)
}

private def parseInt(options: Map[String, String], name: String, default: Int): Int = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import org.apache.cassandra.db._
import org.apache.cassandra.db.rows.{Row, RowIterator, UnfilteredRowIterators}
import org.apache.cassandra.index.Index.Indexer
import org.apache.cassandra.index.transactions.IndexTransaction
import org.apache.cassandra.index.transactions.IndexTransaction.Type.CLEANUP
import org.apache.cassandra.index.transactions.IndexTransaction.Type.{CLEANUP, COMPACTION}
import org.apache.cassandra.utils.concurrent.OpOrder

/** [[Indexer]] for Lucene-based index.
Expand Down Expand Up @@ -116,6 +116,7 @@ abstract class IndexWriter(

// Skip on cleanups
if (transactionType == CLEANUP) return
if (transactionType == COMPACTION && !service.options.useTtl) return

// Finish with mutual exclusion on partition
service.readBeforeWriteLocker.run(key, () => commit())
Expand Down