dcapwell commented on a change in pull request #1180:
URL: https://github.com/apache/cassandra/pull/1180#discussion_r702146012
##########
File path: src/java/org/apache/cassandra/db/ReadCommand.java
##########
@@ -632,6 +654,84 @@ private void maybeDelayForTesting()
}
}
+ private UnfilteredPartitionIterator
withQuerySizeTracking(UnfilteredPartitionIterator iterator)
+ {
+ if (!trackWarnings ||
SchemaConstants.isSystemKeyspace(metadata().keyspace)) // exclude internal
keyspaces
+ return iterator;
+ final long warnThresholdBytes =
DatabaseDescriptor.getLocalReadTooLargeWarningThresholdKb() * 1024;
+ final long abortThresholdBytes =
DatabaseDescriptor.getLocalReadTooLargeAbortThresholdKb() * 1024;
+ if (warnThresholdBytes == 0 && abortThresholdBytes == 0)
+ return iterator;
+ class QuerySizeTracking extends Transformation<UnfilteredRowIterator>
+ {
+ private DecoratedKey currentKey;
+ private long sizeInBytes = 0;
+
+ @Override
+ public UnfilteredRowIterator
applyToPartition(UnfilteredRowIterator iter)
+ {
+ currentKey = iter.partitionKey();
+ sizeInBytes += ObjectSizes.sizeOnHeapOf(currentKey.getKey());
+ return Transformation.apply(iter, this);
+ }
+
+ @Override
+ protected Row applyToStatic(Row row)
+ {
+ return applyToRow(row);
+ }
+
+ @Override
+ protected Row applyToRow(Row row)
+ {
+ addSize(row.unsharedHeapSize());
+ return row;
+ }
+
+ @Override
+ protected RangeTombstoneMarker applyToMarker(RangeTombstoneMarker
marker)
+ {
+ addSize(marker.unsharedHeapSize());
+ return marker;
+ }
+
+ @Override
+ protected DeletionTime applyToDeletion(DeletionTime deletionTime)
+ {
+ addSize(deletionTime.unsharedHeapSize());
+ return deletionTime;
+ }
+
+ private void addSize(long size)
+ {
+ this.sizeInBytes += size;
+ if (abortThresholdBytes != 0 && this.sizeInBytes >=
abortThresholdBytes)
+ {
+ String msg = String.format("Query %s attempted to read %d
bytes but max allowed is %d; query aborted (see
local_read_too_large_abort_threshold_kb)",
+ ReadCommand.this.toCQLString(),
this.sizeInBytes, abortThresholdBytes);
+ Tracing.trace(msg);
+
MessageParams.remove(ParamType.LOCAL_READ_TOO_LARGE_WARNING);
+ MessageParams.add(ParamType.LOCAL_READ_TOO_LARGE_ABORT,
this.sizeInBytes);
+ throw new LocalReadSizeTooLargeException(msg);
+ } else if (warnThresholdBytes != 0 && this.sizeInBytes >=
warnThresholdBytes)
+ {
+ MessageParams.add(ParamType.LOCAL_READ_TOO_LARGE_WARNING,
this.sizeInBytes);
+ }
+ }
+
+ @Override
+ protected void onClose()
+ {
+ ColumnFamilyStore cfs =
Schema.instance.getColumnFamilyStoreInstance(metadata().id);
+ if (cfs != null)
Review comment:
two cases
1) unit tests; I think this is why I handled this in the other code path
which update metrics
2) race condition with drop table
its mostly to be defensive as null is a valid response =)
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]