Added some more error handling into MongoDB Logstream

This commit is contained in:
Andre Lorbach 2012-05-07 15:27:26 +02:00
parent 791ac1901a
commit 27d65d30ab
2 changed files with 53 additions and 26 deletions

View File

@ -1558,9 +1558,22 @@ class LogStreamMongoDB extends LogStream {
if ( ($res = $this->CreateQueryArray($uID)) != SUCCESS )
return $res;
// Append LIMIT clause
// $szSql .= " LIMIT " . $this->_currentRecordStart . ", " . $this->_logStreamConfigObj->RecordsPerQuery;
$myCursor = $this->_myMongoCollection->find($this->_myMongoQuery, $this->_myMongoFields); // ->limit(10); // $collection->find();
try
{
// Debug Informations
OutputDebugMessage("LogStreamMongoDB|ReadNextRecordsFromDB: Running FIND ", DEBUG_ULTRADEBUG);
// Find Data in MongoCollection
$myCursor = $this->_myMongoCollection->find($this->_myMongoQuery, $this->_myMongoFields);
}
catch ( MongoCursorException $e )
{
// Log error!
$this->PrintDebugError("ReadNextRecordsFromDB failed with error ' " . $e->getMessage() . " '");
// Return error code
return ERROR_DB_QUERYFAILED;
}
// Uncomment for debug!
// OutputDebugMessage("LogStreamMongoDB|ReadNextRecordsFromDB: myCursor->info() = <pre>" . var_export($myCursor->info(), true) . "</pre>", DEBUG_ULTRADEBUG);
@ -1571,12 +1584,15 @@ class LogStreamMongoDB extends LogStream {
// OutputDebugMessage("Cursor verbose: " . var_export($myCursor->explain(), true), DEBUG_DEBUG);
$myCursor = $myCursor->sort(array("_id" => -1));
try
{
// Copy rows into the buffer!
$iBegin = $this->_currentRecordNum;
$mongoidprev = -1;
foreach ($myCursor as $mongoid => $myRow)
{
// echo $this->convBaseHelper($mongoid, '0123456789abcdef', '0123456789') . "-" . $mongoid . "<br>";
// echo $this->convBaseHelper($mongoid, '0123456789abcdef', '0123456789') . "-" . $mongoid . "<br>";
// Check if result was successfull! Compare the queried uID and the MONGOID to abort processing if the same ID was returned! Otherwise we have dupplicated results at the end
if ( $myRow === FALSE || !$myRow )
@ -1599,6 +1615,15 @@ class LogStreamMongoDB extends LogStream {
$this->bufferedRecords[$iBegin] = array_change_key_case( $myRow, CASE_LOWER);
$iBegin++;
}
}
catch ( MongoCursorTimeoutException $e )
{
// Log error!
$this->PrintDebugError("ReadNextRecordsFromDB Timeout while operation ' " . $e->getMessage() . " '");
// Return error code
return ERROR_DB_TIMEOUTFAILED;
}
// Uncomment for debug!
// OutputDebugMessage("LogStreamMongoDB|ReadNextRecordsFromDB: bufferedRecords = Array <pre>" . var_export($this->bufferedRecords, true) . "</pre>", DEBUG_ULTRADEBUG);

View File

@ -78,5 +78,7 @@ define('ERROR_DB_TRIGGERFAILED', 29);
define('ERROR_DB_CHECKSUMERROR', 30);
define('ERROR_DB_CHECKSUMCHANGEFAILED', 31);
define('ERROR_DB_ADDDBFIELDFAILED', 32);
define('ERROR_DB_TIMEOUTFAILED', 33);
?>