Commit bb525a81 authored by Frederic Logier's avatar Frederic Logier
Browse files

use mongo::ReplicaSetMonitor::remove instead of mongo::dbexit

parent 60bad724
......@@ -26,6 +26,7 @@ Mongodb *Mongodb::_singleton = NULL;
Mongodb::~Mongodb()
{
qDebug() << "Mongodb connection shutdown";
mongo::dbexit(mongo::EXIT_CLEAN);
}
......@@ -110,6 +111,7 @@ Mongodb::Mongodb(QString a_server, QString a_database) : m_server(a_server), m_d
//m_mongo_connection.runCommand(database, database_options, info);
replicaset.conn().runCommand(database, database_options, info);
replicaset.done();
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
std::cout << "MONGODB OPTIONS : " << info << std::endl;
/************************************/
......@@ -248,7 +250,7 @@ int Mongodb::Count(QString a_document)
int counter = replicaset.conn().count(tmp.toStdString());
replicaset.done();
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return counter;
}
......@@ -285,7 +287,7 @@ void Mongodb::Flush(string a_document, BSONObj query)
std::cout << "caught on remove into " << m_server.toAscii().data() << "." << a_document.data() << " : " << e.what() << std::endl;
}
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
}
BSONObj Mongodb::Find(string a_document, const bo a_query)
......@@ -323,14 +325,14 @@ BSONObj Mongodb::Find(string a_document, const bo a_query)
if ( !cursor->more() ) {
replicaset.done();
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return BSONObj();
}
else
{
BSONObj data = cursor->nextSafe().copy();
replicaset.done();
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return data;
}
}
......@@ -341,7 +343,7 @@ BSONObj Mongodb::Find(string a_document, const bo a_query)
std::cout << "caught on find into " << m_server.toAscii().data() << "." << a_document.data() << " : " << e.what() << std::endl;
exit(1);
}
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return BSONObj();
}
......@@ -376,14 +378,14 @@ BSONObj Mongodb::Find(string a_document, const BSONObj a_query, BSONObj *a_field
if ( !cursor->more() ) {
replicaset.done();
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return BSONObj();
}
else
{
BSONObj data = cursor->nextSafe().copy();
replicaset.done();
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return data;
}
}
......@@ -392,7 +394,7 @@ BSONObj Mongodb::Find(string a_document, const BSONObj a_query, BSONObj *a_field
std::cout << "caught on find into " << m_server.toAscii().data() << "." << a_document.data() << " : " << e.what() << std::endl;
exit(1);
}
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return BSONObj();
}
......@@ -427,16 +429,16 @@ QList <BSONObj> Mongodb::FindAll(string a_document, const bo datas)
res << cursor->nextSafe().copy();
}
replicaset.done();
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return res;
}
}
catch(mongo::DBException &e ) {
std::cout << "caught on find into " << m_server.toAscii().data() << "." << a_document.data() << " : " << e.what() << std::endl;
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return res;
}
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return res;
}
......@@ -556,17 +558,17 @@ QBool Mongodb::ReadFile(const be &gfs_id, const mongo::GridFile **a_gf)
else break;
}
replicaset.done();
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return QBool(true);
}
}
catch(mongo::DBException &e ) {
std::cout << "caught on get file : " << e.what() << std::endl;
qDebug() << "Mongodb::ReadFile ERROR ON GRIDFS";
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return QBool(false);
}
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return QBool(false);
}
......@@ -593,7 +595,7 @@ int Mongodb::GetNumChunck(const be &gfs_id)
std::cout << "Mongodb::ExtractByChunck file not found" << std::endl;
replicaset.done();
delete(m_grid_file);
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return -1;
}
else
......@@ -604,7 +606,7 @@ int Mongodb::GetNumChunck(const be &gfs_id)
replicaset.done();
delete(m_grid_file);
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return num;
}
}
......@@ -612,10 +614,10 @@ int Mongodb::GetNumChunck(const be &gfs_id)
catch(mongo::DBException &e ) {
std::cout << "caught on get file : " << e.what() << std::endl;
qDebug() << "Mongodb::GetNumChunck ERROR ON GRIDFS";
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return -1;
}
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return -1;
}
......@@ -643,7 +645,7 @@ string Mongodb::GetFilename(const be &gfs_id)
std::cout << "Mongodb::GetFilename file not found" << std::endl;
replicaset.done();
delete(m_grid_file);
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return "";
}
else
......@@ -652,7 +654,7 @@ string Mongodb::GetFilename(const be &gfs_id)
std::cout << "Mongodb::GetFilename FILE NAME : " << filename << std::endl;
replicaset.done();
delete(m_grid_file);
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return filename;
}
}
......@@ -660,10 +662,10 @@ string Mongodb::GetFilename(const be &gfs_id)
catch(mongo::DBException &e ) {
std::cout << "caught on get file : " << e.what() << std::endl;
qDebug() << "Mongodb::GetFilename ERROR ON GRIDFS";
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return "";
}
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return "";
}
......@@ -694,7 +696,7 @@ BSONObj Mongodb::GetGfsid(const string filename)
std::cout << "Mongodb::GetGfsid file not found" << std::endl;
replicaset.done();
delete(m_grid_file);
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return gfsid_;
}
else
......@@ -705,7 +707,7 @@ BSONObj Mongodb::GetGfsid(const string filename)
std::cout << "Mongodb::GetGfsid2 : " << gfsid_ << std::endl;
replicaset.done();
delete(m_grid_file);
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return gfsid_;
}
}
......@@ -713,10 +715,10 @@ BSONObj Mongodb::GetGfsid(const string filename)
catch(mongo::DBException &e ) {
std::cout << "caught on get file : " << e.what() << std::endl;
qDebug() << "Mongodb::GetGfsid ERROR ON GRIDFS";
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return gfsid_;
}
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return gfsid_;
}
......@@ -779,7 +781,7 @@ QBool Mongodb::ExtractByChunck(const be &gfs_id, int chunk_index, QByteArray &ch
replicaset.done();
delete(m_grid_file);
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return QBool(true);
}
else
......@@ -788,13 +790,13 @@ QBool Mongodb::ExtractByChunck(const be &gfs_id, int chunk_index, QByteArray &ch
chunk_data.clear();
replicaset.done();
delete(m_grid_file);
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return QBool(false);
}
}
}
replicaset.done();
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return QBool(false);
}
......@@ -802,10 +804,10 @@ QBool Mongodb::ExtractByChunck(const be &gfs_id, int chunk_index, QByteArray &ch
catch(mongo::DBException &e ) {
std::cout << "caught on get file : " << e.what() << std::endl;
qDebug() << "Mongodb::ExtractByChunck ERROR ON GRIDFS";
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return QBool(false);
}
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return QBool(false);
}
......@@ -837,7 +839,7 @@ BSONObj Mongodb::WriteFile(const string filename, const char *data, int size)
std::cout << "caught on write file : " << e.what() << std::endl;
qDebug() << "Mongodb::WriteFile ERROR ON GRIDFS";
}
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return struct_file;
}
......@@ -861,7 +863,7 @@ QBool Mongodb::Insert(QString a_document, BSONObj a_datas)
{
replicaset.conn().insert(tmp.toAscii().data(), a_datas);
replicaset.done();
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return QBool(true);
}
qDebug() << m_server + "." + a_document + " inserted";
......@@ -871,7 +873,7 @@ QBool Mongodb::Insert(QString a_document, BSONObj a_datas)
std::cout << "caught on insert into " << m_server.toAscii().data() << "." << a_document.toAscii().data() << " : " << e.what() << std::endl;
//return QBool(false);
}
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return QBool(false);
}
......@@ -895,7 +897,7 @@ QBool Mongodb::Remove(QString a_document, BSONObj a_datas)
{
replicaset.conn().remove(tmp.toAscii().data(), a_datas);
replicaset.done();
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return QBool(true);
}
qDebug() << m_server + "." + a_document + " removed";
......@@ -905,7 +907,7 @@ QBool Mongodb::Remove(QString a_document, BSONObj a_datas)
std::cout << "caught on insert into " << m_server.toAscii().data() << "." << a_document.toAscii().data() << " : " << e.what() << std::endl;
//return QBool(false);
}
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return QBool(false);
}
......@@ -936,17 +938,17 @@ QBool Mongodb::Update(QString a_document, const BSONObj &element_id, const BSONO
{
replicaset.conn().update(tmp.toAscii().data(), mongo::Query(element_id), data, upsert ,multi);
replicaset.done();
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
qDebug() << m_server + "." + a_document + " updated";
return QBool(true);
}
}
catch(mongo::DBException &e ) {
std::cout << "caught on update into " << m_server.toAscii().data() << "." << a_document.toAscii().data() << " : " << e.what() << std::endl;
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return QBool(false);
}
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return QBool(false);
}
......@@ -977,17 +979,17 @@ QBool Mongodb::Update(QString a_document, const BSONObj &element_id, const BSONO
{
replicaset.conn().update(tmp.toAscii().data(), mongo::Query(element_id), data, upsert ,multi);
replicaset.done();
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
qDebug() << m_server + "." + a_document + " updated";
return QBool(true);
}
}
catch(mongo::DBException &e ) {
std::cout << "caught on update into " << m_server.toAscii().data() << "." << a_document.toAscii().data() << " : " << e.what() << std::endl;
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return QBool(false);
}
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return QBool(false);
}
......@@ -1013,17 +1015,17 @@ QBool Mongodb::Update_raw(mongo_query a_query)
{
replicaset.conn().update(db.toAscii().data(), a_query.query, a_query.data, true);
replicaset.done();
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
qDebug() << m_server + "." + a_query.document + " updated";
return QBool(true);
}
}
catch(mongo::DBException &e ) {
std::cout << "caught on update into " << db.toAscii().data() << " : " << e.what() << std::endl;
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return QBool(false);
}
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return QBool(false);
}
......@@ -1048,17 +1050,17 @@ QBool Mongodb::Addtoarray(QString a_document, const BSONObj &element_id, const B
{
replicaset.conn().update(tmp.toAscii().data(), mongo::Query(element_id), data);
replicaset.done();
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
qDebug() << m_server + "." + a_document + " updated";
return QBool(true);
}
}
catch(mongo::DBException &e ) {
std::cout << "caught on update into " << m_server.toAscii().data() << "." << a_document.toAscii().data() << " : " << e.what() << std::endl;
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return QBool(false);
}
mongo::dbexit(mongo::EXIT_CLEAN);
mongo::ReplicaSetMonitor::remove(m_server.toStdString(), true);
return QBool(false);
}
......
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