Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
milvus
提交
084213c6
milvus
项目概览
BaiXuePrincess
/
milvus
与 Fork 源项目一致
从无法访问的项目Fork
通知
7
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
milvus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
084213c6
编写于
9月 19, 2019
作者:
Y
yudong.cai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
MS-572 re-org signal handle
Former-commit-id: e214a3e449dd0f0a7119d5a96b1222a0bdc64605
上级
520b4015
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
93 addition
and
112 deletion
+93
-112
cpp/CHANGELOG.md
cpp/CHANGELOG.md
+1
-0
cpp/src/main.cpp
cpp/src/main.cpp
+28
-26
cpp/src/server/Server.cpp
cpp/src/server/Server.cpp
+38
-55
cpp/src/server/Server.h
cpp/src/server/Server.h
+1
-7
cpp/src/server/grpc_impl/GrpcRequestTask.cpp
cpp/src/server/grpc_impl/GrpcRequestTask.cpp
+1
-1
cpp/src/server/grpc_impl/GrpcServer.cpp
cpp/src/server/grpc_impl/GrpcServer.cpp
+9
-9
cpp/src/server/grpc_impl/GrpcServer.h
cpp/src/server/grpc_impl/GrpcServer.h
+6
-5
cpp/src/utils/SignalUtil.cpp
cpp/src/utils/SignalUtil.cpp
+9
-9
未找到文件。
cpp/CHANGELOG.md
浏览文件 @
084213c6
...
...
@@ -5,6 +5,7 @@ Please mark all change in change log and use the ticket from JIRA.
# Milvus 0.5.0 (TODO)
## Bug
-
MS-572 - Milvus crash when get SIGINT
## Improvement
-
MS-552 - Add and change the easylogging library
...
...
cpp/src/main.cpp
浏览文件 @
084213c6
...
...
@@ -15,19 +15,20 @@
// specific language governing permissions and limitations
// under the License.
#include "server/Server.h"
#include "version.h"
#include <getopt.h>
#include <libgen.h>
#include <cstring>
#include <string>
#include <signal.h>
#include "utils/easylogging++.h"
#include "metrics/Metrics.h"
#include <unistd.h>
#include "utils/easylogging++.h"
#include "utils/SignalUtil.h"
#include "utils/CommonUtil.h"
#include "metrics/Metrics.h"
#include "server/Server.h"
#include "version.h"
INITIALIZE_EASYLOGGINGPP
...
...
@@ -40,12 +41,6 @@ main(int argc, char *argv[]) {
std
::
cout
<<
std
::
endl
<<
"Welcome to use Milvus by Zilliz!"
<<
std
::
endl
;
std
::
cout
<<
"Milvus "
<<
BUILD_TYPE
<<
" version: v"
<<
MILVUS_VERSION
<<
" built at "
<<
BUILD_TIME
<<
std
::
endl
;
signal
(
SIGINT
,
server
::
SignalUtil
::
HandleSignal
);
signal
(
SIGSEGV
,
server
::
SignalUtil
::
HandleSignal
);
signal
(
SIGUSR1
,
server
::
SignalUtil
::
HandleSignal
);
signal
(
SIGUSR2
,
server
::
SignalUtil
::
HandleSignal
);
std
::
string
app_name
=
basename
(
argv
[
0
]);
static
struct
option
long_options
[]
=
{{
"conf_file"
,
required_argument
,
0
,
'c'
},
{
"log_conf_file"
,
required_argument
,
0
,
'l'
},
{
"help"
,
no_argument
,
0
,
'h'
},
...
...
@@ -55,14 +50,12 @@ main(int argc, char *argv[]) {
int
option_index
=
0
;
int64_t
start_daemonized
=
0
;
// int pid_fd;
std
::
string
config_filename
,
log_config_file
;
std
::
string
pid_filename
;
std
::
string
app_name
=
argv
[
0
];
app_name
=
argv
[
0
];
if
(
argc
<
2
)
{
if
(
argc
<
2
)
{
print_help
(
app_name
);
std
::
cout
<<
"Milvus server exit..."
<<
std
::
endl
;
return
EXIT_FAILURE
;
...
...
@@ -94,29 +87,38 @@ main(int argc, char *argv[]) {
break
;
}
case
'd'
:
start_daemonized
=
1
;
case
'd'
:
start_daemonized
=
1
;
break
;
case
'h'
:
print_help
(
app_name
);
case
'h'
:
print_help
(
app_name
);
return
EXIT_SUCCESS
;
case
'?'
:
print_help
(
app_name
);
case
'?'
:
print_help
(
app_name
);
return
EXIT_FAILURE
;
default:
print_help
(
app_name
);
default:
print_help
(
app_name
);
break
;
}
}
server
::
Server
&
server
=
server
::
Server
::
Instance
();
server
::
Server
&
server
=
server
::
Server
::
Instance
();
server
.
Init
(
start_daemonized
,
pid_filename
,
config_filename
,
log_config_file
);
return
server
.
Start
();
server
.
Start
();
/* Handle Signal */
signal
(
SIGHUP
,
server
::
SignalUtil
::
HandleSignal
);
signal
(
SIGINT
,
server
::
SignalUtil
::
HandleSignal
);
signal
(
SIGUSR1
,
server
::
SignalUtil
::
HandleSignal
);
signal
(
SIGSEGV
,
server
::
SignalUtil
::
HandleSignal
);
signal
(
SIGUSR2
,
server
::
SignalUtil
::
HandleSignal
);
signal
(
SIGTERM
,
server
::
SignalUtil
::
HandleSignal
);
/* wait signal */
pause
();
return
0
;
}
void
print_help
(
const
std
::
string
&
app_name
)
{
std
::
cout
<<
std
::
endl
<<
"Usage: "
<<
app_name
<<
" [OPTIONS]"
<<
std
::
endl
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
<<
"Usage: "
<<
app_name
<<
" [OPTIONS]"
<<
std
::
endl
<<
std
::
endl
;
std
::
cout
<<
" Options:"
<<
std
::
endl
;
std
::
cout
<<
" -h --help Print this help"
<<
std
::
endl
;
std
::
cout
<<
" -c --conf_file filename Read configuration from the file"
<<
std
::
endl
;
...
...
cpp/src/server/Server.cpp
浏览文件 @
084213c6
...
...
@@ -17,7 +17,7 @@
#include <thread>
#include "Server.h"
#include "server/grpc_impl/Grpc
Milvus
Server.h"
#include "server/grpc_impl/GrpcServer.h"
#include "utils/Log.h"
#include "utils/LogUtil.h"
#include "utils/SignalUtil.h"
...
...
@@ -154,74 +154,61 @@ Server::Daemonize() {
}
}
int
void
Server
::
Start
()
{
if
(
daemonized_
)
{
Daemonize
();
}
do
{
try
{
// Read config file
if
(
LoadConfig
()
!=
SERVER_SUCCESS
)
{
return
1
;
}
try
{
/* Read config file */
if
(
LoadConfig
()
!=
SERVER_SUCCESS
)
{
std
::
cerr
<<
"Milvus server fail to load config file"
<<
std
::
endl
;
return
;
}
//log path is defined by LoadConfig, so InitLog must be called after LoadConfig
ServerConfig
&
config
=
ServerConfig
::
GetInstance
();
ConfigNode
server_config
=
config
.
GetConfig
(
CONFIG_SERVER
);
/* log path is defined in Config file, so InitLog must be called after LoadConfig */
ServerConfig
&
config
=
ServerConfig
::
GetInstance
();
ConfigNode
server_config
=
config
.
GetConfig
(
CONFIG_SERVER
);
std
::
string
time_zone
=
server_config
.
GetValue
(
CONFIG_TIME_ZONE
,
"UTC+8"
);
if
(
time_zone
.
length
()
==
3
)
{
std
::
string
time_zone
=
server_config
.
GetValue
(
CONFIG_TIME_ZONE
,
"UTC+8"
);
if
(
time_zone
.
length
()
==
3
)
{
time_zone
=
"CUT"
;
}
else
{
int
time_bias
=
std
::
stoi
(
time_zone
.
substr
(
3
,
std
::
string
::
npos
));
if
(
time_bias
==
0
)
time_zone
=
"CUT"
;
else
if
(
time_bias
>
0
)
{
time_zone
=
"CUT"
+
std
::
to_string
(
-
time_bias
);
}
else
{
int
time_bias
=
std
::
stoi
(
time_zone
.
substr
(
3
,
std
::
string
::
npos
));
if
(
time_bias
==
0
)
time_zone
=
"CUT"
;
else
if
(
time_bias
>
0
)
{
time_zone
=
"CUT"
+
std
::
to_string
(
-
time_bias
);
}
else
{
time_zone
=
"CUT+"
+
std
::
to_string
(
-
time_bias
);
}
}
if
(
setenv
(
"TZ"
,
time_zone
.
c_str
(),
1
)
!=
0
)
{
return
-
1
;
time_zone
=
"CUT+"
+
std
::
to_string
(
-
time_bias
);
}
tzset
();
InitLog
(
log_config_file_
);
}
// Handle Signal
signal
(
SIGINT
,
SignalUtil
::
HandleSignal
);
signal
(
SIGHUP
,
SignalUtil
::
HandleSignal
);
signal
(
SIGTERM
,
SignalUtil
::
HandleSignal
);
server
::
Metrics
::
GetInstance
().
Init
();
server
::
SystemInfo
::
GetInstance
().
Init
();
if
(
setenv
(
"TZ"
,
time_zone
.
c_str
(),
1
)
!=
0
)
{
std
::
cerr
<<
"Fail to setenv"
<<
std
::
endl
;
return
;
}
tzset
();
std
::
cout
<<
"Milvus server start successfully."
<<
std
::
endl
;
StartService
();
InitLog
(
log_config_file_
);
while
(
running_
)
{
sleep
(
10
);
}
server
::
Metrics
::
GetInstance
().
Init
();
server
::
SystemInfo
::
GetInstance
().
Init
();
}
catch
(
std
::
exception
&
ex
)
{
std
::
cerr
<<
"Milvus server encounter exception: "
<<
std
::
string
(
ex
.
what
())
<<
"Is another server instance running?"
;
break
;
}
}
while
(
false
);
std
::
cout
<<
"Milvus server start successfully."
<<
std
::
endl
;
StartService
();
return
0
;
}
catch
(
std
::
exception
&
ex
)
{
std
::
cerr
<<
"Milvus server encounter exception: "
<<
ex
.
what
();
}
}
void
Server
::
Stop
()
{
std
::
cerr
<<
"Milvus server is going to shutdown ..."
<<
std
::
endl
;
/
/ Unlock and close lockfile
/
* Unlock and close lockfile */
if
(
pid_fd
!=
-
1
)
{
int
ret
=
lockf
(
pid_fd
,
F_ULOCK
,
0
);
if
(
ret
!=
0
)
{
...
...
@@ -235,7 +222,7 @@ Server::Stop() {
}
}
/
/ Try to delete lockfile
/
* delete lockfile */
if
(
!
pid_filename_
.
empty
())
{
int
ret
=
unlink
(
pid_filename_
.
c_str
());
if
(
ret
!=
0
)
{
...
...
@@ -245,10 +232,6 @@ Server::Stop() {
}
StopService
();
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
running_
=
false
;
}
std
::
cerr
<<
"Milvus server is closed!"
<<
std
::
endl
;
}
...
...
@@ -271,12 +254,12 @@ Server::StartService() {
engine
::
KnowhereResource
::
Initialize
();
engine
::
StartSchedulerService
();
DBWrapper
::
GetInstance
().
StartService
();
grpc
::
Grpc
Milvus
Server
::
GetInstance
().
Start
();
grpc
::
GrpcServer
::
GetInstance
().
Start
();
}
void
Server
::
StopService
()
{
grpc
::
Grpc
Milvus
Server
::
GetInstance
().
Stop
();
grpc
::
GrpcServer
::
GetInstance
().
Stop
();
DBWrapper
::
GetInstance
().
StopService
();
engine
::
StopSchedulerService
();
engine
::
KnowhereResource
::
Finalize
();
...
...
cpp/src/server/Server.h
浏览文件 @
084213c6
...
...
@@ -37,13 +37,11 @@ class Server {
const
std
::
string
&
config_filename
,
const
std
::
string
&
log_config_file
);
int
Start
();
void
Start
();
void
Stop
();
private:
Server
();
~
Server
();
void
Daemonize
();
...
...
@@ -51,7 +49,6 @@ class Server {
ErrorCode
LoadConfig
();
void
StartService
();
void
StopService
();
private:
...
...
@@ -60,9 +57,6 @@ class Server {
std
::
string
pid_filename_
;
std
::
string
config_filename_
;
std
::
string
log_config_file_
;
std
::
mutex
mutex_
;
bool
running_
=
true
;
};
// Server
}
// server
...
...
cpp/src/server/grpc_impl/GrpcRequestTask.cpp
浏览文件 @
084213c6
...
...
@@ -23,7 +23,7 @@
#include "utils/ValidationUtil.h"
#include "../DBWrapper.h"
#include "version.h"
#include "Grpc
Milvus
Server.h"
#include "GrpcServer.h"
#include "db/Utils.h"
#include "scheduler/SchedInst.h"
//#include <gperftools/profiler.h>
...
...
cpp/src/server/grpc_impl/Grpc
Milvus
Server.cpp
→
cpp/src/server/grpc_impl/GrpcServer.cpp
浏览文件 @
084213c6
...
...
@@ -16,7 +16,7 @@
// under the License.
#include "milvus.grpc.pb.h"
#include "Grpc
Milvus
Server.h"
#include "GrpcServer.h"
#include "server/ServerConfig.h"
#include "server/DBWrapper.h"
#include "utils/Log.h"
...
...
@@ -34,7 +34,6 @@
#include <grpcpp/client_context.h>
#include <grpcpp/create_channel.h>
#include <grpcpp/security/credentials.h>
#include <grpcpp/grpcpp.h>
namespace
zilliz
{
...
...
@@ -52,18 +51,19 @@ class NoReusePortOption : public ::grpc::ServerBuilderOption {
args
->
SetInt
(
GRPC_ARG_ALLOW_REUSEPORT
,
0
);
}
void
UpdatePlugins
(
std
::
vector
<
std
::
unique_ptr
<::
grpc
::
ServerBuilderPlugin
>>
*
plugins
)
override
{}
void
UpdatePlugins
(
std
::
vector
<
std
::
unique_ptr
<::
grpc
::
ServerBuilderPlugin
>>
*
plugins
)
override
{
}
};
void
Grpc
Milvus
Server
::
Start
()
{
thread_ptr_
=
std
::
make_shared
<
std
::
thread
>
(
&
Grpc
Milvus
Server
::
StartService
,
this
);
GrpcServer
::
Start
()
{
thread_ptr_
=
std
::
make_shared
<
std
::
thread
>
(
&
GrpcServer
::
StartService
,
this
);
}
void
Grpc
Milvus
Server
::
Stop
()
{
GrpcServer
::
Stop
()
{
StopService
();
if
(
thread_ptr_
)
{
thread_ptr_
->
join
();
...
...
@@ -72,7 +72,7 @@ GrpcMilvusServer::Stop() {
}
Status
Grpc
Milvus
Server
::
StartService
()
{
GrpcServer
::
StartService
()
{
ServerConfig
&
config
=
ServerConfig
::
GetInstance
();
ConfigNode
server_config
=
config
.
GetConfig
(
CONFIG_SERVER
);
ConfigNode
engine_config
=
config
.
GetConfig
(
CONFIG_ENGINE
);
...
...
@@ -102,7 +102,7 @@ GrpcMilvusServer::StartService() {
}
Status
Grpc
Milvus
Server
::
StopService
()
{
GrpcServer
::
StopService
()
{
if
(
server_ptr_
!=
nullptr
)
{
server_ptr_
->
Shutdown
();
}
...
...
cpp/src/server/grpc_impl/Grpc
Milvus
Server.h
→
cpp/src/server/grpc_impl/GrpcServer.h
浏览文件 @
084213c6
...
...
@@ -24,15 +24,16 @@
#include <thread>
#include <grpcpp/grpcpp.h>
namespace
zilliz
{
namespace
milvus
{
namespace
server
{
namespace
grpc
{
class
Grpc
Milvus
Server
{
class
GrpcServer
{
public:
static
Grpc
MilvusServer
&
GetInstance
()
{
static
Grpc
Milvus
Server
grpc_server
;
static
Grpc
Server
&
GetInstance
()
{
static
GrpcServer
grpc_server
;
return
grpc_server
;
}
...
...
@@ -40,8 +41,8 @@ class GrpcMilvusServer {
void
Stop
();
private:
Grpc
Milvus
Server
()
=
default
;
~
Grpc
Milvus
Server
()
=
default
;
GrpcServer
()
=
default
;
~
GrpcServer
()
=
default
;
Status
StartService
();
Status
StopService
();
...
...
cpp/src/utils/SignalUtil.cpp
浏览文件 @
084213c6
...
...
@@ -22,27 +22,28 @@
#include <signal.h>
#include <execinfo.h>
namespace
zilliz
{
namespace
milvus
{
namespace
server
{
void
SignalUtil
::
HandleSignal
(
int
signum
){
void
SignalUtil
::
HandleSignal
(
int
signum
)
{
switch
(
signum
)
{
switch
(
signum
)
{
case
SIGINT
:
case
SIGUSR2
:{
case
SIGUSR2
:
{
SERVER_LOG_INFO
<<
"Server received signal: "
<<
signum
;
server
::
Server
&
server_ptr
=
server
::
Server
::
Instance
();
server
::
Server
&
server_ptr
=
server
::
Server
::
Instance
();
server_ptr
.
Stop
();
exit
(
0
);
}
default:
{
default:
{
SERVER_LOG_INFO
<<
"Server received critical signal: "
<<
signum
;
SignalUtil
::
PrintStacktrace
();
server
::
Server
&
server_ptr
=
server
::
Server
::
Instance
();
server
::
Server
&
server_ptr
=
server
::
Server
::
Instance
();
server_ptr
.
Stop
();
exit
(
1
);
...
...
@@ -54,9 +55,9 @@ void SignalUtil::PrintStacktrace() {
SERVER_LOG_INFO
<<
"Call stack:"
;
const
int
size
=
32
;
void
*
array
[
size
];
void
*
array
[
size
];
int
stack_num
=
backtrace
(
array
,
size
);
char
**
stacktrace
=
backtrace_symbols
(
array
,
stack_num
);
char
**
stacktrace
=
backtrace_symbols
(
array
,
stack_num
);
for
(
int
i
=
0
;
i
<
stack_num
;
++
i
)
{
std
::
string
info
=
stacktrace
[
i
];
SERVER_LOG_INFO
<<
info
;
...
...
@@ -64,7 +65,6 @@ void SignalUtil::PrintStacktrace() {
free
(
stacktrace
);
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录