Commit d8b85095 authored by Pavel Vainerman's avatar Pavel Vainerman

(PGSQL): fix SIGSEGV in flushInsertBuffer()

parent 217d9a34
...@@ -212,12 +212,9 @@ void DBServer_PostgreSQL::flushBuffer() ...@@ -212,12 +212,9 @@ void DBServer_PostgreSQL::flushBuffer()
//-------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------
void DBServer_PostgreSQL::flushInsertBuffer() void DBServer_PostgreSQL::flushInsertBuffer()
{ {
if( !db || !connect_ok ) if( ibufSize > ibufMaxSize )
{ {
if( ibufSize < ibufMaxSize ) dbcrit << myname << "(flushWriteBuffer): "
return;
dbcrit << myname << "(flushWriteBuffer): DB not connected!"
<< " buffer[" << ibufSize << "] overflow! LOST DATA..." << endl; << " buffer[" << ibufSize << "] overflow! LOST DATA..." << endl;
// Чистим заданное число // Чистим заданное число
...@@ -228,26 +225,29 @@ void DBServer_PostgreSQL::flushInsertBuffer() ...@@ -228,26 +225,29 @@ void DBServer_PostgreSQL::flushInsertBuffer()
// Удаляем последние (новые) // Удаляем последние (новые)
if( lastRemove ) if( lastRemove )
{ {
std::advance(beg, -delnum); end = std::prev(end, delnum);
} }
else else
{ {
// Удаляем первые (старые) // Удаляем первые (старые)
std::advance(end, delnum); beg = std::next(beg, delnum);
} }
if( beg != ibuf.end() )
ibuf.erase(beg, end); ibuf.erase(beg, end);
// ibufSize - беззнаковое, так что надо аккуратно // ibufSize - беззнаковое, так что надо аккуратно
ibufSize = (delnum < ibufSize) ? (ibufSize - delnum) : 0; ibufSize = (delnum < ibufSize) ? (ibufSize - delnum) : 0;
dbwarn << myname << "(flushInsertBuffer): overflow: clear data " << delnum << " records." << endl; dbwarn << myname << "(flushInsertBuffer): overflow: clear data " << delnum << " records." << endl;
return;
} }
if( ibufSize == 0 ) if( ibufSize == 0 )
return; return;
if( !db || !connect_ok )
return;
dbinfo << myname << "(flushInsertBuffer): write insert buffer[" << ibufSize << "] to DB.." << endl; dbinfo << myname << "(flushInsertBuffer): write insert buffer[" << ibufSize << "] to DB.." << endl;
if( !writeInsertBufferToDB("main_history", tblcols, ibuf) ) if( !writeInsertBufferToDB("main_history", tblcols, ibuf) )
......
...@@ -3,5 +3,5 @@ ...@@ -3,5 +3,5 @@
ulimit -Sc 1000000 ulimit -Sc 1000000
uniset2-start.sh -f ./uniset2-pgsql-dbserver --confile test.xml --name DBServer1 \ uniset2-start.sh -f ./uniset2-pgsql-dbserver --confile test.xml --name DBServer1 \
--pgsql-dbserver-buffer-size 100 \ --pgsql-buffer-size 100 \
--pgsql-log-add-levels any $* --pgsql-log-add-levels any $*
...@@ -1815,7 +1815,7 @@ namespace uniset ...@@ -1815,7 +1815,7 @@ namespace uniset
i++; i++;
} }
std::advance(it, sub); std::next(it, sub);
regID += sub; regID += sub;
} }
else else
......
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