forked from filodb/FiloDB
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Simplify Cassandra Schema for Index Data Persistence (fil…
…odb#551) Older time bucketed persistence model for part key data is now changing. This PR: * Vastly simplifies partKey/start+endTime persistence in Cassandra with new simplified schema. We employ a table per shard for efficient download of entire table's contents using token range scans. * Vastly simplifies partKey persistence logic in TimeSeriesShard. Earlier time bucket management and roll-over of keys is gone with simple flush of keys when necessary. * Simplification of index data recovery. No need to maintain partId map at the beginning because they are guaranteed to not repeat. Much less memory is required for bootstrap. Especially needed for long term data retention. This change is absolutely necessary for the FiloDB cluster that will handle serving downsampled data. The old schema is operationally very expensive and not viable for long retention times. It is also essential for simple execution of chunk repair across DCs.
- Loading branch information
1 parent
016621e
commit 31d603b
Showing
32 changed files
with
539 additions
and
740 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 0 additions & 71 deletions
71
cassandra/src/main/scala/filodb.cassandra/columnstore/PartitionIndexTable.scala
This file was deleted.
Oops, something went wrong.
66 changes: 66 additions & 0 deletions
66
cassandra/src/main/scala/filodb.cassandra/columnstore/PartitionKeysTable.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package filodb.cassandra.columnstore | ||
|
||
import java.lang.{Integer => JInt, Long => JLong} | ||
|
||
import scala.collection.JavaConverters._ | ||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
import com.datastax.driver.core.ConsistencyLevel | ||
import monix.reactive.Observable | ||
|
||
import filodb.cassandra.FiloCassandraConnector | ||
import filodb.core.{DatasetRef, Response} | ||
import filodb.core.store.PartKeyRecord | ||
|
||
sealed class PartitionKeysTable(val dataset: DatasetRef, | ||
val shard: Int, | ||
val connector: FiloCassandraConnector, | ||
writeConsistencyLevel: ConsistencyLevel) | ||
(implicit ec: ExecutionContext) extends BaseDatasetTable { | ||
|
||
import filodb.cassandra.Util._ | ||
|
||
val suffix = s"partitionkeys_$shard" | ||
|
||
val createCql = | ||
s"""CREATE TABLE IF NOT EXISTS $tableString ( | ||
| partKey blob, | ||
| startTime bigint, | ||
| endTime bigint, | ||
| PRIMARY KEY (partKey) | ||
|) WITH compression = {'chunk_length_in_kb': '16', 'sstable_compression': '$sstableCompression'}""".stripMargin | ||
|
||
lazy val writePartitionCql = | ||
session.prepare( | ||
s"INSERT INTO ${tableString} (partKey, startTime, endTime) VALUES (?, ?, ?) USING TTL ?") | ||
.setConsistencyLevel(writeConsistencyLevel) | ||
|
||
lazy val writePartitionCqlNoTtl = | ||
session.prepare( | ||
s"INSERT INTO ${tableString} (partKey, startTime, endTime) VALUES (?, ?, ?)") | ||
.setConsistencyLevel(writeConsistencyLevel) | ||
|
||
def writePartKey(pk: PartKeyRecord, diskTimeToLive: Int): Future[Response] = { | ||
if (diskTimeToLive <= 0) { | ||
connector.execStmtWithRetries(writePartitionCqlNoTtl.bind( | ||
toBuffer(pk.partKey), pk.startTime: JLong, pk.endTime: JLong)) | ||
} else { | ||
connector.execStmtWithRetries(writePartitionCql.bind( | ||
toBuffer(pk.partKey), pk.startTime: JLong, pk.endTime: JLong, diskTimeToLive: JInt)) | ||
} | ||
} | ||
|
||
def scanPartKeys(tokens: Seq[(String, String)], shard: Int): Observable[PartKeyRecord] = { | ||
def cql(start: String, end: String): String = | ||
s"SELECT * FROM ${tableString} " + | ||
s"WHERE TOKEN(partKey) >= $start AND TOKEN(partKey) < $end " | ||
val it = tokens.iterator.flatMap { case (start, end) => | ||
session.execute(cql(start, end)).iterator.asScala | ||
.map { row => PartKeyRecord(row.getBytes("partKey").array(), | ||
row.getLong("startTime"), row.getLong("endTime")) } | ||
} | ||
Observable.fromIterator(it).handleObservableErrors | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.