Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

**WIP** feat(cass): add shardKey to partKey table #1361

Draft
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

alextheimer
Copy link
Contributor

@alextheimer alextheimer commented Apr 6, 2022

Adds a Cassandra table that maps shard keys to partition keys.

    s"""CREATE TABLE IF NOT EXISTS $tableString (
       |    shardKey blob,
       |    partKey blob,
       |    PRIMARY KEY (shardKey, partKey)
       |    ...

Now, all time-series partition keys for a given shard key can be efficiently scanned.

@alextheimer alextheimer force-pushed the ns-mig branch 2 times, most recently from 5aa7797 to 69ab230 Compare April 8, 2022 06:59
Comment on lines +551 to +562
def records(ds: Dataset, readerSeq: Seq[RowReader]): SomeData = {
val builder = new RecordBuilder(MemFactory.onHeapFactory)
readerSeq.foreach { row => builder.addFromReader(row, ds.schema) }
builder.allContainers.zipWithIndex.map { case (container, i) => SomeData(container, i) }.head
}

def partKeyFromRecords(ds: Dataset, records: SomeData, builder: Option[RecordBuilder] = None): Seq[Long] = {
val partKeyBuilder = builder.getOrElse(new RecordBuilder(TestData.nativeMem))
records.records.map { case (base, offset) =>
ds.comparator.buildPartKeyFromIngest(base, offset, partKeyBuilder)
}.toVector
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Almost) mirror the same methods in GdeltTestData.

Comment on lines 86 to +91
val partKeyTablesInit = Observable.fromIterable(0.until(numShards)).map { s =>
getOrCreatePartitionKeysTable(dataset, s)
}.mapEval(t => Task.fromFuture(t.initialize())).toListL
val shardKeyToPartKeyTableInit = Observable.fromIterable(0.until(numShards)).map { s =>
getOrCreateShardKeyToPartKeyTable(dataset, s)
}.mapEval(t => Task.fromFuture(t.initialize())).toListL
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every PartKeyTable init/insert/delete has a counterpart ShardKeyToPartKeyTable call.

Comment on lines +576 to +577
val shardKeyToPartKeyTableCache = concurrentCache[DatasetRef,
ConcurrentLinkedHashMap[Int, ShardKeyToPartKeyTable]](tableCacheSize)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a table per shard (like PartitionKeysTable)?

def scanPartKeysByShardKey(ref: DatasetRef, shard: Int, shardKey: Array[Byte]): Observable[Array[Byte]] = {
val table = getOrCreateShardKeyToPartKeyTable(ref, shard)
table.scanPartKeys(shardKey)
// TODO(a_theimer): figure out if token ranges apply here
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These will only apply if we add extra values to the PK to prevent hot-spotting, right?


val suffix = s"shardKeyToPartKey_$shard"

// TODO(a_theimer): compression settings okay?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left the same as PartitionKeyTable

Comment on lines +22 to +23
// TODO(a_theimer): probably need to prevent hot-spotting on a single node
// (i.e. add more fields to [Cassandra's] partition key)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't do this until benchmark tests indicate we need it (or one of you already knows we'll need it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant