Skip to content

Commit 73ee6c6

Browse files
committed
Merge branch 'mysql-8.4' into mysql-trunk
Change-Id: Idc6037269866e7aef5668d39cdd59e9fe0597807
2 parents e88656c + 15ea548 commit 73ee6c6

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]);
@@ -335,6 +340,11 @@ int desc_table(Ndb *myndb, char const *name) {
335340
}
336341
}
337342

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

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

0 commit comments

Comments
 (0)