Skip to content

Commit 15ea548

Browse files
committed
Merge branch 'mysql-8.0' into mysql-8.4
Change-Id: I504b1d86cf1febcd30473c3f2501103f6d026b09
2 parents 58173f1 + 7125eae commit 15ea548

File tree

3 files changed

+173
-0
lines changed

3 files changed

+173
-0
lines changed

mysql-test/suite/ndb/r/ndb_desc_extra.result

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,3 +411,42 @@ PRIMARY(a) - OrderedIndex
411411
-- AutoIncrement info
412412
AutoIncrement: 17
413413
drop table test.t3;
414+
Show embedded-metadata behaviour
415+
sys/def/SYSTAB_0 has no embedded metadata
416+
-- SYSTAB_0 --
417+
Version: Any
418+
Fragment type: HashMapPartition
419+
K Value: 6
420+
Min load factor: 78
421+
Max load factor: 80
422+
Temporary table: no
423+
Number of attributes: 2
424+
Number of primary keys: 1
425+
Length of frm data: XXX
426+
Max Rows: 0
427+
Row Checksum: 1
428+
Row GCI: 1
429+
SingleUserMode: 2
430+
ForceVarPart: 0
431+
PartitionCount: 8
432+
FragmentCount: 8
433+
PartitionBalance: FOR_RP_BY_LDM
434+
ExtraRowGciBits: 0
435+
ExtraRowAuthorBits: 0
436+
TableStatus: Retrieved
437+
Table options:
438+
HashMap: DEFAULT-HASHMAP-3840-8
439+
-- Attributes --
440+
SYSKEY_0 Unsigned PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
441+
NEXTID Bigunsigned NOT NULL AT=FIXED ST=MEMORY
442+
-- Indexes --
443+
PRIMARY KEY(SYSKEY_0) - UniqueHashIndex
444+
-- Embedded metadata
445+
Packed len : 0
446+
447+
mysql/def/ndb_apply_status has embedded frm
448+
include/assert_grep.inc [Version 1 embedded metadata (frm)]
449+
User table has SDI with creating mysqld version
450+
create table test.user_tab(a int primary key, b varchar(50) default 'Hello', c blob, d json) engine=ndb;
451+
include/assert_grep.inc [SDI contains MySQL Server version]
452+
drop table test.user_tab;

mysql-test/suite/ndb/t/ndb_desc_extra.test

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,39 @@ drop table test.t3;
9898
--disable_query_log
9999
set ndb_autoincrement_prefetch_sz = @old_ndb_autoincrement_prefetch_sz;
100100
--enable_query_log
101+
102+
--echo Show embedded-metadata behaviour
103+
104+
--echo sys/def/SYSTAB_0 has no embedded metadata
105+
--let $ndb_desc_opts= --embedded-metadata -dsys SYSTAB_0
106+
--source suite/ndb/include/ndb_desc_print.inc
107+
108+
109+
--let $OUTPUT_FILE = $MYSQLTEST_VARDIR/tmp/ndb_desc_extra.txt
110+
111+
--echo mysql/def/ndb_apply_status has embedded frm
112+
--exec $NDB_DESC -m -dmysql ndb_apply_status > $OUTPUT_FILE
113+
114+
--let $assert_text= Version 1 embedded metadata (frm)
115+
--let $assert_file= $OUTPUT_FILE
116+
--let $assert_select= Metadata version : 1
117+
--let $assert_count= 1
118+
119+
--source include/assert_grep.inc
120+
121+
--remove_file $OUTPUT_FILE
122+
123+
--echo User table has SDI with creating mysqld version
124+
create table test.user_tab(a int primary key, b varchar(50) default 'Hello', c blob, d json) engine=ndb;
125+
126+
--exec $NDB_DESC -m -dtest user_tab > $OUTPUT_FILE
127+
--let $assert_text= SDI contains MySQL Server version
128+
--let $assert_file= $OUTPUT_FILE
129+
--let $assert_select= mysqld_version_id
130+
--let $assert_count= 1
131+
132+
--source include/assert_grep.inc
133+
134+
--remove_file $OUTPUT_FILE
135+
136+
drop table test.user_tab;

storage/ndb/tools/desc.cpp

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ static int _indexinfo = 0;
5454
static int _nodeinfo = 0;
5555
static int _autoinc = 0;
5656
static int _context = 0;
57+
static int _metadata = 0;
5758

5859
static int _retries = 0;
5960

@@ -91,11 +92,15 @@ static struct my_option my_long_options[] = {
9192
nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
9293
{"context", 'x', "Show context information", &_context, nullptr, nullptr,
9394
GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
95+
{"embedded-metadata", 'm', "Show embedded metadata", &_metadata, nullptr,
96+
nullptr, GET_BOOL, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
9497
NdbStdOpt::end_of_options};
9598

9699
static void print_context_info(Ndb *pNdb, NdbDictionary::Table const *pTab);
97100
static void print_autoinc_info(Ndb *pNdb, NdbDictionary::Table const *pTab);
98101
static void print_part_info(Ndb *pNdb, NdbDictionary::Table const *pTab);
102+
static void print_embedded_metadata(Ndb *myndb,
103+
NdbDictionary::Table const *pTab);
99104

100105
int main(int argc, char **argv) {
101106
NDB_INIT(argv[0]);
@@ -334,6 +339,11 @@ int desc_table(Ndb *myndb, char const *name) {
334339
}
335340
}
336341

342+
if (_metadata) {
343+
print_embedded_metadata(myndb, pTab);
344+
ndbout << endl;
345+
}
346+
337347
return 1;
338348
}
339349

@@ -499,3 +509,91 @@ int desc_hashmap(Ndb_cluster_connection &con, Ndb *myndb, char const *name) {
499509
}
500510
return 0;
501511
}
512+
513+
static void print_binary(const void *data, Uint32 len) {
514+
const Uint32 digitsPerLine = 8;
515+
char readable[digitsPerLine + 1];
516+
Uint32 offset = 0;
517+
/* Line format
518+
* 0x00000000: 0x41 0x42 0x43 0x44 0x45 0x46 0x47 0x48 ABCDEFGH
519+
* Offset Bytes as hex Printable chars
520+
*/
521+
522+
ndbout << hex << offset << ": ";
523+
while (offset < len) {
524+
const uint8 digit = ((const uint8 *)data)[offset];
525+
526+
ndbout << hex << digit << " ";
527+
528+
readable[offset % digitsPerLine] = isprint(digit) ? digit : ' ';
529+
530+
offset++;
531+
532+
if ((offset % digitsPerLine) == 0) {
533+
/* End of line */
534+
readable[digitsPerLine] = 0;
535+
ndbout << " " << readable << endl;
536+
if (offset < len) ndbout << hex << offset << ": ";
537+
}
538+
}
539+
540+
Uint32 lastLineDigits = offset % digitsPerLine;
541+
if (lastLineDigits > 0) {
542+
/* Pad out last line */
543+
Uint32 padDigits = digitsPerLine - lastLineDigits;
544+
for (; padDigits; padDigits--)
545+
// 0xHH_
546+
ndbout << " ";
547+
548+
readable[lastLineDigits] = 0;
549+
ndbout << " " << readable << endl;
550+
}
551+
552+
ndbout << endl;
553+
}
554+
555+
static void print_embedded_metadata(Ndb *myndb,
556+
NdbDictionary::Table const *pTab) {
557+
ndbout << "-- Embedded metadata" << endl;
558+
559+
const Uint32 packed_len = pTab->getFrmLength();
560+
561+
ndbout << "Packed len : " << packed_len << endl;
562+
563+
if (packed_len > 0) {
564+
Uint32 metadata_version = 0;
565+
void *metadata_ptr = nullptr;
566+
Uint32 metadata_len = 0;
567+
568+
const int res =
569+
pTab->getExtraMetadata(metadata_version, &metadata_ptr, &metadata_len);
570+
571+
if (res == 0) {
572+
ndbout << "Metadata version : " << metadata_version << endl;
573+
ndbout << "Unpacked length : " << metadata_len << endl;
574+
575+
bool text = true;
576+
for (Uint32 i = 0; i < metadata_len; i++) {
577+
if (!isprint(((const char *)metadata_ptr)[i])) {
578+
text = false;
579+
break;
580+
}
581+
}
582+
583+
ndbout << "Metadata begin" << endl;
584+
if (!text) {
585+
print_binary(metadata_ptr, metadata_len);
586+
} else {
587+
/* All text, direct print, ensuring null termination */
588+
BaseString null_terminated_copy(static_cast<char *>(metadata_ptr),
589+
metadata_len);
590+
ndbout << null_terminated_copy.c_str() << endl;
591+
}
592+
ndbout << "Metadata end" << endl;
593+
594+
free(metadata_ptr);
595+
} else {
596+
ndbout << "Problem reading : " << res << endl;
597+
}
598+
}
599+
}

0 commit comments

Comments
 (0)