@@ -62,6 +62,7 @@ The parts not included are excluded by #ifndef UNIV_INNOCHECKSUM. */
6262#include " fsp0fsp.h" /* fsp_flags_get_page_size() &
6363 fsp_flags_get_zip_size() */
6464#include " ut0crc32.h" /* ut_crc32_init() */
65+ #include " fsp0pagecompress.h" /* fil_get_compression_alg_name */
6566
6667#ifdef UNIV_NONINL
6768# include " fsp0fsp.ic"
@@ -109,6 +110,8 @@ int n_fil_page_type_xdes;
109110int n_fil_page_type_blob;
110111int n_fil_page_type_zblob;
111112int n_fil_page_type_other;
113+ int n_fil_page_type_page_compressed;
114+ int n_fil_page_type_page_compressed_encrypted;
112115
113116int n_fil_page_max_index_id;
114117
@@ -152,6 +155,8 @@ struct per_index_stats {
152155
153156std::map<unsigned long long , per_index_stats> index_ids;
154157
158+ bool encrypted = false ;
159+
155160/* Get the page size of the filespace from the filespace header. */
156161static
157162my_bool
@@ -197,6 +202,8 @@ get_page_size(
197202 {
198203 compressed= true ;
199204 }
205+
206+
200207 return TRUE ;
201208}
202209
@@ -515,6 +522,18 @@ parse_page(
515522 }
516523 n_fil_page_type_zblob++;
517524 break ;
525+ case FIL_PAGE_PAGE_COMPRESSED:
526+ if (per_page_details) {
527+ printf (" FIL_PAGE_PAGE_COMPRESSED\n " );
528+ }
529+ n_fil_page_type_page_compressed++;
530+ break ;
531+ case FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED:
532+ if (per_page_details) {
533+ printf (" FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED\n " );
534+ }
535+ n_fil_page_type_page_compressed_encrypted++;
536+ break ;
518537 default :
519538 if (per_page_details) {
520539 printf (" FIL_PAGE_TYPE_OTHER\n " );
@@ -604,6 +623,8 @@ print_stats()
604623 printf (" %d\t FIL_PAGE_TYPE_XDES\n " , n_fil_page_type_xdes);
605624 printf (" %d\t FIL_PAGE_TYPE_BLOB\n " , n_fil_page_type_blob);
606625 printf (" %d\t FIL_PAGE_TYPE_ZBLOB\n " , n_fil_page_type_zblob);
626+ printf (" %d\t FIL_PAGE_PAGE_COMPRESSED\n " , n_fil_page_type_page_compressed);
627+ printf (" %d\t FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED\n " , n_fil_page_type_page_compressed_encrypted);
607628 printf (" %d\t other\n " , n_fil_page_type_other);
608629 printf (" %d\t max index_id\n " , n_fil_page_max_index_id);
609630 printf (" undo type: %d insert, %d update, %d other\n " ,
@@ -791,7 +812,9 @@ int main(int argc, char **argv)
791812 while (!feof (f))
792813 {
793814 int page_ok = 1 ;
815+
794816 bytes= fread (buf, 1 , physical_page_size, f);
817+
795818 if (!bytes && feof (f))
796819 {
797820 print_stats ();
@@ -809,58 +832,126 @@ int main(int argc, char **argv)
809832 return 1 ;
810833 }
811834
812- if (compressed) {
813- /* compressed pages */
814- if (!page_zip_verify_checksum (buf, physical_page_size)) {
815- fprintf (stderr, " Fail; page %lu invalid (fails compressed page checksum).\n " , ct);
816- if (!skip_corrupt)
817- {
818- free (big_buf);
819- free (big_xdes);
820- return 1 ;
821- }
822- page_ok = 0 ;
823- }
835+ ulint page_type = mach_read_from_2 (buf+FIL_PAGE_TYPE);
836+ ulint key_version = mach_read_from_4 (buf + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION);
837+
838+ if (key_version && page_type != FIL_PAGE_PAGE_COMPRESSED) {
839+ encrypted = true ;
824840 } else {
841+ encrypted = false ;
842+ }
843+
844+ ulint comp_method = 0 ;
825845
826- /* check the "stored log sequence numbers" */
827- logseq= mach_read_from_4 (buf + FIL_PAGE_LSN + 4 );
828- logseqfield= mach_read_from_4 (buf + logical_page_size - FIL_PAGE_END_LSN_OLD_CHKSUM + 4 );
846+ if (encrypted) {
847+ comp_method = mach_read_from_2 (buf+FIL_PAGE_DATA+FIL_PAGE_COMPRESSED_SIZE);
848+ } else {
849+ comp_method = mach_read_from_8 (buf+FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION);
850+ }
851+
852+ ulint comp_size = mach_read_from_2 (buf+FIL_PAGE_DATA);
853+ ib_uint32_t encryption_checksum = mach_read_from_4 (buf+FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION + 4 );
854+
855+
856+ if (page_type == FIL_PAGE_PAGE_COMPRESSED) {
857+ /* Page compressed tables do not have any checksum */
829858 if (debug)
830- printf (" page %lu: log sequence number: first = %lu; second = %lu\n " , ct, logseq, logseqfield);
831- if (logseq != logseqfield)
832- {
833- fprintf (stderr, " Fail; page %lu invalid (fails log sequence number check)\n " , ct);
834- if (!skip_corrupt)
835- {
836- free (big_buf);
837- free (big_xdes);
838- return 1 ;
859+ fprintf (stderr, " Page %lu page compressed with method %s real_size %lu\n " , ct,
860+ fil_get_compression_alg_name (comp_method), comp_size);
861+ page_ok = 1 ;
862+ } else if (compressed) {
863+ /* compressed pages */
864+ ulint crccsum = page_zip_calc_checksum (buf, physical_page_size, SRV_CHECKSUM_ALGORITHM_CRC32);
865+ ulint icsum = page_zip_calc_checksum (buf, physical_page_size, SRV_CHECKSUM_ALGORITHM_INNODB);
866+
867+ if (debug) {
868+ if (key_version != 0 ) {
869+ fprintf (stderr,
870+ " Page %lu encrypted key_version %lu calculated = %lu; crc32 = %lu; recorded = %u\n " ,
871+ ct, key_version, icsum, crccsum, encryption_checksum);
872+ }
873+ }
874+
875+ if (encrypted) {
876+ if (encryption_checksum != 0 && crccsum != encryption_checksum && icsum != encryption_checksum) {
877+ if (debug)
878+ fprintf (stderr, " page %lu: compressed: calculated = %lu; crc32 = %lu; recorded = %u\n " ,
879+ ct, icsum, crccsum, encryption_checksum);
880+ fprintf (stderr, " Fail; page %lu invalid (fails compressed page checksum).\n " , ct);
881+ }
882+ } else {
883+ if (!page_zip_verify_checksum (buf, physical_page_size)) {
884+ fprintf (stderr, " Fail; page %lu invalid (fails compressed page checksum).\n " , ct);
885+ if (!skip_corrupt)
886+ {
887+ free (big_buf);
888+ free (big_xdes);
889+ return 1 ;
890+ }
891+ page_ok = 0 ;
892+ }
893+ }
894+ } else {
895+ if (key_version != 0 ) {
896+ /* Encrypted page */
897+ if (debug) {
898+ if (page_type == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED) {
899+ fprintf (stderr,
900+ " Page %lu page compressed with method %s real_size %lu and encrypted key_version %lu checksum %u\n " ,
901+ ct, fil_get_compression_alg_name (comp_method), comp_size, key_version, encryption_checksum);
902+ } else {
903+ fprintf (stderr,
904+ " Page %lu encrypted key_version %lu checksum %u\n " ,
905+ ct, key_version, encryption_checksum);
906+ }
839907 }
840- page_ok = 0 ;
841908 }
842909
843- /* check old method of checksumming */
844- oldcsum= buf_calc_page_old_checksum (buf);
845- oldcsumfield= mach_read_from_4 (buf + logical_page_size - FIL_PAGE_END_LSN_OLD_CHKSUM);
846- if (debug)
847- printf (" page %lu: old style: calculated = %lu; recorded = %lu\n " , ct, oldcsum, oldcsumfield);
848- if (oldcsumfield != mach_read_from_4 (buf + FIL_PAGE_LSN) && oldcsumfield != oldcsum)
849- {
850- fprintf (stderr, " Fail; page %lu invalid (fails old style checksum)\n " , ct);
851- if (!skip_corrupt)
910+ /* Page compressed tables do not contain FIL tailer */
911+ if (page_type != FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED && page_type != FIL_PAGE_PAGE_COMPRESSED) {
912+ /* check the "stored log sequence numbers" */
913+ logseq= mach_read_from_4 (buf + FIL_PAGE_LSN + 4 );
914+ logseqfield= mach_read_from_4 (buf + logical_page_size - FIL_PAGE_END_LSN_OLD_CHKSUM + 4 );
915+ if (debug)
916+ printf (" page %lu: log sequence number: first = %lu; second = %lu\n " , ct, logseq, logseqfield);
917+ if (logseq != logseqfield)
852918 {
853- free (big_buf);
854- free (big_xdes);
855- return 1 ;
919+ fprintf (stderr, " Fail; page %lu invalid (fails log sequence number check)\n " , ct);
920+ if (!skip_corrupt)
921+ {
922+ free (big_buf);
923+ free (big_xdes);
924+ return 1 ;
925+ }
926+ page_ok = 0 ;
927+ }
928+
929+ /* check old method of checksumming */
930+ oldcsum= buf_calc_page_old_checksum (buf);
931+ oldcsumfield= mach_read_from_4 (buf + logical_page_size - FIL_PAGE_END_LSN_OLD_CHKSUM);
932+ if (debug)
933+ printf (" page %lu: old style: calculated = %lu; recorded = %lu\n " , ct, oldcsum, oldcsumfield);
934+ if (oldcsumfield != mach_read_from_4 (buf + FIL_PAGE_LSN) && oldcsumfield != oldcsum)
935+ {
936+ fprintf (stderr, " Fail; page %lu invalid (fails old style checksum)\n " , ct);
937+ if (!skip_corrupt)
938+ {
939+ free (big_buf);
940+ free (big_xdes);
941+ return 1 ;
942+ }
943+ page_ok = 0 ;
856944 }
857- page_ok = 0 ;
858945 }
859946
860947 /* now check the new method */
861948 csum= buf_calc_page_new_checksum (buf);
862949 crc32= buf_calc_page_crc32 (buf);
863950 csumfield= mach_read_from_4 (buf + FIL_PAGE_SPACE_OR_CHKSUM);
951+
952+ if (key_version)
953+ csumfield = encryption_checksum;
954+
864955 if (debug)
865956 printf (" page %lu: new style: calculated = %lu; crc32 = %lu; recorded = %lu\n " ,
866957 ct, csum, crc32, csumfield);
@@ -903,7 +994,10 @@ int main(int argc, char **argv)
903994 continue ;
904995 }
905996
906- parse_page (buf, xdes);
997+ /* Can't parse compressed or/and encrypted pages */
998+ if (page_type != FIL_PAGE_PAGE_COMPRESSED && !encrypted) {
999+ parse_page (buf, xdes);
1000+ }
9071001
9081002 if (verbose)
9091003 {
0 commit comments