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

CASSANDRA-19677: Adds new size Guardrails #3355

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from

Conversation

bbotella
Copy link
Contributor

@bbotella bbotella commented Jun 7, 2024

CASSANDRA-19677: Adds new size Guardrails

This commit adds these column size guardrails:

column_ascii_value_size_warn_threshold
column_ascii_value_size_fail_threshold
column_blob_value_size_warn_threshold
column_blob_value_size_fail_threshold
column_text_value_size_warn_threshold
column_text_value_size_fail_threshold
column_varchar_value_size_warn_threshold
column_varchar_value_size_fail_threshold

And these collection size guardrails:

collection_map_size_warn_threshold
collection_map_size_fail_threshold
collection_set_size_warn_threshold
collection_set_size_fail_threshold
collection_list_size_warn_threshold
collection_list_size_fail_threshold

patch by Bernardo Botella Corbi; reviewed by for CASSANDRA-19677

Bernardo Botella Corbi added 2 commits June 7, 2024 09:55
Comment on lines 2080 to 2084
# Guardrail to warn or fail when writing ascii column values larger than threshold.
# This guardrail is only applied to the values of regular columns because both the serialized partitions keys and the
# values of the components of the clustering key already have a fixed, relatively small size limit of 65535 bytes, which
# is probably lesser than the thresholds defined here.
# The two thresholds default to null to disable.
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 add the clarification when both column_value_size_warn_threshold and column_ascii_value_size_warn_threshold are enabled?
For example, column_value_size_warn_threshold=100B and column_ascii_value_size_warn_threshold=200B. If the incoming write has the ascii field size of 123B, should it warn or not?

if (column.type instanceof AsciiType) // Ascii size specific guardrail
{
Guardrails.columnAsciiValueSize.guard(value.remaining(), column.name.toString(), false, clientState);
} else if (column.type instanceof BytesType) // Blob size specific guardrail
Copy link
Contributor

Choose a reason for hiding this comment

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

move to new line. There are a few other places that the else if is placed wrongly. Please correct them

Comment on lines 178 to 182
} else if (column.type instanceof UTF8Type) // text and varchar size specific guardrails
{
Guardrails.columnTextValueSize.guard(value.remaining(), column.name.toString(), false, clientState);
Guardrails.columnVarcharValueSize.guard(value.remaining(), column.name.toString(), false, clientState);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It is confusing (sometimes surprising) to end-users to have 2 guardrails to check on the same value. Since text and varchar are identical internally, can you combine those 2 guardrails?

Guardrails.columnValueSize.guard(value.remaining(), column.name.toString(), false, clientState);

if (column.type instanceof AsciiType) // Ascii size specific guardrail
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: prefer comparing the enum type, instead of instanceof, e.g.

Suggested change
if (column.type instanceof AsciiType) // Ascii size specific guardrail
if (column.type.asCQL3Type() == CQL3Type.Native.ASCII)

Style fixes and merge text and varchar guardrail.
Guardrails.columnValueSize.guard(value.remaining(), column.name.toString(), false, clientState);

if (column.type.asCQL3Type() == CQL3Type.Native.ASCII) // Ascii size specific guardrail
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not a switch statement here? if not, no need for the else's with the nested ifs, it makes it more verbose -- use else if instead. Also think moving this to a validateSize function (or something similarly named) would make it more clear

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.

3 participants