/* If the function fails, the return value is zero.*/ int uGetFileSizeByName(const char* name, __int64 * file_size, sys_call_error_fun fun) { int res; UFile fd; fd = uOpenFile(name, U_SHARE_READ, U_READ, 0, __sys_call_error); if (fd == U_INVALID_FD) return 0; res = uGetFileSize(fd, file_size, __sys_call_error); if (res == 0) { uCloseFile(fd, __sys_call_error); return 0; } if (uCloseFile(fd, __sys_call_error) == 0) return 0; return 1; }
inline int client_exception_handler(USOCKET sock, const pping_server *pps) { #if (defined(EL_DEBUG) && (EL_DEBUG == 1)) #ifdef _WIN32 char cc = PPING_PROC_EXCEPTION_MSG; HANDLE proc_h; DWORD proc_id; DWORD except_thread_id; PEXCEPTION_POINTERS client_exceptPtrs; MINIDUMP_EXCEPTION_INFORMATION ExpParam; int component; UFile fh; #define GETVAR(v) if (urecv(sock, (char*)&v, sizeof(v), NULL) != sizeof(v)) \ SYS_FAILURE_SERVER("Failure in pping server (cannot receive exception parameter from the client)."); GETVAR(proc_id) GETVAR(component); GETVAR(except_thread_id); GETVAR(client_exceptPtrs); #undef GETVAR proc_h = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proc_id); if (proc_h == NULL) d_printf2("Failed to open process handle, GetLastError=%u\n", GetLastError()); ExpParam.ThreadId = except_thread_id; ExpParam.ExceptionPointers = client_exceptPtrs; ExpParam.ClientPointers = TRUE; fh = sedna_soft_fault_log_fh(component, "-dump"); if (!MiniDumpWriteDump(proc_h, proc_id, fh, MiniDumpWithDataSegs, &ExpParam, NULL, NULL)) d_printf2("Failed to save minidump, GetLastError=%u\n", GetLastError()); uCloseFile(fh, NULL); if (usend(sock, &cc, sizeof(cc), NULL) != sizeof(cc)) SYS_FAILURE_SERVER("Failure in pping server (cannot send exception ack to the client)."); #endif /* _WIN32 */ #endif /* EL_DEBUG */ return 1; }
void test_db_after_rcv() { std::string rcv_fname = std::string(SEDNA_DATA) + std::string("/data/") + std::string(tr_globals::db_name) + std::string("_files/rcv_test_result.log"); metadata_cell_cptr mdc = XNULL; logfile = fopen(rcv_fname.c_str(), "at"); fprintf(logfile, "---------------------------------------------------------------------\n"); bt_cursor cursor = bt_lm(catalog_get_names(catobj_metadata)); if (!cursor.is_null()) do { mdc = cursor.bt_next_obj(); if (!mdc->is_document()) test_collection(mdc->get_name(), mdc->get_schema_node()); else { xptr blk = mdc->get_schema_node()->bblk; CHECKP(blk); xptr doc_dsc = getFirstBlockNode(blk); test_document(mdc->get_name(), doc_dsc, false); test_indexes(doc_schema_node_cptr(mdc->get_schema_node())->full_index_list->first); } } while(cursor.bt_next_key()); fclose(logfile); #ifdef RCV_TEST_CRASH rcv_fname = std::string(SEDNA_DATA) + std::string("/data/") + std::string(tr_globals::db_name) + std::string("_files"); if (isRcvOK) rcv_fname += std::string("/rcv_ok"); else rcv_fname += std::string("/rcv_failed"); r_fh = uCreateFile(rcv_fname.c_str(), U_SHARE_READ | U_SHARE_WRITE, U_READ_WRITE, U_NO_BUFFERING, NULL, NULL); if (r_fh == U_INVALID_FD) fprintf(stderr, "Cannot create rcv result file\n"); uCloseFile(r_fh, NULL); #endif }
U_THREAD_PROC(pping_client_thread_proc, arg) { if (uThreadBlockAllSignals(NULL) != 0) d_printf1("Failed to block signals for pping_client_thread_proc"); pping_client *ppc = (pping_client*)arg; char c = PPING_KEEP_ALIVE_MSG; while (true) { if (ppc->stop_keep_alive) return 0; int res = usend(ppc->sock, &c, sizeof(c), NULL); if (res != sizeof(c) && !ppc->stop_keep_alive) { sedna_soft_fault("SEDNA GOVERNOR is down", ppc->component); } /* se_stop -hard has been called? */ if(ppc->signaled_flag != NULL && GOV_HEADER_GLOBAL_PTR != NULL && GOV_HEADER_GLOBAL_PTR -> is_server_stop == SE_STOP_HARD) { *(ppc->signaled_flag) = true; } UUnnamedSemaphoreDownTimeout(&(ppc->sem), 1000, NULL); if(ppc->timeout) { if (!ppc->counter && !ppc->reset_flag) { *(ppc->signaled_flag) = true; ppc->counter = ppc->timeout; } if(ppc->reset_flag) { ppc->counter = ppc->timeout; if(ppc->signaled_flag) *(ppc->signaled_flag) = false; ppc->reset_flag = false; } (ppc->counter)--; } #if (defined(EL_DEBUG) && (EL_DEBUG == 1)) #define SENDVAR(v) if (usend(ppc->sock, (char*)&v, sizeof(v), NULL) != sizeof(v)) continue; #ifdef _WIN32 if (ppc->exceptPtrs) { //TODO: do something if usend/urecv fails or get wrong msg char cc = PPING_PROC_EXCEPTION_MSG; DWORD proc_id = GetCurrentProcessId(); if (usend(ppc->sock, &cc, sizeof(cc), NULL) != sizeof(cc)) { ppc->exceptPtrs = NULL; continue; } SENDVAR(proc_id) SENDVAR(ppc->component); SENDVAR(ppc->except_thread_id); SENDVAR(ppc->exceptPtrs); if (urecv(ppc->sock, &cc, sizeof(cc), NULL) != sizeof(cc)) { ppc->exceptPtrs = NULL; continue; } if (cc != PPING_PROC_EXCEPTION_MSG) { ppc->exceptPtrs = NULL; continue; } if (ppc->stacktrace_fh != U_INVALID_FD) { if (StackTraceInit() != 0) { StackTraceWriteFd(ppc->exceptPtrs->ContextRecord, (intptr_t)ppc->stacktrace_fh, 9999, 0); StackTraceDeinit(); } uCloseFile(ppc->stacktrace_fh, NULL); } ppc->exceptPtrs = NULL; } #endif #undef SENDVAR #endif } return 0; }