void praid_entry_startEntrypointListening(){ if(commons_console_logging_isDefault()) puts("[ Proceso RAID en escucha ]"); ServerSocket * serverSocket = commons_socket_openServerConnection(praid_configuration_getDevicePort()); while (TRUE){ ListenSocket listenSocket = commons_socket_acceptConnection(serverSocket); NipcMessage handshake = nipc_receiveHandshake(listenSocket ); if(handshake.header.messageType == NIPC_MESSAGE_TYPE_HANDSHAKE){ /* * Si la replicacion no esta en proceso se aceptan conecciones de nuevos ppds * de lo contrario las mismas son denegadas para no generar inconsistencias * */ if(handshake.header.processHandshakeId == NIPC_PROCESS_ID_PPD && praid_sync_isReplicationActive()){ if(commons_console_logging_isDefault()) puts("[ Se denega la conexion del proceso PPD para mantener la consistencia en la replicacion en curso ]"); log_info_t("Se denega la conexion del proceso PPD para mantener la consistencia en la replicacion en curso"); praid_entry_denegateConnection(handshake.header.processHandshakeId , listenSocket); continue; }else if (handshake.header.processHandshakeId == NIPC_PROCESS_ID_PFS && !praid_state_isThereAnyPpdConnected()){ if(commons_console_logging_isDefault()) puts("[ Se denega la conexion del proceso PFS por ausencia de recursos PPD's conectados ]"); log_info_t("Se denega la conexion del proceso PFS por ausencia de recursos PPD's conectados"); praid_entry_denegateConnection(handshake.header.processHandshakeId , listenSocket); continue; }else{ nipc_sendHandshake(listenSocket , handshake.header.processHandshakeId ); if(handshake.header.processHandshakeId == NIPC_PROCESS_ID_PFS){ praid_pfs_launchNewSlaveThread(listenSocket); }else if(handshake.header.processHandshakeId == NIPC_PROCESS_ID_PPD){ praid_entry_processNewPpdConnection(handshake , listenSocket); } } } } }
void praid_entry_processNewPpdConnection(NipcMessage message , ListenSocket listenSocket){ uint8_t ppdId = message.header.operationId; PPDConnectionStorage * destiny = praid_state_buildPPDConnectionStorageFromId( listenSocket , ppdId , message.header.responseCode); PPDConnectionStorage * master = praid_balancer_selectStorage(); praid_state_addPpdStorage(destiny); praid_utils_printLines(); if(commons_console_logging_isDefault()){ printf("[ Nuevo PPD en el cluster con Id: %i ]\n" , ppdId); } log_info_t( commons_string_concat("Nuevo PPD en el cluster con ID: " , commons_misc_intToString(ppdId))); praid_utils_printClusterInformation(ppdId); if(praid_ppd_sync_isValidReplication()) { if(commons_console_logging_isDefault()){ puts("[ Comenzando la replicación de datos ]"); printf("[ Volumen a replicar: %.3f MiB ]\n" , (float)((float) master->volumeSize /(1024*1024))); } log_info_t("Comenzando la replicación de datos "); sleep(3); if(commons_console_logging_isDefault()){ puts("[ Replicación en proceso .... ]"); } log_info_t("Replicacion en proceso...."); praid_ppd_sync_fireSynchronization(master , destiny); praid_utils_printLines(); } else { if(commons_console_logging_isDefault()) puts("[ No se realiza replicación de datos ]"); praid_endpoint_ppd_callProcessJobs(destiny->connection); } praid_ppd_thread_launchNewSlaveThread(destiny); }
void praid_ppd_processDisconnection(PPDConnectionStorage * storage){ commons_misc_lockThreadMutex(&storage->disconnectionMutex); if(commons_console_logging_isDefault()){ printf("[ Se ha desconectado el PPD %i ]\n" , storage->id); } log_info_t( commons_string_concat("Se ha desconectado el PPD " , commons_misc_intToString(storage->id))); praid_ppd_checkIfContinueDenegatingRequests(storage->id); Queue readingJobs = praid_utils_getReadingJobs(storage); if(readingJobs->size > 0){ printf("[ %i trabajos de lectura huerfanos tras la caida del PPD-%i ]\n" , readingJobs->size , storage->id); if(commons_console_logging_isAll()) praid_utils_printPendingJobs(readingJobs); praid_state_removePddStorage(storage); praid_balancer_redistributeJobs(readingJobs); }else{ praid_state_removePddStorage(storage); } praid_utils_printClusterInformation(); commons_misc_unlockThreadMutex(&storage->disconnectionMutex); //puts("finaliza el listener del ppd muerto"); }
/*------------------------------------------------------------------------------ | main +-----------------------------------------------------------------------------*/ int main(int argc, char** argv) { #if defined(QT_QML_LIB) && defined(QT_QUICK_LIB) QGuiApplication a(argc, argv); #endif #if 0 QElapsedTimer timer; timer.start(); // Test with lc_logging. for (int i = 0; i < 100000; i++) log_verbose("Test: %d.", i); qDebug("Result lc_logging: %lld.", timer.elapsed()); // Test with printf. timer.restart(); for (int i = 0; i < 100000; i++) { fprintf(stdout, "- DEBUG:%s: Test: %d.\n", lc_current_time().c_str(), i); fflush(stdout); } qDebug("Result printf: %lld.", timer.elapsed()); // Test with qDebug. timer.restart(); for (int i = 0; i < 100000; i++) { qDebug("- DEBUG:%s: Test: %d.\n", lc_current_time().c_str(), i); fflush(stderr); } qDebug("Result qDebug: %lld.", timer.elapsed()); #endif #ifdef __GNUC__ LOG_CRITICAL("MyTag", "Oooops!"); #endif log_info("Info log."); log_info_t("MyTag", "Info log."); test_args("Testing %d va_args functions.", 2); log_debug("Some message for debugging..."); log_disabled("A disabled log!!!!!!!!!!! You won't see this."); log_critical("Print int: %d.", 5); log_critical_t("MyTag", "Print int: %d.", 5); log_critical_t("MyTag", "Print with tag only."); /*lc_formatted_printf(stdout, LC_LOG_ATTR_UNDERLINE, LC_LOG_COL_MAGENTA, "Underlined %s! ;-)\n", "magenta");*/ log_formatted(LC_LOG_ATTR_UNDERLINE, LC_LOG_COL_YELLOW, "Formatted text."); log_formatted(LC_LOG_COL_YELLOW, "Formatted text with %s.", "param"); #ifndef __ANDROID__ test_func(); #endif // Using streams. { LC_LogDef logger(NULL, LC_LOG_ATTR_RESET, LC_LOG_COL_BLUE); logger.stream() << "Blue log using stream. " << "Params can be added like " << 1234 << "."; LC_LogDef l(NULL); Q_UNUSED(l); } { LC_Log<LC_Output2Std> logger(LC_LOG_DEBUG); logger.stream() << "Debug log with stream."; } { LC_Log<LC_Output2Std> logger(LC_LOG_WARN); logger.stream() << "Warning log with stream."; } { LC_Log<LC_Output2Std> logger(LC_LOG_CRITICAL); logger.stream() << "Critical log with stream."; } #if defined(QT_QML_LIB) && defined(QT_QUICK_LIB) QQuickView view; LC_QMLLogger::registerObject(view.rootContext()); view.setSource(QUrl("qrc:///main.qml")); #endif assert(log_verbose("") == true); assert(log_info("") == true); assert(log_warn("") == false); assert(log_err("") == false); assert(log_critical("") == false); return 0; }