コード例 #1
0
WriteErrorDetail* BatchSafeWriter::lastErrorToBatchError( const LastError& lastError ) {

    bool isFailedOp = lastError.msg != "";
    bool isStaleOp = lastError.writebackId.isSet();
    dassert( !( isFailedOp && isStaleOp ) );

    if ( isFailedOp ) {
        WriteErrorDetail* batchError = new WriteErrorDetail;
        if ( lastError.code != 0 ) batchError->setErrCode( lastError.code );
        else batchError->setErrCode( ErrorCodes::UnknownError );
        batchError->setErrMessage( lastError.msg );
        return batchError;
    }
    else if ( isStaleOp ) {
        WriteErrorDetail* batchError = new WriteErrorDetail;
        batchError->setErrCode( ErrorCodes::StaleShardVersion );
        batchError->setErrInfo( BSON( "downconvert" << true ) ); // For debugging
        batchError->setErrMessage( "shard version was stale" );
        return batchError;
    }

    return NULL;
}