• Jan Lindström's avatar
    MDEV-11656: 'Data structure corruption' IMPORT TABLESPACE doesn't work for... · 283e9cf4
    Jan Lindström authored
    MDEV-11656: 'Data structure corruption' IMPORT TABLESPACE doesn't work for encrypted InnoDB tables if space_id changed
    
    Problem was that for encryption we use temporary scratch area for
    reading and writing tablespace pages. But if page was not really
    decrypted the correct updated page was not moved to scratch area
    that was then written. This can happen e.g. for page 0 as it is
    newer encrypted even if encryption is enabled and as we write
    the contents of old page 0 to tablespace it contained naturally
    incorrect space_id that is then later noted and error message
    was written. Updated page with correct space_id was lost.
    
    If tablespace is encrypted we use additional
    temporary scratch area where pages are read
    for decrypting readptr == crypt_io_buffer != io_buffer.
    
    Destination for decryption is a buffer pool block
    block->frame == dst == io_buffer that is updated.
    Pages that did not require decryption even when
    tablespace is marked as encrypted are not copied
    instead block->frame is set to src == readptr.
    
    If tablespace was encrypted we copy updated page to
    writeptr != io_buffer. This fixes above bug.
    
    For encryption we again use temporary scratch area
    writeptr != io_buffer == dst
    that is then written to the tablespace
    
    (1) For normal tables src == dst ==  writeptr
    ut_ad(!encrypted && !page_compressed ?
    	src == dst && dst == writeptr + (i * size):1);
    (2) For page compressed tables src == dst == writeptr
    ut_ad(page_compressed && !encrypted ?
    	src == dst && dst == writeptr + (i * size):1);
    (3) For encrypted tables src != dst != writeptr
    ut_ad(encrypted ?
    	src != dst && dst != writeptr + (i * size):1);
    283e9cf4
innodb-discard-import-change.test 4.65 KB