INT32 rtnSQLAddToSet::result( BSONObjBuilder &builder ) { INT32 rc = SDB_OK; PD_CHECK( !_alias.empty(), SDB_INVALIDARG, error, PDERROR, "no aliases for function!" ); try { builder.appendArray( _alias.toString(), _pArrBuilder->arr() ); SDB_OSS_DEL _pArrBuilder; _fieldSet.clear(); _objVec.clear(); _pArrBuilder = SDB_OSS_NEW BSONArrayBuilder(); PD_CHECK( _pArrBuilder != NULL, SDB_OOM, error, PDERROR, "malloc failed" ); } catch( std::exception &e ) { PD_LOG( PDERROR, "received unexpected error:%s", e.what() ); rc = SDB_SYS; goto error; } done: return rc; error: goto done; }
INT32 iPmdDMNChildProc::attachSHM( ossSHMKey shmKey ) { INT32 rc = SDB_OK; if ( NULL != _procInfo ) { goto done; } ossSHMFree( _shmMid, (CHAR **)(&_procInfo) ); _procInfo = ( pmdDMNProcInfo *)ossSHMAttach( shmKey, sizeof( pmdDMNProcInfo ), _shmMid ); #if defined (_LINUX) PD_CHECK( _procInfo != NULL && _shmMid >= 0, SDB_OOM, error, PDWARNING, "failed to get share-memory(key:%u)", shmKey ); #elif defined (_WINDOWS) PD_CHECK( _procInfo != NULL && _shmMid != 0, SDB_OOM, error, PDWARNING, "failed to get share-memory(key:%s)", shmKey ); #else rc = SDB_OOM; goto error; #endif _procInfo->init(); done: return rc; error: goto done; }
INT32 iPmdDMNChildProc::allocSHM( ossSHMKey shmKey ) { INT32 rc = SDB_OK; if ( _procInfo != NULL ) { goto done; } ossSHMFree( _shmMid, (CHAR **)(&_procInfo) ); _procInfo = ( pmdDMNProcInfo *)ossSHMAlloc( shmKey, sizeof( pmdDMNProcInfo ), OSS_SHM_CREATE, _shmMid ); #if defined (_LINUX) PD_CHECK( _procInfo != NULL && _shmMid >= 0, SDB_OOM, error, PDERROR, "failed to allocate share-memory(key:%u)", shmKey ); #elif defined (_WINDOWS) PD_CHECK( _procInfo != NULL && _shmMid != 0, SDB_OOM, error, PDERROR, "failed to allocate share-memory(key:%s)", shmKey ); #else rc = SDB_OOM; goto error; #endif _procInfo->init(); done: return rc; error: goto done; }
/* ** BIF interface */ BIF_RETTYPE get_0(BIF_ALIST_0) { Eterm ret; PD_CHECK(BIF_P->dictionary); ret = pd_hash_get_all(BIF_P, BIF_P->dictionary); PD_CHECK(BIF_P->dictionary); BIF_RET(ret); }
BIF_RETTYPE get_1(BIF_ALIST_1) { Eterm ret; PD_CHECK(BIF_P->dictionary); ret = erts_pd_hash_get(BIF_P, BIF_ARG_1); PD_CHECK(BIF_P->dictionary); BIF_RET(ret); }
BIF_RETTYPE erase_1(BIF_ALIST_1) { Eterm ret; PD_CHECK(BIF_P->dictionary); pd_hash_erase(BIF_P, BIF_ARG_1, &ret); PD_CHECK(BIF_P->dictionary); BIF_RET(ret); }
BIF_RETTYPE put_2(BIF_ALIST_2) { Eterm ret; PD_CHECK(BIF_P->dictionary); ret = pd_hash_put(BIF_P, BIF_ARG_1, BIF_ARG_2); PD_CHECK(BIF_P->dictionary); BIF_RET(ret); }
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; }
INT32 aggrSortParser::buildNode( const BSONElement &elem, const CHAR *pCLName, qgmOptiTreeNode *&pNode, _qgmPtrTable *pTable, _qgmParamTable *pParamTable ) { INT32 rc = SDB_OK; qgmOptiSelect *pSelect = SDB_OSS_NEW qgmOptiSelect( pTable, pParamTable ); PD_CHECK( pSelect!=NULL, SDB_OOM, error, PDERROR, "malloc failed!" ); PD_CHECK( elem.type()==Object, SDB_INVALIDARG, error, PDERROR, "failed to parse the parameter(%s),type must be number!", elem.fieldName() ); try { qgmOpField selectAll; rc = buildOrderBy( elem, pSelect->_orderby, pTable, pCLName ); PD_RC_CHECK( rc, PDERROR, "failed to build \"sort\" field(rc=%d)", rc ); selectAll.type = SQL_GRAMMAR::WILDCARD; pSelect->_selector.push_back( selectAll ); pSelect->_limit = -1; pSelect->_skip = 0; pSelect->_type = QGM_OPTI_TYPE_SELECT; pSelect->_hasFunc = FALSE; rc = pTable->getOwnField( AGGR_CL_DEFAULT_ALIAS, pSelect->_alias ); PD_RC_CHECK( rc, PDERROR, "failed to get the field(%s)", AGGR_CL_DEFAULT_ALIAS ); if ( pCLName != NULL ) { qgmField clValAttr; qgmField clValRelegation; rc = pTable->getOwnField( pCLName, clValAttr ); PD_RC_CHECK( rc, PDERROR, "failed to get the field(%s)", pCLName ); rc = pTable->getOwnField( AGGR_CL_DEFAULT_ALIAS, pSelect->_collection.alias ); PD_RC_CHECK( rc, PDERROR, "failed to get the field(%s)", AGGR_CL_DEFAULT_ALIAS ); pSelect->_collection.value = qgmDbAttr( clValRelegation, clValAttr ); pSelect->_collection.type = SQL_GRAMMAR::DBATTR; } } catch ( std::exception &e ) { PD_CHECK( SDB_INVALIDARG, SDB_INVALIDARG, error, PDERROR, "failed to parse the \"sort\", received unexpected error:%s", e.what() ); } pNode = pSelect; done: return rc; error: SAFE_OSS_DELETE( pSelect ); goto done; }
INT32 rtnCoordInsert::shardDataByGroup( const CoordCataInfoPtr &cataInfo, INT32 count, CHAR *pInsertor, pmdEDUCB *cb, GroupSubCLMap &groupSubCLMap ) { INT32 rc = SDB_OK; std::string subCLName ; while ( count > 0 ) { rc = shardAnObj( pInsertor, cataInfo, cb, groupSubCLMap ); PD_RC_CHECK( rc, PDERROR, "Failed to shard the obj(rc=%d)", rc ); try { BSONObj boInsertor( pInsertor ); pInsertor += ossRoundUpToMultipleX( boInsertor.objsize(), 4 ) ; --count ; } catch ( std::exception &e ) { PD_CHECK( FALSE, SDB_INVALIDARG, error, PDERROR, "Failed to parse the insert-obj, " "occur unexpected error:%s", e.what() ) ; } } done: return rc; error: groupSubCLMap.clear() ; goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB_RTNCOINS_SHARDANOBJ, "rtnCoordInsert::shardAnObj" ) INT32 rtnCoordInsert::shardAnObj( CHAR *pInsertor, const CoordCataInfoPtr &cataInfo, GroupObjsMap &groupObjsMap ) { INT32 rc = SDB_OK; PD_TRACE_ENTRY ( SDB_RTNCOINS_SHARDANOBJ ) ; try { BSONObj insertObj( pInsertor ); UINT32 groupID = 0; rc = cataInfo->getGroupByRecord( insertObj, groupID ); PD_RC_CHECK( rc, PDERROR, "Failed to get the group(rc=%d)", rc ); groupObjsMap[ groupID ].push_back( pInsertor ) ; } catch ( std::exception &e ) { PD_CHECK( FALSE, SDB_INVALIDARG, error, PDERROR, "Failed to shard the data, received unexpected error:%s", e.what() ); } done: PD_TRACE_EXITRC ( SDB_RTNCOINS_SHARDANOBJ, rc ) ; return rc; error: goto done; }
// PD_TRACE_DECLARE_FUNCTION ( SDB_RTNCOINS_SHARDDBGROUP, "rtnCoordInsert::shardDataByGroup" ) INT32 rtnCoordInsert::shardDataByGroup( const CoordCataInfoPtr &cataInfo, INT32 count, CHAR *pInsertor, GroupObjsMap &groupObjsMap ) { INT32 rc = SDB_OK; PD_TRACE_ENTRY ( SDB_RTNCOINS_SHARDDBGROUP ) ; while ( count > 0 ) { rc = shardAnObj( pInsertor, cataInfo, groupObjsMap ); PD_RC_CHECK( rc, PDERROR, "Failed to shard the obj(rc=%d)", rc ); BSONObj boInsertor ; try { boInsertor = BSONObj( pInsertor ); } catch ( std::exception &e ) { PD_CHECK( FALSE, SDB_INVALIDARG, error, PDERROR, "Failed to parse the insert-obj:%s", e.what() ) ; } --count ; pInsertor += ossRoundUpToMultipleX( boInsertor.objsize(), 4 ) ; } done: PD_TRACE_EXITRC ( SDB_RTNCOINS_SHARDDBGROUP, rc ) ; return rc; error: groupObjsMap.clear() ; goto done ; }
// 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; }
// PD_TRACE_DECLARE_FUNCTION ( SDB_RTNCOQUERY_GETNODEGROUPS, "rtnCoordQuery::getNodeGroups" ) INT32 rtnCoordQuery::getNodeGroups( const CoordCataInfoPtr &cataInfo, BSONObj &queryObj, const CoordGroupList &sendGroupLst, CoordGroupList &groupLst ) { INT32 rc = SDB_OK; PD_TRACE_ENTRY ( SDB_RTNCOQUERY_GETNODEGROUPS ) ; cataInfo->getGroupByMatcher( queryObj, groupLst ) ; PD_CHECK( groupLst.size() > 0, SDB_CAT_NO_MATCH_CATALOG, error, PDERROR, "failed to get match groups" ); { CoordGroupList::const_iterator iterList = sendGroupLst.begin(); while( iterList != sendGroupLst.end() ) { groupLst.erase( iterList->first ); ++iterList; } } done: PD_TRACE_EXITRC ( SDB_RTNCOQUERY_GETNODEGROUPS, rc ) ; return rc; error: goto done; }
/* * Called from process_info/1,2. */ Eterm erts_dictionary_copy(Process *p, ProcDict *pd) { Eterm* hp; Eterm* heap_start; Eterm res = NIL; Eterm tmp, tmp2; unsigned int i, num; if (pd == NULL) { return res; } PD_CHECK(pd); num = HASH_RANGE(pd); heap_start = hp = (Eterm *) erts_alloc(ERTS_ALC_T_TMP, sizeof(Eterm) * pd->numElements * 2); for (i = 0; i < num; ++i) { tmp = ARRAY_GET(pd, i); if (is_boxed(tmp)) { ASSERT(is_tuple(tmp)); res = CONS(hp, tmp, res); hp += 2; } else if (is_list(tmp)) { while (tmp != NIL) { tmp2 = TCAR(tmp); res = CONS(hp, tmp2, res); hp += 2; tmp = TCDR(tmp); } } } res = copy_object(res, p); erts_free(ERTS_ALC_T_TMP, (void *) heap_start); return res; }
// PD_TRACE_DECLARE_FUNCTION ( SDB_OSSSK_DISNAG, "ossSocket::disableNagle" ) INT32 _ossSocket::disableNagle () { INT32 rc = SDB_OK ; PD_TRACE_ENTRY ( SDB_OSSSK_DISNAG ); INT32 temp = 1 ; SDB_ASSERT ( _init, "socket is not initialized" ) ; PD_CHECK( _init, SDB_SYS, error, PDWARNING, "Socket is not init" ) ; rc = setsockopt ( _fd, IPPROTO_TCP, TCP_NODELAY, (CHAR *) &temp, sizeof ( INT32 ) ) ; if ( rc ) { PD_LOG ( PDWARNING, "Failed to setsockopt, rc = %d", SOCKET_GETLASTERROR ) ; } rc = setsockopt ( _fd, SOL_SOCKET, SO_KEEPALIVE, (CHAR *) &temp, sizeof ( INT32 ) ) ; if ( rc ) { PD_LOG ( PDWARNING, "Failed to setsockopt, rc = %d", SOCKET_GETLASTERROR ) ; } done: PD_TRACE_EXITRC ( SDB_OSSSK_DISNAG, rc ); return rc ; error: goto done ; }
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 ; }
INT32 rtnCoordInsert::buildInsertMsg( CHAR *pHeadRemain, INT32 remainLen, const GroupObjsMap &groupObjsMap, void *pFiller, GroupInsertMsgMap &groupMsgMap ) { INT32 rc = SDB_OK; GroupObjsMap::const_iterator iterGroup = groupObjsMap.begin(); while( iterGroup != groupObjsMap.end() ) { UINT32 i = 0; UINT32 groupID = iterGroup->first; groupMsgMap[groupID].dataList.clear(); groupMsgMap[groupID].dataLen = 0; netIOV ioHead; ioHead.iovBase = (void *)pHeadRemain; ioHead.iovLen = remainLen; groupMsgMap[groupID].dataList.push_back( ioHead ); for( ; i < iterGroup->second.size(); i++ ) { try { BSONObj boInsertor( (iterGroup->second)[i] ); netIOV ioObj; ioObj.iovBase = (iterGroup->second)[i] ; ioObj.iovLen = boInsertor.objsize(); groupMsgMap[groupID].dataList.push_back( ioObj ); SINT32 usedLen = ossRoundUpToMultipleX( boInsertor.objsize(), 4 ); SINT32 fillLen = usedLen - boInsertor.objsize(); if ( fillLen > 0 ) { netIOV ioFiller; ioFiller.iovBase = pFiller; ioFiller.iovLen = fillLen; groupMsgMap[groupID].dataList.push_back( ioFiller ); } groupMsgMap[groupID].dataLen += usedLen; } catch( std::exception &e ) { PD_CHECK( FALSE, SDB_INVALIDARG, error, PDERROR, "Failed to build insert-message, " "occur unexpected error:%s", e.what() ); } } ++iterGroup ; } done: return rc; error: groupMsgMap.clear() ; goto done; }
INT32 _sptContainer::_loadObj( _sptScope * pScope ) { INT32 rc = SDB_OK ; if ( _loadMask & SPT_OBJ_MASK_STANDARD ) { if ( !InitDbClasses( ((sptSPScope *)pScope)->getContext(), ((sptSPScope *)pScope)->getGlobalObj() ) ) { PD_LOG( PDERROR, "Failed to init dbclass" ) ; rc = SDB_SYS ; goto error ; } } if ( _loadMask & SPT_OBJ_MASK_USR ) { rc = pScope->loadUsrDefObj<_sptUsrSsh>() ; PD_CHECK ( SDB_OK == rc, SDB_SYS, error, PDERROR, "Failed to load class _sptUsrSsh, rc = %d", rc ) ; rc = pScope->loadUsrDefObj<_sptUsrCmd>() ; PD_CHECK ( SDB_OK == rc, SDB_SYS, error, PDERROR, "Failed to load class _sptUsrCmd, rc = %d", rc ) ; rc = pScope->loadUsrDefObj<_sptUsrFile>() ; PD_CHECK ( SDB_OK == rc, SDB_SYS, error, PDERROR, "Failed to load class _sptUsrFile, rc = %d", rc ) ; rc = pScope->loadUsrDefObj<_sptUsrSystem>() ; PD_CHECK ( SDB_OK == rc, SDB_SYS, error, PDERROR, "Failed to load class _sptUsrSystem, rc = %d", rc ) ; rc = pScope->loadUsrDefObj<_sptUsrOma>() ; PD_CHECK ( SDB_OK == rc, SDB_SYS, error, PDERROR, "Failed to load class _sptUsrOma, rc = %d", rc ) ; rc = pScope->loadUsrDefObj<_sptUsrHash>() ; PD_CHECK ( SDB_OK == rc, SDB_SYS, error, PDERROR, "Failed to load class _sptUsrHash, rc = %d", rc ) ; rc = pScope->loadUsrDefObj<_sptUsrSdbTool>() ; PD_CHECK ( SDB_OK == rc, SDB_SYS, error, PDERROR, "Failed to load class _sptUsrSdbTool, rc = %d", rc ) ; } if ( _loadMask & SPT_OBJ_MASK_INNER_JS ) { rc = evalInitScripts2( pScope ) ; PD_CHECK ( SDB_OK == rc, SDB_SYS, error, PDERROR, "Failed to init spt scope, rc = %d", rc ) ; } done: return rc ; error: goto done ; }
INT32 _rtnIXScanner::relocateRID ( const BSONObj &keyObj, const dmsRecordID &rid ) { INT32 rc = SDB_OK ; PD_TRACE_ENTRY ( SDB__RTNIXSCAN_RELORID1 ) ; PD_CHECK ( _indexCB, SDB_OOM, error, PDERROR, "Failed to allocate memory for indexCB" ) ; // sanity check, make sure we are on valid index PD_CHECK ( _indexCB->isInitialized(), SDB_RTN_INDEX_NOTEXIST, error, PDERROR, "Index does not exist" ) ; PD_CHECK ( _indexCB->getFlag() == IXM_INDEX_FLAG_NORMAL, SDB_IXM_UNEXPECTED_STATUS, error, PDERROR, "Unexpected index status: %d", _indexCB->getFlag() ) ; { monAppCB * pMonAppCB = _cb ? _cb->getMonAppCB() : NULL ; // get root dmsExtentID rootExtent = _indexCB->getRoot() ; ixmExtent root ( rootExtent, _su->index() ) ; BOOLEAN found = FALSE ; // locate the new key, the returned RID is stored in _curIndexRID rc = root.locate ( keyObj, rid, _order, _curIndexRID, found, _direction, _indexCB ) ; PD_RC_CHECK ( rc, PDERROR, "Failed to locate from new keyobj and rid: %s, %d,%d", keyObj.toString().c_str(), rid._extent, rid._offset ) ; _savedObj = keyObj.copy() ; _savedRID = rid ; DMS_MON_OP_COUNT_INC( pMonAppCB, MON_INDEX_READ, 1 ) ; DMS_MON_CONTEXT_COUNT_INC ( _pMonCtxCB, MON_INDEX_READ, 1 ) ; } // mark _init to true so that advance won't call keyLocate again _init = TRUE ; done : PD_TRACE_EXITRC ( SDB__RTNIXSCAN_RELORID1, rc ) ; return rc ; error : goto done ; }
INT32 rtnCoordInsert::shardAnObj( CHAR *pInsertor, const CoordCataInfoPtr &cataInfo, pmdEDUCB * cb, GroupSubCLMap &groupSubCLMap ) { INT32 rc = SDB_OK; std::string subCLName ; UINT32 groupID = CAT_INVALID_GROUPID; try { BSONObj insertObj( pInsertor ) ; CoordCataInfoPtr subClCataInfo; rc = cataInfo->getSubCLNameByRecord( insertObj, subCLName ) ; PD_CHECK( SDB_OK == rc, SDB_CLS_COORD_NODE_CAT_VER_OLD, error, PDWARNING, "couldn't find the match sub-collection(rc=%d)", rc ) ; rc = rtnCoordGetCataInfo( cb, subCLName.c_str(), FALSE, subClCataInfo ); PD_CHECK( SDB_OK == rc, SDB_CLS_COORD_NODE_CAT_VER_OLD, error, PDWARNING, "failed to get catalog of sub-collection(%s)", subCLName.c_str() ); rc = subClCataInfo->getGroupByRecord( insertObj, groupID ); PD_CHECK( SDB_OK == rc, SDB_CLS_COORD_NODE_CAT_VER_OLD, error, PDWARNING, "couldn't find the match catalog of " "sub-collection(%s)", subCLName.c_str() ); (groupSubCLMap[ groupID ])[ subCLName ].push_back( pInsertor ); } catch ( std::exception &e ) { PD_CHECK( FALSE, SDB_INVALIDARG, error, PDERROR, "Failed to shard the data, occur unexpected error:%s", e.what() ); } done: return rc ; error: goto done ; }
//PD_TRACE_DECLARE_FUNCTION ( SDB_DPSTRANSLOCK_RELEASE, "dpsTransLock::release" ) void dpsTransLock::release( _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; INT64 lockRef = 0; pLockInfo = eduCB->getTransLock( lockId ); PD_CHECK( pLockInfo, SDB_OK, done, PDWARNING, "duplicate release lock(%s)", lockId.toString().c_str() ) ; lockRef = pLockInfo->decRef(); if ( lockRef <= 0 ) { rc = getBucket( lockId, pLockBucket ); if ( rc ) { PD_LOG( PDWARNING, "Failed to get lock-bucket while release " "lock(rc=%d)", rc ); } else { pLockBucket->release( eduCB, lockId ); } eduCB->delLockInfo( lockId ); pLockInfo = NULL; } if ( lockId._collectionID != DMS_INVALID_MBID ) { iLockId = lockId; if ( lockId._recordOffset != DMS_INVALID_OFFSET ) { iLockId._recordExtentID = DMS_INVALID_EXTENT; iLockId._recordOffset = DMS_INVALID_OFFSET; release( eduCB, iLockId ); } else { iLockId._collectionID = DMS_INVALID_MBID; release( eduCB, iLockId ); } } done: PD_TRACE_EXIT ( SDB_DPSTRANSLOCK_RELEASE ); return ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB_OSSSK_SETTMOUT, "ossSocket::setTimeout" ) INT32 _ossSocket::setTimeout ( INT32 milliSeconds ) { INT32 rc = SDB_OK ; PD_TRACE_ENTRY ( SDB_OSSSK_SETTMOUT ); SDB_ASSERT ( _init, "socket is not initialized" ) ; struct timeval tv ; PD_CHECK( _init, SDB_SYS, error, PDWARNING, "Socket is not init" ) ; tv.tv_sec = milliSeconds / 1000 ; tv.tv_usec = ( milliSeconds % 1000 ) * 1000 ; #if defined (_WINDOWS) tv.tv_sec = milliSeconds ; rc = setsockopt ( _fd, SOL_SOCKET, SO_RCVTIMEO, ( char* ) &tv.tv_sec, sizeof ( INT32 ) ) ; if ( SOCKET_ERROR == rc ) { PD_LOG ( PDWARNING, "Failed to setsockopt, rc = %d", SOCKET_GETLASTERROR ) ; } rc = setsockopt ( _fd, SOL_SOCKET, SO_SNDTIMEO, ( char* ) &tv.tv_sec, sizeof ( INT32 ) ) ; if ( SOCKET_ERROR == rc ) { PD_LOG ( PDWARNING, "Failed to setsockopt, rc = %d", SOCKET_GETLASTERROR ) ; } #else rc = setsockopt ( _fd, SOL_SOCKET, SO_RCVTIMEO, ( char* ) &tv, sizeof ( tv ) ) ; if ( rc ) { PD_LOG ( PDWARNING, "Failed to setsockopt, rc = %d", SOCKET_GETLASTERROR ) ; } rc = setsockopt ( _fd, SOL_SOCKET, SO_SNDTIMEO, ( char* ) &tv, sizeof ( tv ) ) ; if ( rc ) { PD_LOG ( PDWARNING, "Failed to setsockopt, rc = %d", SOCKET_GETLASTERROR ) ; } #endif done: PD_TRACE_EXITRC ( SDB_OSSSK_SETTMOUT, rc ); return rc ; error: goto done ; }
INT32 rtnCoord2PhaseCommit::execute( CHAR * pReceiveBuffer, SINT32 packSize, CHAR * * ppResultBuffer, pmdEDUCB * cb, MsgOpReply & replyHeader, BSONObj **ppErrorObj ) { INT32 rc = SDB_OK; INT32 rcTmp = SDB_OK; MsgHeader *pHeader = (MsgHeader *)pReceiveBuffer; replyHeader.header.messageLength = sizeof( MsgOpReply ); replyHeader.header.opCode = MSG_BS_TRANS_COMMIT_RSP; replyHeader.header.requestID = pHeader->requestID; replyHeader.header.routeID.value = 0; replyHeader.header.TID = pHeader->TID; replyHeader.contextID = -1; replyHeader.flags = SDB_OK; replyHeader.numReturned = 0; replyHeader.startFrom = 0; if ( !cb->isTransaction() ) { rc = SDB_DPS_TRANS_NO_TRANS; goto error; } rc = doPhase1( pReceiveBuffer, packSize, ppResultBuffer, cb, replyHeader ); PD_CHECK( SDB_OK == rc, rc, errorcancel, PDERROR, "execute failed on phase1(rc=%d)", rc ); rc = doPhase2( pReceiveBuffer, packSize, ppResultBuffer, cb, replyHeader ); PD_RC_CHECK( rc, PDERROR, "execute failed on phase2(rc=%d)", rc ); done: return rc; errorcancel: rcTmp = cancelOp( pReceiveBuffer, packSize, ppResultBuffer, cb, replyHeader ); if ( rcTmp ) { PD_LOG ( PDERROR, "failed to cancel the operate(rc=%d)", rcTmp ); } error: replyHeader.flags = rc; goto done; }
// PD_TRACE_DECLARE_FUNCTION ( SDB_OSSSK_BIND_LSTN, "ossSocket::bind_listen" ) INT32 _ossSocket::bind_listen () { INT32 rc = SDB_OK ; PD_TRACE_ENTRY ( SDB_OSSSK_BIND_LSTN ); INT32 temp = 1 ; SDB_ASSERT ( _init, "socket is not initialized" ) ; PD_CHECK( _init, SDB_SYS, error, PDWARNING, "Socket is not init" ) ; rc = setsockopt ( _fd, SOL_SOCKET, SO_REUSEADDR, (char*)&temp, sizeof (INT32) ) ; 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_LOG ( PDERROR, "Failed to bind socket, rc = %d", SOCKET_GETLASTERROR ) ; rc = SDB_NETWORK ; goto error ; } rc = listen ( _fd, SOMAXCONN ) ; if ( rc ) { PD_LOG ( PDERROR, "Failed to listen socket, rc = %d", SOCKET_GETLASTERROR ) ; rc = SDB_NETWORK ; goto error ; } done : PD_TRACE_EXITRC ( SDB_OSSSK_BIND_LSTN, rc ); return rc ; error : close () ; goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB_NETMLTRTAGT_HNDMSG, "netMultiRouteAgent::handleMsg" ) INT32 netMultiRouteAgent::handleMsg( const NET_HANDLE &handle, const _MsgHeader *header, const CHAR *msg ) { INT32 rc = SDB_OK; PD_TRACE_ENTRY ( SDB_NETMLTRTAGT_HNDMSG ); CHAR *pMsgRsp = (CHAR *)SDB_OSS_MALLOC( header->messageLength ); PD_CHECK( pMsgRsp, SDB_OOM, error, PDERROR, "Memory malloc failed(size = %d)", header->messageLength ) ; ossMemcpy( pMsgRsp, msg, header->messageLength ); { ossScopedLock _lock( &_mutex, SHARED ) ; COORD_SESSION_MAP::iterator it = _sessionMap.find( header->TID ); if ( _sessionMap.end() != it ) { it->second->postEvent( pmdEDUEvent( PMD_EDU_EVENT_MSG, PMD_EDU_MEM_ALLOC, pMsgRsp ) ) ; } else { PD_LOG( PDWARNING, "Recieve expired msg[opCode:[%d]%d, TID:%d," "ReqID:%lld] from node[%d:%d:%d]", IS_REPLY_TYPE( header->opCode ), GET_REQUEST_TYPE( header->opCode ), header->TID, header->requestID, header->routeID.columns.groupID, header->routeID.columns.nodeID, header->routeID.columns.serviceID ) ; rc = SDB_SYS ; goto error ; } } done: PD_TRACE_EXITRC ( SDB_NETMLTRTAGT_HNDMSG, rc ); return rc ; error: if ( pMsgRsp ) { SDB_OSS_FREE( pMsgRsp ) ; } goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB_DPSTRANSLOCK_WAIT, "dpsTransLock::wait" ) INT32 dpsTransLock::wait( _pmdEDUCB *eduCB, const dpsTransLockId &lockId ) { INT32 rc = SDB_OK; dpsLockBucket *pLockBucket = NULL; rc = getBucket( lockId, pLockBucket ); PD_CHECK( SDB_OK == rc, rc, error, PDERROR, "Failed to get the lock-bucket, get X-lock failed(rc=%d)", rc ); rc = pLockBucket->waitLockX( eduCB, lockId ); PD_RC_CHECK( rc, PDERROR, "Wait lock failed(rc=%d)", rc ); done: PD_TRACE_EXIT ( SDB_DPSTRANSLOCK_WAIT ); return rc; error: goto done; }
INT32 iPmdDMNChildProc::attachSHM() { INT32 rc = SDB_OK; #if defined ( _WINDOWS ) PD_CHECK( _shmKey != NULL, SDB_OOM, error, PDERROR, "failed to get key because of malloc failed!" ); #endif rc = attachSHM( _shmKey ); #if defined ( _WINDOWS ) done: return rc; error: goto done; #else return rc; #endif }
INT32 catSplitCleanup( const BSONObj & splitInfo, pmdEDUCB * cb, INT16 w ) { INT32 rc = SDB_OK ; UINT64 taskID = 0 ; INT32 status = CLS_TASK_STATUS_READY ; BSONElement ele = splitInfo.getField( CAT_TASKID_NAME ) ; PD_CHECK( ele.isNumber(), SDB_INVALIDARG, error, PDERROR, "Failed to get field[%s], type: %d", CAT_TASKID_NAME, ele.type() ) ; taskID = ( UINT64 )ele.numberLong() ; rc = catGetTaskStatus( taskID, status, cb ) ; if ( rc ) { goto error ; } if ( CLS_TASK_STATUS_META == status ) { rc = catUpdateTaskStatus( taskID, CLS_TASK_STATUS_FINISH, cb, w ) ; if ( rc ) { goto error ; } } else if ( CLS_TASK_STATUS_FINISH == status ) { } else { PD_LOG( PDERROR, "Task[%ll] status error in clean up step", taskID, status ) ; rc = SDB_SYS ; goto error ; } done: return rc ; error: goto done ; }
INT32 catSplitFinish( const BSONObj & splitInfo, pmdEDUCB * cb, INT16 w ) { INT32 rc = SDB_OK ; UINT64 taskID = 0 ; BSONElement ele = splitInfo.getField( CAT_TASKID_NAME ) ; PD_CHECK( ele.isNumber(), SDB_INVALIDARG, error, PDERROR, "Failed to get field[%s], type: %d", CAT_TASKID_NAME, ele.type() ) ; taskID = ( UINT64 )ele.numberLong() ; rc = catRemoveTask( taskID, cb, w ) ; PD_RC_CHECK( rc, PDERROR, "Remove task[%lld] failed, rc: %d", taskID, rc ) ; done: return rc ; error: goto done ; }