tokudb笔记

官方文档
http://docs.tokutek.com/tokudb/

tokudb 特点 
    Fast Insertions and Richer Indexes
    
    可以创建多个cluster 索引
        CREATE TABLE table (
            column_a INT,
            column_b INT,
            column_c INT,
            PRIMARY KEY index_a (column_a),
            CLUSTERING KEY index_b (column_b)
        ) ENGINE = TokuDB;


    Hot Index Creation
        SET tokudb_create_index_online=ON;
        CREATE INDEX index ON table (field_name);
        注意:必须使用CREATE INDEX 命令,alter table xxx add index 命令默认使用offline方式,无视tokudb_create_index_online参数
            hot creating比 create index offline要慢,取决于系统的繁忙程度
            
    Hot Column Add, Delete, Expand, and Rename (HCADER)
        列在线操作:增、删、扩展、改名
            列改名时,已落地的数据不会被修改,只有在被读取时才会被应用
            HCADER typically blocks other queries with a table lock for no more than a few seconds. After that initial short-term table locking
            , the system modifies each row (when adding, deleting, or expanding columns) later, when the row is next brought into main memory from disk.
            For column rename, all the work is done during the seconds of downtime. On-disk rows need not be modified.
        持有一段时间的表锁,取决于flush dirty page
            持有表锁是因为mysql在DDL后,都会做次close table,从而触发flush dirty page
        注意:
            一次只能操作一个列,最好不要同时操作多列
            避免删除索引中的列,如果要删除,最好先删除索引,再删除列
            列类型Expand时,只支持char, varchar, varbinary, and integer data types.不支持操作主键或二级索引中的列(可能是因为涉及到索引重构)
                Hot column expansion operations are only supported to char, varchar, varbinary, and integer data types.
                Hot column expansion is not supported if the given column is part of the primary key or any secondary keys.
            列改名时不支持 TIME, ENUM, BLOB, TINYBLOB, MEDIUMBLOB, LONGBLOB.这几种类型
                Hot column rename does not support the following data types: TIME, ENUM, BLOB, TINYBLOB, MEDIUMBLOB, LONGBLOB.
                Renaming columns of these types will revert to the standard MySQL blocking behavior.
            不能操作 Temporary table
                Temporary tables cannot take advantage of HCADER. Temporary tables are typically small anyway, so altering them using the standard method is usually fast.
    
    Compression Details
        最高能达到25倍的压缩
        
    Read Free Replication 待细看
        TokuDB slaves can be configured to perform significantly less read IO in order to apply changes from the master. By utilizing the power of Fractal Tree indexes:
            insert/update/delete operations can be configured to eliminate read-modify-write behavior and simply inject messages into the appropriate Fractal Tree indexes
            update/delete operations can be configured to eliminate the IO required for uniqueness checking


        To enable Read Free Replication, the servers must be configured as follows:
            On the replication master
                Enable row based replication: set BINLOG_FORMAT=ROW


            On the replication slave(s)
                Note: You can modify one or both behaviors on the slave(s).
                The slave must be in read-only mode: set read_only=1
                Disable unique checks: set tokudb_rpl_unique_checks=0
                Disable lookups (read-modify-write): set tokudb_rpl_lookup_rows=0


        In MySQL 5.5 and MariaDB 5.5 only tables with a defined primary key are eligible for this optimization. 
        That will not be the case in MySQL 5.6, Percona Server 5.6, and MariaDB 10.x.
        As long as the master is using row based replication, this optimization is available on a TokuDB slave. 
        This means that it's available even if the master is using InnoDB or MyISAM tables, or running non-TokuDB binaries.
        
    Transactions and ACID-compliant Recovery
        记录两次checkpoint中间的所有变化日志,崩溃恢复使用。恢复提交的事务,回滚未提交的事务
        checkpoint触发的几种情况
            默认60s做一次checkpoint
            flush logs会手动触发
            log file达到100M,切换logfile时自动触发
    Disabling the Write Cache,几种文件系统下的配置
        On ATA/SATA drives a command such as "hdparm -W0 /dev/hda"
        Write caching can remain enabled when using XFS, but only if XFS reports that disk write barriers work. 
        If you see one of the following messages in /var/log/messages, then you must disable the write cache:
            Disabling barriers, not supported with external log device
            Disabling barriers, not supported by the underlying device
            Disabling barriers, trial barrier write failed


        XFS write barriers appear to succeed for single disks (with no LVM), or for very recent kernels (such as that provided by Fedora 12). For more details, see XFS FAQ


        In some cases, you must disable the write cache:
            If you use the ext3 filesystem, you must disable the write cache.
            If you use LVM, you must disable the write cache. (Although recent Linux kernels, such as Fedora 12, have fixed this problem.)
            If you use Linux's software RAID, you must disable the write cache.
            If you use a RAID controller with battery-backed-up memory, you must disable the write cache. This may seem counter-intuitive. See the xfs.org link above for details.
            In summary, you should disable the write cache unless you have a very specific reason not to do so.


    Progress Tracking 跟踪调试
        TokuDB has a system for tracking progress of long running statements, thereby removing the need to define triggers to track statement execution, as follows:
            Bulk Load: When loading large tables using LOAD DATA INFILE commands, doing a SHOW PROCESSLIST command in a separate client session shows progress.
                There are two progress stages. 
                    The first will state something like Inserted about 1000000 rows. After all rows are processed like this, 
                    the next stage tracks progress by showing what fraction of the work is done (e.g. Loading of data about 45% done)
            Adding Indexes: When adding indexes via ALTER TABLE or CREATE INDEX, the command SHOW PROCESSLIST shows progress. 
                When adding indexes via ALTER TABLE or CREATE INDEX, the command SHOW PROCESSLIST will include an estimate of the number of rows processed use this information to verify progress is being made. 
                Similar to bulk loading, the first stage shows how many rows have been processed, and the second stage shows progress with a fraction.
            Commits and Aborts: When committing or aborting a transaction, the command SHOW PROCESSLIST will include an estimate of the transactional operations processed.
            
    支持  LOAD DATA INFILE
    
    Hot Backup
    Hot Backup 7.5.5 and later 热备使用
        install plugin tokudb_backup soname 'tokudb_backup.so';
        # 设置路径,会自动启动备份
        set tokudb_backup_dir='/path_to_empty_directory';
        
        # 观察备份情况
        mysql> show full processlist;
            | Id | User | Host      | db   | Command | Time  | State                                                                                                                                                                                                                                                                                                     | Info                                   |
            |  7 | root | localhost | test | Query   |     1 | tokudb backup about 59% done: Backup progress 666489350 bytes, 19 files.  Copying file: 265289728/374562816 bytes done of /data.ssd/data/mysql_755e_rc2/_test_testtable_unpartitioned_main_da92_5_1b_B_0.tokudb to /tmp/backupdir/mysql_data_dir/_test_testtable_unpartitioned_main_da92_5_1b_B_0.tokudb. | set tokudb_backup_dir='/tmp/backupdir' |
        # 查看备份出错信息
            They are @@tokudb_backup_last_error and @@tokudb_backup_last_error_string.When Hot Backup encounters an error,
            mysql> select @@tokudb_backup_last_error;
            mysql> select @@tokudb_backup_last_error_string;
        
        # 相关配置参数
            tokudb_backup_allowed_prefix
            tokudb_backup_throttle:This session level variable throttles the write rate in bytes per second of the backup to prevent Hot Backup from crowding out other jobs in the system.
                The default and max values are 18446744073709551615
            tokudb_backup_dir: 如果设置的是空目录,并且存在,则备份立即开始
                When set, this session level variable serves two purposes, to point to the destination directory where the backups will be dumped and to kick off the backup as soon as its set.
            tokudb_backup_last_error:    This session variable will contain the error number from the last backup. 0 indicates success.
            tokudb_backup_last_error_string:This session variable will contain the error string from the last backup.
            
            
请使用浏览器的分享功能分享到微信等