You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "michaelsembwever (via GitHub)" <gi...@apache.org> on 2026/09/18 08:07:58 UTC
[PR] CASSANDRA-11745 Support query paging by bytes [cassandra]
michaelsembwever opened a new pull request, #5183:
URL: https://github.com/apache/cassandra/pull/5183
Introduce PageSize to express paging limits in rows or bytes and propagate it through query options, read limits and pagers. Use byte limits for index builds and aggregation subpages, with coverage for paging state and serialization.
Target Cassandra 6.0 and serialize byte limits only from internode VERSION_60, preserving the 4.0 and 5.0 wire formats. Retain request timing, transaction conflict handling, top-K behavior and index-build failure injection.
Count live row data for byte limits so purging and filtering do not change paging counts. Include the fix and aggregation regression tests from datastax/cassandra commit bfd09f4, adapting the renamed SAI wrappers and the hex conversion helper for this branch. ref: datastax@bfd09f4
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-11745 Support query paging by bytes [cassandra]
Posted by "michaelsembwever (via GitHub)" <gi...@apache.org>.
michaelsembwever commented on code in PR #5183:
URL: https://github.com/apache/cassandra/pull/5183#discussion_r4185790557
##########
src/java/org/apache/cassandra/cql3/statements/SelectStatement.java:
##########
@@ -599,34 +626,44 @@ private ResultMessage.Rows execute(QueryState state,
Pager pager,
QueryOptions options,
Selectors selectors,
- int pageSize,
+ PageSize pageSize,
long nowInSec,
int userLimit,
AggregationSpecification aggregationSpec,
Dispatcher.RequestTime requestTime,
boolean unmask)
{
- Guardrails.pageSize.guard(pageSize, table(), false, state.getClientState());
+ // Guard the client request in its original unit, even after a compatibility fallback.
+ PageSize requestedPageSize = options.getPageSize();
+ if (requestedPageSize.isDefined())
+ {
+ if (requestedPageSize.getUnit() == PageSize.PageUnit.ROWS)
+ Guardrails.pageSize.guard(requestedPageSize.rows(), table(), false, state.getClientState());
+ else
+ Guardrails.pageSizeInBytes.guard(requestedPageSize.bytes(), table(), false, state.getClientState());
+ }
if (aggregationSpecFactory != null)
{
if (!restrictions.hasPartitionKeyRestrictions())
{
- warn("Aggregation query used without partition key");
- noSpamLogger.warn(String.format("Aggregation query used without partition key on table %s.%s, aggregation type: %s",
- keyspace(), table(), aggregationSpec.kind()));
+ ClientWarn.instance.warn("Aggregation query used without partition key");
+
+ noSpamLogger.warn("Aggregation query used without partition key on table {}.{}, aggregation type: {}",
+ keyspace(), table(), aggregationSpec.kind());
}
else if (restrictions.keyIsInRelation())
{
- warn("Aggregation query used on multiple partition keys (IN restriction)");
- noSpamLogger.warn(String.format("Aggregation query used on multiple partition keys (IN restriction) on table %s.%s, aggregation type: %s",
- keyspace(), table(), aggregationSpec.kind()));
+ ClientWarn.instance.warn("Aggregation query used on multiple partition keys (IN restriction)");
+
+ noSpamLogger.warn("Aggregation query used on multiple partition keys (IN restriction) on table {}.{}, aggregation type: {}",
+ keyspace(), table(), aggregationSpec.kind());
}
}
// We can't properly do post-query ordering if we page (see #6722)
// For GROUP BY or aggregation queries we always page internally even if the user has turned paging off
- checkFalse(pageSize > 0 && needsPostQueryOrdering(),
+ checkFalse(pageSize.isDefined() && needsPostQueryOrdering(),
Review Comment:
Yes.
Ordinary positive sizes behave equivalently, but zero is now a defined budget and Integer.MAX_VALUE represents unlimited paging.
Native QUERY and EXECUTE requests already reject zero before reaching this check. Direct internal callers can still supply it, so their contract needs an explicit compatibility decision. The unlimited also changes the predicate, although whether a query reaches this check depends on its execution path.
The behaviour change is why this has to happen before 6.0-beta1
I see reason why we need the change, and no way to not… 🤷
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-11745 Support query paging by bytes [cassandra]
Posted by "michaelsembwever (via GitHub)" <gi...@apache.org>.
michaelsembwever commented on code in PR #5183:
URL: https://github.com/apache/cassandra/pull/5183#discussion_r4186063395
##########
src/java/org/apache/cassandra/service/pager/PartitionRangeQueryPager.java:
##########
@@ -82,18 +86,18 @@ public PagingState state()
}
@Override
- protected PartitionRangeReadQuery nextPageReadQuery(int pageSize)
+ protected PartitionRangeReadQuery nextPageReadQuery(PageSize pageSize, DataLimits limits)
{
- DataLimits limits;
DataRange fullRange = query.dataRange();
DataRange pageRange;
+ // if it is the first page
if (lastReturnedKey == null)
{
pageRange = fullRange;
- limits = query.limits().forPaging(pageSize);
+ limits = limits.forPaging(pageSize);
}
// if the last key was the one of the end of the range we know that we are done
- else if (lastReturnedKey.equals(fullRange.keyRange().right) && remainingInPartition() == 0 && lastReturnedRow == null)
Review Comment:
Good catch.
This got carried over from Andrés de la Peña and Jacek Lewandowski commits: 6cd2d07d9a and 5a2e0f07cb.
I can infer but cannot trace any explanation why this change was made.
It has been reverted in https://github.com/apache/cassandra/pull/5183/changes/3304218ce881ad1f4f8df8fd1a2c848a534f5680
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-11745 Support query paging by bytes [cassandra]
Posted by "michaelsembwever (via GitHub)" <gi...@apache.org>.
michaelsembwever commented on code in PR #5183:
URL: https://github.com/apache/cassandra/pull/5183#discussion_r4186063395
##########
src/java/org/apache/cassandra/service/pager/PartitionRangeQueryPager.java:
##########
@@ -82,18 +86,18 @@ public PagingState state()
}
@Override
- protected PartitionRangeReadQuery nextPageReadQuery(int pageSize)
+ protected PartitionRangeReadQuery nextPageReadQuery(PageSize pageSize, DataLimits limits)
{
- DataLimits limits;
DataRange fullRange = query.dataRange();
DataRange pageRange;
+ // if it is the first page
if (lastReturnedKey == null)
{
pageRange = fullRange;
- limits = query.limits().forPaging(pageSize);
+ limits = limits.forPaging(pageSize);
}
// if the last key was the one of the end of the range we know that we are done
- else if (lastReturnedKey.equals(fullRange.keyRange().right) && remainingInPartition() == 0 && lastReturnedRow == null)
Review Comment:
Good catch.
This originally was from Andrés de la Peña 6cd2d07d9a, and the change to it got carried over from Jacek Lewandowski 5a2e0f07cb.
I can infer but cannot trace any explanation why this change was made.
It has been reverted in https://github.com/apache/cassandra/pull/5183/changes/3304218ce881ad1f4f8df8fd1a2c848a534f5680
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-11745 Support query paging by bytes [cassandra]
Posted by "michaelsembwever (via GitHub)" <gi...@apache.org>.
michaelsembwever commented on code in PR #5183:
URL: https://github.com/apache/cassandra/pull/5183#discussion_r4185754697
##########
src/java/org/apache/cassandra/cql3/PageSize.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cassandra.cql3;
+
+import java.util.Objects;
+
+import com.google.common.base.Preconditions;
+
+import org.apache.cassandra.db.filter.DataLimits;
+
+import static org.apache.cassandra.utils.LocalizeString.toLowerCaseLocalized;
+
+public class PageSize
+{
+ public static final PageSize NONE = new PageSize(DataLimits.NO_LIMIT, PageUnit.ROWS);
+
+ public enum PageUnit
+ {
+ ROWS, BYTES
+ }
+
+ private final int size;
+ private final PageUnit unit;
+
+ public PageSize(int size, PageUnit unit)
+ {
+ Preconditions.checkArgument(size >= 0);
+ Preconditions.checkNotNull(unit);
+ this.size = size;
+ this.unit = unit;
+ }
+
+ public int getSize()
+ {
+ return size;
+ }
+
+ public PageUnit getUnit()
+ {
+ return unit;
+ }
+
+ public int bytes()
+ {
+ return unit == PageUnit.BYTES ? size : DataLimits.NO_LIMIT;
+ }
+
+ public int rows()
+ {
+ return unit == PageUnit.ROWS ? size : DataLimits.NO_LIMIT;
+ }
+
+ /**
+ * Creates a page size representing {@code count} rows.
+ *
+ * @throws IllegalArgumentException if the size is not strictly positive.
+ */
+ public static PageSize inRows(int rowsCount)
+ {
+ return new PageSize(rowsCount, PageUnit.ROWS);
+ }
+
+ /**
+ * Creates a page size representing {@code size} bytes.
+ *
+ * @throws IllegalArgumentException if the size is not strictly positive.
+ */
+ public static PageSize inBytes(int bytesCount)
+ {
+ return new PageSize(bytesCount, PageUnit.BYTES);
+ }
+
+ /**
+ * Returns the minimum number of rows for the given number and the number of rows represented by this page size.
+ * If this page size is defined in bytes or undefined, it will just return the provided number of rows.
+ */
+ public int minRowsCount(int rowsCount)
+ {
+ return unit == PageUnit.ROWS ? Math.min(rowsCount, size) : rowsCount;
+ }
+
+ /**
+ * Returns the minimum number of bytes for the given number and the number of bytes represented by this page size.
+ * If this page size is defined in rows or undefined, it will just return the provided number of bytes.
+ */
+ public int minBytesCount(int bytesCount)
+ {
+ return unit == PageUnit.BYTES ? Math.min(bytesCount, size) : bytesCount;
+ }
+
+ public boolean isDefined()
+ {
+ return size < DataLimits.NO_LIMIT;
+ }
+
+ public PageSize withDecreasedRows(int rowsCount) {
+ return unit == PageUnit.ROWS && size != DataLimits.NO_LIMIT
+ ? inRows((int) Math.min(Integer.MAX_VALUE, Math.max(0L, (long) size - (long) rowsCount)))
+ : this;
+ }
+
+ public PageSize withDecreasedBytes(int bytesCount) {
+ return unit == PageUnit.BYTES && size != DataLimits.NO_LIMIT
+ ? inBytes((int) Math.min(Integer.MAX_VALUE, Math.max(0L, (long) size - (long) bytesCount)))
+ : this;
+ }
+
+ /**
+ * Assuming we went through the provided number of rows/bytes, it returns whether the page is completed.
+ * It will always return {@code false} if the page size is undefined (unlimited).
+ */
+ public boolean isCompleted(int count, PageUnit unit)
Review Comment:
yup. removed in bfe30581a9
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-11745 Support query paging by bytes [cassandra]
Posted by "michaelsembwever (via GitHub)" <gi...@apache.org>.
michaelsembwever commented on PR #5183:
URL: https://github.com/apache/cassandra/pull/5183#issuecomment-6302087437
@clohfink , note that i added a commit to clean up the QueryOptions enums. the list of reserved UNUSED enums isn't needed upstream. https://github.com/apache/cassandra/pull/5183/changes/c30ef11e0b29adf258cff87bf323349a09a4f699
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-11745 Support query paging by bytes [cassandra]
Posted by "michaelsembwever (via GitHub)" <gi...@apache.org>.
michaelsembwever commented on code in PR #5183:
URL: https://github.com/apache/cassandra/pull/5183#discussion_r4185820922
##########
src/java/org/apache/cassandra/cql3/statements/SelectStatement.java:
##########
@@ -359,6 +362,18 @@ public void validate(ClientState state) throws InvalidRequestException
Guardrails.allowFilteringEnabled.ensureEnabled(state);
}
+ /**
+ * Returns whether the paging can be skipped based on the user limits and the page size - that is, if the user limit
+ * is provided and does not exceed the page size, it means that we will only return at most one page and thus paging
+ * is unnecessary in this case. That applies to the page size defined in rows - if the page size is defined in bytes
+ * we cannot say anything about the relation beteween the user rows limit and the page size.
+ */
+ private boolean canSkipPaging(DataLimits userLimits, PageSize pageSize)
+ {
+ return !pageSize.isDefined() ||
Review Comment:
Yes.
But, the native client example is rejected earlier with “The page size cannot be 0.”
This is still a concern for direct internal callers. A zero page_size can produce an empty page without advancing the pager; a caller that repeatedly fetches until exhaustion could loop.
We need to decide whether those entry points should reject zero or preserve its former meaning of disabling paging. I'm in favour of rejecting zero (use Integer.MAX_VALUE to disable paging, so we simplify interpretation regardless of caller type).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-11745 Support query paging by bytes [cassandra]
Posted by "jaydeepkumar1984 (via GitHub)" <gi...@apache.org>.
jaydeepkumar1984 commented on code in PR #5183:
URL: https://github.com/apache/cassandra/pull/5183#discussion_r4118225434
##########
src/java/org/apache/cassandra/cql3/statements/SelectStatement.java:
##########
@@ -599,34 +626,44 @@ private ResultMessage.Rows execute(QueryState state,
Pager pager,
QueryOptions options,
Selectors selectors,
- int pageSize,
+ PageSize pageSize,
long nowInSec,
int userLimit,
AggregationSpecification aggregationSpec,
Dispatcher.RequestTime requestTime,
boolean unmask)
{
- Guardrails.pageSize.guard(pageSize, table(), false, state.getClientState());
+ // Guard the client request in its original unit, even after a compatibility fallback.
+ PageSize requestedPageSize = options.getPageSize();
+ if (requestedPageSize.isDefined())
+ {
+ if (requestedPageSize.getUnit() == PageSize.PageUnit.ROWS)
+ Guardrails.pageSize.guard(requestedPageSize.rows(), table(), false, state.getClientState());
+ else
+ Guardrails.pageSizeInBytes.guard(requestedPageSize.bytes(), table(), false, state.getClientState());
+ }
if (aggregationSpecFactory != null)
{
if (!restrictions.hasPartitionKeyRestrictions())
{
- warn("Aggregation query used without partition key");
- noSpamLogger.warn(String.format("Aggregation query used without partition key on table %s.%s, aggregation type: %s",
- keyspace(), table(), aggregationSpec.kind()));
+ ClientWarn.instance.warn("Aggregation query used without partition key");
+
+ noSpamLogger.warn("Aggregation query used without partition key on table {}.{}, aggregation type: {}",
+ keyspace(), table(), aggregationSpec.kind());
}
else if (restrictions.keyIsInRelation())
{
- warn("Aggregation query used on multiple partition keys (IN restriction)");
- noSpamLogger.warn(String.format("Aggregation query used on multiple partition keys (IN restriction) on table %s.%s, aggregation type: %s",
- keyspace(), table(), aggregationSpec.kind()));
+ ClientWarn.instance.warn("Aggregation query used on multiple partition keys (IN restriction)");
+
+ noSpamLogger.warn("Aggregation query used on multiple partition keys (IN restriction) on table {}.{}, aggregation type: {}",
+ keyspace(), table(), aggregationSpec.kind());
}
}
// We can't properly do post-query ordering if we page (see #6722)
// For GROUP BY or aggregation queries we always page internally even if the user has turned paging off
- checkFalse(pageSize > 0 && needsPostQueryOrdering(),
+ checkFalse(pageSize.isDefined() && needsPostQueryOrdering(),
Review Comment:
Isn't this a behavior change? Previously, it checked pageSize > 0, but now it only checks pageSize < DataLimits.NO_LIMIT
##########
src/java/org/apache/cassandra/cql3/PageSize.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cassandra.cql3;
+
+import java.util.Objects;
+
+import com.google.common.base.Preconditions;
+
+import org.apache.cassandra.db.filter.DataLimits;
+
+import static org.apache.cassandra.utils.LocalizeString.toLowerCaseLocalized;
+
+public class PageSize
+{
+ public static final PageSize NONE = new PageSize(DataLimits.NO_LIMIT, PageUnit.ROWS);
+
+ public enum PageUnit
+ {
+ ROWS, BYTES
+ }
+
+ private final int size;
+ private final PageUnit unit;
+
+ public PageSize(int size, PageUnit unit)
+ {
+ Preconditions.checkArgument(size >= 0);
+ Preconditions.checkNotNull(unit);
+ this.size = size;
+ this.unit = unit;
+ }
+
+ public int getSize()
+ {
+ return size;
+ }
+
+ public PageUnit getUnit()
+ {
+ return unit;
+ }
+
+ public int bytes()
+ {
+ return unit == PageUnit.BYTES ? size : DataLimits.NO_LIMIT;
+ }
+
+ public int rows()
+ {
+ return unit == PageUnit.ROWS ? size : DataLimits.NO_LIMIT;
+ }
+
+ /**
+ * Creates a page size representing {@code count} rows.
+ *
+ * @throws IllegalArgumentException if the size is not strictly positive.
+ */
+ public static PageSize inRows(int rowsCount)
+ {
+ return new PageSize(rowsCount, PageUnit.ROWS);
+ }
+
+ /**
+ * Creates a page size representing {@code size} bytes.
+ *
+ * @throws IllegalArgumentException if the size is not strictly positive.
+ */
+ public static PageSize inBytes(int bytesCount)
+ {
+ return new PageSize(bytesCount, PageUnit.BYTES);
+ }
+
+ /**
+ * Returns the minimum number of rows for the given number and the number of rows represented by this page size.
+ * If this page size is defined in bytes or undefined, it will just return the provided number of rows.
+ */
+ public int minRowsCount(int rowsCount)
+ {
+ return unit == PageUnit.ROWS ? Math.min(rowsCount, size) : rowsCount;
+ }
+
+ /**
+ * Returns the minimum number of bytes for the given number and the number of bytes represented by this page size.
+ * If this page size is defined in rows or undefined, it will just return the provided number of bytes.
+ */
+ public int minBytesCount(int bytesCount)
+ {
+ return unit == PageUnit.BYTES ? Math.min(bytesCount, size) : bytesCount;
+ }
+
+ public boolean isDefined()
+ {
+ return size < DataLimits.NO_LIMIT;
+ }
+
+ public PageSize withDecreasedRows(int rowsCount) {
+ return unit == PageUnit.ROWS && size != DataLimits.NO_LIMIT
+ ? inRows((int) Math.min(Integer.MAX_VALUE, Math.max(0L, (long) size - (long) rowsCount)))
+ : this;
+ }
+
+ public PageSize withDecreasedBytes(int bytesCount) {
+ return unit == PageUnit.BYTES && size != DataLimits.NO_LIMIT
+ ? inBytes((int) Math.min(Integer.MAX_VALUE, Math.max(0L, (long) size - (long) bytesCount)))
+ : this;
+ }
+
+ /**
+ * Assuming we went through the provided number of rows/bytes, it returns whether the page is completed.
+ * It will always return {@code false} if the page size is undefined (unlimited).
+ */
+ public boolean isCompleted(int count, PageUnit unit)
Review Comment:
nit: Is this dead code?
##########
src/java/org/apache/cassandra/cql3/statements/SelectStatement.java:
##########
@@ -359,6 +362,18 @@ public void validate(ClientState state) throws InvalidRequestException
Guardrails.allowFilteringEnabled.ensureEnabled(state);
}
+ /**
+ * Returns whether the paging can be skipped based on the user limits and the page size - that is, if the user limit
+ * is provided and does not exceed the page size, it means that we will only return at most one page and thus paging
+ * is unnecessary in this case. That applies to the page size defined in rows - if the page size is defined in bytes
+ * we cannot say anything about the relation beteween the user rows limit and the page size.
+ */
+ private boolean canSkipPaging(DataLimits userLimits, PageSize pageSize)
+ {
+ return !pageSize.isDefined() ||
Review Comment:
Wouldn't this break an existing contract? Here is an example:
"SELECT * FROM TABLE LIMIT 1000" and the client supplied page_size=0
With this,
`!pageSize.isDefined()` -> `false`
`userLimits.count() <= pageSize.rows()` -> `1000 <= 0`
As a result, `canSkipPaging` will return `false` and this query would never finish; it will
##########
src/java/org/apache/cassandra/cql3/PageSize.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cassandra.cql3;
+
+import java.util.Objects;
+
+import com.google.common.base.Preconditions;
+
+import org.apache.cassandra.db.filter.DataLimits;
+
+import static org.apache.cassandra.utils.LocalizeString.toLowerCaseLocalized;
+
+public class PageSize
+{
+ public static final PageSize NONE = new PageSize(DataLimits.NO_LIMIT, PageUnit.ROWS);
+
+ public enum PageUnit
+ {
+ ROWS, BYTES
+ }
+
+ private final int size;
+ private final PageUnit unit;
+
+ public PageSize(int size, PageUnit unit)
+ {
+ Preconditions.checkArgument(size >= 0);
+ Preconditions.checkNotNull(unit);
+ this.size = size;
+ this.unit = unit;
+ }
+
+ public int getSize()
+ {
+ return size;
+ }
+
+ public PageUnit getUnit()
+ {
+ return unit;
+ }
+
+ public int bytes()
+ {
+ return unit == PageUnit.BYTES ? size : DataLimits.NO_LIMIT;
+ }
+
+ public int rows()
+ {
+ return unit == PageUnit.ROWS ? size : DataLimits.NO_LIMIT;
+ }
+
+ /**
+ * Creates a page size representing {@code count} rows.
+ *
+ * @throws IllegalArgumentException if the size is not strictly positive.
Review Comment:
nit: the `PageSize` constructor allows 0 size so the comment is a bit misleading
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-11745 Support query paging by bytes [cassandra]
Posted by "michaelsembwever (via GitHub)" <gi...@apache.org>.
michaelsembwever commented on PR #5183:
URL: https://github.com/apache/cassandra/pull/5183#issuecomment-6302781925
@jaydeepkumar1984 , here's alternative stacking of commits and PRs, hopefully to make reviewing a bit easier…
(they end up the same diff as this PR. i didn't know how to break the second one up more…)
1. https://github.com/apache/cassandra/pull/5284
2. https://github.com/thelastpickle/cassandra/pull/8
3. https://github.com/thelastpickle/cassandra/pull/9
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-11745 Support query paging by bytes [cassandra]
Posted by "michaelsembwever (via GitHub)" <gi...@apache.org>.
michaelsembwever commented on code in PR #5183:
URL: https://github.com/apache/cassandra/pull/5183#discussion_r4185886839
##########
src/java/org/apache/cassandra/db/rows/ComplexColumnData.java:
##########
@@ -142,13 +142,25 @@ public int dataSize()
return size;
}
+ @Override
+ public int liveDataSize(long nowInSec)
Review Comment:
Correct. Complex-column live sizing now includes deletion metadata when live cells survive, matching row-level accounting. It remains zero when no live cells survive because filtering removes that column.
Extended the existing test to check expiry and deletion, and compare byte counts before and after purging surviving columns. Fixed in f2ed7994687.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-11745 Support query paging by bytes [cassandra]
Posted by "jaydeepkumar1984 (via GitHub)" <gi...@apache.org>.
jaydeepkumar1984 commented on code in PR #5183:
URL: https://github.com/apache/cassandra/pull/5183#discussion_r4127575888
##########
src/java/org/apache/cassandra/db/rows/ComplexColumnData.java:
##########
@@ -142,13 +142,25 @@ public int dataSize()
return size;
}
+ @Override
+ public int liveDataSize(long nowInSec)
Review Comment:
In `BTreeRow,` we include `deletion.dataSize()`; however, here we don't. There needs to be uniformity across.
##########
src/java/org/apache/cassandra/service/pager/PartitionRangeQueryPager.java:
##########
@@ -82,18 +86,18 @@ public PagingState state()
}
@Override
- protected PartitionRangeReadQuery nextPageReadQuery(int pageSize)
+ protected PartitionRangeReadQuery nextPageReadQuery(PageSize pageSize, DataLimits limits)
{
- DataLimits limits;
DataRange fullRange = query.dataRange();
DataRange pageRange;
+ // if it is the first page
if (lastReturnedKey == null)
{
pageRange = fullRange;
- limits = query.limits().forPaging(pageSize);
+ limits = limits.forPaging(pageSize);
}
// if the last key was the one of the end of the range we know that we are done
- else if (lastReturnedKey.equals(fullRange.keyRange().right) && remainingInPartition() == 0 && lastReturnedRow == null)
Review Comment:
Why are we changing the behavior here `&& lastReturnedRow == null` and how is it related to this PR? With the update, we may lose the data for the following corner-case:
```
1. The last partition in the scan range (lastReturnedKey == fullRange.keyRange().right) has a static row and regular rows.
2. The current page's byte/row budget runs out right after counting that partition's static row, before any regular row of the same partition is counted (e.g. the static row alone is large enough to fill the byte-based page, or the page's row count happens to land there).
3. In AbstractQueryPager.PagerTransformation.onClose():
if (lastRow != null && (lastRow.clustering() == Clustering.STATIC_CLUSTERING || lastRow.clustering().isEmpty()))
remainingInPartition = 0;
remainingInPartition is forced to 0 because the last row processed was static — even though this partition's regular rows were never read.
4. In PartitionRangeQueryPager.recordLast():
if (last.clustering() != Clustering.STATIC_CLUSTERING)
lastReturnedRow = PagingState.RowMark.create(...);
lastReturnedRow is not updated when the last row is static, so it's left stale (possibly null, possibly a leftover value from an earlier partition).
5. On the next fetchPage call, nextPageReadQuery now sees lastReturnedKey == right and remainingInPartition() == 0, and returns null — the pager marks itself exhausted and stops paging for good.
```
##########
src/java/org/apache/cassandra/service/pager/AbstractQueryPager.java:
##########
@@ -37,139 +45,199 @@
import org.apache.cassandra.transport.Dispatcher;
import org.apache.cassandra.transport.ProtocolVersion;
+@NotThreadSafe
abstract class AbstractQueryPager<T extends ReadQuery> implements QueryPager
{
+ private static final Logger logger = LoggerFactory.getLogger(AbstractQueryPager.class);
+
protected final T query;
- protected final DataLimits limits;
+
protected final ProtocolVersion protocolVersion;
+
private final boolean enforceStrictLiveness;
+ /**
+ * This is the counter which was used for the last page we fetched.
+ * It can be used to obtain the number of fetched rows or bytes.
+ */
+ private DataLimits.Counter lastCounter;
+
+ /**
+ * The {@link #remaining} and {@link #remainingInPartition} are initially set to the user limits provided
+ * in the query (via the LIMIT and PER PARTITION LIMIT clauses - those values are obtained from {@link #limits}).
+ * When a page is fetched, iterated and closed, those values are updated with the number of items counted
+ * on that recently fetched page.
+ */
private int remaining;
+ private int remainingInPartition;
- // This is the last key we've been reading from (or can still be reading within). This the key for
- // which remainingInPartition makes sense: if we're starting another key, we should reset remainingInPartition
- // (and this is done in PagerIterator). This can be null (when we start).
+ /**
+ * This is the current key at which the data is being read. This is the key for which {@link #remainingInPartition}
+ * makes sense: when a next partition (key) is started, {@link #remainingInPartition} should be reset to the value
+ * provided in {@link #limits}. This can be null (before a first data item is read).
+ */
private DecoratedKey lastKey;
- private int remainingInPartition;
+ /**
+ * Whether the pager is exhausted or not. The pager gets exhausted if the recently fetched, iterated and closed
+ * page had fewer items than the requested page size.
+ */
private boolean exhausted;
+ /**
+ * The paging transformation which is used for the recently requested page. It is set when a new page is requested
+ * and then cleaned (nulled), when the page is closed. It is used to prevent fetching a new page until the previous
+ * one is still being iterated.
+ */
+ private PagerTransformation<?> currentPagerTransformation;
+
protected AbstractQueryPager(T query, ProtocolVersion protocolVersion)
{
this.query = query;
this.protocolVersion = protocolVersion;
- this.limits = query.limits();
this.enforceStrictLiveness = query.metadata().enforceStrictLiveness();
- this.remaining = limits.count();
- this.remainingInPartition = limits.perPartitionCount();
+ this.remaining = query.limits().count();
+ this.remainingInPartition = query.limits().perPartitionCount();
}
+ @Override
public ReadExecutionController executionController()
{
return query.executionController();
}
- public PartitionIterator fetchPage(int pageSize, ConsistencyLevel consistency, ClientState clientState, Dispatcher.RequestTime requestTime)
+ private ReadQuery startNextPage(PageSize pageSize, DataLimits limits)
{
+ assert currentPagerTransformation == null;
+
if (isExhausted())
- return EmptyIterators.partition();
+ return null;
- pageSize = Math.min(pageSize, remaining);
- Pager pager = new RowPager(limits.forPaging(pageSize), query.nowInSec());
- ReadQuery readQuery = nextPageReadQuery(pageSize);
+ ReadQuery readQuery = nextPageReadQuery(pageSize, limits);
if (readQuery == null)
- {
exhausted = true;
- return EmptyIterators.partition();
- }
- return Transformation.apply(readQuery.execute(consistency, clientState, requestTime), pager);
+
+ return readQuery;
}
- public PartitionIterator fetchPageInternal(int pageSize, ReadExecutionController executionController)
+ @Override
+ public PartitionIterator fetchPage(PageSize pageSize, ConsistencyLevel consistency, ClientState clientState, Dispatcher.RequestTime requestTime)
{
- if (isExhausted())
+ DataLimits nextPageLimits = nextPageLimits();
+ ReadQuery readQuery = startNextPage(pageSize, nextPageLimits);
+ if (readQuery == null)
return EmptyIterators.partition();
- pageSize = Math.min(pageSize, remaining);
- RowPager pager = new RowPager(limits.forPaging(pageSize), query.nowInSec());
- ReadQuery readQuery = nextPageReadQuery(pageSize);
+ RowPagerTransformation pagerTransformation = new RowPagerTransformation(nextPageLimits.forPaging(pageSize), query.nowInSec());
+ currentPagerTransformation = pagerTransformation;
+ return Transformation.apply(readQuery.execute(consistency, clientState, requestTime), pagerTransformation);
Review Comment:
Since line no. 134, `currentPagerTransformation` is non-null; if any exception is thrown in the execute, then "onClose" will not be invoked. As a result, any subsequent invocation will fail the assert as `currentPagerTransformation != null`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-11745 Support query paging by bytes [cassandra]
Posted by "michaelsembwever (via GitHub)" <gi...@apache.org>.
michaelsembwever commented on PR #5183:
URL: https://github.com/apache/cassandra/pull/5183#issuecomment-5998746273
> PR Scope: This PR is quite large and introduces several backward-incompatible and behavioral changes. To make this easier and safer to review, please break it down into smaller, focused PRs.
I could separate the aggregation iterator’s `next()` handling fix (which also applies back to 3.11), but it is very few lines of code so won't reduce your review burden.
For reducing PR scope, the row-only pager test reorganisation could land first, and index-build/aggregation adoption could follow the core byte-paging support.
Specifically,
1. **Preparatory PR:** pager test reorganisation and expanded row-only coverage, using the existing APIs. The independent aggregation iterator fix can land separately.
2. **CASSANDRA-11745:** byte-based limits and paging, including live-byte accounting, protocol support, guardrails, compatibility handling and the correctness fixes required for byte paging.
3. **Consumer adoption:** switch index builds and aggregation’s internal subpages to byte budgets, with their configuration and tests. These could be separate PRs.
@jaydeepkumar1984 , what do you want ? Since we want this in before 6.0-beta1 and I do see this as all part of bytes-based limit and paging (which are coupled), I'd rather keep it together. But if the review is going to be slower then i'm ok to split it up to those three steps, though still keeping it under this one ticket (e.g. squash all the current commits, then create three commits to match those three steps, all in this PR and with the intention to squash them back to one commit before merge)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-11745 Support query paging by bytes [cassandra]
Posted by "michaelsembwever (via GitHub)" <gi...@apache.org>.
michaelsembwever commented on PR #5183:
URL: https://github.com/apache/cassandra/pull/5183#issuecomment-6443553084
Committed https://github.com/apache/cassandra/commit/8f6787959e001c2d50696ef0f9df3e9c85ac36c8
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-11745 Support query paging by bytes [cassandra]
Posted by "jaydeepkumar1984 (via GitHub)" <gi...@apache.org>.
jaydeepkumar1984 commented on PR #5183:
URL: https://github.com/apache/cassandra/pull/5183#issuecomment-5879816175
General feedback:
**PR Scope:** This PR is quite large and introduces several backward-incompatible and behavioral changes. To make this easier and safer to review, please break it down into smaller, focused PRs.
**Behavioral Changes:** Avoid introducing behavioral changes unless strictly necessary. If a change is required, please call it out explicitly with the context and justification.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-11745 Support query paging by bytes [cassandra]
Posted by "michaelsembwever (via GitHub)" <gi...@apache.org>.
michaelsembwever commented on code in PR #5183:
URL: https://github.com/apache/cassandra/pull/5183#discussion_r4186063395
##########
src/java/org/apache/cassandra/service/pager/PartitionRangeQueryPager.java:
##########
@@ -82,18 +86,18 @@ public PagingState state()
}
@Override
- protected PartitionRangeReadQuery nextPageReadQuery(int pageSize)
+ protected PartitionRangeReadQuery nextPageReadQuery(PageSize pageSize, DataLimits limits)
{
- DataLimits limits;
DataRange fullRange = query.dataRange();
DataRange pageRange;
+ // if it is the first page
if (lastReturnedKey == null)
{
pageRange = fullRange;
- limits = query.limits().forPaging(pageSize);
+ limits = limits.forPaging(pageSize);
}
// if the last key was the one of the end of the range we know that we are done
- else if (lastReturnedKey.equals(fullRange.keyRange().right) && remainingInPartition() == 0 && lastReturnedRow == null)
Review Comment:
Good catch.
This originally was from Andrés de la Peña 6cd2d07d9a, and the change to it got carried over from Jacek Lewandowski 5a2e0f07cb.
It has been reverted in https://github.com/apache/cassandra/pull/5183/changes/3304218ce881ad1f4f8df8fd1a2c848a534f5680
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-11745 Support query paging by bytes [cassandra]
Posted by "michaelsembwever (via GitHub)" <gi...@apache.org>.
michaelsembwever commented on code in PR #5183:
URL: https://github.com/apache/cassandra/pull/5183#discussion_r4185830461
##########
src/java/org/apache/cassandra/service/pager/AbstractQueryPager.java:
##########
@@ -37,139 +45,199 @@
import org.apache.cassandra.transport.Dispatcher;
import org.apache.cassandra.transport.ProtocolVersion;
+@NotThreadSafe
abstract class AbstractQueryPager<T extends ReadQuery> implements QueryPager
{
+ private static final Logger logger = LoggerFactory.getLogger(AbstractQueryPager.class);
+
protected final T query;
- protected final DataLimits limits;
+
protected final ProtocolVersion protocolVersion;
+
private final boolean enforceStrictLiveness;
+ /**
+ * This is the counter which was used for the last page we fetched.
+ * It can be used to obtain the number of fetched rows or bytes.
+ */
+ private DataLimits.Counter lastCounter;
+
+ /**
+ * The {@link #remaining} and {@link #remainingInPartition} are initially set to the user limits provided
+ * in the query (via the LIMIT and PER PARTITION LIMIT clauses - those values are obtained from {@link #limits}).
+ * When a page is fetched, iterated and closed, those values are updated with the number of items counted
+ * on that recently fetched page.
+ */
private int remaining;
+ private int remainingInPartition;
- // This is the last key we've been reading from (or can still be reading within). This the key for
- // which remainingInPartition makes sense: if we're starting another key, we should reset remainingInPartition
- // (and this is done in PagerIterator). This can be null (when we start).
+ /**
+ * This is the current key at which the data is being read. This is the key for which {@link #remainingInPartition}
+ * makes sense: when a next partition (key) is started, {@link #remainingInPartition} should be reset to the value
+ * provided in {@link #limits}. This can be null (before a first data item is read).
+ */
private DecoratedKey lastKey;
- private int remainingInPartition;
+ /**
+ * Whether the pager is exhausted or not. The pager gets exhausted if the recently fetched, iterated and closed
+ * page had fewer items than the requested page size.
+ */
private boolean exhausted;
+ /**
+ * The paging transformation which is used for the recently requested page. It is set when a new page is requested
+ * and then cleaned (nulled), when the page is closed. It is used to prevent fetching a new page until the previous
+ * one is still being iterated.
+ */
+ private PagerTransformation<?> currentPagerTransformation;
+
protected AbstractQueryPager(T query, ProtocolVersion protocolVersion)
{
this.query = query;
this.protocolVersion = protocolVersion;
- this.limits = query.limits();
this.enforceStrictLiveness = query.metadata().enforceStrictLiveness();
- this.remaining = limits.count();
- this.remainingInPartition = limits.perPartitionCount();
+ this.remaining = query.limits().count();
+ this.remainingInPartition = query.limits().perPartitionCount();
}
+ @Override
public ReadExecutionController executionController()
{
return query.executionController();
}
- public PartitionIterator fetchPage(int pageSize, ConsistencyLevel consistency, ClientState clientState, Dispatcher.RequestTime requestTime)
+ private ReadQuery startNextPage(PageSize pageSize, DataLimits limits)
{
+ assert currentPagerTransformation == null;
+
if (isExhausted())
- return EmptyIterators.partition();
+ return null;
- pageSize = Math.min(pageSize, remaining);
- Pager pager = new RowPager(limits.forPaging(pageSize), query.nowInSec());
- ReadQuery readQuery = nextPageReadQuery(pageSize);
+ ReadQuery readQuery = nextPageReadQuery(pageSize, limits);
if (readQuery == null)
- {
exhausted = true;
- return EmptyIterators.partition();
- }
- return Transformation.apply(readQuery.execute(consistency, clientState, requestTime), pager);
+
+ return readQuery;
}
- public PartitionIterator fetchPageInternal(int pageSize, ReadExecutionController executionController)
+ @Override
+ public PartitionIterator fetchPage(PageSize pageSize, ConsistencyLevel consistency, ClientState clientState, Dispatcher.RequestTime requestTime)
{
- if (isExhausted())
+ DataLimits nextPageLimits = nextPageLimits();
+ ReadQuery readQuery = startNextPage(pageSize, nextPageLimits);
+ if (readQuery == null)
return EmptyIterators.partition();
- pageSize = Math.min(pageSize, remaining);
- RowPager pager = new RowPager(limits.forPaging(pageSize), query.nowInSec());
- ReadQuery readQuery = nextPageReadQuery(pageSize);
+ RowPagerTransformation pagerTransformation = new RowPagerTransformation(nextPageLimits.forPaging(pageSize), query.nowInSec());
+ currentPagerTransformation = pagerTransformation;
+ return Transformation.apply(readQuery.execute(consistency, clientState, requestTime), pagerTransformation);
Review Comment:
Yes.
The active transformation is now recorded only after execution and iterator wrapping succeeds. An execution failure would no longer leaves the pager looking as though a page is still open.
Added a regression test that throws on the first execution and successfully retries using the same pager. It covers distributed, internal and unfiltered execution paths. Fixed in 345a483c6d2.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-11745 Support query paging by bytes [cassandra]
Posted by "michaelsembwever (via GitHub)" <gi...@apache.org>.
michaelsembwever commented on code in PR #5183:
URL: https://github.com/apache/cassandra/pull/5183#discussion_r4185820922
##########
src/java/org/apache/cassandra/cql3/statements/SelectStatement.java:
##########
@@ -359,6 +362,18 @@ public void validate(ClientState state) throws InvalidRequestException
Guardrails.allowFilteringEnabled.ensureEnabled(state);
}
+ /**
+ * Returns whether the paging can be skipped based on the user limits and the page size - that is, if the user limit
+ * is provided and does not exceed the page size, it means that we will only return at most one page and thus paging
+ * is unnecessary in this case. That applies to the page size defined in rows - if the page size is defined in bytes
+ * we cannot say anything about the relation beteween the user rows limit and the page size.
+ */
+ private boolean canSkipPaging(DataLimits userLimits, PageSize pageSize)
+ {
+ return !pageSize.isDefined() ||
Review Comment:
Yes.
But, the native client example is rejected earlier with “The page size cannot be 0.”
This is still a concern for direct internal callers. A zero page_size (budget) can produce an empty page without advancing the pager; a caller that repeatedly fetches until exhaustion could loop.
We need to decide whether those entry points should reject zero or preserve its former meaning of disabling paging. I'm in favour of rejecting zero (use Integer.MAX_VALUE to disable paging, so we simplify interpretation regardless of caller type).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-11745 Support query paging by bytes [cassandra]
Posted by "michaelsembwever (via GitHub)" <gi...@apache.org>.
michaelsembwever commented on code in PR #5183:
URL: https://github.com/apache/cassandra/pull/5183#discussion_r4185764210
##########
src/java/org/apache/cassandra/cql3/PageSize.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cassandra.cql3;
+
+import java.util.Objects;
+
+import com.google.common.base.Preconditions;
+
+import org.apache.cassandra.db.filter.DataLimits;
+
+import static org.apache.cassandra.utils.LocalizeString.toLowerCaseLocalized;
+
+public class PageSize
+{
+ public static final PageSize NONE = new PageSize(DataLimits.NO_LIMIT, PageUnit.ROWS);
+
+ public enum PageUnit
+ {
+ ROWS, BYTES
+ }
+
+ private final int size;
+ private final PageUnit unit;
+
+ public PageSize(int size, PageUnit unit)
+ {
+ Preconditions.checkArgument(size >= 0);
+ Preconditions.checkNotNull(unit);
+ this.size = size;
+ this.unit = unit;
+ }
+
+ public int getSize()
+ {
+ return size;
+ }
+
+ public PageUnit getUnit()
+ {
+ return unit;
+ }
+
+ public int bytes()
+ {
+ return unit == PageUnit.BYTES ? size : DataLimits.NO_LIMIT;
+ }
+
+ public int rows()
+ {
+ return unit == PageUnit.ROWS ? size : DataLimits.NO_LIMIT;
+ }
+
+ /**
+ * Creates a page size representing {@code count} rows.
+ *
+ * @throws IllegalArgumentException if the size is not strictly positive.
Review Comment:
Yup. Updated both factory comments to state that negative sizes are rejected and zero is accepted. Also corrected the parameter references.
Zero remains useful internally when subtracting consumed rows or bytes leaves no page budget.
Fixed in b35fa446553.
note, a full run-through and update of the comments are still pending…
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org