Exemplo n.º 1
0
   /*
      rest agent entry point
   */
   INT32 pmdRestAgentEntryPoint( pmdEDUCB *cb, void *pData )
   {
      INT32 rc = SDB_OK ;

      SOCKET s = *(( SOCKET *) &pData ) ;

      pmdRestSession restSession( s ) ;
      restSession.attach( cb ) ;
      if ( SDB_ROLE_OM == pmdGetDBRole() )
      {
         rc = restSession.run() ;
      }
      else if ( SDB_ROLE_STANDALONE == pmdGetDBRole() 
                || SDB_ROLE_DATA == pmdGetDBRole() )
      {
         _pmdDataProcessor processor ;
         restSession.attachProcessor( &processor ) ;
         processor.attachSession( &restSession ) ;
         rc = restSession.run1() ;
         processor.detachSession() ;
         restSession.detachProcessor() ;
      }
      else if ( SDB_ROLE_COORD == pmdGetDBRole() )
      {
         _pmdCoordProcessor processor ;
         restSession.attachProcessor( &processor ) ;
         processor.attachSession( &restSession ) ;
         rc = restSession.run1() ;
         processor.detachSession() ;
         restSession.detachProcessor() ;
      }
      restSession.detach() ;

      return rc ;
   }
Exemplo n.º 2
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB_PMDLOCALAGENTENTPNT, "pmdLocalAgentEntryPoint" )
   INT32 pmdLocalAgentEntryPoint( pmdEDUCB *cb, void *arg )
   {
      INT32 rc = SDB_OK ;
      PD_TRACE_ENTRY ( SDB_PMDLOCALAGENTENTPNT );

      SOCKET s = *(( SOCKET *) &arg ) ;
      pmdLocalSession localSession( s ) ;
      localSession.attach( cb ) ;

      if ( pmdGetDBRole() == SDB_ROLE_COORD )
      {
         pmdCoordProcessor coordProcessor ;
         localSession.attachProcessor( &coordProcessor ) ;
         rc = localSession.run() ;
         localSession.detachProcessor() ;
      }
      else
      {
         pmdDataProcessor dataProcessor ;
         localSession.attachProcessor( &dataProcessor ) ;
         rc = localSession.run() ;
         localSession.detachProcessor() ;
      }

      localSession.detach() ;

      pmdGetKRCB()->getMonDBCB ()->connDec();

      PD_TRACE_EXITRC ( SDB_PMDLOCALAGENTENTPNT, rc );
      return rc ;
   }
Exemplo n.º 3
0
   /*
      rest agent entry point
   */
   INT32 pmdRestAgentEntryPoint( pmdEDUCB *cb, void *pData )
   {
      INT32 rc = SDB_OK ;

      SOCKET s = *(( SOCKET *) &pData ) ;

      if ( SDB_ROLE_OM == pmdGetDBRole() )
      {
         _omRestSession omRS( s ) ;
         omRS.attach( cb ) ;

         _pmdDataProcessor processor ;
         omRS.attachProcessor( &processor ) ;
         rc = omRS.run() ;
         omRS.detachProcessor() ;

         omRS.detach() ;
      }
      else if ( SDB_ROLE_COORD == pmdGetDBRole() )
      {
         pmdRestSession restSession( s ) ;
         restSession.attach( cb ) ;

         _pmdCoordProcessor processor ;
         restSession.attachProcessor( &processor ) ;
         rc = restSession.run() ;
         restSession.detachProcessor() ;
         restSession.detach() ;
      }
      else
      {
         pmdRestSession restSession( s ) ;
         restSession.attach( cb ) ;

         _pmdDataProcessor processor ;
         restSession.attachProcessor( &processor ) ;
         rc = restSession.run() ;
         restSession.detachProcessor() ;
         restSession.detach() ;
      }
      
      pmdGetKRCB()->getMonDBCB ()->connDec();

      return rc ;
   }
Exemplo n.º 4
0
   INT32 _pmdController::active ()
   {
      INT32 rc = SDB_OK ;
      pmdEDUParam *pProtocolData = NULL ;
      pmdEDUMgr *pEDUMgr = pmdGetKRCB()->getEDUMgr() ;
      EDUID eduID = PMD_INVALID_EDUID ;

      rc = _restAdptor.init( _fixBufSize, _maxRestBodySize, _restTimeout ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to init rest adaptor, rc: %d", rc ) ;

      rc = pEDUMgr->startEDU( EDU_TYPE_SYNCCLOCK, NULL, &eduID ) ;
      pEDUMgr->regSystemEDU( EDU_TYPE_SYNCCLOCK, eduID ) ;

      rc = pEDUMgr->startEDU( EDU_TYPE_TCPLISTENER, (void*)_pTcpListener,
                              &eduID ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to start tcp listerner, rc: %d",
                   rc ) ;
      pEDUMgr->regSystemEDU( EDU_TYPE_TCPLISTENER, eduID ) ;

      rc = pEDUMgr->waitUntil ( eduID, PMD_EDU_RUNNING ) ;
      PD_RC_CHECK( rc, PDERROR, "Wait Tcp Listerner active failed, rc: %d",
                   rc ) ;

      rc = pEDUMgr->startEDU( EDU_TYPE_RESTLISTENER, (void*)_pHttpListener,
                              &eduID ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to start rest listerner, rc: %d",
                   rc ) ;
      pEDUMgr->regSystemEDU( EDU_TYPE_RESTLISTENER, eduID ) ;

      rc = pEDUMgr->waitUntil ( eduID, PMD_EDU_RUNNING ) ;
      PD_RC_CHECK( rc, PDERROR, "Wait rest Listener active failed, rc: %d",
                   rc ) ;


      if ( SDB_ROLE_COORD != pmdGetDBRole() )
      {
         UINT32 pageTaskNum = pmdGetOptionCB()->getPageCleanNum() ;
         UINT32 pageIntervel = pmdGetOptionCB()->getPageCleanInterval() ;
         for ( UINT32 i = 0; i < pageTaskNum ; ++i )
         {
            startPageCleanerJob( NULL, (INT32)pageIntervel ) ;
         }
         rtnStartLoadJob() ;
      }

   done:
      return rc ;
   error:
      goto done ;
   }
Exemplo n.º 5
0
   INT32 pmdFapAgentEntryPoint( pmdEDUCB *cb, void *arg )
   {
      INT32 rc = SDB_OK ;
      PD_TRACE_ENTRY ( SDB_PMDLOCALAGENTENTPNT ) ;
      pmdSession *session = NULL ;
      pmdEDUParam *pParam = ( pmdEDUParam * )arg ;
      SOCKET s = *((SOCKET *)&pParam->pSocket) ;
      IPmdAccessProtocol* protocol = pParam->protocol ;
      SDB_OSS_DEL pParam ;
      pParam = NULL ;

      session = protocol->getSession( s ) ;
      if ( NULL == session )
      {
         PD_LOG( PDERROR, "Failed to get Session of protocol" ) ;
         rc = SDB_OOM ;
         goto error ;
      }
      session->attach( cb ) ;

      if ( pmdGetDBRole() == SDB_ROLE_COORD )
      {
         pmdCoordProcessor coordProcessor ;
         session->attachProcessor( &coordProcessor ) ;
         rc = session->run() ;
         session->detachProcessor() ;
      }
      else
      {
         pmdDataProcessor dataProcessor ;
         session->attachProcessor( &dataProcessor ) ;
         rc = session->run() ;
         session->detachProcessor() ;
      }
      session->detach() ;

   done:
      if ( session )
      {
         protocol->releaseSession( session ) ;
         session = NULL ;
      }
      PD_TRACE_EXITRC ( SDB_PMDLOCALAGENTENTPNT, rc );
      return rc ;
   error:
      goto done ;
   }
Exemplo n.º 6
0
   INT32 _pmdDataProcessor::_onTransRollbackMsg ( SDB_DPSCB *dpsCB )
   {
      INT32 rc = SDB_OK ;
      if ( pmdGetDBRole() != SDB_ROLE_STANDALONE )
      {
         rc = SDB_PERM ;
         PD_LOG( PDERROR, "In sharding mode, couldn't execute "
                 "transaction operation from local service" ) ;
         goto error ;
      }
      else
      {
         rc = rtnTransRollback( eduCB(), dpsCB ) ;
      }

   done:
      return rc ;
   error:
      goto done ;
   }
Exemplo n.º 7
0
   INT32 _SDB_DMSCB::init ()
   {
      INT32 rc = SDB_OK ;

      if ( SDB_ROLE_COORD != pmdGetDBRole() )
      {
         rc = rtnLoadCollectionSpaces ( pmdGetOptionCB()->getDbPath(),
                                        pmdGetOptionCB()->getIndexPath(),
                                        pmdGetOptionCB()->getLobPath(),
                                        this ) ;
         PD_RC_CHECK( rc, PDERROR, "Failed to load collectionspaces, rc: %d",
                      rc ) ;
      }

      rc = _tempCB.init() ;
      PD_RC_CHECK( rc, PDERROR, "Failed to init temp cb, rc: %d", rc ) ;

   done:
      return rc ;
   error:
      goto done ;
   }
Exemplo n.º 8
0
void _pmdSession::attach( _pmdEDUCB * cb )
{
    SDB_ASSERT( cb, "cb can't be NULL" ) ;

    PD_LOG( PDINFO, "Session[%s] attach edu[%d]", sessionName(),
            cb->getID() ) ;

    _pDPSCB = pmdGetKRCB()->getDPSCB() ;
    if ( SDB_ROLE_COORD != pmdGetDBRole() &&
            _pDPSCB && !_pDPSCB->isLogLocal() )
    {
        _pDPSCB = NULL ;
    }

    _pEDUCB = cb ;
    _eduID  = cb->getID() ;
    _pEDUCB->attachSession( this ) ;
    _pEDUCB->setName( sessionName() ) ;
    _pEDUCB->setClientSock( socket() ) ;
    _client.attachCB( cb ) ;

    _onAttach() ;
}
Exemplo n.º 9
0
   /*
      rest service entry point
   */
   INT32 pmdRestSvcEntryPoint ( pmdEDUCB *cb, void *pData )
   {
      INT32 rc                = SDB_OK ;
      pmdKRCB *krcb           = pmdGetKRCB() ;
      monDBCB *mondbcb        = krcb->getMonDBCB () ;
      pmdEDUMgr *eduMgr       = cb->getEDUMgr() ;
      ossSocket *pListerner   = ( ossSocket* )pData ;
      EDUID agentEDU          = PMD_INVALID_EDUID ;

      if ( SDB_OK != ( rc = eduMgr->activateEDU ( cb )) )
      {
         goto error ;
      }

      while ( !cb->isDisconnected() )
      {
         SOCKET s ;
         rc = pListerner->accept ( &s, NULL, NULL ) ;
         if ( SDB_TIMEOUT == rc || SDB_TOO_MANY_OPEN_FD == rc  )
         {
            rc = SDB_OK ;
            continue ;
         }
         if ( rc && PMD_IS_DB_DOWN )
         {
            rc = SDB_OK ;
            goto done ;
         }
         else if ( rc )
         {
            PD_LOG ( PDERROR, "Failed to accept rest socket, rc: %d",
                     rc ) ;
            if ( pListerner->isClosed() )
            {
               break ;
            }
            else
            {
               continue ;
            }
         }

         cb->incEventCount() ;
         ++mondbcb->numConnects ;

         void *pData = NULL ;
         *((SOCKET *) &pData) = s ;

         if ( !krcb->isActive() )
         {
            ossSocket newsock ( &s ) ;
            newsock.close () ;
            continue ;
         }

         if ( SDB_ROLE_OM == pmdGetDBRole() || SDB_ROLE_DATA == pmdGetDBRole() 
              || SDB_ROLE_STANDALONE == pmdGetDBRole() 
              || SDB_ROLE_COORD == pmdGetDBRole() )
         {
            rc = eduMgr->startEDU ( EDU_TYPE_RESTAGENT, pData, &agentEDU ) ;
         }
         else
         {
            rc = eduMgr->startEDU ( EDU_TYPE_HTTPAGENT, pData, &agentEDU ) ;
         }

         if ( rc )
         {
            PD_LOG( ( rc == SDB_QUIESCED ? PDWARNING : PDERROR ),
                    "Failed to start edu, rc: %d", rc ) ;

            ossSocket newsock ( &s ) ;
            newsock.close () ;
            continue ;
         }
      } //while ( ! cb->isDisconnected() )

   done :
      return rc ;
   error :
      goto done ;
   }
Exemplo n.º 10
0
   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
   }
Exemplo n.º 11
0
   INT32 _pmdController::active ()
   {
      INT32 rc = SDB_OK ;
      pmdEDUMgr *pEDUMgr = pmdGetKRCB()->getEDUMgr() ;
      EDUID eduID = PMD_INVALID_EDUID ;

      rc = _restAdptor.init( _fixBufSize, _maxRestBodySize, _restTimeout ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to init rest adaptor, rc: %d", rc ) ;

      // start time sync edu
      rc = pEDUMgr->startEDU( EDU_TYPE_SYNCCLOCK, NULL, &eduID ) ;
      PD_RC_CHECK( rc, PDERROR, "Start sync clock edu failed, rc: %d", rc ) ;
      pEDUMgr->regSystemEDU( EDU_TYPE_SYNCCLOCK, eduID ) ;

      // start db monitor edu
      rc = pEDUMgr->startEDU( EDU_TYPE_DBMONITOR, NULL, &eduID ) ;
      PD_RC_CHECK( rc, PDERROR, "Start db monitor edu failed, rc: %d", rc ) ;
      pEDUMgr->regSystemEDU( EDU_TYPE_DBMONITOR, eduID ) ;

#if defined ( _LINUX )
      // start signal test
      if ( pmdGetOptionCB()->getSignalInterval() > 0 )
      {
         pmdEDUCB *mainCB = pmdGetThreadEDUCB() ;
         rc = pEDUMgr->startEDU( EDU_TYPE_SIGNALTEST, (void*)mainCB, &eduID ) ;
         PD_RC_CHECK( rc, PDERROR, "Start signal test edu failed, rc: %d", rc ) ;
         pEDUMgr->regSystemEDU( EDU_TYPE_SIGNALTEST, eduID ) ;
      }
#endif // _LINUX

      // start tcp listern edu and http listerner edu
      rc = pEDUMgr->startEDU( EDU_TYPE_TCPLISTENER, (void*)_pTcpListener,
                              &eduID ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to start tcp listerner, rc: %d",
                   rc ) ;
      pEDUMgr->regSystemEDU( EDU_TYPE_TCPLISTENER, eduID ) ;

      // wait until tcp listener starts
      rc = pEDUMgr->waitUntil ( eduID, PMD_EDU_RUNNING ) ;
      PD_RC_CHECK( rc, PDERROR, "Wait Tcp Listerner active failed, rc: %d",
                   rc ) ;

      rc = pEDUMgr->startEDU( EDU_TYPE_RESTLISTENER, (void*)_pHttpListener,
                              &eduID ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to start rest listerner, rc: %d",
                   rc ) ;
      pEDUMgr->regSystemEDU( EDU_TYPE_RESTLISTENER, eduID ) ;

      // wait until http listener starts
      rc = pEDUMgr->waitUntil ( eduID, PMD_EDU_RUNNING ) ;
      PD_RC_CHECK( rc, PDERROR, "Wait rest Listener active failed, rc: %d",
                   rc ) ;

      rc = activeForeignModule() ;
      PD_RC_CHECK( rc, PDERROR, "active Foreign module failed, rc: %d",
                   rc ) ;

      // For non-coord nodes, we need to start page cleaners
      if ( SDB_ROLE_COORD != pmdGetDBRole() )
      {
         UINT32 pageTaskNum = pmdGetOptionCB()->getPageCleanNum() ;
         UINT32 pageIntervel = pmdGetOptionCB()->getPageCleanInterval() ;
         // start page flush background task
         for ( UINT32 i = 0; i < pageTaskNum ; ++i )
         {
            startPageCleanerJob( NULL, (INT32)pageIntervel ) ;
         }
         // start load job
         rtnStartLoadJob() ;
      }

      // For data nodes(both primary and slavery nodes), we need to start
      // dictionary creating threads.
      if ( SDB_ROLE_DATA == pmdGetDBRole()
           || SDB_ROLE_STANDALONE == pmdGetDBRole() )
      {
         rc = startDictCreatorJob( NULL ) ;
         PD_RC_CHECK( rc, PDERROR, "Start dictionary creating job thread failed, "
                      "rc: %d", rc ) ;
      }

   done:
      return rc ;
   error:
      goto done ;
   }