Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CBRD-25436] Creating monitoring thread and data structures for cub_server monitoring #5293

Merged
merged 31 commits into from
Jul 12, 2024

Conversation

YeunjunLee
Copy link
Contributor

@YeunjunLee YeunjunLee commented Jul 2, 2024

http://jira.cubrid.org/browse/CBRD-25436

cub_server 모니터링을 위한 자료 구조와 server_monitor_thread 생성

  • server_monitor클래스 생성

    • inner class로 server_entryserver_monitor_list를 가짐
    • server_monitor_list server_entny를 삽입/제거/탐색 하기 위한 class 함수 구현
    • server_monitor_list 의 특정 server_entry에 대해 server 재구동을 하기 위한 함수 구현 (내부 구현은 CBRD-25438 이슈에서 구현)
  • server_entry 클래스 생성

    • server에서 넘겨 받은 정보를 통해 server_entry를 생성하기 위한 server_entry 생성자 구현
    • argv 해제를 위한 소멸자 구현
  • server_monitor_list 클래스 생성

    • 생성자를 통해 revive에 필요한 system parameter들 저장
  • server_monitor_thread 생성

    • server_monitor의 멤버 변수
    • server_monitor 소멸자에서 server_monitor_thread 종료 후, server_monitor_list 삭제
  • master 구동 시 server_monitor 생성

    • 현재 issue애서는 server_monitor는 non-HA 환경에서만 생성됨
    • sub-task 들에 대한 구현이 끝난 후, HA 환경에서 server_monitor 생성에 대한 구현 진행 예정

@YeunjunLee YeunjunLee marked this pull request as ready for review July 2, 2024 02:09
@YeunjunLee YeunjunLee changed the base branch from develop to feature/server_revive_2 July 2, 2024 02:22
src/connection/server_revive.cpp Outdated Show resolved Hide resolved
sa/CMakeLists.txt Outdated Show resolved Hide resolved
src/connection/server_revive.cpp Outdated Show resolved Hide resolved
src/connection/server_revive.cpp Outdated Show resolved Hide resolved
src/connection/server_revive.cpp Outdated Show resolved Hide resolved
src/executables/master.c Outdated Show resolved Hide resolved
src/connection/server_revive.hpp Outdated Show resolved Hide resolved
src/connection/server_revive.hpp Outdated Show resolved Hide resolved
src/connection/server_revive.hpp Outdated Show resolved Hide resolved
src/connection/server_revive.hpp Outdated Show resolved Hide resolved
@YeunjunLee YeunjunLee marked this pull request as draft July 2, 2024 08:38
@YeunjunLee YeunjunLee marked this pull request as ready for review July 3, 2024 09:37
@YeunjunLee YeunjunLee changed the title [CBRD-25436] cub_server 모니터링을 위한 자료 구조와 monitoring thread 생성 [CBRD-25436] Creating monitoring thread and data structures for cub_server monitoring Jul 4, 2024
Copy link
Contributor

@hornetmj hornetmj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아직 리뷰 진행 중 입니다. 명일 출근 후 이어서 진행하겠습니다.

@@ -182,6 +182,7 @@ set(CONNECTION_SOURCES
${CONNECTION_DIR}/server_support.c
${CONNECTION_DIR}/connection_support.c
${CONNECTION_DIR}/host_lookup.c
${CONNECTION_DIR}/server_revive.cpp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cub_master에서만 사용된다면, 포함시킬 필요는 없습니다. cub_master는 cs 라이브러리만 링크합니다.

$ ldd cub_master | grep libcub
        libcubridcs.so.11.4 => /home/hornetmj/work/cubrid/build_x86_64_debug/_install/CUBRID/lib/libcubridcs.so.11.4 (0x00007fc7c2b58000)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cubrid/CMakeList에서 제거 하였습니다.

src/connection/server_revive.hpp Outdated Show resolved Hide resolved
src/connection/server_revive.cpp Outdated Show resolved Hide resolved
src/connection/server_revive.cpp Outdated Show resolved Hide resolved
src/connection/server_revive.cpp Outdated Show resolved Hide resolved
src/connection/server_revive.cpp Outdated Show resolved Hide resolved
src/executables/master.c Outdated Show resolved Hide resolved
src/executables/master.c Outdated Show resolved Hide resolved
src/connection/server_revive.hpp Outdated Show resolved Hide resolved
src/executables/master.c Outdated Show resolved Hide resolved
src/connection/server_revive.cpp Outdated Show resolved Hide resolved
src/connection/server_revive.hpp Outdated Show resolved Hide resolved
src/connection/server_revive.cpp Outdated Show resolved Hide resolved
src/connection/server_revive.cpp Outdated Show resolved Hide resolved
src/connection/server_revive.cpp Outdated Show resolved Hide resolved
std::strcpy (this->exec_path, exec_path);

proc_make_arg (argv, args);
this->argv = argv;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지역 변수를 참조하고 있습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수정하였습니다.

* argv(in):
*/
void
proc_make_arg (char **arg, char *args)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

master_monitor::server_entry 내부 클래스에서만 사용된다면, private 클래스 함수로 만드는게 어떨까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

server_monitor::server_entry 내부의 클래스 함수로 변경하였습니다.

src/connection/server_revive.hpp Outdated Show resolved Hide resolved
src/connection/server_revive.hpp Outdated Show resolved Hide resolved
src/connection/server_revive.hpp Outdated Show resolved Hide resolved
src/connection/server_revive.cpp Outdated Show resolved Hide resolved
@YeunjunLee YeunjunLee requested a review from hornetmj July 8, 2024 05:09
Copy link
Contributor

@joohok joohok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 깔끔해졌습니다.
사소한 comment만 남겼습니다. 구조 변경이 없다면, re-request 안해주셔도 됩니다.

Comment on lines 1142 to 1144
// *INDENT-OFF*
server_monitor& server_monitoring_manager = server_monitor::get_instance();
// *INDENT-ON*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// *INDENT-OFF*
server_monitor& server_monitoring_manager = server_monitor::get_instance();
// *INDENT-ON*
// *INDENT-OFF*
server_monitor& server_monitoring_manager = server_monitor::get_instance();
// *INDENT-ON*

시작 지점 맞춰주는게 좋을 것 같아요.

src/executables/master_server_monitor.cpp Outdated Show resolved Hide resolved
src/executables/master_server_monitor.cpp Outdated Show resolved Hide resolved
src/executables/master_server_monitor.cpp Outdated Show resolved Hide resolved
// CBRD-24741 is done, this condition will be removed. And server_monitor will be initialized wh
// en first non-HA server is started in HA environment. (server_monitor will be finalized when last
// non-HA server is stopped in HA environment.)
if (HA_DISABLED ())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

master_util_config_startup()에서 sysprm_load_and_init() 호출을 통해 시스템 파라미터 관련된 모듈이 초기화 되기 때문에 HA_DISABLED() 호출이 정상적으로 동작하지 않을 것 입니다. main 함수 아래 쪽에 HA_DISABLED() 조건 검사 후 hb_master_init()를 호출해 주는 코드부가 있습니다. 해당 위치로 옮겨주시면 좋겠네요.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

위치 변경하였습니다.

src/executables/master_server_monitor.hpp Show resolved Hide resolved
#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <memory>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

필요 없어 보이네요?

Suggested change
#include <memory>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제거하였습니다.

#include "connection_defs.h"

#ifdef __cplusplus
extern "C"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

별도의 API 함수를 제공할 계획인가요? 단일 인스턴스를 통해 접근 시 필요해 보이진 않습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이전 코드의 잔재입니다. 제거하였습니다.

Comment on lines 42 to 43
class server_entry;
class server_monitor_list;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class server_entry; 불필요한 전방 선언이며, using server_entry_uptr_t를 server_entry class 정의 뒤 쪽으로 옮기면, class server_monitor_list; 역시 제거 가능

Suggested change
class server_entry;
class server_monitor_list;
class server_entry;
class server_monitor_list;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수정하였습니다.

timeval m_last_revive_time;
bool m_need_revive;

private:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT:

가독성을 위해 변수를 가장 마지막에 배치하고, 함수는 생성자 등에 이어서 배치하는게 어떨까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

각 클래스에 대해, 생성자-함수-변수 순으로 정의하도록 전체적으로 배치를 정리하였습니다.

void proc_make_arg (char *args);
};

class server_monitor_list
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

server_monitor_list를 별도의 내부 클래스로 유지하는 목적이 있을까요? server_entry를 위한 std::verctor<>는 server_monitor에 위치시켜도 충분할 것 같습니다. using을 이용해서 적당한 타입을 선언해 주면 될 것 같구요.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추후에 server_monitor_list 에 대한 탐색/삽입/제거/서버 revive 관련 함수들을 배치할 때, server_monitor class에 배치시키기 보다는 list에 대한 함수로서 배치하는 것이 더 보기 좋아보인다고 생각해서 별도의 클래스로 설계하였습니다.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::vector 자체가 list의 의미를 담고 있습니다. 다음 경우가 아니라면 크게 의미는 없지 않을까요?

  1. server_monitor가 여러개의 server_monitor_list를 만들어서 사용해야 하는 경우
  2. server_monitor_list 내부의 구조를 숨기고 싶은 경우
    • ex) server_monitor_list는 add_server_entry(), remove_server_entry() 인터페이스를 제공하며, server_monitor_list 내부에서 std::vector가 사용됨을 숨긴다. 이후 필요에 따라 std::vector는 다른 컨테이너나 사용자 정의 자료구조로 대체 가능하다.

그렇지 않다면, server_monitor는 std::vector에 접근하기 위해 server_monitor_list에 한번 더 접근해야 하기에 코드 복잡도가 증가합니다. 또한, class 타입 증가, 부모 class 라인수 증가 등의 이슈도 있습니다.

이후 진행될 sub-task에서 server_monitor_list 클래스 사용의 이점이 설명될 수 있다면, 이 리뷰는 해당 이슈에서 추가 논의해도 좋습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

server_monitor가 현재 위 두 경우에 해당하는 것 같지는 않습니다. 따라서 말씀 주신 대로, server_monior_list를 별개의 class로 설정하는 것 보다 server_monitor의 멤버로 직접 두는 것이 훨씬 간편할 것 같습니다.

해당 내용 반영하였고, 추가로 server_monitor_list 내부에 저장하고 있던 system parameter들도 사용 시 직접 가져와 사용하는 것이 클래스 구조를 간소화 하는데 더 좋을 것 같아서 제거하였습니다.

~server_monitor ();

std::unique_ptr<std::thread> m_monitoring_thread;
std::unique_ptr<server_monitor_list> m_monitor_list;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

server_monitor_list 제거(위 커멘트 참고) 시 다음 명칭이 더 적합해 보일 것 같습니다.

Suggested change
std::unique_ptr<server_monitor_list> m_monitor_list;
std::unique_ptr<server_monitor_list> m_server_entry_list;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수정하였습니다.

, m_last_revive_time {0, 0}
, m_need_revive {false}
{
proc_make_arg (args);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재는 null일 것 같은데, null이 아닌 경우에만 호출하는게 어떨까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nullptr 조건문을 추가하였습니다.

Comment on lines 73 to 79
const int m_pid;
const std::string m_server_name;
const std::string m_exec_path;
std::vector<std::string> m_argv;
CSS_CONN_ENTRY *m_conn;
timeval m_last_revive_time;
bool m_need_revive;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

각 변수에 대한 설명을 주석으로 남겨주세요. class/struct의 멤버 변수에 대해서는 기본적으로 설명 주석을 남겨주시는게 좋습니다. 너무 명료한 경우엔 남기지 않아도 되겠지만요.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추가하였습니다.

src/executables/master.c Outdated Show resolved Hide resolved
Copy link
Contributor

@hornetmj hornetmj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

master_server_monitor.cpp 파일은 아직 리뷰하지 않았습니다. 남긴 리뷰 내용 결정된 이후에 리뷰 진행하도록 하겠습니다. 답변해 주시면 되겠습니다.

src/executables/master.c Outdated Show resolved Hide resolved
src/executables/master.c Outdated Show resolved Hide resolved
src/executables/master_server_monitor.hpp Outdated Show resolved Hide resolved
void proc_make_arg (char *args);
};

class server_monitor_list
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::vector 자체가 list의 의미를 담고 있습니다. 다음 경우가 아니라면 크게 의미는 없지 않을까요?

  1. server_monitor가 여러개의 server_monitor_list를 만들어서 사용해야 하는 경우
  2. server_monitor_list 내부의 구조를 숨기고 싶은 경우
    • ex) server_monitor_list는 add_server_entry(), remove_server_entry() 인터페이스를 제공하며, server_monitor_list 내부에서 std::vector가 사용됨을 숨긴다. 이후 필요에 따라 std::vector는 다른 컨테이너나 사용자 정의 자료구조로 대체 가능하다.

그렇지 않다면, server_monitor는 std::vector에 접근하기 위해 server_monitor_list에 한번 더 접근해야 하기에 코드 복잡도가 증가합니다. 또한, class 타입 증가, 부모 class 라인수 증가 등의 이슈도 있습니다.

이후 진행될 sub-task에서 server_monitor_list 클래스 사용의 이점이 설명될 수 있다면, 이 리뷰는 해당 이슈에서 추가 논의해도 좋습니다.

src/executables/master_server_monitor.hpp Outdated Show resolved Hide resolved
src/executables/master_server_monitor.hpp Outdated Show resolved Hide resolved
src/executables/master.c Outdated Show resolved Hide resolved
if (HA_DISABLED ())
{
// *INDENT-OFF*
master_server_monitor.reset(new server_monitor());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
master_server_monitor.reset(new server_monitor());
master_server_monitor.reset (new server_monitor ());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수정하였습니다.

src/executables/master_server_monitor.hpp Outdated Show resolved Hide resolved
fflush (stdout);
}

// In server_monitor destructor, it should guerentee that
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// In server_monitor destructor, it should guerentee that
// In server_monitor destructor, it should guarantee that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수정하였습니다.

@YeunjunLee YeunjunLee requested a review from hornetmj July 11, 2024 02:01
src/executables/master_server_monitor.cpp Outdated Show resolved Hide resolved
src/executables/master_server_monitor.hpp Outdated Show resolved Hide resolved
src/executables/master_server_monitor.hpp Outdated Show resolved Hide resolved
src/executables/master_server_monitor.cpp Outdated Show resolved Hide resolved
Comment on lines 32 to 35
m_thread_shutdown = false;

m_server_entry_list = std::make_unique<std::vector<server_entry>> ();
fprintf (stdout, "server_monitor_list is created. \n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
m_thread_shutdown = false;
m_server_entry_list = std::make_unique<std::vector<server_entry>> ();
fprintf (stdout, "server_monitor_list is created. \n");
m_server_entry_list = std::make_unique<std::vector<server_entry>> ();
fprintf (stdout, "server_entry_list is created. \n");
m_thread_shutdown = false;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수정하였습니다.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

메세지 출력 시 server_monitor_list 아닌 server_entry_list로 제안드렸습니다. 제안된 내용을 그대로 반영하시려면, Commit suggestion 버튼을 이용하시면 됩니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

server_entry_list 생성 / 제거 디버깅 메시지 둘 다 수정하였습니다.

src/executables/master_server_monitor.cpp Outdated Show resolved Hide resolved
Comment on lines 50 to 60
server_monitor::~server_monitor ()
{
m_thread_shutdown = true;
if (m_monitoring_thread->joinable())
{
m_monitoring_thread->join();
fprintf (stdout, "server_monitor_thread is terminated. \n");
}
fprintf (stdout, "server_monitor_list is deleted. \n");
fflush (stdout);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
server_monitor::~server_monitor ()
{
m_thread_shutdown = true;
if (m_monitoring_thread->joinable())
{
m_monitoring_thread->join();
fprintf (stdout, "server_monitor_thread is terminated. \n");
}
fprintf (stdout, "server_monitor_list is deleted. \n");
fflush (stdout);
}
server_monitor::~server_monitor ()
{
m_thread_shutdown = true;
if (m_monitoring_thread->joinable())
{
m_monitoring_thread->join();
fprintf (stdout, "server_monitor_thread is terminated. \n");
}
assert (m_server_entry_list->size () == 0);
fprintf (stdout, "server_entry_list is deleted. \n");
fflush (stdout);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수정하였습니다.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

메세지 출력 시 server_monitor_list 아닌 server_entry_list로 제안드렸습니다. 제안된 내용을 그대로 반영하시려면, Commit suggestion 버튼을 이용하시면 됩니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

server_entry_list 생성 / 제거 디버깅 메시지 둘 다 수정하였습니다.

Copy link
Contributor

@hornetmj hornetmj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

출력 메시지 관련해서 커멘트 남겼고, 제안(suggestion) 받은 코드를 PR 상에서 바로 반영하는 방법에 대해 커멘트 남겼습니다.

@YeunjunLee YeunjunLee removed the request for review from beyondykk9 July 11, 2024 08:48
@hornetmj hornetmj merged commit bcb80f6 into CUBRID:feature/server_revive_2 Jul 12, 2024
7 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants