WL#6965: InnoDB: Truncate UNDO logs/tablespace

Status: Complete

Let me first clarify difference between TRUNCATE and SHRINK.

TRUNCATE:
- Truncating undo tablespace to make it equivaluent to what it was when it was
created new. The physical size of undo tablespace file will be reset to its
default initially configured size and all the undo logs within the tablespace
will be removed

SHRINKING:
- Shrinking undo tablespace to reduce the file size.
(New size of undo tablespace can be anything between least possible size and
current size. The undo records up to the shrink size are maintained and are valid.

This WL aims at truncating (and not shrinkng) of UNDO tablespace.

UNDO logs and UNDO tablespaces are used interchangebly.

-----------------

When transaction performs any DML activity it would result in generation of UNDO
logs. Once transaction is committed then INSERT generated UNDO logs are cleared
immediately but UPDATE/DELETE generated UNDO logs are kept to service MVCC.

Purge tracks the limit and once it identifies that the said UNDO log entries are
no more needed it removes it from the UNDO logs.
Removal here means pages related to these entries can be marked as free and
ready-for-reallocation. This activity doesn't result in reducing the size of
UNDO logs/tablespace.

On a heavily loaded system even though we re-use the UNDO log pages.
In order to implement MVCC (and purge) new pages areadded to the UNDO logs at a
higher rate than purge can truncate (remove). This can result in an increase in
the undo log file size and can consume a significant size on disk.

WL will try to address this problem by periodically truncating undo
logs/tablespace. Truncate will be done online without affecting server operation
While the undo tablespace is taken offline for truncate it would not be
available for attaching to new transactions and so the total transaction
handling capacity of the server will reduced till TRUNCATE is complete. The
truncate of the UNDO tablespace is a millisecond operation and therefore no
significant user impact expected. Note: Other UNDO tablespaces will be available
to service transaction so it will not stall the server except we can see some
slowness or delayed allocation.

One of the tablespace will be selected for truncate and will be made inactive
for that time period. During this time-period there should be another UNDO
tablespace to service the new upcoming transactions.

Requirement for UNDO tablespace truncate:

- There should be at-least 2 UNDO tablespaces and innobase_undo_logs should be
configured accordingly so that there are enough rsegs.
- Server should be configured to use UNDO tablespace (if used with system
tablespace it will never be truncated.)