55 #define LOG_CURRENT_FUNCTION SRV_LOG(Warning, "this: " << (void*)this);
57 #define LOG_CURRENT_FUNCTION
65 #define USE_ALWAYS_COPY_UPD 0
669 #if USE_ALWAYS_COPY_UPD
1730 return cmd_status < 300;
1738 m_CmdProcessor(
NULL),
1740 m_write_event(
NULL),
1746 #if __NC_TASKS_MONITOR
1747 m_TaskName =
"CNCMessageHandler";
1771 CNCMessageHandler::State
1790 CNCMessageHandler::State
1811 CNCMessageHandler::State
1820 CNCMessageHandler::State
1830 CNCMessageHandler::State
1846 SRV_FATAL(
"Unexpected client status: " << status);
1867 CNCMessageHandler::State
1894 size_t auth_size = auth_line.
size();
1895 if (auth_size > 8 && auth_line[auth_size-8] ==
'H') {
1897 if (auth_line[auth_size-1] ==
'0') {
1899 }
else if (auth_line[auth_size-1] ==
'1') {
1912 << auth_line <<
"': " << ex);
1913 params[
"client"] = auth_line;
1934 << auth_line <<
"').");
1967 bool quorum_was_set =
false;
1968 bool search_was_set =
false;
1992 if (
key ==
"cache") {
1997 if (
key ==
"cmd_ver") {
2002 if (
key ==
"confirm") {
2010 if (
key ==
"cr_time") {
2013 else if (
key ==
"cr_id") {
2016 else if (
key ==
"cr_srv") {
2023 if (
key ==
"dead") {
2033 if (
key ==
"flags") {
2035 }
else if (
key ==
"fcr_ago_ge") {
2037 }
else if (
key ==
"fcr_ago_lt") {
2039 }
else if (
key ==
"fcr_epoch_ge") {
2041 }
else if (
key ==
"fcr_epoch_lt") {
2043 }
else if (
key ==
"fexp_now_ge") {
2045 }
else if (
key ==
"fexp_now_lt") {
2047 }
else if (
key ==
"fexp_epoch_ge") {
2049 }
else if (
key ==
"fexp_epoch_lt") {
2051 }
else if (
key ==
"fvexp_now_ge") {
2053 }
else if (
key ==
"fvexp_now_lt") {
2055 }
else if (
key ==
"fvexp_epoch_ge") {
2057 }
else if (
key ==
"fvexp_epoch_lt") {
2059 }
else if (
key ==
"fcr_srv") {
2061 }
else if (
key ==
"fsize_ge") {
2063 }
else if (
key ==
"fsize_lt") {
2068 if (
key ==
"http") {
2087 if (
key ==
"log_rec") {
2090 else if (
key ==
"log_srv") {
2093 else if (
key ==
"log_time") {
2096 else if (
key ==
"local") {
2101 if (
key ==
"md5_pass") {
2106 if (
key ==
"ncbi_phid") {
2113 if (
key ==
"pass") {
2117 unsigned char digest[16];
2118 md5.Finalize(digest);
2123 else if (
key ==
"prev") {
2128 if (
key ==
"qrum") {
2130 quorum_was_set =
true;
2134 if (
key ==
"rec_my") {
2137 else if (
key ==
"rec_your") {
2151 else if (
key ==
"size") {
2156 if (
key ==
"slot") {
2161 if (
key ==
"srv_id") {
2164 else if (
key ==
"srch") {
2166 search_was_set =
true;
2170 if (
key ==
"start") {
2175 if (
key ==
"subkey") {
2185 else if (
key ==
"type") {
2190 if (
key ==
"version") {
2193 else if (
key ==
"ver_ttl") {
2196 else if (
key ==
"ver_dead") {
2214 if (cmd_line.
empty()) {
2217 const string content_length(
"Content-Length:");
2218 const string user_agent(
"User-Agent:");
2219 const string content_range(
"Range:");
2220 size_t max_pos = cmd_line.
size();
2223 size_t pos = content_length.size();
2229 size_t pos = content_range.size();
2230 const char* begin = cmd_line.
data() + pos;
2231 while (!
isdigit(*begin) && pos < max_pos) {
2235 while (
isdigit(*begin) && pos < max_pos) {
2239 while (!
isdigit(*begin) && pos < max_pos) {
2243 while (
isdigit(*begin) && pos < max_pos) {
2251 list<CTempString>
arr;
2252 size_t pos = user_agent.size();
2267 list<CTempString>
arr;
2268 if (headers.
find(
"NCBI-SID") != headers.
end()) {
2275 if (headers.
find(
"NCBI-PHID") != headers.
end()) {
2283 if (!client_ip.empty()) {
2294 if (cache_name.
empty()) {
2306 if (!quorum_was_set)
2310 if (!search_was_set)
2337 CNCMessageHandler::State
2541 CNCMessageHandler::State
2575 list<CTempString>
arr;
2576 ncbi_NStr_Split(cmd_line,
" ",
arr);
2578 if (
arr.size() >= 3) {
2582 if (arr_cmd ==
"DELETE" ||
2584 arr_cmd ==
"HEAD" ||
2585 arr_cmd ==
"POST" ||
2589 list<CTempString> uri_parts;
2590 ncbi_NStr_Split(arr_uri,
"/", uri_parts);
2591 if (uri_parts.size() > 0) {
2592 if (arr_cmd !=
"POST") {
2593 arr_key = uri_parts.back();
2595 uri_parts.pop_back();
2598 if (!uri_parts.empty()) {
2651 Uint4 main_srv_ip = 0;
2656 if (main_srv_ip != 0) {
2753 CNCMessageHandler::State
2854 CNCMessageHandler::State
2876 Uint8 cur_time = cur_srv_time.AsUSec();
2877 int now =
int(cur_srv_time.Sec());
2878 int new_expire = now + add_time;
2879 if (new_expire < now) {
2892 new_expire =
min(new_expire,retire);
2903 event->orig_time = cur_time;
2915 Uint8 cur_time = cur_srv_time.AsUSec();
2928 event->orig_time = cur_time;
2940 bool print_size =
false;
2941 Uint8 written_size = 0;
3052 CNCMessageHandler::State
3069 CNCMessageHandler::State
3083 CNCMessageHandler::State
3094 <<
" (received " <<
m_BlobSize <<
" bytes)");
3099 SRV_LOG(
Error,
"Blob size exceeds the allowed maximum of "
3101 <<
" (received " <<
m_BlobSize <<
" bytes)");
3130 int cur_secs =
int(cur_srv_time.
Sec());
3188 SRV_LOG(
Warning,
"Received blob is too big and will not be mirrored:"
3219 CNCMessageHandler::State
3230 CNCMessageHandler::State
3246 if (sig == 0x04030201) {
3250 if (sig == 0x01020304) {
3256 SRV_LOG(
Error,
"Cannot determine the byte order. Got: "
3261 CNCMessageHandler::State
3271 if (active_sock && active_sock->
HasError())
3280 SRV_FATAL(
"Unexpected client status: " << status);
3289 bool has_chunklen =
true;
3343 <<
" (received at least "
3352 SRV_LOG(
Error,
"Blob size exceeds the allowed maximum of "
3355 <<
", next chunk " <<
m_ChunkLen <<
" bytes)");
3379 CNCMessageHandler::State
3421 CNCMessageHandler::State
3440 if (n_written != 0) {
3457 CNCMessageHandler::State
3483 CNCMessageHandler::State
3492 CNCMessageHandler::State
3502 SRV_FATAL(
"Previous client not released");
3518 CNCMessageHandler::State
3540 SRV_FATAL(
"Unexpected client status: " << status);
3546 switch (proxy_cmd) {
3602 CNCMessageHandler::State
3625 SRV_FATAL(
"Unexpected client status: " << status);
3637 if (!err_msg.empty()) {
3643 CNCMessageHandler::State
3654 SRV_FATAL(
"Previous client not released");
3660 CNCMessageHandler::State
3675 SRV_FATAL(
"Unexpected client status: " << status);
3684 CNCMessageHandler::State
3694 goto results_processed;
3696 SRV_FATAL(
"Unexpected client status: " << status);
3702 cur_blob_sum = &
handler->GetBlobSummary();
3704 cur_exist =
handler->IsBlobExists();
3706 goto results_processed;
3711 goto meta_search_finished;
3723 goto meta_search_finished;
3734 meta_search_finished:
3744 CNCMessageHandler::State
3757 Uint8 creation = vttl != 0 ?
3802 CNCMessageHandler::State
3812 SRV_FATAL(
"Previous client not released");
3821 CNCMessageHandler::State
3837 SRV_FATAL(
"Unexpected client status: " << status);
3846 CNCMessageHandler::State
3857 goto results_processed;
3859 SRV_FATAL(
"Unexpected client status: " << status);
3884 CNCMessageHandler::State
3893 SRV_FATAL(
"Previous client not released");
3902 CNCMessageHandler::State
3916 SRV_FATAL(
"Unexpected client status: " << status);
3925 CNCMessageHandler::State
3935 goto results_processed;
3937 SRV_FATAL(
"Unexpected client status: " << status);
3954 CNCMessageHandler::State
3958 const char* health_coeff =
"1";
3960 health_coeff =
"0 (does not accept writes)";
3962 health_coeff =
"0.1 (caching not finished)";
3964 health_coeff =
"0.2 (draining)";
3966 health_coeff =
"0.5 (initial sync not finished)";
3968 health_coeff =
"0.8 (some peers unaccessible)";
3994 CNCMessageHandler::State
3999 if (param.find(
"drain") != param.end() && param[
"drain"] !=
"0") {
4001 }
else if (param.find(
"reset") != param.end() && param[
"reset"] !=
"0") {
4010 CNCMessageHandler::State
4023 CNCMessageHandler::State
4028 if (params.find(
"section") != params.end()) {
4029 string section(params[
"section"]);
4032 if (section ==
"task_server") {
4034 }
else if (section ==
"netcache") {
4036 if (params.find(
"port") != params.end()) {
4037 client[
"port"] = params[
"port"];
4039 if (params.find(
"cache") != params.end()) {
4040 client[
"cache"] = params[
"cache"];
4049 }
else if (section ==
"storage") {
4051 }
else if (section ==
"mirror") {
4053 }
else if (section ==
"env") {
4057 }
else if (section ==
"stat") {
4060 stat->PrintState(*
this);
4064 }
else if (section ==
"syncstat") {
4067 #if __NC_TASKS_MONITOR
4068 }
else if (section ==
"tasks") {
4071 }
else if (section ==
"allalerts") {
4073 }
else if (section ==
"alerts") {
4075 }
else if (section ==
"sync") {
4084 }
else if (section ==
"db") {
4093 }
else if (section ==
"blobs") {
4095 }
else if (section ==
"blist") {
4105 WriteText(
",\n\"error\": \"Unknown section name, valid names: ");
4106 #if __NC_TASKS_MONITOR
4107 WriteText(
"task_server, netcache, storage, mirror, alerts, allalerts, env, stat, sync, tasks, blobs, db\"");
4109 WriteText(
"task_server, netcache, storage, mirror, alerts, allalerts, env, stat, sync, blobs, db\"");
4123 CNCMessageHandler::State
4129 if (params.
find(
"alert") != params.
end()) {
4130 string alert(params[
"alert"]);
4131 if (params.
find(
"user") != params.
end()) {
4132 string user(params[
"user"]);
4144 CNCMessageHandler::State
4154 string err_message(
"ERR:Unknown section name");
4156 if (params.
find(
"section") != params.
end()) {
4157 string section(params[
"section"]);
4158 if (section !=
"task_server" &&
4159 section !=
"mirror" &&
4160 section !=
"storage") {
4161 err_message +=
": " + section;
4167 err_message =
"ERR:Failed to load registry";
4170 if (section ==
"task_server") {
4172 }
else if (section ==
"mirror") {
4177 }
else if (section ==
"storage") {
4191 CNCMessageHandler::State
4201 stat->PrintToSocket(
this);
4207 CNCMessageHandler::State