void gov_ugc(bool background_off_from_background_on, int os_primitives_bound) { #ifdef _WIN32 #else USemaphore sem; UShMem shm; UMMap map; char buf[1024]; if (background_off_from_background_on) return; d_printf1("Starting CLEANUP\n"); SEMAPHORE_CLEANUP(CHARISMA_GOVERNOR_IS_READY); SEMAPHORE_CLEANUP(SE_EVENT_LOG_SEMAPHORES_NAME); SHAREDMEM_CLEANUP(SE_EVENT_LOG_SHARED_MEMORY_NAME, sizeof(event_log_msg)); SHAREDMEM_CLEANUP(GOVERNOR_SHARED_MEMORY_NAME, sizeof(gov_config_struct)); FILE_MAPPING_CLEANUP(SEDNA_GLOBAL_MEMORY_MAPPING); /// releasing semaphores depending on sessions for (int i = 0; i < MAX_SESSIONS_NUMBER; i++) { SEMAPHORE_CLEANUP2(SM_TO_VMM_CALLBACK_SEM1_BASE_STR(i, buf, 1024), SM_TO_VMM_CALLBACK_SEM1_BASE_STR); SEMAPHORE_CLEANUP2(SM_TO_VMM_CALLBACK_SEM2_BASE_STR(i, buf, 1024), SM_TO_VMM_CALLBACK_SEM2_BASE_STR); SEMAPHORE_CLEANUP2(SEDNA_TRANSACTION_LOCK(i, buf, 1024), SEDNA_TRANSACTION_LOCK); } d_printf1("CLEANUP completed\n\n"); #endif }
void sm_ugc(bool background_off_from_background_on, int db_id, int os_primitives_bound) { #ifdef _WIN32 #else USemaphore sem; UShMem shm; UMMap map; UEvent ev; char buf[1024]; if (background_off_from_background_on) return; d_printf1("Starting CLEANUP\n"); SEMAPHORE_CLEANUP(CHARISMA_SM_WAIT_FOR_SHUTDOWN); SEMAPHORE_CLEANUP(VMM_SM_SEMAPHORE_STR); SEMAPHORE_CLEANUP(VMM_SM_EXCLUSIVE_MODE_SEM_STR); SEMAPHORE_CLEANUP(CATALOG_NAMETABLE_SEMAPHORE_STR); SEMAPHORE_CLEANUP(CATALOG_MASTER_SEMAPHORE_STR); // SEMAPHORE_CLEANUP(METADATA_SEMAPHORE_STR); // SEMAPHORE_CLEANUP(INDEX_SEMAPHORE_STR); #ifdef SE_ENABLE_FTSEARCH //SEMAPHORE_CLEANUP(FT_INDEX_SEMAPHORE_STR); #endif #ifdef SE_ENABLE_TRIGGERS //SEMAPHORE_CLEANUP(TRIGGER_SEMAPHORE_STR); #endif SHAREDMEM_CLEANUP(CHARISMA_SM_CALLBACK_SHARED_MEMORY_NAME, 8); SHAREDMEM_CLEANUP(CHARISMA_LOGICAL_LOG_SHARED_MEM_NAME, 0/*CHARISMA_LOGICAL_LOG_SHARED_MEM_SIZE*/); SHAREDMEM_CLEANUP(SEDNA_LFS_SHARED_MEM_NAME, 0); //SEMAPHORE_CLEANUP(CHARISMA_CHECKPOINT_SEM); SEMAPHORE_CLEANUP(SEDNA_TRNS_FINISHED); SEMAPHORE_CLEANUP(CHARISMA_LOGICAL_LOG_PROTECTION_SEM_NAME); SEMAPHORE_CLEANUP(CHARISMA_DB_RECOVERED_BY_LOGICAL_LOG); //SEMAPHORE_CLEANUP(CHARISMA_WAIT_FOR_CHECKPOINT); SEMAPHORE_CLEANUP(SEDNA_CHECKPOINT_FINISHED_SEM); SEMAPHORE_CLEANUP(SEDNA_LOCK_MANAGER_SEM); SEMAPHORE_CLEANUP(SEDNA_LFS_SEM_NAME); EVENT_CLEANUP(SNAPSHOT_CHECKPOINT_EVENT); EVENT_CLEANUP(TRY_ADVANCE_SNAPSHOT_EVENT); SHAREDMEM_CLEANUP(CHARISMA_LRU_STAMP_SHARED_MEMORY_NAME, 8); SEMAPHORE_CLEANUP(CHARISMA_SYNC_TRN_IDS_TABLE); //SEMAPHORE_CLEANUP(CHARISMA_SM_SMSD_ID); SEMAPHORE_CLEANUP(CHARISMA_SM_IS_READY); SSMMsg::ipc_cleanup(CHARISMA_SSMMSG_SM_ID(db_id, buf, 1024)); FILE_MAPPING_CLEANUP(CHARISMA_BUFFER_SHARED_MEMORY_NAME); d_printf1("CLEANUP completed\n\n"); // std::string buf_dir = SEDNA_DATA + std::string("/data/") + db_name + std::string("_files/buf"); #endif }
void nid_print(xptr node) { t_nid the_nid = nid_get_nid(node); t_prefix p = nid_get_prefix(the_nid); d_printf1("("); for (int i=0; i<p.size; i++) d_printf2("%d=",(int)(unsigned char)p.prefix[i]); d_printf1(")"); nid_free(p.prefix); }
U_THREAD_PROC(pping_server_cli_thread_proc, arg) { if (uThreadBlockAllSignals(NULL) != 0) d_printf1("Failed to block signals for SSMMsg_server_proc"); pping_server *pps = ((pping_serv_arg*)arg)->pps; USOCKET sock = ((pping_serv_arg*)arg)->sock; int component = ((pping_serv_arg*)arg)->pps->component; delete ((pping_serv_arg*)arg); char c = PPING_DISCONNECT_MSG; while (true) { if (urecv(sock, &c, sizeof(c), NULL) != sizeof(c)) goto sys_failure; if (c == PPING_DISCONNECT_MSG) break; #if (defined(EL_DEBUG) && (EL_DEBUG == 1)) if (c == PPING_PROC_EXCEPTION_MSG) { if (client_exception_handler(sock, pps) != 1) return 0; continue; } #endif if (c != PPING_KEEP_ALIVE_MSG) goto sys_failure; } //d_printf1("pping_server's client is closed\n"); if (uclose_socket(sock, NULL) == U_SOCKET_ERROR) goto sys_failure; return 0; sys_failure: sedna_soft_fault("One of SEDNA processes is down", component); return 0; }
int USemaphoreCreate(USemaphore *sem, int init_value, int max_value, global_name name, USECURITY_ATTRIBUTES* sa, sys_call_error_fun fun) #ifdef _WIN32 { char buf[128]; const char *wName = UWinIPCNameFromGlobalName(name,buf,128); *sem = CreateSemaphore(sa, init_value, max_value, wName); if (*sem == NULL) { sys_call_error("CreateSemaphore"); return 1; } else { if (GetLastError() == ERROR_ALREADY_EXISTS) { d_printf1("CreateSemaphore: already exists\n"); return 1; } } return 0; }
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; }
/* Single threaded version of pping server. * Uses select() to create connections and serve * previously created as well. * * TODO: read all buffer at once * TODO: better failures diagnostric * TODO: place accept+uNotInherit into a critical section to prevent * descriptors inheritance on fork * */ U_THREAD_PROC(pping_server_lstn_thread_proc_st, arg) { if (uThreadBlockAllSignals(NULL) != 0) d_printf1("Failed to block signals for pping server thread."); U_SSET allset, rset; pping_server *pps = (pping_server*)arg; int res; char c = PPING_DISCONNECT_MSG; bool maxfd_valid = true; USOCKET client_sock, maxfd, i; U_SSET_ZERO(&allset); U_SSET_SET(pps->sock, &allset); maxfd = pps->sock + 1; while (true) { rset = allset; res = uselect_read_arr(&rset, maxfd, NULL, NULL); if (res == U_SOCKET_ERROR) { SYS_FAILURE_SERVER("Failure in pping server (select() call failed)."); } /* Iterate through ready to read client descriptors */ for (i = 0; i < maxfd; i++) { if(U_SSET_ISSET(i, &rset) && i != pps->sock) { res = urecv(i, &c, sizeof(c), NULL); if( res != sizeof(c) ) { SYS_FAILURE_SERVER("Failure in pping server (recv() call failed, one of the clients may be down)."); } if (c == PPING_DISCONNECT_MSG) { U_SSET_CLR(i, &allset); if(uclose_socket(i, NULL) == U_SOCKET_ERROR) SYS_FAILURE_SERVER("Failure in pping server (cannot close a socket descriptor on disconnect)."); if ( maxfd-1 == i ) maxfd_valid = false; } #if (defined(EL_DEBUG) && (EL_DEBUG == 1)) else if (c == PPING_PROC_EXCEPTION_MSG) { if (client_exception_handler(i, pps) != 1) return 0; } #endif else if (c != PPING_KEEP_ALIVE_MSG) SYS_FAILURE_SERVER("Failure in pping server (unexpected message from client)."); } } /* Renew maximum descriptor number */ if( !maxfd_valid ) { for (i = maxfd-1; i >= 0; i--) { if(U_SSET_ISSET(i, &allset)) { maxfd = i + 1; maxfd_valid = true; break; } } } /* Create a new connection */ if (U_SSET_ISSET(pps->sock, &rset)) { client_sock = uaccept(pps->sock, NULL); if(client_sock == U_INVALID_SOCKET) SYS_FAILURE_SERVER("Failure in pping server (accept() call failed)."); U_SSET_SET(client_sock, &allset); if (client_sock > maxfd-1) { maxfd = client_sock + 1; } /* Check if governor wants to shutdown us */ if (pps->close_lstn_thread) { for (i = 0; i < maxfd; i++) { if(U_SSET_ISSET(i, &allset) && i != pps->sock && uclose_socket(i, NULL) == U_SOCKET_ERROR) SYS_FAILURE_SERVER("Failure in pping server (cannot close a socket descriptor)."); } break; } /* Make the client descriptor unheritable */ if (uNotInheritDescriptor(UHANDLE(client_sock), NULL) != 0) SYS_FAILURE_SERVER("Failure in pping server (cannot make a socket descriptor unheritable)."); } } return 0; }