_omaTask* getTaskByType( OMA_TASK_TYPE taskType, INT64 taskID ) { _omaTask *pTask = NULL ; switch ( taskType ) { case OMA_TASK_ADD_HOST : pTask = SDB_OSS_NEW _omaAddHostTask( taskID ) ; break ; case OMA_TASK_ADD_HOST_SUB : pTask = SDB_OSS_NEW _omaAddHostSubTask( taskID ) ; break ; case OMA_TASK_INSTALL_DB : pTask = SDB_OSS_NEW _omaInstDBBusTask( taskID ) ; break ; case OMA_TASK_INSTALL_DB_SUB : pTask = SDB_OSS_NEW _omaInstDBBusSubTask( taskID ) ; break ; case OMA_TASK_REMOVE_DB : pTask= SDB_OSS_NEW _omaRemoveDBBusTask( taskID ) ; break ; default : PD_LOG_MSG( PDERROR, "Unknow task type[%d]", taskType ) ; break ; } if ( NULL == pTask ) { PD_LOG_MSG( PDERROR, "Failed to malloc for task with the type[%d]", taskType ) ; } return pTask ; }
_omaTask* getTaskByType( OMA_TASK_TYPE taskType, INT64 taskID ) { _omaTask *pTask = NULL ; switch ( taskType ) { // pTask will be free in _omagentJob::~_omagentJob() // when job is destroy // add host case OMA_TASK_ADD_HOST : pTask = SDB_OSS_NEW _omaAddHostTask( taskID ) ; break ; case OMA_TASK_ADD_HOST_SUB : pTask = SDB_OSS_NEW _omaAddHostSubTask( taskID ) ; break ; // remove host case OMA_TASK_REMOVE_HOST : pTask = SDB_OSS_NEW _omaRemoveHostTask( taskID ) ; break ; // install db business case OMA_TASK_INSTALL_DB : pTask = SDB_OSS_NEW _omaInstDBBusTask( taskID ) ; break ; case OMA_TASK_INSTALL_DB_SUB : pTask = SDB_OSS_NEW _omaInstDBBusSubTask( taskID ) ; break ; // remove db business case OMA_TASK_REMOVE_DB : pTask = SDB_OSS_NEW _omaRemoveDBBusTask( taskID ) ; break ; // add znode business case OMA_TASK_INSTALL_ZN : pTask = SDB_OSS_NEW _omaInstZNBusTask( taskID ) ; break ; case OMA_TASK_INSTALL_ZN_SUB : pTask = SDB_OSS_NEW _omaInstZNBusSubTask( taskID ) ; break ; // remove znode business case OMA_TASK_REMOVE_ZN : pTask = SDB_OSS_NEW _omaRemoveZNBusTask( taskID ) ; break ; // ssql exec case OMA_TASK_SSQL_EXEC : pTask = SDB_OSS_NEW _omaSsqlExecTask( taskID ) ; break; default : PD_LOG_MSG( PDERROR, "Unknow task type[%d]", taskType ) ; break ; } if ( NULL == pTask ) { PD_LOG_MSG( PDERROR, "Failed to malloc for task with the type[%d]", taskType ) ; } return pTask ; }
INT32 _omaAddHostSubTask::init( const BSONObj &info, void *ptr ) { INT32 rc = SDB_OK ; stringstream ss ; _pTask = (_omaAddHostTask *)ptr ; if ( NULL == _pTask ) { rc = SDB_INVALIDARG ; PD_LOG_MSG( PDERROR, "No add host task's info for " "add host sub task" ) ; goto error ; } ss << _taskName << "[" << _pTask->getSubTaskSerialNum() << "]" ; _taskName = ss.str() ; done: return rc ; error: goto done ; }
INT32 _qgmOptiNLJoin::_validate() { PD_TRACE_ENTRY( SDB__QGMOPTINLJOIN__VALIDATE ) ; SDB_ASSERT( 2 == _children.size(), "impossible" ) ; INT32 rc = SDB_OK ; _qgmOptiTreeNode *left = _children.at( 0 ) ; _qgmOptiTreeNode *right = _children.at( 1 ) ; if ( left->_alias == right->_alias ) { PD_LOG_MSG( PDERROR, "same alias:%s", left->_alias.toString().c_str() ) ; rc = SDB_INVALIDARG ; goto error ; } if ( NULL != _condition ) { qgmOpStream lstream, rstream ; vector<qgmDbAttr*> conditionFields ; vector<qgmDbAttr*>::iterator citr ; _qgmConditionNodeHelper cTree( _condition ) ; rc = cTree.getAllAttr( conditionFields ) ; if ( SDB_OK != rc ) { goto error ; } rc = left->outputStream( lstream ) ; if ( SDB_OK != rc ) { goto error ; } rc = right->outputStream( rstream ) ; if ( SDB_OK != rc ) { goto error ; } for ( citr = conditionFields.begin() ; citr != conditionFields.end() ; citr++ ) { if ( lstream.find( *(*citr) ) ) { continue ; } else if ( !rstream.find( *(*citr) ) ) { rc = SDB_INVALIDARG ; PD_LOG_MSG( PDERROR, "condition field[%s] not found in sub output.", (*citr)->toString().c_str() ) ; goto error ; } else { continue ; } } } done: PD_TRACE_EXITRC( SDB__QGMOPTINLJOIN__VALIDATE, rc ) ; return rc ; error: goto done ; }
INT32 _qgmOptiNLJoin::_makeCondVar( qgmConditionNode * cond ) { PD_TRACE_ENTRY( SDB__QGMOPTINLJOIN__MAKECONDVAR ) ; INT32 rc = SDB_OK ; BOOLEAN existed = FALSE ; varItem item ; if ( cond->type == SQL_GRAMMAR::OR ) { PD_LOG_MSG( PDERROR, "Join condition not suport or" ) ; rc = SDB_SYS ; goto error ; } else if ( cond->type == SQL_GRAMMAR::NOT ) { PD_LOG_MSG( PDERROR, "Join condition not suport not" ) ; rc = SDB_SYS ; goto error ; } else if ( cond->type == SQL_GRAMMAR::AND ) { rc = _makeCondVar( cond->left ) ; if ( SDB_OK != rc ) { goto error ; } rc = _makeCondVar( cond->right ) ; if ( SDB_OK != rc ) { goto error ; } } else { if ( cond->left->value.relegation() == outer()->getAlias( TRUE ) ) { _qgmConditionNode *tmp = cond->left ; cond->left = cond->right ; cond->right = tmp ; if ( SQL_GRAMMAR::LT == cond->type ) { cond->type = SQL_GRAMMAR::GT ; } else if ( SQL_GRAMMAR::GT == cond->type ) { cond->type = SQL_GRAMMAR::LT ; } else if ( SQL_GRAMMAR::GTE == cond->type ) { cond->type = SQL_GRAMMAR::LTE ; } else if ( SQL_GRAMMAR::LTE == cond->type ) { cond->type = SQL_GRAMMAR::GTE ; } else { } } #ifdef _DEBUG if ( cond->right->type != SQL_GRAMMAR::DBATTR || cond->right->value.relegation() != outer()->getAlias( TRUE ) ) { PD_LOG_MSG( PDERROR, "Join condition[%s] invalid", qgmConditionNodeHelper(cond).toJson().c_str() ) ; rc = SDB_INVALIDARG ; goto error ; } #endif //_DEBUG item._fieldName = cond->right->value ; item._varName = cond->right->value ; item._varName.relegation() = _uniqueNameR ; rc = _param->addVar( item._varName, cond->right->var, &existed ) ; if ( SDB_OK != rc ) { PD_LOG( PDERROR, "Add var[%s, %s] failed, rc: %d", item._fieldName.toString().c_str(), item._varName.toString().c_str(), rc ) ; goto error ; } if ( !existed ) { _varList.push_back( item ) ; } if ( _hints.empty() ) { cond->right->type = SQL_GRAMMAR::SQLMAX + 1 ; } } done: PD_TRACE_EXITRC( SDB__QGMOPTINLJOIN__MAKECONDVAR, rc ) ; return rc ; error: goto done ; }
INT32 _qgmOptiNLJoin::_pushOprUnit( qgmOprUnit * oprUnit, PUSH_FROM from ) { PD_TRACE_ENTRY( SDB__QGMOPTINLJOIN__PUSHOPRUNIT ) ; INT32 rc = SDB_OK ; qgmFilterUnit *filterUnit = NULL ; qgmFilterUnit *outerUnit = NULL ; qgmFilterUnit *innerUnit = NULL ; if ( needMakeCondition() ) { rc = makeCondition() ; if ( SDB_OK != rc ) { PD_LOG( PDERROR, "Node[%s] make condition failed, rc: %d", toString().c_str(), rc ) ; goto error ; } } if ( QGM_OPTI_TYPE_SORT == oprUnit->getType() ) { oprUnit->setDispatchAlias( outer()->getAlias( TRUE ) ) ; oprUnit->resetNodeID() ; _oprUnits.insert( _oprUnits.begin(), oprUnit ) ; _hasPushSort = TRUE ; } else if ( QGM_OPTI_TYPE_FILTER == oprUnit->getType() ) { qgmConditionNodePtrVec conds ; qgmConditionNodePtrVec::iterator itCond ; BOOLEAN outerChange = FALSE ; BOOLEAN innerChange = FALSE ; outerUnit = SDB_OSS_NEW qgmFilterUnit( QGM_OPTI_TYPE_FILTER ) ; innerUnit = SDB_OSS_NEW qgmFilterUnit( QGM_OPTI_TYPE_FILTER ) ; if ( !outerUnit || !innerUnit ) { rc = SDB_OOM ; goto error ; } outerUnit->setOptional( TRUE ) ; innerUnit->setOptional( TRUE ) ; filterUnit = (qgmFilterUnit*)oprUnit ; qgmOPFieldVec *fields = filterUnit->getFields() ; for ( UINT32 index = 0 ; index < fields->size() ; index++ ) { qgmOpField &field = (*fields)[index] ; if ( field.value.relegation() == outer()->getAlias( TRUE ) ) { outerUnit->addOpField( field ) ; outerChange = TRUE ; } else if ( field.value.relegation() == inner()->getAlias( TRUE ) ) { innerUnit->addOpField( field ) ; innerChange = TRUE ; } else { PD_LOG_MSG( PDERROR, "oprUnit[%s] field[%s] is not in outer[%s] or " "inner[%s]", oprUnit->toString().c_str(), field.toString().c_str(), outer()->getAlias( TRUE ).toString().c_str(), inner()->getAlias( TRUE ).toString().c_str() ) ; rc = SDB_INVALIDARG ; goto error ; } } conds = filterUnit->getConditions() ; itCond = conds.begin() ; while ( itCond != conds.end() ) { qgmConditionNode *condNode = *itCond ; while ( condNode->left ) { condNode = condNode->left ; } if ( condNode->type != SQL_GRAMMAR::DBATTR ) { outerUnit->addCondition( *itCond ) ; innerUnit->addCondition( SDB_OSS_NEW qgmConditionNode( *itCond ) ) ; outerChange = TRUE ; innerChange = TRUE ; } else if ( condNode->value.relegation() == outer()->getAlias( TRUE ) ) { outerUnit->addCondition( *itCond ) ; outerChange = TRUE ; } else if ( condNode->value.relegation() == inner()->getAlias( TRUE ) ) { innerUnit->addCondition( *itCond ) ; innerChange = TRUE ; } else { PD_LOG_MSG( PDERROR, "oprUnit[%s] condition attr[%s] is not in " "outer[%s] or inner[%s]", oprUnit->toString().c_str(), condNode->value.toString().c_str(), outer()->getAlias( TRUE ).toString().c_str(), inner()->getAlias( TRUE ).toString().c_str() ) ; rc = SDB_INVALIDARG ; goto error ; } ++itCond ; } if ( !outerChange && _varList.size() == 0 ) { qgmOpField dummyField ; dummyField.value.relegation() = outer()->getAlias( TRUE ) ; _table->getUniqueFieldAlias( dummyField.value.attr() ) ; dummyField.type = SQL_GRAMMAR::DBATTR ; outerUnit->addOpField( dummyField ) ; } QGM_VARLIST::iterator itVar = _varList.begin() ; while ( itVar != _varList.end() ) { if ( !isFromOne( (*itVar)._fieldName, *(outerUnit->getFields()), FALSE ) && ((*itVar)._fieldName.relegation() == outer()->getAlias()) ) { outerUnit->addOpField( qgmOpField( (*itVar)._fieldName, SQL_GRAMMAR::DBATTR) ) ; } ++itVar ; } if ( !_hints.empty() ) { SDB_ASSERT( _varList.empty(), "must be empty" ) ; _qgmConditionNodeHelper ctree( _condition ) ; qgmDbAttrPtrVec attrVec ; rc = ctree.getAllAttr( attrVec ) ; if ( SDB_OK != rc ) { PD_LOG( PDERROR, "failed to get all attrs from condition tree:%d", rc ) ; goto error ; } qgmDbAttrPtrVec::const_iterator itr = attrVec.begin() ; for ( ; itr != attrVec.end(); itr++ ) { if ( !isFromOne( **itr, *(outerUnit->getFields()), FALSE ) && ((*itr)->relegation() == outer()->getAlias()) ) { outerUnit->addOpField( qgmOpField( **itr, SQL_GRAMMAR::DBATTR) ) ; } else if ( !isFromOne( **itr, *(innerUnit->getFields()), FALSE ) && ((*itr)->relegation() == inner()->getAlias())) { innerUnit->addOpField( qgmOpField(**itr, SQL_GRAMMAR::DBATTR) ) ; } } } outerUnit->setDispatchAlias( outer()->getAlias( TRUE ) ) ; _oprUnits.push_back( outerUnit ) ; outerUnit = NULL ; if ( !innerChange ) { qgmOpField dummyField ; dummyField.value.relegation() = inner()->getAlias( TRUE ) ; _table->getUniqueFieldAlias( dummyField.value.attr() ) ; dummyField.type = SQL_GRAMMAR::DBATTR ; innerUnit->addOpField( dummyField ) ; } innerUnit->setDispatchAlias( inner()->getAlias( TRUE ) ) ; _oprUnits.push_back( innerUnit ) ; innerUnit = NULL ; filterUnit->emptyCondition() ; SDB_OSS_DEL filterUnit ; } else { rc = SDB_SYS ; goto error ; } done: PD_TRACE_EXITRC( SDB__QGMOPTINLJOIN__PUSHOPRUNIT, rc ) ; return rc ; error: if ( outerUnit ) { SDB_OSS_DEL outerUnit ; } if ( innerUnit ) { SDB_OSS_DEL innerUnit ; } goto done ; }