Bug #65560 --print_data not printing trailing 0s on Longvarbinary field
Submitted: 7 Jun 2012 17:15 Modified: 19 Mar 2018 9:21
Reporter: Dustin Koupal Email Updates:
Status: Closed Impact on me:
Category:MySQL Cluster: Cluster (NDB) storage engine Severity:S3 (Non-critical)
Version:7.2.6 OS:Any
Assigned to: CPU Architecture:Any

[7 Jun 2012 17:15] Dustin Koupal
When attempting to use ndb_restore --print_data --hex on a Longvarbinary field, the trailing 0s end up not being printed.  It seems this is by design, looking at pretty_print_string.  Would it be possible to update the documentation or to not print the trailing 0s when the --hex option is passed?

How to repeat:
mysql> create database test;
Query OK, 1 row affected (0.01 sec)

mysql> use test;
Database changed

mysql> CREATE TABLE `longvarbinary_test` (   `entity` binary(16) NOT NULL,   `blob` varbinary(8000) NOT NULL,   `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,   PRIMARY KEY (`entity`) ) ENGINE=ndbcluster DEFAULT CHARSET=latin1;120607 10:00:48 [Note] NDB Binlog: CREATE TABLE Event: REPL$test/longvarbinary_test
Query OK, 0 rows affected (0.10 sec)

mysql> insert into longvarbinary_test values(0x0100000000000000000000000FFFFFFF, 0xFFFF1000000, now());Query OK, 1 row affected (0.00 sec)

### The 6 trailing 0s show up with no problem in mysql

mysql> select hex(entity), hex(`blob`), modified from longvarbinary_test\G                                                                                    *************************** 1. row ***************************
hex(entity): 0100000000000000000000000FFFFFFF
hex(`blob`): 0FFFF1000000
   modified: 2012-06-07 10:11:00
1 row in set (0.00 sec)

# Do a ndb backup with the defaults, then use ndb_restore

ndb_mgm> start backup;
Connected to Management Server at: localhost:1186
Waiting for completed, this may take several minutes
Node 3: Backup 3 started from node 1
Node 3: Backup 3 started from node 1 completed
 StartGCP: 2086 StopGCP: 2089
 #Records: 2060 #LogRecords: 0
 Data: 51960 bytes Log: 0 bytes

$ /usr/local/mysql/bin/ndb_restore -n 3 -b 3 --include-tables=test.longvarbinary_test --print-data --hex
Nodeid = 3
Backup Id = 3
backup path = ./
Including tables: test.longvarbinary_test 
Opening file './BACKUP-3.3.ctl'
File size 15104 bytes
Backup version in files: ndb-6.3.11 ndb version: mysql-5.5.22 ndb-7.2.6
Stop GCP of Backup: 2088
Opening file './BACKUP-3-0.3.Data'
File size 27176 bytes
Processing data in table: mysql/def/NDB$BLOB_7_3(8) fragment 0
Processing data in table: mysql/def/ndb_index_stat_sample(5) fragment 0
Processing data in table: sys/def/NDB$EVENTS_0(3) fragment 0
Processing data in table: mysql/def/ndb_apply_status(9) fragment 0
Processing data in table: mysql/def/ndb_index_stat_head(4) fragment 0
Processing data in table: test/def/longvarbinary_test(10) fragment 0
0x0100000000000000000000000FFFFFFF	0x0FFFF1	1339089060
Processing data in table: sys/def/SYSTAB_0(2) fragment 0
Processing data in table: mysql/def/ndb_schema(7) fragment 0

NDBT_ProgramExit: 0 - OK

The trailing 0s don't appear when doing ndb_restore --print-data --hex

Suggested fix:
I don't know if this will break anything, but I was able to get this working in my environment by only chomping the trailing 0s if --hex isn't specified.

2834   const unsigned char* ref = (const unsigned char*)aref;
2835   int i, len, printable= 1;
2836   // trailing zeroes are not printed unless --hex is specified
2837   if (!f.hex_format) {
2838       for (i=sz-1; i >= 0; i--)
2839         if (ref[i] == 0) sz--;
2840         else break;
2841   }
[14 Jun 2012 19:42] Sveta Smirnova
Thank you for the report.

Verified as described.
[16 Dec 2013 19:06] David Squier
Since this is not getting any traction, I have asked Michael Kludjian (michael.kludjian@oracle.com) to look into this for us.
[19 Dec 2013 17:58] Sveta Smirnova

I am sorry for late notice, but for us to be able to accept your patches you need to sign OCA agreement as described in the "Contributions" tab of this bug report.
[19 Mar 2018 9:21] Jon Stephens
Documented fix as follows, in the NDB 7.2.33, 7.3.21, 7.4.19, 7.5.10, 7.6.5, and 8.0.1 changelogs:

    ndb_restore --print_data --hex did not print trailing 0s of
    Longvarbinary values.