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 ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB__SDB_DMSCB_DUMPINFO, "_SDB_DMSCB::dumpInfo" ) void _SDB_DMSCB::dumpInfo ( std::set<monCollection> &collectionList, BOOLEAN sys ) { PD_TRACE_ENTRY ( SDB__SDB_DMSCB_DUMPINFO ); dmsStorageUnit *su = NULL ; ossScopedLock _lock(&_mutex, SHARED) ; #if defined (_WINDOWS) std::map<const CHAR*, dmsStorageUnitID, cmp_cscb>::const_iterator it ; #elif defined (_LINUX) std::map<const CHAR*, dmsStorageUnitID>::const_iterator it ; #endif for ( it = _cscbNameMap.begin(); it != _cscbNameMap.end(); it++ ) { su = NULL ; dmsStorageUnitID suID = (*it).second ; SDB_DMS_CSCB *cscb = _cscbVec[suID] ; if ( !cscb ) continue ; su = cscb->_su ; SDB_ASSERT ( su, "storage unit pointer can't be NULL" ) ; if ( ( !sys && dmsIsSysCSName(su->CSName()) ) || ( ossStrcmp ( su->CSName(), SDB_DMSTEMP_NAME ) == 0 ) ) { continue ; } su->dumpInfo ( collectionList, sys ) ; } // for ( it = _cscbNameMap.begin(); it != _cscbNameMap.end(); it++ ) PD_TRACE_EXIT ( SDB__SDB_DMSCB_DUMPINFO ); } // void dumpInfo
/* _pmdExternClient implement */ _pmdExternClient::_pmdExternClient( ossSocket *pSocket ) { SDB_ASSERT( pSocket, "Socket can't be NULL" ) ; _isAuthed = FALSE ; _pSocket = pSocket ; _pEDUCB = NULL ; _localPort = 0 ; _peerPort = 0 ; ossMemset( _localIP, 0, sizeof( _localIP ) ) ; ossMemset( _peerIP, 0, sizeof( _peerIP ) ) ; ossMemset( _fromIP, 0, sizeof( _fromIP ) ) ; ossMemset( _clientName, 0, sizeof( _clientName ) ) ; if ( pSocket ) { _localPort = pSocket->getLocalPort() ; _peerPort = pSocket->getPeerPort() ; pSocket->getLocalAddress( _localIP, PMD_IPADDR_LEN ) ; pSocket->getPeerAddress( _peerIP, PMD_IPADDR_LEN ) ; ossStrcpy( _fromIP, _peerIP ) ; #if defined ( SDB_ENGINE ) if ( 0 == ossStrcmp( _peerIP, "127.0.0.1" ) ) { ossIP2Str( _netFrame::getLocalAddress(), _fromIP, PMD_IPADDR_LEN ) ; } #endif // SDB_ENGINE } _makeName() ; }
BOOLEAN _pmdDMNProcInfo::isInit() { if ( ossStrcmp( szTag, PMDDMN_SHM_TAG ) == 0 ) { return TRUE ; } return FALSE ; }
// 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 ; }
bool operator<( const strContainner &right ) const { if ( !right._pStr ) { return false ; } else if ( !_pStr ) { return true ; } return ossStrcmp( _pStr, right._pStr ) < 0 ? true : false ; }
INT32 _qgmOptiAggregation::parse( const qgmOpField &field, BOOLEAN &isFunc, BOOLEAN needRele ) { PD_TRACE_ENTRY( SDB__QGMOPTIAGGREGATION_PARSE ) ; INT32 rc = SDB_OK ; _qgmAggrSelector selector ; if ( SQL_GRAMMAR::FUNC == field.type ) { rc = qgmFindFieldFromFunc( field.value.attr().begin(), field.value.attr().size(), selector.value.value.attr(), selector.param, _table, needRele ) ; if ( SDB_OK != rc ) { goto error ; } isFunc = TRUE ; CHAR *pFuncName = NULL; rc = utilStrToUpper( field.value.attr().begin(), pFuncName ) ; if ( SDB_OK != rc ) { goto error ; } if ( 0 != ossStrcmp( "MERGEARRAYSET", pFuncName ) ) { _hasAggrFunc = TRUE ; } } else { isFunc = FALSE ; selector.value.value = field.value ; } if ( !field.alias.empty() ) { selector.value.alias = field.alias ; } selector.value.type = field.type ; _selector.push_back( selector ) ; done: PD_TRACE_EXITRC( SDB__QGMOPTIAGGREGATION_PARSE, rc ) ; return rc ; error: goto done ; }
INT32 _ixmIndexCB::keyPatternOffset( const CHAR *key ) const { SDB_ASSERT ( _isInitialized, "index details must be initialized first" ) ; BSONObjIterator i ( keyPattern() ) ; INT32 n = 0 ; while ( i.more() ) { BSONElement e = i.next() ; if ( ossStrcmp ( key, e.fieldName() ) == 0 ) return n ; n++ ; } return -1 ; }
BOOLEAN _coordShardKicker::_isUpdateReplace( const BSONObj &updator ) { BSONObjIterator iter( updator ) ; while ( iter.more() ) { BSONElement beTmp = iter.next() ; if ( 0 == ossStrcmp( beTmp.fieldName(), CMD_ADMIN_PREFIX FIELD_OP_VALUE_REPLACE ) ) { return TRUE ; } } return FALSE ; }
INT32 utilBuildFullPath( const CHAR *path, const CHAR *name, UINT32 fullSize, CHAR *full ) { INT32 rc = SDB_OK ; if ( ossStrlen( path ) + ossStrlen( name ) + 2 > fullSize ) { rc = SDB_INVALIDARG ; goto error ; } ossMemset( full, 0, fullSize ); ossStrcpy( full, path ) ; if ( '\0' != path[0] && 0 != ossStrcmp(&path[ossStrlen(path)-1], OSS_FILE_SEP ) ) { ossStrncat( full, OSS_FILE_SEP, 1 ) ; } ossStrncat( full, name, ossStrlen( name ) ) ; done: return rc ; error: goto done ; }
INT32 ossEnumFiles( const string &dirPath, map< string, string > &mapFiles, const CHAR *filter, UINT32 deep ) { string newFilter ; OSS_MATCH_TYPE type = OSS_MATCH_NULL ; if ( !filter || filter[0] == 0 || 0 == ossStrcmp( filter, "*" ) ) { type = OSS_MATCH_NULL ; } else if ( filter[0] != '*' && filter[ ossStrlen( filter ) - 1 ] != '*' ) { type = OSS_MATCH_ALL ; newFilter = filter ; } else if ( filter[0] == '*' && filter[ ossStrlen( filter ) - 1 ] == '*' ) { type = OSS_MATCH_MID ; newFilter.assign( &filter[1], ossStrlen( filter ) - 2 ) ; } else if ( filter[0] == '*' ) { type = OSS_MATCH_RIGHT ; newFilter.assign( &filter[1], ossStrlen( filter ) - 1 ) ; } else { type = OSS_MATCH_LEFT ; newFilter.assign( filter, ossStrlen( filter ) -1 ) ; } return _ossEnumFiles( dirPath, mapFiles, newFilter.c_str(), newFilter.length(), type, deep ) ; }
INT32 _coordShardKicker::_kickShardingKey( const CoordCataInfoPtr &cataInfo, const BSONObj &updator, BSONObj &newUpdator, BOOLEAN &hasShardingKey ) { INT32 rc = SDB_OK ; UINT32 skSiteID = cataInfo->getShardingKeySiteID() ; if ( skSiteID > 0 ) { map< UINT32, BOOLEAN >::iterator it = _skSiteIDs.find( skSiteID ); if ( it != _skSiteIDs.end() ) { newUpdator = updator ; hasShardingKey = it->second ; goto done ; } } try { BSONObjBuilder bobNewUpdator( updator.objsize() ) ; BSONObj boShardingKey ; BSONObj subObj ; BOOLEAN isReplace = _isUpdateReplace( updator ) ; cataInfo->getShardingKey( boShardingKey ) ; BSONObjIterator iter( updator ) ; while ( iter.more() ) { BSONElement beTmp = iter.next() ; if ( beTmp.type() != Object ) { rc = SDB_INVALIDARG; PD_LOG( PDERROR, "updator's element must be an Object type:" "updator=%s", updator.toString().c_str() ) ; goto error ; } subObj = beTmp.embeddedObject() ; if ( isReplace && 0 == ossStrcmp( beTmp.fieldName(), CMD_ADMIN_PREFIX FIELD_OP_VALUE_KEEP ) ) { _addKeys( subObj ) ; continue ; } BSONObjBuilder subBuilder( bobNewUpdator.subobjStart( beTmp.fieldName() ) ) ; BSONObjIterator iterField( subObj ) ; while( iterField.more() ) { BSONElement beField = iterField.next() ; BSONObjIterator iterKey( boShardingKey ) ; BOOLEAN isKey = FALSE ; while( iterKey.more() ) { BSONElement beKey = iterKey.next(); const CHAR *pKey = beKey.fieldName(); const CHAR *pField = beField.fieldName(); while( *pKey == *pField && *pKey != '\0' ) { ++pKey ; ++pField ; } if ( *pKey == *pField || ( '\0' == *pKey && '.' == *pField ) || ( '.' == *pKey && '\0' == *pField ) ) { isKey = TRUE ; break ; } } if ( isKey ) { hasShardingKey = TRUE; } else { subBuilder.append( beField ) ; } } // while( iterField.more() ) subBuilder.done() ; } // while ( iter.more() ) if ( isReplace ) { UINT32 count = _addKeys( boShardingKey ) ; if ( count > 0 ) { hasShardingKey = TRUE ; } if ( !_setKeys.empty() ) { BSONObjBuilder keepBuilder( bobNewUpdator.subobjStart( CMD_ADMIN_PREFIX FIELD_OP_VALUE_KEEP ) ) ; SET_SHARDINGKEY::iterator itKey = _setKeys.begin() ; while( itKey != _setKeys.end() ) { keepBuilder.append( itKey->_pStr, (INT32)1 ) ; ++itKey ; } keepBuilder.done() ; } } // if ( isReplace ) newUpdator = bobNewUpdator.obj() ; } catch ( std::exception &e ) { rc = SDB_INVALIDARG; PD_LOG ( PDERROR,"Failed to kick sharding key from the record," "occured unexpected error: %s", e.what() ) ; goto error; } if ( skSiteID > 0 ) { _skSiteIDs.insert( pair< UINT32, BOOLEAN >( skSiteID, hasShardingKey ) ) ; } done: return rc; error: goto done; }
// PD_TRACE_DECLARE_FUNCTION ( SDB__SDB_DMSCB_DUMPINFO2, "_SDB_DMSCB::dumpInfo" ) void _SDB_DMSCB::dumpInfo ( std::set<monCollectionSpace> &csList, BOOLEAN sys ) { PD_TRACE_ENTRY ( SDB__SDB_DMSCB_DUMPINFO2 ); dmsStorageUnit *su = NULL ; INT64 totalDataFreeSize = 0 ; INT64 totalIndexFreeSize = 0 ; INT64 totalLobFreeSize = 0 ; ossScopedLock _lock(&_mutex, SHARED) ; #if defined (_WINDOWS) std::map<const CHAR*, dmsStorageUnitID, cmp_cscb>::const_iterator it ; #elif defined (_LINUX) std::map<const CHAR*, dmsStorageUnitID>::const_iterator it ; #endif for ( it = _cscbNameMap.begin(); it != _cscbNameMap.end(); it++ ) { dmsStorageUnitID suID = (*it).second ; SDB_DMS_CSCB *cscb = _cscbVec[suID] ; if ( !cscb ) { continue ; } su = cscb->_su ; SDB_ASSERT ( su, "storage unit pointer can't be NULL" ) ; if ( !sys && dmsIsSysCSName(cscb->_name) ) { continue ; } else if ( dmsIsSysCSName(cscb->_name) && 0 == ossStrcmp(cscb->_name, SDB_DMSTEMP_NAME ) ) { continue ; } monCollectionSpace cs ; dmsStorageUnitStat statInfo ; su->getStatInfo( statInfo ) ; totalDataFreeSize = su->totalFreeSize( DMS_SU_DATA ) + statInfo._totalDataFreeSpace ; totalIndexFreeSize = su->totalFreeSize( DMS_SU_INDEX ) + statInfo._totalIndexFreeSpace ; totalLobFreeSize = su->totalFreeSize( DMS_SU_LOB ) ; ossMemset ( cs._name, 0, sizeof(cs._name) ) ; ossStrncpy ( cs._name, cscb->_name, DMS_COLLECTION_SPACE_NAME_SZ); cs._pageSize = su->getPageSize() ; cs._lobPageSize = su->getLobPageSize() ; cs._totalSize = su->totalSize() ; cs._clNum = statInfo._clNum ; cs._totalRecordNum = statInfo._totalCount ; cs._freeSize = totalDataFreeSize + totalIndexFreeSize + totalLobFreeSize ; cs._totalDataSize = su->totalSize( DMS_SU_DATA ) ; cs._freeDataSize = totalDataFreeSize ; cs._totalIndexSize = su->totalSize( DMS_SU_INDEX ) ; cs._freeIndexSize = totalIndexFreeSize ; cs._totalLobSize = su->totalSize( DMS_SU_LOB ) ; cs._freeLobSize = totalLobFreeSize ; su->dumpInfo ( cs._collections, sys ) ; csList.insert ( cs ) ; } PD_TRACE_EXIT ( SDB__SDB_DMSCB_DUMPINFO2 ); }
INT32 _coordShardKicker::_checkShardingKey( const CoordCataInfoPtr &cataInfo, const BSONObj &updator, BOOLEAN &hasInclude ) { INT32 rc = SDB_OK ; UINT32 skSiteID = cataInfo->getShardingKeySiteID() ; if ( skSiteID > 0 ) { if ( _skSiteIDs.count( skSiteID ) > 0 ) { goto done ; } _skSiteIDs.insert( pair< UINT32, BOOLEAN >( skSiteID, TRUE ) ) ; } try { BSONObjBuilder bobNewUpdator( updator.objsize() ) ; BSONObj boShardingKey ; BSONObj subObj ; BOOLEAN isReplace = _isUpdateReplace( updator ) ; cataInfo->getShardingKey( boShardingKey ) ; BSONObjIterator iter( updator ) ; while ( iter.more() ) { BSONElement beTmp = iter.next() ; if ( beTmp.type() != Object ) { rc = SDB_INVALIDARG; PD_LOG( PDERROR, "updator's element must be an Object type:" "updator=%s", updator.toString().c_str() ) ; goto error ; } subObj = beTmp.embeddedObject() ; if ( isReplace && 0 == ossStrcmp( beTmp.fieldName(), CMD_ADMIN_PREFIX FIELD_OP_VALUE_KEEP ) ) { _addKeys( subObj ) ; continue ; } BSONObjIterator iterField( subObj ) ; while( iterField.more() ) { BSONElement beField = iterField.next() ; BSONObjIterator iterKey( boShardingKey ) ; BOOLEAN isKey = FALSE ; while( iterKey.more() ) { BSONElement beKey = iterKey.next() ; const CHAR *pKey = beKey.fieldName() ; const CHAR *pField = beField.fieldName() ; while( *pKey == *pField && *pKey != '\0' ) { ++pKey ; ++pField ; } if ( *pKey == *pField || ( '\0' == *pKey && '.' == *pField ) || ( '.' == *pKey && '\0' == *pField ) ) { isKey = TRUE ; break ; } } if ( isKey ) { hasInclude = TRUE ; goto done ; } } // while( iterField.more() ) } // while ( iter.more() ) if ( isReplace && _addKeys( boShardingKey ) > 0 ) { hasInclude = TRUE ; goto done ; } } catch ( std::exception &e ) { rc = SDB_INVALIDARG; PD_LOG ( PDERROR,"Failed to check the record is include sharding-key," "occured unexpected error: %s", e.what() ) ; goto error; } done: return rc; error: goto done; }
INT32 _rtnSQLFuncFactory::create( const CHAR *funcName, UINT32 paramNum, _rtnSQLFunc *&func ) { INT32 rc = SDB_OK ; CHAR *name = NULL ; rc = utilStrToUpper( funcName, name ) ; if ( SDB_OK != rc ) { goto error ; } if ( 0 == ossStrcmp("COUNT", name) && 1 == paramNum ) { func = SDB_OSS_NEW _rtnSQLCount() ; } else if ( 0 == ossStrcmp( "SUM", name ) && 1 == paramNum ) { func = SDB_OSS_NEW _rtnSQLSum() ; } else if ( 0 == ossStrcmp( "MIN", name ) && 1 == paramNum ) { func = SDB_OSS_NEW _rtnSQLMin() ; } else if ( 0 == ossStrcmp( "MAX", name) && 1 == paramNum ) { func = SDB_OSS_NEW _rtnSQLMax() ; } else if ( 0 == ossStrcmp( "AVG", name) && 1 == paramNum ) { func = SDB_OSS_NEW _rtnSQLAvg() ; } else if ( 0 == ossStrcmp( "FIRST", name ) && 1 == paramNum ) { func = SDB_OSS_NEW _rtnSQLFirst() ; } else if ( 0 == ossStrcmp( "LAST", name ) && 1 == paramNum ) { func = SDB_OSS_NEW rtnSQLLast() ; } else if ( 0 == ossStrcmp( "PUSH", name ) && 1 == paramNum ) { func = SDB_OSS_NEW rtnSQLPush() ; } else if ( 0 == ossStrcmp( "ADDTOSET", name ) && 1 == paramNum ) { func = SDB_OSS_NEW rtnSQLAddToSet() ; } else if ( 0 == ossStrcmp( "BUILDOBJ", name ) && paramNum > 0 ) { func = SDB_OSS_NEW rtnSQLBuildObj() ; } else if ( 0 == ossStrcmp( "MERGEARRAYSET", name ) && 1 == paramNum ) { func = SDB_OSS_NEW rtnSQLMergeArraySet() ; } else { rc = SDB_INVALIDARG ; goto error ; } if ( NULL == func ) { PD_LOG( PDERROR, "failed to allocated mem." ) ; rc = SDB_OOM ; goto error ; } done: if ( NULL != name ) { SDB_OSS_FREE( name ) ; name = NULL ; } return rc ; error: goto done ; }
bool operator()( const CHAR *a, const CHAR *b ) { return ossStrcmp( a, b ) < 0 ; }
BOOLEAN operator()( const CHAR *l, const CHAR *r )const { return ossStrcmp( l, r ) == 0 ; }
static INT32 _ossEnumFiles( const string &dirPath, map<string, string> &mapFiles, const CHAR *filter, UINT32 filterLen, OSS_MATCH_TYPE type, UINT32 deep ) { INT32 rc = SDB_OK ; const CHAR *pFind = NULL ; try { fs::path dbDir ( dirPath ) ; fs::directory_iterator end_iter ; if ( 0 == deep ) { goto done ; } if ( fs::exists ( dbDir ) && fs::is_directory ( dbDir ) ) { for ( fs::directory_iterator dir_iter ( dbDir ); dir_iter != end_iter; ++dir_iter ) { try { if ( fs::is_regular_file ( dir_iter->status() ) ) { const std::string fileName = dir_iter->path().filename().string() ; if ( ( OSS_MATCH_NULL == type ) || ( OSS_MATCH_LEFT == type && 0 == ossStrncmp( fileName.c_str(), filter, filterLen ) ) || ( OSS_MATCH_MID == type && ossStrstr( fileName.c_str(), filter ) ) || ( OSS_MATCH_RIGHT == type && ( pFind = ossStrstr( fileName.c_str(), filter ) ) && pFind[filterLen] == 0 ) || ( OSS_MATCH_ALL == type && 0 == ossStrcmp( fileName.c_str(), filter ) ) ) { mapFiles[ fileName ] = dir_iter->path().string() ; } } else if ( fs::is_directory( dir_iter->path() ) && deep > 1 ) { _ossEnumFiles( dir_iter->path().string(), mapFiles, filter, filterLen, type, deep - 1 ) ; } } catch( std::exception &e ) { PD_LOG( PDWARNING, "File or dir[%s] occur exception: %s", dir_iter->path().string().c_str(), e.what() ) ; } } } else { rc = SDB_INVALIDARG ; goto error ; } } catch( std::exception &e ) { PD_LOG( PDERROR, "Occur exception: %s", e.what() ) ; rc = SDB_SYS ; goto error ; } done: return rc ; error: goto done ; }
INT32 catSplitPrepare( const BSONObj &splitInfo, const CHAR *clFullName, clsCatalogSet *cataSet, INT32 &groupID, pmdEDUCB *cb ) { INT32 rc = SDB_OK ; BSONObj splitQuery ; BOOLEAN existQuery = TRUE ; FLOAT64 percent = 0.0 ; const CHAR* sourceName = NULL ; const CHAR* dstName = NULL ; groupID = CAT_INVALID_GROUPID ; BOOLEAN dstInCSDomain = FALSE ; rc = rtnGetObjElement( splitInfo, CAT_SPLITQUERY_NAME, splitQuery ) ; if ( SDB_FIELD_NOT_EXIST == rc ) { existQuery = FALSE ; rc = SDB_OK ; } PD_RC_CHECK( rc , PDERROR, "Failed to get field[%s], rc: %d", CAT_SPLITQUERY_NAME, rc ) ; percent = splitInfo.getField( CAT_SPLITPERCENT_NAME ).numberDouble() ; rc = rtnGetStringElement( splitInfo, CAT_SOURCE_NAME, &sourceName ) ; PD_RC_CHECK( rc, PDERROR, "Failed to get field[%s], rc: %d", CAT_SOURCE_NAME, rc ) ; rc = catGroupNameValidate( sourceName, FALSE ) ; PD_RC_CHECK( rc, PDERROR, "Source group name[%s] is not valid, rc: %d", sourceName, rc ) ; rc = rtnGetStringElement( splitInfo, CAT_TARGET_NAME, &dstName ) ; PD_RC_CHECK( rc, PDERROR, "Failed to get field[%s], rc: %d", CAT_TARGET_NAME, rc ) ; rc = catGroupNameValidate( dstName, FALSE ) ; PD_RC_CHECK( rc, PDERROR, "Target group name[%s] is not valid, rc: %d", dstName, rc ) ; PD_CHECK( 0 != ossStrcmp( dstName, sourceName ), SDB_INVALIDARG, error, PDERROR, "Target group name can not the same with source group" " name" ) ; rc = _checkDstGroupInCSDomain( dstName, clFullName, dstInCSDomain, cb ) ; PD_RC_CHECK( rc, PDWARNING, "Check destination group in collection space" "domain failed, rc: %d", rc ) ; PD_CHECK( dstInCSDomain, SDB_CAT_GROUP_NOT_IN_DOMAIN, error, PDWARNING, "Split target group[%s] is not in collection space domain", dstName ) ; if ( FALSE == existQuery ) { PD_CHECK( percent > 0.0 && percent <= 100.0, SDB_INVALIDARG, error, PDERROR, "Split percent value[%f] error", percent ) ; } rc = catGroupName2ID( sourceName, groupID, cb ) ; PD_RC_CHECK( rc, PDERROR, "Group name[%s] to id failed, rc: %d", sourceName, rc ) ; PD_CHECK( isGroupInCataSet( groupID, *cataSet ), SDB_CL_NOT_EXIST_ON_GROUP, error, PDWARNING, "The collection[%s] does not exist on source " "group[%s]", clFullName, sourceName ) ; done: return rc ; error: goto done ; }
INT32 catSplitReady( const BSONObj & splitInfo, const CHAR * clFullName, clsCatalogSet * cataSet, INT32 & groupID, clsTaskMgr &taskMgr, pmdEDUCB * cb, INT16 w, UINT64 *pTaskID ) { INT32 rc = SDB_OK ; BSONObj bKey ; BSONObj eKey ; BOOLEAN usePercent = FALSE ; FLOAT64 percent = 0.0 ; const CHAR* sourceName = NULL ; const CHAR* dstName = NULL ; groupID = CAT_INVALID_GROUPID ; INT32 sourceID = CAT_INVALID_GROUPID ; BOOLEAN dstInCSDomain = FALSE ; rc = rtnGetObjElement( splitInfo, CAT_SPLITVALUE_NAME, bKey ) ; if ( SDB_FIELD_NOT_EXIST == rc || ( SDB_OK == rc && bKey.isEmpty() ) ) { usePercent = TRUE ; rc = SDB_OK ; } PD_RC_CHECK( rc, PDERROR, "Failed to get field[%s], rc: %d", CAT_SPLITVALUE_NAME, rc ) ; percent = splitInfo.getField( CAT_SPLITPERCENT_NAME ).numberDouble() ; if ( !usePercent ) { rc = rtnGetObjElement( splitInfo, CAT_SPLITENDVALUE_NAME, eKey ) ; if ( SDB_FIELD_NOT_EXIST == rc ) { rc = SDB_OK ; } PD_RC_CHECK( rc, PDERROR, "Failed to get field[%s], rc: %d", CAT_SPLITENDVALUE_NAME, rc ) ; } else { PD_CHECK( percent > 0.0 && percent <= 100.0, SDB_INVALIDARG, error, PDERROR, "Split percent value[%f] error", percent ) ; PD_CHECK( cataSet->isHashSharding(), SDB_SYS, error, PDERROR, "Split by percent must be hash sharding" ) ; } rc = rtnGetStringElement( splitInfo, CAT_SOURCE_NAME, &sourceName ) ; PD_RC_CHECK( rc, PDERROR, "Failed to get field[%s], rc: %d", CAT_SOURCE_NAME, rc ) ; rc = catGroupNameValidate( sourceName, FALSE ) ; PD_RC_CHECK( rc, PDERROR, "Source group name[%s] is not valid, rc: %d", sourceName, rc ) ; rc = rtnGetStringElement( splitInfo, CAT_TARGET_NAME, &dstName ) ; PD_RC_CHECK( rc, PDERROR, "Failed to get field[%s], rc: %d", CAT_TARGET_NAME, rc ) ; rc = catGroupNameValidate( dstName, FALSE ) ; PD_RC_CHECK( rc, PDERROR, "Target group name[%s] is not valid, rc: %d", dstName, rc ) ; PD_CHECK( 0 != ossStrcmp( dstName, sourceName ), SDB_INVALIDARG, error, PDERROR, "Target group name can not the same with source group" " name" ) ; rc = _checkDstGroupInCSDomain( dstName, clFullName, dstInCSDomain, cb ) ; PD_RC_CHECK( rc, PDWARNING, "Check destination group in collection space" "domain failed, rc: %d", rc ) ; PD_CHECK( dstInCSDomain, SDB_CAT_GROUP_NOT_IN_DOMAIN, error, PDWARNING, "Split target group[%s] is not in collection space domain", dstName ) ; rc = catGroupName2ID( sourceName, sourceID, cb ) ; PD_RC_CHECK( rc, PDERROR, "Group name[%s] to id failed, rc: %d", sourceName, rc ) ; PD_CHECK( isGroupInCataSet( sourceID, *cataSet ), SDB_CL_NOT_EXIST_ON_GROUP, error, PDWARNING, "The collection[%s] does not exist on source " "group[%s]", clFullName, sourceName ) ; rc = catGroupName2ID( dstName, groupID, cb ) ; PD_RC_CHECK( rc, PDERROR, "Group name[%s] to id failed, rc: %d", dstName, rc ) ; if ( !usePercent ) { rc = _checkSplitKey( bKey, *cataSet, sourceID, FALSE, FALSE ) ; PD_RC_CHECK( rc, PDERROR, "Check split key failed, rc: %d", rc ) ; rc = _checkSplitKey( eKey, *cataSet, sourceID, TRUE, TRUE ) ; PD_RC_CHECK( rc, PDERROR, "Check split end key failed, rc: %d", rc ) ; } { BSONObj match ; BSONObj taskObj ; BOOLEAN conflict = FALSE ; clsSplitTask splitTask( taskMgr.getTaskID() ) ; if ( usePercent ) { rc = splitTask.calcHashPartition( *cataSet, sourceID, percent, bKey, eKey ) ; PD_RC_CHECK( rc, PDERROR, "Calc hash percent partition split key " "falied, rc: %d", rc ) ; } rc = splitTask.init( clFullName, sourceID, sourceName, groupID, dstName, bKey, eKey, percent, *cataSet ) ; PD_RC_CHECK( rc, PDERROR, "Init split task failed, rc: %d", rc ) ; match = splitTask.toBson( CLS_SPLIT_MASK_CLNAME ) ; rc = catSplitCheckConflict( match, splitTask, conflict, cb ) ; PD_RC_CHECK( rc, PDERROR, "Check task conflict failed, rc: %d", rc ) ; PD_CHECK( FALSE == conflict, SDB_CLS_MUTEX_TASK_EXIST, error, PDERROR, "Exist task not compatible with the new task" ) ; taskObj = splitTask.toBson( CLS_MASK_ALL ) ; rc = catAddTask( taskObj, cb, w ) ; PD_RC_CHECK( rc, PDERROR, "Add split task failed, rc: %d", rc ) ; if ( pTaskID ) { *pTaskID = splitTask.taskID() ; } } done: return rc ; error: goto done ; }
void _sptInvoker::_reportError( JSContext *cx, INT32 rc, const bson::BSONObj &detail ) { sdbSetErrno( rc ) ; if ( SDB_OK != rc ) { stringstream ss ; BSONObjIterator itr( detail) ; INT32 fieldNum = detail.nFields() ; INT32 count = 0 ; while ( itr.more() ) { if ( count > 0 ) { ss << ", " ; } BSONElement e = itr.next() ; if ( fieldNum > 1 || 0 != ossStrcmp( SPT_ERR, e.fieldName() ) ) { ss << e.fieldName() << ": " ; } if ( String == e.type() ) { ss << e.valuestr() ; } else if ( NumberInt == e.type() ) { ss << e.numberInt() ; } else if ( NumberLong == e.type() ) { ss << e.numberLong() ; } else if ( NumberDouble == e.type() ) { ss << e.numberDouble() ; } else if ( Bool == e.type() ) { ss << ( e.boolean() ? "true" : "false" ) ; } else { ss << e.toString( false, false ) ; } ++count ; } sdbSetErrMsg( ss.str().c_str() ) ; if ( sdbIsErrMsgEmpty() ) { sdbSetErrMsg( getErrDesp( rc ) ) ; } JS_SetPendingException( cx , INT_TO_JSVAL( rc ) ) ; } else { sdbSetErrMsg( NULL ) ; } return ; }
// PD_TRACE_DECLARE_FUNCTION ( COORD_GETINDEX_GENRESULT, "_coordCMDGetIndexes::generateResult" ) INT32 _coordCMDGetIndexes::generateResult( rtnContext *pContext, pmdEDUCB *cb ) { INT32 rc = SDB_OK ; PD_TRACE_ENTRY ( COORD_GETINDEX_GENRESULT ) ; CoordIndexMap indexMap ; rtnContextBuf buffObj ; while( TRUE ) { rc = pContext->getMore( 1, buffObj, cb ) ; if ( rc ) { if ( SDB_DMS_EOC == rc ) { rc = SDB_OK ; break ; } else { PD_LOG ( PDERROR, "Failed to get index data, rc: %d", rc ) ; goto error ; } } try { BSONObj boTmp( buffObj.data() ) ; BSONObj boIndexDef ; BSONElement ele ; string strIndexName ; CoordIndexMap::iterator iter ; ele = boTmp.getField( IXM_FIELD_NAME_INDEX_DEF ) ; PD_CHECK ( ele.type() == Object, SDB_INVALIDARG, error, PDERROR, "Failed to get the field(%s)", IXM_FIELD_NAME_INDEX_DEF ) ; boIndexDef = ele.embeddedObject() ; ele = boIndexDef.getField( IXM_NAME_FIELD ) ; PD_CHECK ( ele.type() == String, SDB_INVALIDARG, error, PDERROR, "Failed to get the field(%s)", IXM_NAME_FIELD ) ; strIndexName = ele.valuestr() ; iter = indexMap.find( strIndexName ) ; if ( indexMap.end() == iter ) { indexMap[ strIndexName ] = boTmp.getOwned() ; } else { BSONObjIterator newIter( boIndexDef ) ; BSONObj boOldDef ; ele = iter->second.getField( IXM_FIELD_NAME_INDEX_DEF ) ; PD_CHECK ( ele.type() == Object, SDB_INVALIDARG, error, PDERROR, "Failed to get the field(%s)", IXM_FIELD_NAME_INDEX_DEF ) ; boOldDef = ele.embeddedObject() ; BSONElement beTmp1, beTmp2 ; while( newIter.more() ) { beTmp1 = newIter.next() ; if ( 0 == ossStrcmp( beTmp1.fieldName(), "_id" ) ) { continue ; } beTmp2 = boOldDef.getField( beTmp1.fieldName() ) ; if ( 0 != beTmp1.woCompare( beTmp2 ) ) { PD_LOG( PDWARNING, "Corrupted index(name:%s, define1:%s, " "define2:%s)", strIndexName.c_str(), boIndexDef.toString().c_str(), boOldDef.toString().c_str() ) ; break ; } } } } catch ( std::exception &e ) { PD_RC_CHECK( rc, PDERROR, "Failed to get index, occured unexpected" "error:%s", e.what() ) ; } } { CoordIndexMap::iterator iterMap = indexMap.begin(); while( iterMap != indexMap.end() ) { rc = pContext->append( iterMap->second ) ; PD_RC_CHECK( rc, PDERROR, "Failed to get index, append the data " "failed(rc=%d)", rc ) ; ++iterMap ; } } done: PD_TRACE_EXITRC ( COORD_GETINDEX_GENRESULT, rc ) ; return rc ; error: goto done ; }