Skip to content

CASSANALYTICS-128: Add flag to allow bulk write to indexed tables#181

Open
jmckenzie-dev wants to merge 4 commits intoapache:trunkfrom
jmckenzie-dev:allow_write_2i
Open

CASSANALYTICS-128: Add flag to allow bulk write to indexed tables#181
jmckenzie-dev wants to merge 4 commits intoapache:trunkfrom
jmckenzie-dev:allow_write_2i

Conversation

@jmckenzie-dev
Copy link

Patch by Josh McKenzie; reviewed by TBD for CASSANALYTICS-128

Patch by Josh McKenzie; reviewed by YYYY for CASSANALYTICS-128
Copy link
Contributor

@sarankk sarankk left a comment

Choose a reason for hiding this comment

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

Thanks Josh, Lgtm. 1 minor nit. Would it be useful to test writer with this flag in integration test too?

public final int commitThreadsPerInstance;
public final double importCoordinatorTimeoutMultiplier;
public boolean quoteIdentifiers;
public boolean skipSecondaryIndexCheck;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public boolean skipSecondaryIndexCheck;
public final boolean skipSecondaryIndexCheck;

* with the understanding that the secondary indexes will NOT be updated by the bulk write and must be
* rebuilt separately after the job completes.
*/
SKIP_SECONDARY_INDEX_CHECK,
Copy link
Contributor

Choose a reason for hiding this comment

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

How about defining it in the spark conf, instead of write options?

The rationale is that the toggle is to for advanced use case and not directly related to the write behavior. There is another existing spark conf, org.apache.cassandra.spark.bulkwriter.BulkSparkConf#SKIP_CLEAN that skips cleaning up SSTable when job fails.

Admittedly, there are some existing inconsistency of where to have conf and where to have write options in the project.

Copy link
Author

Choose a reason for hiding this comment

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

Would putting this in BulkSparkConf force it session-wide? i.e. a user would lose the ability to reason about and easily configure this setting on a per-table / per operation basis vs. the public exposure of it via WriterOptions?

My intuition right now is that this is something that probably should have been enabled by default all this time w/a configurable guardrail to turn it off, so while I'm sympathetic to the idea of taking a small step from "don't allow it" to "allow it but make it hard to use", the risk of this being easily accessible for users is that they'll bulk write to a table that will then have a long running index building operation happen in the background. Which, other than "load on node" and "application might read a partial index if you don't have automation that clearly delineates when a bulk insert and reindex finish from application accessing it", doesn't represent a structural or correctness risk to the data.

@jmckenzie-dev
Copy link
Author

jmckenzie-dev commented Mar 11, 2026

Would it be useful to test writer with this flag in integration test too?

Eh, I didn't because ultimately it's a validation error inside the TableSchema construction so basically, if we can get past that point then we should be good to go.

The rest of the integration path would effectively be testing whether bulk import on cassandra with a table that has legacy SecondaryIndexes on it works correctly. Which, to be completely honest, I'm not super confident of (dug around a bit and ImportTest.java doesn't seem to have coverage). BUT - that's a core C* test coverage problem and not an analytics / sidecar problem.

So maybe a follow up JIRA to add test coverage in C* proper for legacy 2i on imports would be reasonable?

@jmckenzie-dev
Copy link
Author

Copy link
Contributor

@jyothsnakonisa jyothsnakonisa left a comment

Choose a reason for hiding this comment

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

looks good to me

this.ttl = MapUtils.getOrDefault(options, WriterOptions.TTL.name(), null);
this.timestamp = MapUtils.getOrDefault(options, WriterOptions.TIMESTAMP.name(), null);
this.quoteIdentifiers = MapUtils.getBoolean(options, WriterOptions.QUOTE_IDENTIFIERS.name(), false, "quote identifiers");
this.skipSecondaryIndexCheck = MapUtils.getBoolean(options, WriterOptions.SKIP_SECONDARY_INDEX_CHECK.name(), false, "skip secondary index check");
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the default value be true?

// process today. 2i and SAI have different ergonomics here regarding if stale data is served during index build;
// ultimately we want the bulk writer to also write native SAI index files alongside sstables but until
// then, this is allowable and fine for users who Know What They're Doing.
if (!skipSecondaryIndexCheck)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add a test if possible that check this behavior, basically the if block

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.

4 participants