Beispiel #1
0
int _ossSocket::bind_listen ()
{
   int rc = EDB_OK ;
   int temp = 1 ;
   rc = setsockopt ( _fd, SOL_SOCKET,
                     SO_REUSEADDR, (char*)&temp, sizeof(int) ) ;
   if ( rc )
   {
      PD_LOG ( PDWARNING, "Failed to setsockopt SO_REUSEADDR, rc = %d",
               SOCKET_GETLASTERROR ) ;
   }
   rc = setSocketLi ( 1, 30 ) ;
   if ( rc )
   {
      PD_LOG ( PDWARNING, "Failed to setsockopt SO_LINGER, rc = %d",
               SOCKET_GETLASTERROR ) ;
   }
   rc = ::bind ( _fd, (struct sockaddr*)&_sockAddress, _addressLen ) ;
   if ( rc )
   {
      PD_RC_CHECK( EDB_NETWORK, PDERROR,
                   "Failed to bind socket, rc = %d", SOCKET_GETLASTERROR ) ;
   }
   rc = listen ( _fd, SOMAXCONN ) ;
   if ( rc )
   {
      PD_RC_CHECK( EDB_NETWORK, PDERROR,
                   "Failed to listen socket, rc = %d", SOCKET_GETLASTERROR ) ;
   }
done :
   return rc ;
error :
   close () ;
   goto done ;
}
Beispiel #2
0
 INT32 iPmdDMNChildProc::active()
 {
    INT32 rc = SDB_OK;
    rc = attachSHM();
    if ( SDB_OK == rc )
    {
       UINT32 i = 3;
       UINT32 sn = _procInfo->sn;
       while( i-- > 0 )
       {
          if ( sn != _procInfo->sn &&
               (sn + 1) != _procInfo->sn )
          {
             rc = SDB_PERM;
             PD_RC_CHECK( rc, PDERROR, "Don't repeat start the process" );
          }
          ossSleep( 2 * OSS_ONE_SEC ) ;
       }
       _procInfo->szTag[ 0 ] = 0 ;
       _procInfo->init() ;
    }
    else
    {
       rc = allocSHM();
       PD_RC_CHECK( rc, PDERROR, "Failed to allocate share-memory(rc=%d)",
                    rc ) ;
    }
 done:
    return rc;
 error:
    detachSHM();
    goto done;
 }
   INT32 _pmdController::loadForeignModule()
   {
      INT32 rc = SDB_OK ;
      const CHAR *MONGO_MODULE_NAME = "fapmongo" ;
      const CHAR *MONGO_MODULE_PATH = "./bin/fap/" ;
      _fapMongo = SDB_OSS_NEW pmdModuleLoader() ;
      if ( NULL == _fapMongo )
      {
         PD_LOG( PDERROR, "Failed to alloc foreign access protocol module" ) ;
         rc = SDB_OOM ;
         goto error ;
      }
      rc = _fapMongo->load( MONGO_MODULE_NAME, MONGO_MODULE_PATH ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to load module: %s, path: %s"
                   " rc: %d", MONGO_MODULE_NAME, MONGO_MODULE_PATH, rc ) ;
      rc = _fapMongo->create( _protocol ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to create protocol service" ) ;
      rc = _protocol->init( pmdGetKRCB() ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to init protocol" ) ;

   done:
      return rc ;
   error:
      goto done ;
   }
Beispiel #4
0
   INT32 aggrProjectParser::addField( const CHAR *pAlias, const CHAR *pPara,
                                    const CHAR *pCLName, qgmOPFieldVec &selectorVec,
                                    _qgmPtrTable *pTable )
   {
      INT32 rc = SDB_OK;
      qgmField slValAttr;
      qgmField slValRelegation;
      qgmOpField selector;

      rc = pTable->getOwnField( AGGR_CL_DEFAULT_ALIAS, slValRelegation );
      PD_RC_CHECK( rc, PDERROR,
                  "failed to get the field(%s)",
                  AGGR_CL_DEFAULT_ALIAS );

      rc = pTable->getOwnField( pPara, slValAttr );
      PD_RC_CHECK( rc, PDERROR,
                  "failed to get the field(%s)",
                  pPara );

      rc = pTable->getOwnField( pAlias, selector.alias );
      PD_RC_CHECK( rc, PDERROR,
                  "failed to get the field(%s)",
                  pAlias );

      {
         qgmDbAttr slVal( slValRelegation, slValAttr );
         selector.value = slVal;
         selector.type = SQL_GRAMMAR::DBATTR;
         selectorVec.push_back( selector );
      }
   done:
      return rc;
   error:
      goto done;
   }
   INT32 rtnCoord2PhaseCommit::doPhase2( CHAR * pReceiveBuffer, SINT32 packSize,
                                         CHAR * * ppResultBuffer, pmdEDUCB * cb,
                                         MsgOpReply & replyHeader )
   {
      INT32 rc = SDB_OK;
      pmdKRCB *pKrcb                   = pmdGetKRCB();
      CoordCB *pCoordcb                = pKrcb->getCoordCB();
      netMultiRouteAgent *pRouteAgent  = pCoordcb->getRouteAgent();
      CHAR *pMsgReq                    = NULL;
      MsgHeader *pMsgHead              = NULL;
      CoordGroupList groupLst;
      CoordGroupList sendGroupLst;

      rc = buildPhase2Msg( pReceiveBuffer, &pMsgReq );
      PD_RC_CHECK( rc, PDERROR,
                  "failed to build the message on phase1(rc=%d)",
                  rc );

      pMsgHead = (MsgHeader *)pMsgReq;
      pMsgHead->TID = cb->getTID();

      rc = executeOnDataGroup( pMsgReq, pRouteAgent, cb );
      PD_RC_CHECK( rc, PDERROR,
                  "failed to execute on data-group on phase1(rc=%d)",
                  rc );
   done:
      if ( pMsgReq )
      {
         SDB_OSS_FREE( pMsgReq );
         pMsgReq = NULL;
      }
      return rc;
   error:
      goto done;
   }
   INT32 _utilESBulkActionBase::output( CHAR *buffer, INT32 size,
                                        INT32 &length, BOOLEAN withIndex,
                                        BOOLEAN withType, BOOLEAN withID ) const
   {
      INT32 rc = SDB_OK ;
      INT32 metaLen = 0 ;
      INT32 dataLen = 0 ;

      if ( size < outSizeEstimate() )
      {
         rc = SDB_INVALIDARG ;
         PD_LOG( PDERROR, "Buffer size[%d] is too small", size ) ;
         goto error ;
      }

      rc = _outputActionAndMeta( buffer, size, metaLen,
                                 withIndex, withType, withID ) ;
      PD_RC_CHECK( rc, PDERROR, "Output action and metadata failed[ %d ]",
                   rc ) ;

      if ( _hasSourceData() )
      {
         rc = _outputSrcData( buffer + metaLen, size - metaLen, dataLen ) ;
         PD_RC_CHECK( rc, PDERROR, "Output source data failed[ %d ]", rc ) ;
      }

      length = metaLen + dataLen ;

   done:
      return rc ;
   error:
      goto done ;
   }
   INT32 rtnCoord2PhaseCommit::doPhase1( MsgHeader *pMsg,
                                         pmdEDUCB *cb,
                                         INT64 &contextID,
                                         rtnContextBuf *buf )
   {
      INT32 rc = SDB_OK;
      CHAR *pMsgReq                    = NULL;

      rc = buildPhase1Msg( (CHAR*)pMsg, &pMsgReq );
      PD_RC_CHECK( rc, PDERROR,
                   "Failed to build the message on phase1(rc=%d)",
                   rc );

      // execute on data nodes
      rc = executeOnDataGroup( (MsgHeader*)pMsgReq, cb, contextID, buf ) ;
      PD_RC_CHECK( rc, PDERROR,
                   "Failed to execute on data-group on phase1(rc=%d)",
                   rc ) ;

   done:
      if ( pMsgReq )
      {
         SDB_OSS_FREE( pMsgReq );
         pMsgReq = NULL;
      }
      return rc;
   error:
      goto done;
   }
Beispiel #8
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB__DMSSU_UPDATECOLLECTIONATTRIBUTES, "_dmsStorageUnit::updateCollectionAttributes" )
   INT32 _dmsStorageUnit::updateCollectionAttributes( const CHAR *pName,
                                                      UINT32 newAttributes,
                                                      dmsMBContext *context )
   {
      INT32 rc                     = SDB_OK ;
      BOOLEAN getContext           = FALSE ;

      PD_TRACE_ENTRY ( SDB__DMSSU_UPDATECOLLECTIONATTRIBUTES ) ;
      if ( NULL == context )
      {
         SDB_ASSERT( pName, "Collection name can't be NULL" ) ;

         rc = _pDataSu->getMBContext( &context, pName, SHARED ) ;
         PD_RC_CHECK( rc, PDERROR, "Get collection[%s] mb context failed, "
                      "rc: %d", pName, rc ) ;
         getContext = TRUE ;
      }
      else if ( !context->isMBLock() )
      {
         rc = context->mbLock( SHARED ) ;
         PD_RC_CHECK( rc, PDERROR, "Lock collection failed, rc: %d", rc ) ;
      }

      context->mb()->_attributes = newAttributes ;

   done :
      if ( getContext && context )
      {
         _pDataSu->releaseMBContext( context ) ;
      }
      PD_TRACE_EXITRC ( SDB__DMSSU_UPDATECOLLECTIONATTRIBUTES, rc ) ;
      return rc ;
   error :
      goto done ;
   }
Beispiel #9
0
int InsertCommand::execute( ossSocket & sock, std::vector<std::string> & argVec )
{
   int rc = EDB_OK;
   if( argVec.size() <1 )
   {
      return getError(EDB_INSERT_INVALID_ARGUMENT);
   }
   _jsonString = argVec[0];
     if( !sock.isConnected() )
   {
      return getError(EDB_SOCK_NOT_CONNECT);
   }

   rc = sendOrder( sock, msgBuildInsert );
   PD_RC_CHECK ( rc, PDERROR, "Failed to send order, rc = %d", rc ) ;

   rc = recvReply( sock );
   PD_RC_CHECK ( rc, PDERROR, "Failed to receive reply, rc = %d", rc ) ;
   rc = handleReply();
   PD_RC_CHECK ( rc, PDERROR, "Failed to receive reply, rc = %d", rc ) ;
done :
   return rc;
error :
   goto done ;
}
Beispiel #10
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB__DMSSU_REMOVE, "_dmsStorageUnit::remove" )
   INT32 _dmsStorageUnit::remove ()
   {
      INT32 rc = SDB_OK ;
      PD_TRACE_ENTRY ( SDB__DMSSU_REMOVE ) ;
      if ( _pDataSu )
      {
         rc = _pDataSu->removeStorage() ;
         PD_RC_CHECK( rc, PDERROR, "Failed to remove collection space[%s] "
                      "data file, rc: %d", CSName(), rc ) ;
      }

      if ( _pIndexSu )
      {
         rc = _pIndexSu->removeStorage() ;
         PD_RC_CHECK( rc, PDERROR, "Failed to remove collection space[%s] "
                      "index file, rc: %d", CSName(), rc ) ;
      }

      if ( _pLobSu )
      {
         _pLobSu->removeStorageFiles() ;
      }

      PD_LOG( PDEVENT, "Remove collection space[%s] files succeed", CSName() ) ;

   done:
      PD_TRACE_EXITRC ( SDB__DMSSU_REMOVE, rc ) ;
      return rc ;
   error:
      goto done ;
   }
Beispiel #11
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB__DMSSU_CHANGECOLLECTIONFLAG, "_dmsStorageUnit::changeCollectionFlag" )
   INT32 _dmsStorageUnit::changeCollectionFlag( const CHAR *pName, UINT16 flag,
                                                dmsMBContext *context )
   {
      INT32 rc                     = SDB_OK ;
      BOOLEAN getContext           = FALSE ;

      PD_TRACE_ENTRY ( SDB__DMSSU_CHANGECOLLECTIONFLAG ) ;
      if ( NULL == context )
      {
         SDB_ASSERT( pName, "Collection name can't be NULL" ) ;

         rc = _pDataSu->getMBContext( &context, pName, SHARED ) ;
         PD_RC_CHECK( rc, PDERROR, "Get collection[%s] mb context failed, "
                      "rc: %d", pName, rc ) ;
         getContext = TRUE ;
      }
      else if ( !context->isMBLock() )
      {
         rc = context->mbLock( SHARED ) ;
         PD_RC_CHECK( rc, PDERROR, "Lock collection failed, rc: %d", rc ) ;
      }

      context->mb()->_flag = flag ;

   done :
      if ( getContext && context )
      {
         _pDataSu->releaseMBContext( context ) ;
      }
      PD_TRACE_EXITRC ( SDB__DMSSU_CHANGECOLLECTIONFLAG, rc ) ;
      return rc ;
   error :
      goto done ;
   }
   INT32 _rtnCtxDataDispatcher::_processData ( INT64 processorType,
                                               INT64 dataID,
                                               const CHAR * data,
                                               INT32 dataSize,
                                               INT32 dataNum )
   {
      INT32 rc = SDB_OK ;

      for ( rtnCtxDataProcessorList::iterator iter = _processors.begin() ;
            iter != _processors.end() ;
            iter ++ )
      {
         _IRtnCtxDataProcessor * processor = ( *iter ) ;

         SDB_ASSERT( NULL != processor, "processor is invalid" ) ;

         if ( processorType == (INT64)processor->getProcessType() )
         {
            rc = processor->processData( dataID, data, dataSize, dataNum ) ;
            PD_RC_CHECK( rc, PDERROR, "Failed to process data, rc: %d", rc ) ;
         }
         else if ( processor->needCheckData() )
         {
            rc = processor->checkData( dataID, data, dataSize, dataNum ) ;
            PD_RC_CHECK( rc, PDERROR, "Failed to check data, rc: %d", rc ) ;
         }
      }

   done :
      return rc ;

   error :
      goto done ;
   }
Beispiel #13
0
   INT32 _pmdController::activeForeignModule()
   {
      INT32 rc = SDB_OK ;
      pmdEDUParam *pProtocolData = NULL ;
      pmdEDUMgr *pEDUMgr = pmdGetKRCB()->getEDUMgr() ;
      EDUID eduID = PMD_INVALID_EDUID ;

      if ( NULL == _fapMongo )
      {
         goto done ;
      }

      // listener for access protocol
      pProtocolData = new pmdEDUParam() ;
      pProtocolData->pSocket = (void *)_pMongoListener ;
      pProtocolData->protocol = _protocol ;
      rc = pEDUMgr->startEDU( EDU_TYPE_FAPLISTENER, (void*)pProtocolData,
                              &eduID ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to start FAP listerner, rc: %d",
                   rc ) ;
      pEDUMgr->regSystemEDU( EDU_TYPE_FAPLISTENER, eduID ) ;

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

   done:
      return rc ;
   error:
      goto done ;
   }
Beispiel #14
0
int pmdMasterThreadMain(int argc, char **argv)
{
	int rc = EDB_OK;
	EDB_KRCB *krcb = pmdGetKRCB();
	pmdEDUMgr* eduMgr = krcb->getEDUMgr();
	EDUID agentEDU = PMD_INVALID_EDUID;
	
	rc = pmdSetupSignalHandler();
	PD_RC_CHECK(rc, PDERROR, "Failed to setup signal handler, rc = %d", rc);
	rc = pmdResolveArguments(argc, argv);
	if (EDB_PMD_HELP_ONLY == rc) {
		goto done;	
	}	

	PD_RC_CHECK(rc, PDERROR, "Failed to resolve argument, rc = %d", rc);

	rc = eduMgr->startEDU(EDU_TYPE_TCPLISTENER, NULL, &agentEDU);
	PD_RC_CHECK ( rc, PDERROR, "Failed to start tcplistener edu, rc = %d", rc ) ;
	while(EDB_IS_DB_UP) {
		sleep(1);	
	}
	eduMgr->reset();

done:
	return rc;
error:
	goto done;
}
Beispiel #15
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB_DPSTRANSLOCK_TRYUPGRADE, "dpsTransLock::tryUpgrade" )
   INT32 dpsTransLock::tryUpgrade( _pmdEDUCB *eduCB,
                                   const dpsTransLockId &lockId,
                                   dpsTransCBLockInfo *pLockInfo,
                                   DPS_TRANSLOCK_TYPE lockType )
   {
      SDB_ASSERT( eduCB, "eduCB can't be null" ) ;
      INT32 rc = SDB_OK;
      DPS_TRANSLOCK_TYPE lastLockType;
      dpsLockBucket *pLockBucket = NULL;

      rc = upgradeCheck( pLockInfo->getType(), lockType );
      PD_RC_CHECK( rc, PDERROR, "Upgrade lock failed(rc=%d)", rc );

      rc = getBucket( lockId, pLockBucket );
      PD_RC_CHECK( rc, PDERROR, "Failed to get lock-bucket, upgrade lock "
                   "failed(rc=%d)", rc );

      lastLockType = pLockInfo->getType();
      pLockInfo->setType( lockType );
      rc = pLockBucket->tryAcquire( eduCB, lockId, lockType );
      PD_CHECK( SDB_OK == rc, rc, rollbackType, PDERROR,
                "Upgrade lock failed(rc=%d)", rc );

   done:
      PD_TRACE_EXIT ( SDB_DPSTRANSLOCK_TRYUPGRADE );
      return rc;
   rollbackType:
      pLockInfo->setType( lastLockType );
   error:
      goto done;
   }
Beispiel #16
0
int _ossSocket::connect ()
{
   int rc = EDB_OK ;
   rc = ::connect ( _fd, (struct sockaddr *)&_sockAddress, _addressLen ) ;
   if ( rc )
   {
      PD_RC_CHECK ( EDB_NETWORK, PDERROR,
                    "Failed to connect, rc = %d", SOCKET_GETLASTERROR ) ;
   }
   rc = getsockname ( _fd, (sockaddr*)&_sockAddress, &_addressLen ) ;
   if ( rc )
   {
      PD_RC_CHECK ( EDB_NETWORK, PDERROR,
                    "Failed to get local address, rc = %d", rc ) ;
   }
   // get peer address
   rc = getpeername ( _fd, (sockaddr*)&_peerAddress, &_peerAddressLen ) ;
   if ( rc ) 
   {
      PD_RC_CHECK ( EDB_NETWORK, PDERROR,
                    "Failed to get peer address, rc = %d", rc ) ;
   }
done :
   return rc ;
error :
   goto done ;
}
   INT32 rtnCoordTransRollback::execute( CHAR * pReceiveBuffer, SINT32 packSize,
                                         CHAR * * ppResultBuffer, pmdEDUCB * cb,
                                         MsgOpReply & replyHeader,
                                         BSONObj **ppErrorObj )
   {
      INT32 rc                         = SDB_OK;
      CHAR *pMsgReq                    = NULL;
      MsgHeader *pMsgHead              = NULL;
      INT32 bufferSize                 = 0;
      pmdKRCB *pKrcb                   = pmdGetKRCB();
      CoordCB *pCoordcb                = pKrcb->getCoordCB();
      netMultiRouteAgent *pRouteAgent  = pCoordcb->getRouteAgent();
      MsgHeader *pHeader               = (MsgHeader *)pReceiveBuffer;
      replyHeader.header.messageLength = sizeof( MsgOpReply );
      replyHeader.header.opCode        = MSG_BS_TRANS_ROLLBACK_RSP;
      replyHeader.header.routeID.value = 0;
      replyHeader.contextID            = -1;
      replyHeader.flags                = SDB_OK;
      replyHeader.numReturned          = 0;
      replyHeader.startFrom            = 0;

      if ( pHeader )
      {
         replyHeader.header.requestID     = pHeader->requestID;
         replyHeader.header.TID           = pHeader->TID;
      }

      if ( !cb->isTransaction() )
      {
         rc = SDB_DPS_TRANS_NO_TRANS;
         goto error;
      }

      cb->startRollback();

      rc = msgBuildTransRollbackMsg( &pMsgReq, &bufferSize );
      PD_RC_CHECK( rc, PDERROR,
                  "failed to build the message(rc=%d)",
                  rc );

      pMsgHead = (MsgHeader *)pMsgReq;
      pMsgHead->TID = cb->getTID();
      rc = executeOnDataGroup( pMsgReq, pRouteAgent, cb );
      cb->delTransaction();
      PD_RC_CHECK( rc, PDERROR,
                  "failed to rollback(rc=%d)",
                  rc );
   done:
      if ( pMsgReq )
      {
         SDB_OSS_FREE( pMsgReq );
      }
      cb->stopRollback();
      return rc;
   error:
      replyHeader.flags = rc;
      goto done;
   }
Beispiel #18
0
   static INT32 _checkDstGroupInCSDomain( const CHAR * groupName,
                                          const CHAR * clFullName,
                                          BOOLEAN & existed,
                                          pmdEDUCB *cb )
   {
      INT32 rc = SDB_OK ;
      CHAR szSpace [ DMS_COLLECTION_SPACE_NAME_SZ + 1 ]  = {0} ;
      CHAR szCollection [ DMS_COLLECTION_NAME_SZ + 1 ] = {0} ;

      existed = FALSE ;

      BSONObj csObj ;
      BOOLEAN csExist = FALSE ;

      const CHAR *domainName = NULL ;

      rc = catResolveCollectionName( clFullName, ossStrlen( clFullName ),
                                     szSpace, DMS_COLLECTION_SPACE_NAME_SZ,
                                     szCollection, DMS_COLLECTION_NAME_SZ ) ;
      PD_RC_CHECK( rc, PDERROR, "Resolve collection name[%s] failed, rc: %d",
                   clFullName, rc ) ;

      rc = catCheckSpaceExist( szSpace, csExist, csObj, cb ) ;
      PD_RC_CHECK( rc, PDWARNING, "Check collection space[%s] exist failed, "
                   "rc: %d", szSpace, rc ) ;
      PD_CHECK( csExist, SDB_DMS_CS_NOTEXIST, error, PDWARNING,
                "Collection space[%s] is not exist", szSpace ) ;

      rc = rtnGetStringElement( csObj, CAT_DOMAIN_NAME, &domainName ) ;
      if ( SDB_FIELD_NOT_EXIST == rc )
      {
         existed = TRUE ;
         rc = SDB_OK ;
         goto done ;
      }
      else if ( SDB_OK == rc )
      {
         BSONObj domainObj ;
         map<string, INT32> groups ;
         rc = catGetDomainObj( domainName, domainObj, cb ) ;
         PD_RC_CHECK( rc, PDERROR, "Get domain[%s] failed, rc: %d",
                      domainName, rc ) ;

         rc = catGetDomainGroups( domainObj,  groups ) ;
         PD_RC_CHECK( rc, PDERROR, "Failed to get groups from domain info[%s], "
                      "rc: %d", domainObj.toString().c_str(), rc ) ;

         if ( groups.find( groupName ) != groups.end() )
         {
            existed = TRUE ;
         }
      }

   done:
      return rc ;
   error:
      goto done ;
   }
Beispiel #19
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB__DMSSU_GETINDEX, "_dmsStorageUnit::getIndex" )
   INT32 _dmsStorageUnit::getIndex( const CHAR *pName,
                                    const CHAR *pIndexName,
                                    _monIndex &resultIndex,
                                    dmsMBContext *context )
   {
      INT32 rc                     = SDB_IXM_NOTEXIST ;
      BOOLEAN getContext           = FALSE ;
      UINT32 indexID               = 0 ;

      PD_TRACE_ENTRY ( SDB__DMSSU_GETINDEX ) ;
      SDB_ASSERT( pIndexName, "Index name can't be NULL" ) ;

      if ( NULL == context )
      {
         SDB_ASSERT( pName, "Collection name can't be NULL" ) ;

         rc = _pDataSu->getMBContext( &context, pName, SHARED ) ;
         PD_RC_CHECK( rc, PDERROR, "Get collection[%s] mb context failed, "
                      "rc: %d", pName, rc ) ;
         getContext = TRUE ;
      }
      else
      {
         rc = context->mbLock( SHARED ) ;
         PD_RC_CHECK( rc, PDERROR, "dms mb context lock failed, rc: %d", rc ) ;
      }

      for ( indexID = 0 ; indexID < DMS_COLLECTION_MAX_INDEX ; ++indexID )
      {
         if ( DMS_INVALID_EXTENT == context->mb()->_indexExtent[indexID] )
         {
            break ;
         }

         ixmIndexCB indexCB ( context->mb()->_indexExtent[indexID],
                              _pIndexSu, NULL ) ;
         if ( 0 == ossStrcmp( indexCB.getName(), pIndexName ) )
         {
            resultIndex._indexFlag = indexCB.getFlag () ;
            resultIndex._scanExtLID = indexCB.scanExtLID () ;
            resultIndex._version = indexCB.version () ;
            resultIndex._indexDef = indexCB.getDef().copy () ;

            rc = SDB_OK ;
            break ;
         }
      }

   done :
      if ( context && getContext )
      {
         _pDataSu->releaseMBContext( context ) ;
      }
      PD_TRACE_EXITRC ( SDB__DMSSU_GETINDEX, rc ) ;
      return rc ;
   error :
      goto done ;
   }
Beispiel #20
0
int _ossSocket::accept ( SOCKET *sock, struct sockaddr *addr, socklen_t *addrlen,
                        int timeout )
{
   int rc = EDB_OK ;
   int maxFD = (int)_fd ;
   struct timeval maxSelectTime ;

   fd_set fds ;
   maxSelectTime.tv_sec = timeout / 1000000 ;
   maxSelectTime.tv_usec = timeout % 1000000 ;
   while ( true )
   {
      FD_ZERO ( &fds ) ;
      FD_SET ( _fd, &fds ) ;
      rc = select ( maxFD + 1, &fds, NULL, NULL,
                    timeout>=0?&maxSelectTime:NULL ) ;

      // 0 means timeout
      if ( 0 == rc )
      {
         *sock = 0 ;
         rc = EDB_TIMEOUT ;
         goto done ;
      }
      // if < 0, means something wrong
      if ( 0 > rc )
      {
         rc = SOCKET_GETLASTERROR ;
         // if we failed due to interrupt, let's continue
         if ( OSS_EINTR == rc )
         {
            continue ;
         }
         PD_RC_CHECK ( EDB_NETWORK, PDERROR,
                       "Failed to select from socket, rc = %d",
                       SOCKET_GETLASTERROR);
      }

      // if the socket we interested is not receiving anything, let's continue
      if ( FD_ISSET ( _fd, &fds ) )
      {
         break ;
      }
   }
   rc = EDB_OK ;
   *sock = ::accept ( _fd, addr, addrlen );
   if ( -1 == *sock )
   {
      PD_RC_CHECK ( EDB_NETWORK, PDERROR,
                    "Failed to accept socket, rc = %d",
                    SOCKET_GETLASTERROR ) ;
   }
done :
   return rc ;
error :
   close () ;
   goto done ;
}
Beispiel #21
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB_DPSTRANSLOCK_ACQUIREIS, "dpsTransLock::acquireIS" )
   INT32 dpsTransLock::acquireIS( _pmdEDUCB *eduCB,
                                  const dpsTransLockId &lockId )
   {
      SDB_ASSERT( eduCB, "eduCB can't be null" ) ;
      SDB_ASSERT( ( DMS_INVALID_OFFSET == lockId._recordOffset
                  && DMS_INVALID_EXTENT == lockId._recordExtentID ),
                  "IX-Lock only used for collection or collectionspace" ) ;

      INT32 rc = SDB_OK;
      dpsLockBucket *pLockBucket = NULL;
      dpsTransLockId sLockId;
      dpsTransCBLockInfo *pLockInfo = NULL;
      BOOLEAN isISLocked = FALSE;

      if ( lockId._collectionID != DMS_INVALID_MBID )
      {
         sLockId._logicCSID = lockId._logicCSID;
         rc = acquireIS( eduCB, sLockId );
         PD_RC_CHECK( rc, PDERROR, "Failed to get the S-lock of space, "
                      "get IS-lock failed(rc=%d)", rc );
         isISLocked = TRUE;
      }

      pLockInfo = eduCB->getTransLock( lockId );
      if ( pLockInfo != NULL )
      {
         pLockInfo->incRef();
         goto done;
      }

      rc = getBucket( lockId, pLockBucket );
      PD_RC_CHECK( rc, PDERROR, "Failed to get the lock-bucket, "
                   "get IS-lock failed(rc=%d)", rc );

      {
      DPS_TRANS_WAIT_LOCK _transWaitLock( eduCB, lockId ) ;
      eduCB->addLockInfo( lockId, DPS_TRANSLOCK_IS );
      rc = pLockBucket->acquire( eduCB, lockId, DPS_TRANSLOCK_IS );
      }
      if ( rc )
      {
         eduCB->delLockInfo( lockId );
      }
      PD_RC_CHECK( rc, PDERROR, "Failed to get the IS-lock(rc=%d)", rc );

      PD_LOG( PDDEBUG, "Get the IS-lock(%s)", lockId.toString().c_str() );

   done:
      PD_TRACE_EXIT ( SDB_DPSTRANSLOCK_ACQUIREIS );
      return rc;
   error:
      if ( isISLocked )
      {
         release( eduCB, sLockId );
      }
      goto done;
   }
Beispiel #22
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB__DMSSU_GETSEGEXTENTS, "_dmsStorageUnit::getSegExtents" )
   INT32 _dmsStorageUnit::getSegExtents( const CHAR *pName,
                                         vector < dmsExtentID > &segExtents,
                                         dmsMBContext *context )
   {
      INT32 rc                     = SDB_OK ;
      BOOLEAN getContext           = FALSE ;
      dmsMBEx *mbEx                = NULL ;
      dmsExtentID firstID          = DMS_INVALID_EXTENT ;

      PD_TRACE_ENTRY ( SDB__DMSSU_GETSEGEXTENTS ) ;
      segExtents.clear() ;

      if ( NULL == context )
      {
         SDB_ASSERT( pName, "Collection name can't be NULL" ) ;

         rc = _pDataSu->getMBContext( &context, pName, SHARED ) ;
         PD_RC_CHECK( rc, PDERROR, "Get collection[%s] mb context failed, "
                      "rc: %d", pName, rc ) ;
         getContext = TRUE ;
      }
      else
      {
         rc = context->mbLock( SHARED ) ;
         PD_RC_CHECK( rc, PDERROR, "dms mb context lock failed, rc: %d", rc ) ;
      }

      if ( DMS_INVALID_EXTENT == context->mb()->_mbExExtentID ||
           NULL == ( mbEx = ( dmsMBEx* )_pDataSu->extentAddr(
           context->mb()->_mbExExtentID ) ) )
      {
         PD_LOG( PDERROR, "Invalid meta extent id: %d, collection name: %s",
                 context->mb()->_mbExExtentID,
                 context->mb()->_collectionName ) ;
         rc = SDB_SYS ;
         goto error ;
      }

      for ( UINT32 i = 0 ; i < mbEx->_header._segNum ; ++i )
      {
         mbEx->getFirstExtentID( i, firstID ) ;
         if ( DMS_INVALID_EXTENT != firstID )
         {
            segExtents.push_back( firstID ) ;
         }
      }

   done :
      if ( context && getContext )
      {
         _pDataSu->releaseMBContext( context ) ;
      }
      PD_TRACE_EXITRC ( SDB__DMSSU_GETSEGEXTENTS, rc ) ;
      return rc ;
   error :
      goto done ;
   }
Beispiel #23
0
int _ossSocket::recvNF(char *pMsg, int len, int timeout) {
    int rc = EDB_OK;
    int maxFD = _fd;
    struct timeval maxSelectTime;
    fd_set fds;

    if (len == 0) {
        return EDB_OK;
    }
    maxSelectTime.tv_sec = timeout / 1000000;
    maxSelectTime.tv_usec = timeout % 1000000;
    while (1) {
        FD_ZERO(&fds);
        FD_SET(_fd, &fds);
        rc = select(maxFD+1, &fds, NULL, NULL,
                    timeout>=0?&maxSelectTime:NULL);
        // 0 means timeout
        if (rc == 0) {
            rc = EDB_TIMEOUT;
            goto done;
        }
        if (rc < 0) {
            rc = SOCKET_GETLASTERROR;
            if (rc == EINTR) {
                continue;
            }
            PD_RC_CHECK(EDB_NETWORK, PDERROR, "Failed to select from socket, rc = %d", rc);
        }
        if (FD_ISSET(_fd, &fds)) {
            break;
        }
    }

    rc = ::recv(_fd, pMsg, len, MSG_NOSIGNAL);

    if (rc > 0) {
        len = rc;
    } else if (rc == 0) {
        PD_RC_CHECK(EDB_NETWORK, PDERROR, "Peer unexpected shutdown");
    } else {
        rc = SOCKET_GETLASTERROR;
        if ((rc == EAGAIN || rc == EWOULDBLOCK) && _timeout > 0) {
            PD_RC_CHECK(EDB_NETWORK, PDERROR, "Recv() timeout: rc = %d", rc);
        } else if (rc == EINTR) {
            // do nothing
        } else {
            PD_RC_CHECK(EDB_NETWORK, PDERROR, "Recv() Failed: rc = %d", rc);
        }
    }
    rc = EDB_OK;
done:
    return rc;
error:
    goto done;

}
 INT32 rtnCoordTransCommit::executeOnDataGroup( CHAR * pMsg,
                                                netMultiRouteAgent * pRouteAgent,
                                                pmdEDUCB * cb )
 {
    INT32 rc = SDB_OK;
    REQUESTID_MAP requestIdMap;
    REPLY_QUE replyQue;
    MsgHeader *pMsgHead = (MsgHeader *)pMsg;
    DpsTransNodeMap *pNodeMap = cb->getTransNodeLst();
    DpsTransNodeMap::iterator iterMap = pNodeMap->begin();
    while( iterMap != pNodeMap->end() )
    {
       rc = rtnCoordSendRequestToNode( (void *)pMsg, iterMap->second,
                                       pRouteAgent, cb, requestIdMap );
       if ( rc )
       {
          rtnCoordClearRequest( cb, requestIdMap );
       }
       PD_RC_CHECK( rc, PDERROR,
                   "failed to send the request to the node"
                   "(groupID=%u, nodeID=%u, rc=%d). ",
                   iterMap->second.columns.groupID,
                   iterMap->second.columns.nodeID,
                   rc );
       ++iterMap;
    }
    rc = rtnCoordGetReply( cb, requestIdMap, replyQue,
                           MAKE_REPLY_TYPE( pMsgHead->opCode ) ) ;
    PD_RC_CHECK( rc, PDERROR,
                "failed to get the reply(rc=%d)",
                rc );
    while ( !replyQue.empty() )
    {
       MsgOpReply *pReply = NULL;
       pReply = (MsgOpReply *)(replyQue.front());
       replyQue.pop();
       INT32 rcTmp = pReply->flags;
       if ( rcTmp != SDB_OK )
       {
          rc = rc ? rc : rcTmp;
          PD_LOG( PDERROR,
                "failed to execute on data node(rc=%d, groupID=%u, nodeID=%u)",
                rcTmp, pReply->header.routeID.columns.groupID,
                pReply->header.routeID.columns.nodeID );
       }
       SDB_OSS_FREE( pReply );
    }
    if ( rc )
    {
       goto error;
    }
 done:
    return rc;
 error:
    goto done;
 }
Beispiel #25
0
 INT32 aggrSortParser::buildOrderBy( const BSONElement &elem,
                                     qgmOPFieldVec &orderBy,
                                     _qgmPtrTable *pTable,
                                     const CHAR *pCLName )
 {
    INT32 rc = SDB_OK;
    try
    {
       BSONObj obj = elem.embeddedObject();
       BSONObjIterator iter( obj );
       while ( iter.more() )
       {
          BSONElement beField = iter.next();
          PD_CHECK( beField.isNumber(), SDB_INVALIDARG, error, PDERROR,
                   "type of sort-field must be number!" );
          {
             qgmField obValAttr;
             qgmField obValRelegation;
             rc = pTable->getOwnField( AGGR_CL_DEFAULT_ALIAS,
                                     obValRelegation );
             PD_RC_CHECK( rc, PDERROR, "failed to get the field(%s)",
                         AGGR_CL_DEFAULT_ALIAS );
             rc = pTable->getOwnField( beField.fieldName(), obValAttr );
             PD_RC_CHECK( rc, PDERROR, "failed to get the field(%s)",
                         beField.fieldName() );
             {
                qgmDbAttr obVal( obValRelegation, obValAttr );
                qgmField obAlias;
                qgmOpField obOpField;
                obOpField.value = obVal;
                obOpField.alias = obAlias;
                if ( beField.number() > 0 )
                {
                   obOpField.type = SQL_GRAMMAR::ASC;
                }
                else
                {
                   obOpField.type = SQL_GRAMMAR::DESC;
                }
                orderBy.push_back( obOpField );
             }
          }
       }
    }
    catch ( std::exception &e )
    {
       PD_CHECK( SDB_INVALIDARG, SDB_INVALIDARG, error, PDERROR,
                "failed to parse the \"sort\", received unexpected error:%s",
                e.what() );
    }
 done:
    return rc;
 error:
    goto done;
 }
Beispiel #26
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB_RTNCOINS_INSTOGROUP, "rtnCoordInsert::insertToAGroup" )
   INT32 rtnCoordInsert::insertToAGroup( CHAR *pBuffer,
                                         UINT32 grpID,
                                         netMultiRouteAgent *pRouteAgent,
                                         pmdEDUCB *cb )
   {
      INT32 rc = SDB_OK;
      PD_TRACE_ENTRY ( SDB_RTNCOINS_INSTOGROUP ) ;
      BOOLEAN isNeedRetry = FALSE;
      BOOLEAN hasRetry = FALSE;
      CoordGroupList groupLst;
      CoordGroupList successGroupLst;
      groupLst[grpID] = grpID;
      MsgHeader *pHead = (MsgHeader *)pBuffer ;

      if ( cb->isTransaction() )
      {
         pHead->opCode = MSG_BS_TRANS_INSERT_REQ;
      }
      do
      {
         hasRetry = isNeedRetry;
         isNeedRetry = FALSE;
         REQUESTID_MAP sendNodes;
         rc = rtnCoordSendRequestToNodeGroups( pBuffer, groupLst, TRUE,
                                               pRouteAgent, cb, sendNodes );
         if ( rc )
         {
            rtnCoordClearRequest( cb, sendNodes );
         }
         PD_RC_CHECK( rc, PDERROR, "Failed to insert on data-node, "
                      "send request failed(rc=%d)", rc ) ;

         REPLY_QUE replyQue;
         rc = rtnCoordGetReply( cb, sendNodes, replyQue,
                                MAKE_REPLY_TYPE( pHead->opCode ) );
         PD_RC_CHECK( rc, PDWARNING, "Failed to insert on data-node, "
                      "get reply failed(rc=%d)", rc );

         rc = processReply( replyQue, successGroupLst, cb );
         if ( SDB_CLS_NOT_PRIMARY == rc && !hasRetry )
         {
            isNeedRetry = TRUE;
            rc = SDB_OK;
         }
         PD_RC_CHECK( rc, PDWARNING, "Failed to process the reply(rc=%d)",
                      rc );
      } while ( isNeedRetry );

   done:
      PD_TRACE_EXITRC ( SDB_RTNCOINS_INSTOGROUP, rc ) ;
      return rc;
   error:
      goto done;
   }
Beispiel #27
0
   static INT32 _rtnParseQueryMeta( const BSONObj &meta, const CHAR *&scanType,
                                    const CHAR *&indexName, INT32 &indexLID,
                                    INT32 &direction, BSONObj &blockObj )
   {
      INT32 rc = SDB_OK ;
      BSONElement ele ;

      rc = rtnGetStringElement( meta, FIELD_NAME_SCANTYPE, &scanType ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to get field[%s], rc: %d",
                   FIELD_NAME_SCANTYPE, rc ) ;

      if ( 0 == ossStrcmp( scanType, VALUE_NAME_IXSCAN ) )
      {
         ele = meta.getField( FIELD_NAME_INDEXBLOCKS ) ;

         rc = rtnGetStringElement( meta, FIELD_NAME_INDEXNAME, &indexName ) ;
         PD_RC_CHECK( rc, PDERROR, "Failed to get field[%s], rc: %d",
                      FIELD_NAME_INDEXNAME, rc ) ;

         rc = rtnGetIntElement( meta, FIELD_NAME_INDEXLID, indexLID ) ;
         PD_RC_CHECK( rc, PDERROR, "Failed to get field[%s], rc: %d",
                      FIELD_NAME_INDEXLID, rc ) ;

         rc = rtnGetIntElement( meta, FIELD_NAME_DIRECTION, direction ) ;
         PD_RC_CHECK( rc, PDERROR, "Failed to get field[%s], rc: %d",
                      FIELD_NAME_DIRECTION, rc ) ;
      }
      else if ( 0 == ossStrcmp( scanType, VALUE_NAME_TBSCAN ) )
      {
         ele = meta.getField( FIELD_NAME_DATABLOCKS ) ;
      }
      else
      {
         PD_LOG( PDERROR, "Query meta[%s] scan type error",
                 meta.toString().c_str() ) ;
         rc = SDB_INVALIDARG ;
         goto error ;
      }

      if ( Array != ele.type() )
      {
         PD_LOG( PDERROR, "Block field[%s] type error",
                 ele.toString().c_str() ) ;
         rc = SDB_INVALIDARG ;
         goto error ;
      }
      blockObj = ele.embeddedObject() ;

   done:
      return rc ;
   error:
      goto done ;
   }
Beispiel #28
0
   INT32 catSplitCheckConflict( BSONObj & match, clsSplitTask & splitTask,
                                BOOLEAN & conflict, pmdEDUCB * cb )
   {
      INT32 rc = SDB_OK ;
      pmdKRCB *krcb = pmdGetKRCB() ;
      SDB_DMSCB *dmsCB = krcb->getDMSCB() ;
      SDB_RTNCB *rtnCB = krcb->getRTNCB() ;
      BSONObj dummyObj ;
      INT64 contextID = -1 ;

      rtnContextBuf buffObj ;
      INT64 startPos = 0 ;

      rc = rtnQuery( CAT_TASK_INFO_COLLECTION, dummyObj, match, dummyObj,
                     dummyObj, 0, cb, 0, -1, dmsCB, rtnCB, contextID ) ;
      PD_RC_CHECK ( rc, PDERROR, "Failed to perform query, rc = %d", rc ) ;

      while ( SDB_OK == rc )
      {
         rc = rtnGetMore( contextID, -1, buffObj, startPos, cb, rtnCB ) ;
         if ( rc )
         {
            if ( SDB_DMS_EOC == rc )
            {
               contextID = -1 ;
               rc = SDB_OK ;
               break ;
            }
            PD_LOG( PDERROR, "Failed to retreive record, rc = %d", rc ) ;
            goto error ;
         }

         rc = _checkSplitTaskConflict( &buffObj, conflict, &splitTask ) ;
         PD_RC_CHECK( rc, PDERROR, "Check split task conflict error, rc: %d",
                      rc ) ;

         if ( conflict )
         {
            break ;
         }
      }

   done:
      if ( -1 != contextID )
      {
         rtnCB->contextDelete ( contextID, cb ) ;
      }
      return rc ;
      return rc ;
   error:
      goto done ;
   }
Beispiel #29
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB_DPSTRANSLOCK_TESTX, "dpsTransLock::testX" )
   INT32 dpsTransLock::testX( _pmdEDUCB *eduCB, const dpsTransLockId &lockId )
   {
      SDB_ASSERT( eduCB, "eduCB can't be null" ) ;
      INT32 rc = SDB_OK;
      dpsLockBucket *pLockBucket = NULL;
      dpsTransLockId iLockId;
      dpsTransCBLockInfo *pLockInfo = NULL;

      pLockInfo = eduCB->getTransLock( lockId );
      if ( pLockInfo != NULL && pLockInfo->isLockMatch( DPS_TRANSLOCK_X ))
      {
         goto done;
      }

      if ( lockId._collectionID != DMS_INVALID_MBID )
      {
         iLockId = lockId ;
         if ( lockId._recordOffset != DMS_INVALID_OFFSET )
         {
            iLockId._recordExtentID = DMS_INVALID_EXTENT;
            iLockId._recordOffset = DMS_INVALID_OFFSET;
         }
         else
         {
            iLockId._collectionID = DMS_INVALID_MBID;
         }
         rc = testIX( eduCB, iLockId);
   
         PD_RC_CHECK( rc, PDINFO, "Failed to test the intention-lock, "
                      "test IX-lock failed(rc=%d)", rc );
      }

      if ( pLockInfo )
      {
         rc = testUpgrade( eduCB, lockId, pLockInfo, DPS_TRANSLOCK_X );
      }
      else
      {
         rc = getBucket( lockId, pLockBucket );
         PD_RC_CHECK( rc, PDERROR, "Failed to get the lock-bucket, "
                      "test X-lock failed(rc=%d)", rc );
         rc = pLockBucket->test( eduCB, lockId, DPS_TRANSLOCK_X );
      }
      PD_RC_CHECK( rc, PDINFO, "Failed to test the X-lock(rc=%d)", rc );

   done:
      PD_TRACE_EXIT ( SDB_DPSTRANSLOCK_TESTX );
      return rc;
   error:
      goto done;
   }
 // PD_TRACE_DECLARE_FUNCTION ( SDB_CLSCATAMATCHER_PARSECMPOP, "clsCatalogMatcher::parseCmpOp" )
 INT32 clsCatalogMatcher::parseCmpOp( const  BSONElement & beField,
                                      clsCatalogPredicateTree & predicateSet )
 {
    INT32 rc = SDB_OK;
    PD_TRACE_ENTRY ( SDB_CLSCATAMATCHER_PARSECMPOP ) ;
    const CHAR *pFieldName = NULL ;
    predicateSet.setLogicType( CLS_CATA_LOGIC_AND ) ;
    BSONObj boValue;
    try
    {
       pFieldName = beField.fieldName() ;
       BSONElement beTmp = _shardingKey.getField( pFieldName );
       if ( beTmp.eoo() )
       {
          // ignore the field which is not sharding-key
          goto done ;
       }
       if ( beField.type() == Object )
       {
          boValue = beField.embeddedObject() ;
          if ( isOpObj( boValue ))
          {
             BSONObjIterator i( boValue );
             while( i.more() )
             {
                BSONElement beTmp = i.next();
                rc = predicateSet.addPredicate( pFieldName, beTmp );
                PD_RC_CHECK( rc, PDERROR,
                            "failed to add predicate(rc=%d)", rc );
             }
             goto done;
          }
       }
       rc = predicateSet.addPredicate( pFieldName, beField );
       PD_RC_CHECK( rc, PDERROR,
                   "failed to add predicate(rc=%d)", rc );
    }
    catch ( std::exception &e )
    {
       rc = SDB_INVALIDARG;
       PD_RC_CHECK( rc, PDERROR,
                   "failed to parse the field "
                   "occured unexpected error:%s",
                   e.what() );
    }
 done:
    PD_TRACE_EXITRC ( SDB_CLSCATAMATCHER_PARSECMPOP, rc ) ;
    return rc;
 error:
    goto done;
 }