@@ -62,6 +62,7 @@ The parts not included are excluded by #ifndef UNIV_INNOCHECKSUM. */
62
62
#include " fsp0fsp.h" /* fsp_flags_get_page_size() &
63
63
fsp_flags_get_zip_size() */
64
64
#include " ut0crc32.h" /* ut_crc32_init() */
65
+ #include " fsp0pagecompress.h" /* fil_get_compression_alg_name */
65
66
66
67
#ifdef UNIV_NONINL
67
68
# include " fsp0fsp.ic"
@@ -109,6 +110,8 @@ int n_fil_page_type_xdes;
109
110
int n_fil_page_type_blob;
110
111
int n_fil_page_type_zblob;
111
112
int n_fil_page_type_other;
113
+ int n_fil_page_type_page_compressed;
114
+ int n_fil_page_type_page_compressed_encrypted;
112
115
113
116
int n_fil_page_max_index_id;
114
117
@@ -152,6 +155,8 @@ struct per_index_stats {
152
155
153
156
std::map<unsigned long long , per_index_stats> index_ids;
154
157
158
+ bool encrypted = false ;
159
+
155
160
/* Get the page size of the filespace from the filespace header. */
156
161
static
157
162
my_bool
@@ -197,6 +202,8 @@ get_page_size(
197
202
{
198
203
compressed= true ;
199
204
}
205
+
206
+
200
207
return TRUE ;
201
208
}
202
209
@@ -515,6 +522,18 @@ parse_page(
515
522
}
516
523
n_fil_page_type_zblob++;
517
524
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 ;
518
537
default :
519
538
if (per_page_details) {
520
539
printf (" FIL_PAGE_TYPE_OTHER\n " );
@@ -604,6 +623,8 @@ print_stats()
604
623
printf (" %d\t FIL_PAGE_TYPE_XDES\n " , n_fil_page_type_xdes);
605
624
printf (" %d\t FIL_PAGE_TYPE_BLOB\n " , n_fil_page_type_blob);
606
625
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);
607
628
printf (" %d\t other\n " , n_fil_page_type_other);
608
629
printf (" %d\t max index_id\n " , n_fil_page_max_index_id);
609
630
printf (" undo type: %d insert, %d update, %d other\n " ,
@@ -791,7 +812,9 @@ int main(int argc, char **argv)
791
812
while (!feof (f))
792
813
{
793
814
int page_ok = 1 ;
815
+
794
816
bytes= fread (buf, 1 , physical_page_size, f);
817
+
795
818
if (!bytes && feof (f))
796
819
{
797
820
print_stats ();
@@ -809,58 +832,126 @@ int main(int argc, char **argv)
809
832
return 1 ;
810
833
}
811
834
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 ;
824
840
} else {
841
+ encrypted = false ;
842
+ }
843
+
844
+ ulint comp_method = 0 ;
825
845
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 */
829
858
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
+ }
839
907
}
840
- page_ok = 0 ;
841
908
}
842
909
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)
852
918
{
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 ;
856
944
}
857
- page_ok = 0 ;
858
945
}
859
946
860
947
/* now check the new method */
861
948
csum= buf_calc_page_new_checksum (buf);
862
949
crc32= buf_calc_page_crc32 (buf);
863
950
csumfield= mach_read_from_4 (buf + FIL_PAGE_SPACE_OR_CHKSUM);
951
+
952
+ if (key_version)
953
+ csumfield = encryption_checksum;
954
+
864
955
if (debug)
865
956
printf (" page %lu: new style: calculated = %lu; crc32 = %lu; recorded = %lu\n " ,
866
957
ct, csum, crc32, csumfield);
@@ -903,7 +994,10 @@ int main(int argc, char **argv)
903
994
continue ;
904
995
}
905
996
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
+ }
907
1001
908
1002
if (verbose)
909
1003
{
0 commit comments