Commit 6dff7fc9 authored by Pavel Vainerman's avatar Pavel Vainerman

(LogDB): исправил ошибку с некорректным завершением процесса

parent 6dd29f3d
......@@ -46,7 +46,10 @@ SQLiteInterface::~SQLiteInterface()
}
catch( ... ) // пропускаем все необработанные исключения, если требуется обработать нужно вызывать close() до деструктора
{
cerr << "MySQLInterface::~MySQLInterface(): an error occured while closing connection!" << endl;
std::exception_ptr p = std::current_exception();
cerr << "(SQLiteInterface::~SQLiteInterface): "
<< (p ? p.__cxa_exception_type()->name() : "an error occured while closing connection!")
<< std::endl;
}
}
......
......@@ -110,6 +110,9 @@ LogDB::LogDB( const string& name, int argc, const char* const* argv, const strin
flushBufferTimer.set<LogDB, &LogDB::onCheckBuffer>(this);
wsactivate.set<LogDB, &LogDB::onActivate>(this);
sigTERM.set<LogDB, &LogDB::onTerminate>(this);
sigQUIT.set<LogDB, &LogDB::onTerminate>(this);
sigINT.set<LogDB, &LogDB::onTerminate>(this);
bool dbDisabled = ( uniset::findArgParam("--" + prefix + "db-disable", argc, argv) != -1 );
......@@ -225,7 +228,7 @@ LogDB::LogDB( const string& name, int argc, const char* const* argv, const strin
httpParams->setMaxQueued(maxQ);
httpParams->setMaxThreads(maxT);
httpserv = std::make_shared<Poco::Net::HTTPServer>(this, Poco::Net::ServerSocket(sa), httpParams );
httpserv = std::make_shared<Poco::Net::HTTPServer>(new LogDBRequestHandlerFactory(this), Poco::Net::ServerSocket(sa), httpParams );
}
catch( std::exception& ex )
{
......@@ -249,6 +252,49 @@ LogDB::~LogDB()
db->close();
}
//--------------------------------------------------------------------------------------------
void LogDB::onTerminate( ev::sig& evsig, int revents )
{
if( EV_ERROR & revents )
{
dbcrit << myname << "(onTerminate): invalid event" << endl;
return;
}
dbinfo << myname << "(onTerminate): terminate..." << endl;
try
{
flushBuffer();
}
catch( std::exception& ex )
{
dbinfo << myname << "(onTerminate): " << ex.what() << endl;
}
evsig.stop();
//evsig.loop.break_loop();
try
{
httpserv->stop();
}
catch( std::exception& ex )
{
dbinfo << myname << "(onTerminate): " << ex.what() << endl;
}
try
{
evstop();
}
catch( std::exception& ex )
{
dbinfo << myname << "(onTerminate): " << ex.what() << endl;
}
}
//--------------------------------------------------------------------------------------------
void LogDB::flushBuffer()
{
if( !db || qbuf.empty() || !db->isConnection() )
......@@ -428,6 +474,13 @@ void LogDB::evprepare()
for( const auto& s : logservers )
s->set(loop);
sigTERM.set(loop);
sigTERM.start(SIGTERM);
sigQUIT.set(loop);
sigQUIT.start(SIGQUIT);
sigINT.set(loop);
sigINT.start(SIGINT);
}
// -----------------------------------------------------------------------------
void LogDB::onCheckBuffer(ev::timer& t, int revents)
......@@ -716,12 +769,12 @@ class LogDBWebSocketRequestHandler:
LogDB* logdb;
};
// -----------------------------------------------------------------------------
Poco::Net::HTTPRequestHandler* LogDB::createRequestHandler( const Poco::Net::HTTPServerRequest& req )
Poco::Net::HTTPRequestHandler* LogDB::LogDBRequestHandlerFactory::createRequestHandler( const Poco::Net::HTTPServerRequest& req )
{
if( req.find("Upgrade") != req.end() && Poco::icompare(req["Upgrade"], "websocket") == 0 )
return new LogDBWebSocketRequestHandler(this);
return new LogDBWebSocketRequestHandler(logdb);
return new LogDBRequestHandler(this);
return new LogDBRequestHandler(logdb);
}
// -----------------------------------------------------------------------------
void LogDB::handleRequest( Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPServerResponse& resp )
......
......@@ -120,7 +120,7 @@ namespace uniset
\section sec_LogDB_WEBSOCK LogDB Поддержка web socket
В LogDB встроена возможность просмотра логов в реальном времени, через websocket.
Список доступных для подключения лог-серверов доступен по адресу:
Список лог-серверов доступен по адресу:
\code
ws://host:port/logdb/ws/
\endcode
......@@ -171,7 +171,6 @@ namespace uniset
public EventLoopServer
#ifndef DISABLE_REST_API
, public Poco::Net::HTTPRequestHandler
, public Poco::Net::HTTPRequestHandlerFactory
#endif
{
public:
......@@ -191,7 +190,6 @@ namespace uniset
void run( bool async );
#ifndef DISABLE_REST_API
Poco::Net::HTTPRequestHandler* createRequestHandler( const Poco::Net::HTTPServerRequest& req );
virtual void handleRequest( Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPServerResponse& resp ) override;
void onWebSocketSession( Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPServerResponse& resp );
#endif
......@@ -251,6 +249,11 @@ namespace uniset
size_t maxdbRecords = { 200 * 1000 };
size_t numOverflow = { 0 }; // вычисляется из параметра "overflow factor"(float)
ev::sig sigTERM;
ev::sig sigQUIT;
ev::sig sigINT;
void onTerminate( ev::sig& evsig , int revents );
ev::async wsactivate; // активация LogWebSocket-ов
class Log
......@@ -391,6 +394,20 @@ namespace uniset
std::list<std::shared_ptr<LogWebSocket>> wsocks;
uniset::uniset_rwmutex wsocksMutex;
size_t maxwsocks = { 50 }; // максимальное количество websocket-ов
class LogDBRequestHandlerFactory:
public Poco::Net::HTTPRequestHandlerFactory
{
public:
LogDBRequestHandlerFactory( LogDB* l ): logdb(l) {}
virtual ~LogDBRequestHandlerFactory() {};
virtual Poco::Net::HTTPRequestHandler* createRequestHandler( const Poco::Net::HTTPServerRequest& req ) override;
private:
LogDB* logdb;
};
#endif
private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment