Ceph rgw CephContext的属性_service_thread

CephContext的_service_thread属性

CephContext代表这进程的上下文,该实例中几乎包含进程的所有信息。这里主要介绍他的_service_thread属性。

_service_thread代表着一个线程,主要用来完成重新打开log file和更新performance counter;GIGHUP会唤醒该线程。其主要逻辑如下:

 void *entry()
  {
    while (1) {
      Mutex::Locker l(_lock);
//heartbeat_interval==5
      if (_cct->_conf->heartbeat_interval) {
        utime_t interval(_cct->_conf->heartbeat_interval, 0);
        _cond.WaitInterval(_cct, _lock, interval); //wait interval time
      } else
        _cond.Wait(_lock);

      if (_exit_thread) {
        break;
      }

      if (_reopen_logs) {
        _cct->_log->reopen_log_file();
        _reopen_logs = false;
      }
      _cct->_heartbeat_map->check_touch_file();

      // refresh the perf coutners
      _cct->refresh_perf_values();
    }
    return NULL;
  }

下面是重新打开日志文件的过程:

void Log::reopen_log_file()
{
  pthread_mutex_lock(&m_flush_mutex);
  m_flush_mutex_holder = pthread_self();
  if (m_fd >= 0)
    VOID_TEMP_FAILURE_RETRY(::close(m_fd));
  if (m_log_file.length()) {
    m_fd = ::open(m_log_file.c_str(), O_CREAT|O_WRONLY|O_APPEND, 0644);
  } else {
    m_fd = -1;
  }
  m_flush_mutex_holder = 0;
  pthread_mutex_unlock(&m_flush_mutex);
}

你可能感兴趣的:(ceph)