当减少buffer pool大小的时候,为后台线程执行,大概操作的步骤为
1、整体删除AHI
2、从free list和LRU中回收需要的page,如果为脏数据需要刷脏数据
3、删除回收的page的内存
4、启动AHI
第一步删除AHI
[Note] InnoDB: Requested to resize buffer pool. (new size: 12884901888 bytes)
[Note] InnoDB: Resizing buffer pool from 68719476736 to 12884901888 (unit=134217728).
[Note] InnoDB: Disabling adaptive hash index.
[Note] InnoDB: disabled adaptive hash index.
第二步回收page
整个过程中最后可能出现问题的就是第2步,且加锁比较强,比如free list mutex和LRU list mutex,其主要是为了收集到
能够回收的page,如果这个时候压力较高脏数据较多,free list和LRU中不能及时的收集到可以回收的page,那么将会循环
回收,因为加锁严重必定会影响正常session获取page和刷脏等操作,影响系统的并发。这个状态在Innodb_buffer_pool_resize_status中为
Withdrawing blocks to be shrunken。
[Note] InnoDB: Withdrawing blocks to be shrunken.
[Note] InnoDB: buffer pool 0 : start to withdraw the last 425984 blocks.
[Note] InnoDB: buffer pool 0 : withdrawing blocks. (425982/425984)
[Note] InnoDB: buffer pool 0 : withdrew 288532 blocks from free list. Tried to relocate 97721 pages (425982/425984).
[Note] InnoDB: buffer pool 0 : withdrawing blocks. (425984/425984)
[Note] InnoDB: buffer pool 0 : withdrew 0 blocks from free list. Tried to relocate 2 pages (425984/425984).
[Note] InnoDB: buffer pool 0 : withdrawn target 425984 blocks.
[Note] InnoDB: buffer pool 1 : start to withdraw the last 425984 blocks.
[Note] InnoDB: buffer pool 1 : withdrawing blocks. (425983/425984)
[Note] InnoDB: buffer pool 1 : withdrew 289275 blocks from free list. Tried to relocate 97801 pages (425983/425984).
[Note] InnoDB: buffer pool 1 : withdrawing blocks. (425984/425984)
[Note] InnoDB: buffer pool 1 : withdrew 0 blocks from free list. Tried to relocate 1 pages (425984/425984).
[Note] InnoDB: buffer pool 1 : withdrawn target 425984 blocks.
[Note] InnoDB: buffer pool 2 : start to withdraw the last 425984 blocks.
[Note] InnoDB: buffer pool 2 : withdrawing blocks. (425982/425984)
[Note] InnoDB: buffer pool 5 : withdrawing blocks. (425983/425984)
[Note] InnoDB: buffer pool 5 : withdrew 0 blocks from free list. Tried to relocate 0 pages (425983/425984).
[Note] InnoDB: buffer pool 5 : withdrawing blocks. (425983/425984)
[Note] InnoDB: buffer pool 5 : withdrew 0 blocks from free list. Tried to relocate 0 pages (425983/425984).
[Note] InnoDB: buffer pool 5 : withdrawing blocks. (425983/425984)
[Note] InnoDB: buffer pool 5 : withdrew 0 blocks from free list. Tried to relocate 0 pages (425983/425984).
[Note] InnoDB: buffer pool 5 : withdrawing blocks. (425983/425984)
[Note] InnoDB: buffer pool 5 : withdrew 0 blocks from free list. Tried to relocate 0 pages (425983/425984).
[Note] InnoDB: buffer pool 5 : withdrawing blocks. (425983/425984)
[Note] InnoDB: buffer pool 5 : withdrew 0 blocks from free list. Tried to relocate 0 pages (425983/425984).
[Note] InnoDB: buffer pool 5 : withdrawing blocks. (425983/425984)
[Note] InnoDB: buffer pool 5 : withdrew 0 blocks from free list. Tried to relocate 0 pages (425983/425984).
[Note] InnoDB: buffer pool 5 : withdrawing blocks. (425983/425984)
[Note] InnoDB: buffer pool 5 : withdrew 0 blocks from free list. Tried to relocate 0 pages (425983/425984).
[Note] InnoDB: buffer pool 5 : withdrawing blocks. (425983/425984)
[Note] InnoDB: buffer pool 5 : withdrew 0 blocks from free list. Tried to relocate 0 pages (425983/425984).
[Note] InnoDB: buffer pool 5 : withdrawing blocks. (425983/425984)
[Note] InnoDB: buffer pool 5 : withdrew 0 blocks from free list. Tried to relocate 0 pages (425983/425984).
[Note] InnoDB: buffer pool 5 : withdrawing blocks. (425983/425984)
[Note] InnoDB: buffer pool 5 : withdrew 0 blocks from free list. Tried to relocate 0 pages (425983/425984).回收过程中出现ERROR,线程池满了,这是因为回收page,加锁,导致线程被阻塞,不断累加。
[ERROR] Threadpool could not create additional thread to handle queries, because the number of allowed threads was reached.
Increasing 'thread_pool_max_threads' parameter can help in this situation.第三步删除内存
而第3步对应的Innodb_buffer_pool_resize_status状态为Latching whole of buffer pool。
这个步骤会锁定整个buffer pool不允许任何操作但是只是删除内存一般比较快。
[Note] InnoDB: Latching whole of buffer pool.
[Note] InnoDB: buffer pool 0 : resizing with chunks 64 to 12.
[Note] InnoDB: buffer pool 0 : 52 chunks (425984 blocks) were freed.
[Note] InnoDB: buffer pool 1 : resizing with chunks 64 to 12.
[Note] InnoDB: buffer pool 1 : 52 chunks (425984 blocks) were freed.
[Note] InnoDB: buffer pool 2 : resizing with chunks 64 to 12.
[Note] InnoDB: buffer pool 2 : 52 chunks (425984 blocks) were freed.
[Note] InnoDB: buffer pool 3 : resizing with chunks 64 to 12.
[Note] InnoDB: buffer pool 3 : 52 chunks (425984 blocks) were freed.
[Note] InnoDB: buffer pool 4 : resizing with chunks 64 to 12.
[Note] InnoDB: buffer pool 4 : 52 chunks (425984 blocks) were freed.
[Note] InnoDB: buffer pool 5 : resizing with chunks 64 to 12.
[Note] InnoDB: buffer pool 5 : 52 chunks (425984 blocks) were freed.
[Note] InnoDB: buffer pool 6 : resizing with chunks 64 to 12.
[Note] InnoDB: buffer pool 6 : 52 chunks (425984 blocks) were freed.
[Note] InnoDB: buffer pool 7 : resizing with chunks 64 to 12.
[Note] InnoDB: buffer pool 7 : 52 chunks (425984 blocks) were freed.
[Note] InnoDB: Resizing hash tables.
[Note] InnoDB: buffer pool 0 : hash tables were resized.
[Note] InnoDB: buffer pool 1 : hash tables were resized.
[Note] InnoDB: buffer pool 2 : hash tables were resized.
[Note] InnoDB: buffer pool 3 : hash tables were resized.
[Note] InnoDB: buffer pool 4 : hash tables were resized.
[Note] InnoDB: buffer pool 5 : hash tables were resized.
[Note] InnoDB: buffer pool 6 : hash tables were resized.
[Note] InnoDB: buffer pool 7 : hash tables were resized.
[Note] InnoDB: page_cleaner: 1000ms intended loop took 5218ms. The settings might not be optimal. (flushed=0 and evicted=0, during the time.)
[Note] InnoDB: Resizing also other hash tables.
[Note] InnoDB: Resized hash tables at lock_sys, adaptive hash index, dictionary.
[Note] InnoDB: Completed to resize buffer pool from 68719476736 to 12884901888.第四步重启AHI
[Note] InnoDB: Re-enabled adaptive hash index.
[Note] InnoDB: Completed resizing buffer pool at 230616
整个步骤完成后Innodb_buffer_pool_resize_status状态为Completed resizing buffer pool at ***。
因此建议在低压的情况下进行,也就是数据修改量小的情况下进行。现有资料显示整个resize 减少buffer pool 可能会影响TPS
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




