[ 
https://issues.apache.org/jira/browse/IMPALA-15422?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18120716#comment-18120716
 ] 

ASF subversion and git services commented on IMPALA-15422:
----------------------------------------------------------

Commit 66db905e078d0962517f7e7982a18c0e6ee3f2bc in impala's branch 
refs/heads/master from Zoltan Borok-Nagy
[ https://gitbox.apache.org/repos/asf?p=impala.git;h=66db905e0 ]

IMPALA-15422: Fix fall-through in system table DECIMAL writer

The switch in WriteDecimalSlot() (system-table-scanner.cc) had no
break statements, so after writing the value with the correct width
it also wrote it as a Decimal16Value to the same address. All DECIMAL
columns of sys.impala_query_live are DECIMAL(18,3), i.e. 8 bytes
wide, so every write also overwrote the next 8 bytes of the tuple.
Depending on the selected columns, this zeroed other slots or null
indicators. E.g. 'select backends_count, total_time_ms from
sys.impala_query_live' returned 0 for backends_count.

This patch adds the missing break statements.

Testing:
 - Added a custom cluster test that selects backends_count together
   with each DECIMAL column of sys.impala_query_live. It failed
   without the fix.

Change-Id: I395a217c443f52d3588e0d25bdb1859fb245d04c
Assisted-by: Claude Opus 5.5 (1M context) <[email protected]>
Reviewed-on: http://gerrit.cloudera.org:8080/24948
Reviewed-by: Impala Public Jenkins <[email protected]>
Tested-by: Impala Public Jenkins <[email protected]>


> WriteDecimalSlot in system-table-scanner.cc falls through its switch and 
> writes 16 bytes into 8-byte DECIMAL slots
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: IMPALA-15422
>                 URL: https://issues.apache.org/jira/browse/IMPALA-15422
>             Project: IMPALA
>          Issue Type: Bug
>          Components: Backend
>            Reporter: Zoltán Borók-Nagy
>            Assignee: Zoltán Borók-Nagy
>            Priority: Major
>
> The switch in WriteDecimalSlot() has no break statements:
> {code:cpp}
> // be/src/exec/system-table-scanner.cc:101
> static void WriteDecimalSlot(
>     const ColumnType& type, double value, void* slot) {
>   bool overflow = false;
>   switch (type.GetByteSize()) {
>     case 4:
>       *reinterpret_cast<Decimal4Value*>(slot) =
>           Decimal4Value::FromDouble(type, value, false, &overflow);
>     case 8:
>       *reinterpret_cast<Decimal8Value*>(slot) =
>           Decimal8Value::FromDouble(type, value, false, &overflow);
>     case 16:
>       *reinterpret_cast<Decimal16Value*>(slot) =
>           Decimal16Value::FromDouble(type, value, false, &overflow);
>   }
>   DCHECK(!overflow);
> }
> {code}
> All DECIMAL columns of sys.impala_query_live are DECIMAL(18,3) 
> (DURATION_DECIMAL_PRECISION
> / SCALE in workload-management.h), so GetByteSize() is 8. The 8-byte value is 
> written,
> then execution falls through and a Decimal16Value is written at the same 
> address. The 8
> bytes after the slot are overwritten: zeros for non-negative values, 0xFF 
> bytes for
> negative ones.
> Affected columns: TOTAL_TIME_MS, ROW_MATERIALIZATION_TIME_MS, 
> READ_IO_WAIT_TOTAL_MS,
> READ_IO_WAIT_MEAN_MS, and all EVENT_* timeline columns (written through 
> WriteEvent()).
> Depending on the tuple layout of the projected columns, the extra bytes 
> overwrite one of:
> * a neighbouring slot that was already written, which then reads as 0;
> * null-indicator bytes, so a NULL value can read as non-NULL;
> * memory past the end of the tuple, if the decimal is the last slot.
> h3. Repro
> Start the cluster with --enable_workload_mgmt=true (impalad and catalogd) and 
> run a few
> queries. Then:
> {code:sql}
> select query_id, backends_count from sys.impala_query_live order by query_id;
> {code}
> {noformat}
> 2c4087f2a5bfa360:b53e19f800000000     3
> d341c86929ab53f0:ad99a3f700000000     3
> {noformat}
> {code:sql}
> select query_id, backends_count, total_time_ms from sys.impala_query_live 
> order by query_id;
> {code}
> {noformat}
> 2c4087f2a5bfa360:b53e19f800000000     0       466.204
> 6e4b4ced99079f15:268d851900000000     0       181.613
> d341c86929ab53f0:ad99a3f700000000     0       193.144
> {noformat}
> backends_count (INT) is written first and laid out right after the 8-byte 
> decimal slot.
> The 16-byte decimal write then zeroes it. Queries on a debug build don't hit 
> the DCHECK.
> h3. Proposed fix
> Add the missing break statements. Add a test that selects all columns of
> sys.impala_query_live, preferably run under ASAN, or a BE unit test for
> WriteDecimalSlot with a guard value next to the slot.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to