diff --git "a/app/zh/blogs/jiangyan/CM\345\203\265\346\255\273\346\243\200\346\265\213\344\273\243\347\240\201\350\265\260\350\257\273.md" "b/app/zh/blogs/jiangyan/CM\345\203\265\346\255\273\346\243\200\346\265\213\344\273\243\347\240\201\350\265\260\350\257\273.md" new file mode 100644 index 0000000000000000000000000000000000000000..5723282bfa219c952d2804c2f8c884c1b8823999 --- /dev/null +++ "b/app/zh/blogs/jiangyan/CM\345\203\265\346\255\273\346\243\200\346\265\213\344\273\243\347\240\201\350\265\260\350\257\273.md" @@ -0,0 +1,43 @@ +--- +title: 'CM僵死检测代码走读' + +date: '2021-01-25' + +category: 'blog' +tags: ['CM'] + +archives: '2025-01' + +author: 'jiangayn' + +summary: 'CM僵死检测代码走读' + +img: '/zh/blogs/jiangyan/title/img1.png' + +times: '16:30' +--- +# CM僵死检测代码走读 + +## 线程函数 **DNPhonyDeadStatusCheckMain** +僵死检测线程是通过cm_agent进程启动,线程函数为 **DNPhonyDeadStatusCheckMain** ,其中真正检测是否僵死的函数为**DnPhonyDeadStatusCheck**,在线程中如果**DnPhonyDeadStatusCheck**的返回值为true,则将g_dnPhonyDeadTimes[i](g_dnPhonyDeadTimes[i]为全局变量,记录每个节点僵死的次数,其中i为节点索引),**DnPhonyDeadStatusCheck**的返回值为false则将g_dnPhonyDeadTimes[i]重新置为0,如果g_dnPhonyDeadTimes[i] > 0 记录日志(has found %d times for instance(dn_%u) phony dead check.)。 + +## DnPhonyDeadStatusCheck函数流程: + + + 在**DnPhonyDeadStatusCheck**函数中首先会进入**check_one_instance_status**对进程状态进行检查,检查结果将存于变量phonyDead中,先来看不开启enable_e2e_rto的情况。 + +- 如果**check_one_instance_status**检测phonyDead为D状态,在资源池化下认为不僵死,**DnPhonyDeadStatusCheck**会返回false,而在其他情况下则会认为僵死; + +- 如果**check_one_instance_status**检测phonyDead为T状态,则**DnPhonyDeadStatusCheck**直接返回true; + +- 如果**check_one_instance_status**检测phonyDead为Z状态,则**DnPhonyDeadStatusCheck**直接返回true; + +做完上述检查以后,**DnPhonyDeadStatusCheck**函数会进入**CheckDnStausPhonyDead**函数继续检查,**CheckDnStausPhonyDead**函 + +数会有一些预置的sql语句连进数据库进行一些检查。如果**CheckDnStausPhonyDead**返回结果为0的话,再进入**check_disc_state**函数 + +进行检查,如果**check_disc_state**返回结果仍为0,则认为没有僵死,否则**DnPhonyDeadStatusCheck**返回false认为僵死,如果不为0 + +且enable_e2e_rto为1且g_dnPhonyDeadTimes[i] > PHONY_DEAD_THRESHOLD(很难触发)则杀死数据库。 + +其中g_dnPhonyDeadTimes[i]的次数会通过**DatanodeStatusReport**函数上报给cms,cms会进行仲裁,如果超过五次则cms会杀死数据库,并且需要等待(默认21600s)的时间才能继续操作数据库。 \ No newline at end of file diff --git a/app/zh/blogs/jiangyan/img1.png b/app/zh/blogs/jiangyan/img1.png new file mode 100644 index 0000000000000000000000000000000000000000..65e2d4c4751f069c64357704715e2ba99beb511a Binary files /dev/null and b/app/zh/blogs/jiangyan/img1.png differ