bool DBcore::DoQuery_locked(DBerror &err, const char *query, int32 querylen, bool retry) { if (pStatus != Connected) Open_locked(); if (mysql_real_query(&mysql, query, querylen)) { int num = mysql_errno(&mysql); if (num == CR_SERVER_GONE_ERROR) pStatus = Error; if (retry && (num == CR_SERVER_LOST || num == CR_SERVER_GONE_ERROR)) { sLog.Error("DBCore", "Lost connection, attempting to recover...."); return DoQuery_locked(err, query, querylen, false); } pStatus = Error; err.SetError(num, mysql_error(&mysql)); sLog.Error("DBCore Query", "#%d in '%s': %s", err.GetErrNo(), query, err.c_str()); return false; } err.ClearError(); return true; }
SignalingFileReservation FileReferenceImpl::GetReservation() { // run when pool.mutex is NOT locked khLockGuard lock(pool.mutex); // see if somebody elase already closed my file and left me an error to // deal with if (closeError) { assert(!reservation); errno = closeError; closeError = 0; throw khSimpleErrnoException("Error closing ") << fname; } while (1) { if (operationPending) { // Another thread is opening or closing this file // wait until something changes and try again pool.WaitForChanges_locked(); continue; } // If I already have a reservation , just return it if (reservation) { return SignalingFileReservation(pool, reservation); } // Mark myself as being in the middle of the open (makes others wait) // This is beacause the "steal" operation below will cause me to // temporarily release the lock ChangingGuard changeGuard(this); while (pool.AllReservationsInUse_locked()) { FileReference closeFile; if (!pool.FindOldestUnusedReservation_locked(&closeFile)) { // All the reservations are busy and I'm not allowed to steal one // wait until something changes and try again pool.WaitForChanges_locked(); continue; } // Close the reservation closeFile->ReleaseReservation_locked(); } reservation = khRefGuardFromNew(new FileReservationImpl()); // Basic check since this was broken in geFilePool implementation. if (pool.numFdsUsed >= pool.maxNumFds) { throw khSimpleException( "FileReferenceImpl::GetReservation: too many files open: ") << "numFdsUsed: " << pool.numFdsUsed << " maxNumFds:" << pool.maxNumFds; } // Now open the file with my new reservation // Will temporarily release lock Open_locked(); return SignalingFileReservation(pool, reservation); } }
bool DBcore::Open(const char* iHost, const char* iUser, const char* iPassword, const char* iDatabase, int16 iPort, int32* errnum, char* errbuf, bool iCompress, bool iSSL) { MutexLock lock(MDatabase); pHost = iHost; pUser = iUser; pPassword = iPassword; pDatabase = iDatabase; pCompress = iCompress; pPort = iPort; pSSL = iSSL; return Open_locked(errnum, errbuf); }
bool DBcore::Open(DBerror &err, const char* iHost, const char* iUser, const char* iPassword, const char* iDatabase, int16 iPort, bool iCompress, bool iSSL) { MutexLock lock(MDatabase); pHost = iHost; pUser = iUser; pPassword = iPassword; pDatabase = iDatabase; pCompress = iCompress; pPort = iPort; pSSL = iSSL; int32 errnum; char errbuf[1024]; if(!Open_locked(&errnum, errbuf)) { err.SetError(errnum, errbuf); return false; } return true; }