//PD_TRACE_DECLARE_FUNCTION ( SDB_RTNCODEL_EXECUTE, "rtnCoordDelete::execute" ) INT32 rtnCoordDelete::execute( MsgHeader *pMsg, pmdEDUCB *cb, INT64 &contextID, rtnContextBuf *buf ) { INT32 rc = SDB_OK ; INT32 rcTmp = SDB_OK ; PD_TRACE_ENTRY ( SDB_RTNCODEL_EXECUTE ) ; pmdKRCB *pKrcb = pmdGetKRCB() ; CoordCB *pCoordcb = pKrcb->getCoordCB() ; netMultiRouteAgent *pRouteAgent = pCoordcb->getRouteAgent() ; // process define rtnSendOptions sendOpt( TRUE ) ; rtnSendMsgIn inMsg( pMsg ) ; rtnProcessResult result ; ROUTE_RC_MAP nokRC ; result._pNokRC = &nokRC ; CoordCataInfoPtr cataInfo ; MsgRouteID errNodeID ; UINT64 deleteNum = 0 ; inMsg._pvtData = ( CHAR* )&deleteNum ; inMsg._pvtType = PRIVATE_DATA_NUMBERLONG ; BSONObj boDeletor ; // fill default-reply(delete success) MsgOpDelete *pDelMsg = (MsgOpDelete *)pMsg ; INT32 oldFlag = pDelMsg->flags ; pDelMsg->flags |= FLG_DELETE_RETURNNUM ; contextID = -1 ; INT32 flag = 0; CHAR *pCollectionName = NULL ; CHAR *pDeletor = NULL ; CHAR *pHint = NULL ; rc = msgExtractDelete( (CHAR*)pMsg, &flag, &pCollectionName, &pDeletor, &pHint ) ; if( rc ) { PD_LOG( PDERROR,"Failed to parse delete request, rc: %d", rc ) ; pCollectionName = NULL ; goto error ; } try { boDeletor = BSONObj( pDeletor ) ; } catch ( std::exception &e ) { PD_RC_CHECK( SDB_INVALIDARG, PDERROR, "Delete failed, received unexpected error:%s", e.what() ) ; } // add last op info MON_SAVE_OP_DETAIL( cb->getMonAppCB(), pMsg->opCode, "Collection:%s, Deletor:%s, Hint:%s, " "Flag:0x%08x(%u)", pCollectionName, boDeletor.toString().c_str(), BSONObj(pHint).toString().c_str(), oldFlag, oldFlag ) ; rc = rtnCoordGetCataInfo( cb, pCollectionName, FALSE, cataInfo ) ; PD_RC_CHECK( rc, PDERROR, "Delete failed, failed to get the " "catalogue info(collection name: %s), rc: %d", pCollectionName, rc ) ; retry: do { pDelMsg->version = cataInfo->getVersion() ; pDelMsg->w = 0 ; if ( cataInfo->isMainCL() ) { rcTmp = doOpOnMainCL( cataInfo, boDeletor, inMsg, sendOpt, pRouteAgent, cb, result ) ; } else { rcTmp = doOpOnCL( cataInfo, boDeletor, inMsg, sendOpt, pRouteAgent, cb, result ) ; } }while( FALSE ) ; if ( SDB_OK == rcTmp && nokRC.empty() ) { goto done ; } else if ( checkRetryForCLOpr( rcTmp, &nokRC, inMsg.msg(), sendOpt._retryTimes, cataInfo, cb, rc, &errNodeID, TRUE ) ) { nokRC.clear() ; ++sendOpt._retryTimes ; goto retry ; } else { PD_LOG( PDERROR, "Delete failed on node[%s], rc: %d", routeID2String( errNodeID ).c_str(), rc ) ; goto error ; } done: if ( oldFlag & FLG_DELETE_RETURNNUM ) { contextID = deleteNum ; } if ( pCollectionName ) { /// AUDIT PD_AUDIT_OP( AUDIT_DML, MSG_BS_DELETE_REQ, AUDIT_OBJ_CL, pCollectionName, rc, "DeletedNum:%u, Deletor:%s, Hint:%s, Flag:0x%08x(%u)", deleteNum, boDeletor.toString().c_str(), BSONObj(pHint).toString().c_str(), oldFlag, oldFlag ) ; } PD_TRACE_EXITRC ( SDB_RTNCODEL_EXECUTE, rc ) ; return rc ; error: goto done ; }
//PD_TRACE_DECLARE_FUNCTION ( COORD_OPERATORDEL_EXE, "_coordDeleteOperator::execute" ) INT32 _coordDeleteOperator::execute( MsgHeader *pMsg, pmdEDUCB *cb, INT64 &contextID, rtnContextBuf *buf ) { INT32 rc = SDB_OK ; INT32 rcTmp = SDB_OK ; PD_TRACE_ENTRY ( COORD_OPERATORDEL_EXE ) ; coordSendOptions sendOpt( TRUE ) ; coordSendMsgIn inMsg( pMsg ) ; coordProcessResult result ; ROUTE_RC_MAP nokRC ; result._pNokRC = &nokRC ; coordCataSel cataSel ; MsgRouteID errNodeID ; BSONObj boDeletor ; MsgOpDelete *pDelMsg = (MsgOpDelete *)pMsg ; INT32 oldFlag = pDelMsg->flags ; pDelMsg->flags |= FLG_DELETE_RETURNNUM ; contextID = -1 ; INT32 flag = 0; CHAR *pCollectionName = NULL ; CHAR *pDeletor = NULL ; CHAR *pHint = NULL ; rc = msgExtractDelete( (CHAR*)pMsg, &flag, &pCollectionName, &pDeletor, &pHint ) ; if( rc ) { PD_LOG( PDERROR,"Failed to parse delete request, rc: %d", rc ) ; pCollectionName = NULL ; goto error ; } try { boDeletor = BSONObj( pDeletor ) ; } catch ( std::exception &e ) { PD_RC_CHECK( SDB_INVALIDARG, PDERROR, "Delete failed, received unexpected error: %s", e.what() ) ; } MON_SAVE_OP_DETAIL( cb->getMonAppCB(), pMsg->opCode, "Collection:%s, Deletor:%s, Hint:%s, " "Flag:0x%08x(%u)", pCollectionName, boDeletor.toString().c_str(), BSONObj(pHint).toString().c_str(), oldFlag, oldFlag ) ; rc = cataSel.bind( _pResource, pCollectionName, cb, FALSE, TRUE ) ; if ( rc ) { PD_LOG( PDERROR, "Get or update collection[%s]'s catalog info " "failed, rc: %d", pCollectionName, rc ) ; goto error ; } retry: pDelMsg->version = cataSel.getCataPtr()->getVersion() ; pDelMsg->w = 0 ; rcTmp = doOpOnCL( cataSel, boDeletor, inMsg, sendOpt, cb, result ) ; if ( SDB_OK == rcTmp && nokRC.empty() ) { goto done ; } else if ( checkRetryForCLOpr( rcTmp, &nokRC, cataSel, inMsg.msg(), cb, rc, &errNodeID, TRUE ) ) { nokRC.clear() ; _groupSession.getGroupCtrl()->incRetry() ; goto retry ; } else { PD_LOG( PDERROR, "Delete failed on node[%s], rc: %d", routeID2String( errNodeID ).c_str(), rc ) ; goto error ; } done: if ( oldFlag & FLG_DELETE_RETURNNUM ) { contextID = _recvNum ; } if ( pCollectionName ) { PD_AUDIT_OP( AUDIT_DML, MSG_BS_DELETE_REQ, AUDIT_OBJ_CL, pCollectionName, rc, "DeletedNum:%u, Deletor:%s, Hint:%s, Flag:0x%08x(%u)", _recvNum, boDeletor.toString().c_str(), BSONObj(pHint).toString().c_str(), oldFlag, oldFlag ) ; } PD_TRACE_EXITRC ( COORD_OPERATORDEL_EXE, rc ) ; return rc ; error: if ( buf && nokRC.size() > 0 ) { *buf = rtnContextBuf( coordBuildErrorObj( _pResource, rc, cb, &nokRC ) ) ; } goto done ; }
INT32 _pmdExternClient::authenticate( MsgHeader *pMsg ) { #if defined ( SDB_ENGINE ) INT32 rc = SDB_OK ; BSONObj authObj ; BSONElement user, pass ; rc = extractAuthMsg( pMsg, authObj ) ; if ( rc ) { PD_LOG( PDERROR, "Client[%s] extract auth msg failed, rc: %d", clientName(), rc ) ; goto error ; } user = authObj.getField( SDB_AUTH_USER ) ; pass = authObj.getField( SDB_AUTH_PASSWD ) ; _isAuthed = FALSE ; if ( SDB_ROLE_STANDALONE == pmdGetDBRole() ) // not auth { _isAuthed = TRUE ; goto done ; } else if ( SDB_ROLE_OM == pmdGetDBRole() ) { rc = sdbGetOMManager()->authenticate( authObj, _pEDUCB ) ; if ( rc ) { PD_LOG( PDERROR, "Client[%s] authenticate failed[user: %s, " "passwd: %s], rc: %d", clientName(), user.valuestrsafe(), pass.valuestrsafe(), rc ) ; goto error ; } _isAuthed = TRUE ; } else if ( SDB_ROLE_COORD == pmdGetDBRole() ) { INT64 contextID = -1 ; rtnContextBuf buf ; CoordCB *pCoordcb = pmdGetKRCB()->getCoordCB(); rtnCoordProcesserFactory *pProcesserFactory = pCoordcb->getProcesserFactory(); rtnCoordOperator *pOperator = NULL ; pOperator = pProcesserFactory->getOperator( pMsg->opCode ); rc = pOperator->execute( pMsg, _pEDUCB, contextID, &buf ) ; // special handling for password verification when there is no // addrlist specified. Usually this happen when there is only // one coord node before creating the first catalog if ( MSG_AUTH_VERIFY_REQ == pMsg->opCode && SDB_CAT_NO_ADDR_LIST == rc ) { rc = SDB_OK ; _isAuthed = TRUE ; } else if ( rc ) { PD_LOG( PDERROR, "Client[%s] authenticate failed[user: %s, " "passwd: %s], rc: %d", clientName(), user.valuestrsafe(), pass.valuestrsafe(), rc ) ; goto error ; } else { _isAuthed = TRUE ; } } else { MsgHeader *pAuthRes = NULL ; shardCB *pShard = sdbGetShardCB() ; UINT32 retryTimes = 0 ; MsgOpReply replyHeader ; replyHeader.contextID = -1 ; replyHeader.numReturned = 0 ; while ( TRUE ) { ++retryTimes ; rc = pShard->syncSend( pMsg, CATALOG_GROUPID, TRUE, &pAuthRes ) ; if ( SDB_OK != rc ) { rc = pShard->syncSend( pMsg, CATALOG_GROUPID, FALSE, &pAuthRes ) ; PD_RC_CHECK( rc, PDERROR, "Client[%s] failed to send auth " "req to catalog, rc: %d", clientName(), rc ) ; } if ( NULL == pAuthRes ) { rc = SDB_SYS ; PD_LOG( PDERROR, "syncsend return ok but res is NULL" ) ; goto error ; } rc = MSG_GET_INNER_REPLY_RC(pAuthRes) ; replyHeader.flags = rc ; replyHeader.startFrom = MSG_GET_INNER_REPLY_STARTFROM(pAuthRes) ; ossMemcpy( &(replyHeader.header), pAuthRes, sizeof( MsgHeader ) ) ; /// release recv msg SDB_OSS_FREE( (BYTE*)pAuthRes ) ; pAuthRes = NULL ; if ( SDB_CLS_NOT_PRIMARY == rc && retryTimes < PMD_AUTH_RETRY_TIMES ) { INT32 rcTmp = SDB_OK ; rcTmp = pShard->updatePrimaryByReply( &(replyHeader.header) ) ; if ( SDB_NET_CANNOT_CONNECT == rcTmp ) { /// the node is crashed, sleep some seconds PD_LOG( PDWARNING, "Catalog group primary node is crashed " "but other nodes not aware, sleep %d seconds", NET_NODE_FAULTUP_MIN_TIME ) ; ossSleep( NET_NODE_FAULTUP_MIN_TIME * OSS_ONE_SEC ) ; } if ( rcTmp ) { pShard->updateCatGroup( CLS_SHARD_TIMEOUT ) ; } continue ; } else if ( rc ) { PD_LOG( PDERROR, "Client[%s] authenticate failed[user: %s, " "passwd: %s], rc: %d", clientName(), user.valuestrsafe(), pass.valuestrsafe(), rc ) ; goto error ; } else { _isAuthed = TRUE ; } break ; } } done: if ( SDB_OK == rc && _isAuthed ) { _username = user.valuestrsafe() ; if ( !_username.empty() ) { _password = pass.valuestrsafe() ; } _pEDUCB->setUserInfo( _username, _password ) ; _makeName() ; CHAR szTmp[ 16 ] = { 0 } ; ossSnprintf( szTmp, sizeof(szTmp)-1, "%llu", _pEDUCB->getID() ) ; PD_AUDIT_OP( AUDIT_ACCESS, MSG_AUTH_VERIFY_REQ, AUDIT_OBJ_SESSION, szTmp, SDB_OK, "User[UserName:%s, RemoteIP:%s, RemotePort:%u, " "LocalIP:%s, LocalPort:%u] login succeed", getUsername(), getPeerIPAddr(), getPeerPort(), getLocalIPAddr(), getLocalPort() ) ; } return rc ; error: if ( SDB_AUTH_AUTHORITY_FORBIDDEN == rc ) { _pEDUCB->printInfo( EDU_INFO_ERROR, "username or passwd is wrong" ) ; } goto done ; #else _isAuthed = TRUE ; return SDB_OK ; #endif // SDB_ENGINE }