[alibaba/tengine][dyups_module] worker意外退出被master重新拉起之后的配置一致性问题

2024-05-15 143 views
2

在dyups_module的ngx_http_dyups_init_process函数里面,有以下代码片段,用于在woker意外退出之后被master重新拉起时的执行逻辑,这里看起来的意图是要解决woker间的配置一致性问题,但仔细看逻辑好像并没有起到任何作用。请问这段逻辑的意图何在呢?

    if (sh->version != 0) {
        ngx_shmtx_unlock(&shpool->mutex);

        ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
                      "[dyups] process start after abnormal exits");

        ngx_msleep(dmcf->read_msg_timeout * 2);

        ngx_time_update();
        tp = ngx_timeofday();
        now = (ngx_msec_t) (tp->sec * 1000 + tp->msec);

        ngx_shmtx_lock(&shpool->mutex);

        if (sh->status == NULL) {
            ngx_shmtx_unlock(&shpool->mutex);
            return NGX_OK;
        }

        status = &sh->status[0];

        for (i = 1; i < ccf->worker_processes; i++) {

            ngx_log_error(NGX_LOG_WARN, cycle->log, 0,
                          "[dyups] process %P %ui %ui",
                          sh->status[i].pid, status->time, sh->status[i].time);

            if (status->time > sh->status[i].time) {
                status = &sh->status[i];
            }
        }

        pid = status->pid;
        status->time = now;
        status->pid = ngx_pid;

        ngx_log_error(NGX_LOG_WARN, cycle->log, 0,
                      "[dyups] new process is %P, old process is %P",
                      ngx_pid, pid);

        ngx_dyups_purge_msg(pid, ngx_pid);
    }

回答

8

@chobits @wangfakang

0

这个只能解决共享内存中有upstream消息的场景,如果共享内存中没有ups信息,master重启worker之后,该worker 是没有动态新增的ups 信息的。

4

所以还是会造成配置不一致的问题,这里感觉可以用存状态而不是存消息队列来解决不一致的问题