Beispiel #1
0
TEST(cursor,sdbCursor_get_over_then_close)
{
   INT32 rc = SDB_OK ;
   rc = initEnv( HOST, SERVER, USER, PASSWD ) ;
   ASSERT_EQ( SDB_OK, rc ) ;
   sdbConnectionHandle connection    = 0 ;
   sdbCollectionHandle collection    = 0 ;
   sdbCursorHandle cursor            = 0 ;
   INT32 NUM                         = 1 ;
   bson obj ;
   bson obj1 ;
   bson obj2 ;
   rc = sdbConnect ( HOST, SERVER, USER, PASSWD, &connection ) ;
   ASSERT_EQ( SDB_OK, rc ) ;
   rc = getCollection ( connection,
                        COLLECTION_FULL_NAME,
                        &collection ) ;
   ASSERT_EQ( SDB_OK, rc ) ;
   insertRecords ( collection, NUM ) ;
   rc = sdbQuery( collection, NULL, NULL, NULL, NULL, 0, -1, &cursor ) ;
   ASSERT_EQ( SDB_OK, rc ) ;

   bson_init(&obj);
   bson_init(&obj1);
   bson_init(&obj2);

   rc = sdbNext ( cursor, &obj ) ;
   CHECK_MSG("%s%d\n","rc = ",rc) ;
   ASSERT_EQ( SDB_OK, rc ) ;
   printf( "SdbNext record is:\n" ) ;
   bson_print( &obj ) ;
   printf("\n") ;
   rc = sdbNext ( cursor, &obj1 ) ;
   CHECK_MSG("%s%d\n","rc = ",rc) ;
   ASSERT_EQ( SDB_DMS_EOC, rc ) ;
   rc = sdbNext ( cursor, &obj1 ) ;
   CHECK_MSG("%s%d\n","rc = ",rc) ;
   ASSERT_EQ( SDB_DMS_CONTEXT_IS_CLOSE, rc ) ;

   bson_destroy( &obj ) ;
   bson_destroy( &obj1 ) ;
   bson_destroy( &obj2 ) ;

   rc = sdbCloseCursor( cursor ) ;
   CHECK_MSG("%s%d\n","rc = ",rc) ;
   ASSERT_EQ( SDB_OK, rc ) ;

   sdbDisconnect ( connection ) ;
   sdbReleaseCursor ( cursor ) ;
   sdbReleaseCollection ( collection ) ;
   sdbReleaseConnection ( connection ) ;
}
Beispiel #2
0
TEST(cursor,sdbNext)
{
   INT32 rc = SDB_OK ;
   rc = initEnv( HOST, SERVER, USER, PASSWD ) ;
   ASSERT_EQ( SDB_OK, rc ) ;
   sdbConnectionHandle connection    = 0 ;
   sdbCollectionHandle collection    = 0 ;
   sdbCursorHandle cursor            = 0 ;
   INT32 NUM                         = 10 ;
   SINT64 count                      = 0 ;
   bson obj ;
   rc = sdbConnect ( HOST, SERVER, USER, PASSWD, &connection ) ;
   ASSERT_EQ( SDB_OK, rc ) ;
   rc = getCollection ( connection,
                        COLLECTION_FULL_NAME,
                        &collection ) ;
   ASSERT_EQ( SDB_OK, rc ) ;
   insertRecords( collection, NUM ) ;
   rc = sdbQuery ( collection, NULL, NULL, NULL, NULL, 0, -1, &cursor ) ;
   ASSERT_EQ( SDB_OK, rc ) ;
   bson_init(&obj);
   rc = sdbCurrent( cursor, &obj ) ;
   printf( "Current record is:\n" ) ;
   bson_print( &obj ) ;
   printf("\n") ;
   bson_destroy( &obj ) ;
   bson_init(&obj);
   rc = sdbNext( cursor, &obj ) ;
   ASSERT_EQ( SDB_OK, rc ) ;
   printf( "Next record is:\n" ) ;
   bson_print( &obj ) ;
   printf("\n") ;
   bson_destroy(&obj);
   rc = sdbGetCount( collection, NULL, &count ) ;
   CHECK_MSG("%s%d\n","rc = ",rc) ;
   CHECK_MSG("%s%d%s%lld\n", "NUM = ", NUM, " count = ", count) ;
   ASSERT_EQ ( NUM, count ) ;
   sdbDisconnect ( connection ) ;
   sdbReleaseCursor ( cursor ) ;
   sdbReleaseCollection ( collection ) ;
   sdbReleaseConnection ( connection ) ;
}
Beispiel #3
0
INT32 migExport::_run( const CHAR *pCSName, const CHAR *pCLName, INT32 &total )
{
   INT32 rc = SDB_OK ;
   const CHAR *pTemp = NULL ;
   bson obj ;
   bson_iterator it ;
   bson_type type ;

   bson_init( &obj ) ;
   if ( ( pCSName == NULL && pCLName == NULL ) ||
        ( pCSName == NULL && pCLName != NULL ) )
   {
      //never cs cl
      rc = _getCSList() ;
      if ( rc )
      {
         PD_LOG ( PDERROR, "Failed to get collection space list, rc = %d",
                  rc ) ;
         goto error ;
      }
      while( TRUE )
      {
         rc = sdbNext( _gCSList, &obj ) ;
         if ( rc )
         {
            if ( SDB_DMS_EOC != rc )
            {
               PD_LOG ( PDERROR, "Failed to get collection space list, rc = %d",
                        rc ) ;
               goto error ;
            }
            else
            {
               rc = SDB_OK ;
               goto done ;
            }
         }
         type = bson_find( &it, &obj, "Name" ) ;
         if ( type != BSON_STRING )
         {
            rc = SDB_SYS ;
            PD_LOG ( PDERROR, "List collection space does not string, rc = %d",
                     rc ) ;
            goto error ;
         }
         pTemp = bson_iterator_string( &it ) ;
         rc = _run( pTemp, pCLName, total ) ;
         if ( rc )
         {
            PD_LOG ( PDERROR, "Faild to call _run, rc = %d", rc ) ;
            goto error ;
         }
      }
   }
   else if ( pCSName != NULL && pCLName == NULL )
   {
      //cs
      rc = _getCLList() ;
      if ( rc )
      {
         PD_LOG ( PDERROR, "Failed to get collection list, rc = %d",
                  rc ) ;
         goto error ;
      }
      while ( TRUE )
      {
         rc = sdbNext( _gCLList, &obj ) ;
         if ( rc )
         {
            if ( SDB_DMS_EOC != rc )
            {
               PD_LOG ( PDERROR, "Failed to get collection list, rc = %d",
                        rc ) ;
               goto error ;
            }
            else
            {
               rc = SDB_OK ;
               goto done ;
            }
         }
         type = bson_find( &it, &obj, "Name" ) ;
         if ( type != BSON_STRING )
         {
            rc = SDB_SYS ;
            PD_LOG ( PDERROR, "List collection does not string, rc = %d",
                     rc ) ;
            goto error ;
         }
         pTemp = bson_iterator_string( &it ) ;
         rc = _run( pCSName, pTemp, total ) ;
         if ( rc )
         {
            PD_LOG ( PDERROR, "Faild to call _run, rc = %d", rc ) ;
            goto error ;
         }
      }
   }
   else
   {
      //cs and cl
      rc = _exportCL( pCSName, pCLName, total ) ;
      if ( rc )
      {
         PD_LOG ( PDERROR, "Faild to call _export, rc = %d", rc ) ;
         goto error ;
      }
   }
done:
   bson_destroy ( &obj ) ;
   return rc ;
error:
   goto done ;
}
Beispiel #4
0
INT32 migExport::_exportCL( const CHAR *pCSName,
                            const CHAR *pCLName,
                            INT32 &total )
{
   INT32 rc = SDB_OK ;
   INT32 clTotal = 0 ;
   bson obj ;

   bson_init( &obj ) ;
   _gCollection = 0 ;
   _gCollectionSpace = 0 ;

   rc = _getCS( pCSName ) ;
   if ( rc )
   {
      PD_LOG ( PDERROR, "Failed to get collection space, rc = %d",
               rc ) ;
      goto error ;
   }
   rc = _getCL( pCLName ) ;
   if ( rc )
   {
      PD_LOG ( PDERROR, "Failed to get collection, rc = %d",
               rc ) ;
      goto error ;
   }
   rc = _query() ;
   if ( rc )
   {
      if ( SDB_DMS_EOC == rc )
      {
         rc = SDB_OK ;
         goto done ;
      }
      else
      {
         PD_LOG ( PDERROR, "Failed to get record, rc = %d",
                  rc ) ;
         goto error ;
      }
   }
   while ( TRUE )
   {
      rc = sdbNext( _gCursor, &obj ) ;
      if ( rc )
      {
         if ( SDB_DMS_EOC != rc )
         {
            PD_LOG ( PDERROR, "Failed to get collection list, rc = %d",
                     rc ) ;
            goto error ;
         }
         else
         {
            rc = SDB_OK ;
            goto done ;
         }
      }
      rc = _writeRecord( &obj ) ;
      if ( rc )
      {
         PD_LOG ( PDERROR, "Failed to write record to file, rc = %d",
                  rc ) ;
         goto error ;
      }
      bson_destroy ( &obj ) ;
      ++clTotal ;
   }
done:
   total += clTotal ;
   bson_destroy ( &obj ) ;
   if ( _gCollection )
   {
      sdbReleaseCollection ( _gCollection ) ;
   }
   if ( _gCollectionSpace )
   {
      sdbReleaseCS ( _gCollectionSpace ) ;
   }
   _gCollection = 0 ;
   _gCollectionSpace = 0 ;
   PD_LOG ( PDEVENT, "%s.%s export record %d in file",pCSName, pCLName, clTotal ) ;
   return rc ;
error:
   goto done ;
}
Beispiel #5
0
   INT32 expCLExporter::_exportRecords( sdbCursorHandle hCusor, 
                                        UINT64 &exportedCount, 
                                        UINT64 &failCount )
   {
      INT32 rc = SDB_OK ;
      bson record ;
      const CHAR *buf = NULL ;
      UINT32 size = 0 ;
      UINT64 accumulatedSize = 0 ;
      UINT64 _exportedCount = 0 ;
      UINT64 _failCount = 0 ;
      bson_init ( &record ) ;

      while ( TRUE )
      {
         rc = sdbNext( hCusor, &record ) ;
         if ( SDB_DMS_EOC == rc )
         {
            rc = SDB_OK ;
            break ;
         }
         else if ( SDB_OK != rc )
         {
            PD_LOG( PDERROR, "Failed to get the next record, rc = %d", rc ) ;
            goto error ;
         }

         rc = _convertor.convert( record, buf, size ) ;
         if ( SDB_OK != rc )
         {
            PD_LOG( PDERROR, "Failed to convert the record, rc = %d",  rc ) ;
            ++failCount ;
            goto error ;
         }

         rc = _out.output( buf, size ) ;
         if ( SDB_OK != rc )
         {
            PD_LOG( PDERROR, "Failed to output the record, rc = %d", rc ) ;
            ++_failCount ;
            goto error ;
         }
         ++_exportedCount ;

         accumulatedSize += size ;
         if ( accumulatedSize > EXP_LOG_OUTPUT_SIZE )
         {
            PD_LOG( PDINFO, "Successed to exported %llu records, "
                            "failed to to exported %llu records",
                    _exportedCount, _failCount ) ;
            accumulatedSize = 0 ;
         }

         buf = _options.delRecord().c_str() ;
         size = (UINT32)_options.delRecord().size() ;
         accumulatedSize += size ;
         rc = _out.output( buf, size ) ;
         if ( SDB_OK != rc )
         {
            PD_LOG( PDERROR, "Failed to output record-delimiter after"
                             " the record , rc = %d", rc ) ;
            goto error ;
         }
      }
      
   done :
      exportedCount += _exportedCount ;
      failCount += _failCount ;
      bson_destroy( &record ) ;
      return rc ;
   error :
      goto done ;
   }
Beispiel #6
0
INT32 main ( INT32 argc, CHAR **argv )
{
   // initialize local variables
   CHAR *pHostName                   = NULL ;
   CHAR *pServiceName                = NULL ;
   CHAR *pUsr                        = NULL ;
   CHAR *pPasswd                     = NULL ;
   // define a connetion handle; use to connect to database
   sdbConnectionHandle connection    = 0 ;
   // define a collection space handle
   sdbCSHandle collectionspace       = 0 ;
   // define a collection handle
   sdbCollectionHandle collection    = 0 ;
   // define a cursor handle for query
   sdbCursorHandle cursor            = 0 ;
   sdbCursorHandle cursor1           = 0 ;
   // define local variables
   // initialize them before use
   INT32 rc    = SDB_OK ;
   bson obj ;
   bson rule ;
   bson record ;
   bson updatecondition ;
   bson tmp ;
   bson_iterator it ;

   // verify syntax
   if ( 5 != argc )
   {
      displaySyntax ( (CHAR*)argv[0] ) ;
      exit ( 0 ) ;
   }
   // read argument
   pHostName    = (CHAR*)argv[1] ;
   pServiceName = (CHAR*)argv[2] ;
   pUsr         = (CHAR*)argv[3] ;
   pPasswd      = (CHAR*)argv[4] ;

   // connect to database
   rc = sdbConnect ( pHostName, pServiceName, pUsr, pPasswd, &connection ) ;
   if( rc!=SDB_OK )
   {
      printf("Failed to connet to database, rc = %d" OSS_NEWLINE, rc ) ;
      goto error ;
   }
   // create collection space
   rc = sdbCreateCollectionSpace ( connection, COLLECTION_SPACE_NAME,
                                   SDB_PAGESIZE_4K, &collectionspace ) ;
   if( rc!=SDB_OK )
   {
      printf("Failed to create collection space, rc = %d" OSS_NEWLINE, rc ) ;
      goto error ;
   }

   // create collection in a specified colletion space.
   rc = sdbCreateCollection ( collectionspace, COLLECTION_NAME, &collection ) ;
   if( rc!=SDB_OK )
   {
      printf("Failed to create collection, rc = %d" OSS_NEWLINE, rc ) ;
      goto error ;
   }
   
   // prepare record
   bson_init( &record ) ;
   bson_append_int( &record, "age", 10 ) ;
   rc = bson_finish( &record ) ;
   CHECK_RC ( rc, "Failed to build bson" ) ;

   // insert record into database
   rc = sdbInsert( collection, &record ) ;
   if( rc!=SDB_OK )
   {
      printf("Failed to insert, rc = %d" OSS_NEWLINE, rc ) ;
      goto error ;
   }
   bson_destroy( &record ) ;
   // query all the record in this collection
   rc = sdbQuery(collection, NULL, NULL, NULL, NULL, 0, -1, &cursor ) ;
   if( rc!=SDB_OK )
   {
      printf("Failed to query, rc = %d" OSS_NEWLINE, rc ) ;
      goto error ;
   }
   // get the record from cursor
   bson_init(&obj) ;
   bson_init(&tmp) ;
   rc=sdbNext( cursor, &obj ) ;
   if ( rc!= SDB_OK )
   {
      printf("Failed to get next, rc = %d" OSS_NEWLINE, rc ) ;
      goto error ;
   }
   rc = bson_copy( &tmp, &obj ) ;
   CHECK_RC ( rc, "Failed to copy bson" ) ;
   printf("Before update, the record is:\n") ;
   bson_print( &tmp ) ;
   // set the update condition using "_id"
   bson_find( &it, &obj, "_id" ) ;
   bson_init( &updatecondition ) ;
   bson_append_element( &updatecondition, NULL, &it ) ;
   rc = bson_finish( &updatecondition ) ;
   CHECK_RC ( rc, "Failed to build bson" ) ;
   // set the update rule
   bson_init( &rule ) ;
   bson_append_start_object ( &rule, "$set" ) ;
   bson_append_int ( &rule, "age", 99 ) ;
   bson_append_finish_object ( &rule ) ;
   rc = bson_finish ( &rule ) ;
   CHECK_RC ( rc, "Failed to build bson" ) ;

   // update
   rc = sdbUpdate(collection, &rule, &updatecondition, NULL ) ;
   if ( rc!=SDB_OK )
   {
      printf("Failed to update, rc = %d" OSS_NEWLINE, rc ) ;
      goto error ;
   }
   bson_destroy(&obj) ;
   bson_destroy(&rule) ;
   bson_destroy(&updatecondition) ;
   // query all the record in this collection again
   rc = sdbQuery(collection, NULL, NULL, NULL, NULL, 0, -1, &cursor1 ) ;
   if( rc!=SDB_OK )
   {
      printf("Failed to query, rc = %d" OSS_NEWLINE, rc ) ;
      goto error ;
   }
   // get record from cursor1
   bson_init(&obj) ;
   rc=sdbNext( cursor1, &obj ) ;
   if ( rc!= SDB_OK )
   {
      printf("Failed to get next, rc = %d" OSS_NEWLINE, rc ) ;
      goto error ;
   }
   printf("after update, the record is:\n") ;
   bson_print( &obj ) ;
   bson_destroy(&obj) ;

done:
   // drop collection space
   rc = sdbDropCollectionSpace( connection, COLLECTION_SPACE_NAME ) ;
   if ( rc != SDB_OK )
   {
     printf("Failed to drop collection space, rc = %d" OSS_NEWLINE, rc ) ;
   }
   // disconnect the connection
   sdbDisconnect ( connection ) ;
   // release the local variables
   sdbReleaseCursor ( cursor ) ;
   sdbReleaseCursor ( cursor1 ) ;
   sdbReleaseCollection ( collection ) ;
   sdbReleaseCS ( collectionspace ) ;
   sdbReleaseConnection ( connection ) ;
   return 0;
error:
   goto done ;
}
Beispiel #7
0
INT32 main ( INT32 argc, CHAR **argv )
{
   // initialize local variables
   CHAR *pHostName                   = NULL ;
   CHAR *pServiceName                = NULL ;
   CHAR *pUsr                        = NULL ;
   CHAR *pPasswd                     = NULL ;
   // define a connetion handle; use to connect to database
   sdbConnectionHandle connection    = 0 ;
   // define a collection space handle
   sdbCSHandle collectionspace       = 0 ;
   // define a collection handle
   sdbCollectionHandle collection    = 0 ;
   // define a cursor handle for query
   sdbCursorHandle cursor            = 0 ;
   // define local variables
   // initialize them before use
   INT32 rc    = SDB_OK ;
   INT32 count = 0 ;
   bson obj ;
   bson rule ;
   bson objList [ NUM_RECORD ] ;

   // verify syntax
   if ( 5 != argc )
   {
      displaySyntax ( (CHAR*)argv[0] ) ;
      exit ( 0 ) ;
   }
   // read argument
   pHostName    = (CHAR*)argv[1] ;
   pServiceName = (CHAR*)argv[2] ;
   pUsr         = (CHAR*)argv[3] ;
   pPasswd      = (CHAR*)argv[4] ;

   // connect to database
   rc = sdbConnect ( pHostName, pServiceName, pUsr, pPasswd, &connection ) ;
   CHECK_RC ( rc, "Failed to connet to database" ) ;

   // create collection space
   rc = sdbCreateCollectionSpace ( connection, COLLECTION_SPACE_NAME,
                                   SDB_PAGESIZE_4K, &collectionspace ) ;
   CHECK_RC ( rc, "Failed to create collection space" ) ;

   // create collection in a specified colletion space.
   // Here,we build it up in the new collection.
   rc = sdbCreateCollection ( collectionspace, COLLECTION_NAME, &collection ) ;
   CHECK_RC ( rc, "Failed to create collection" ) ;

   // create record list using objList
   createRecordList ( &objList[0], NUM_RECORD ) ;

   // insert obj and free memory that allocated by createRecordList
   for ( count = 0; count < NUM_RECORD; count++ )
   {
      // all the contents of inserted record are the same except _id
      rc = sdbInsert ( collection, &objList[count] ) ;
      if ( rc )
      {
         printf ( "Failed to insert record, rc = %d" OSS_NEWLINE, rc ) ;
      }
      bson_destroy ( &objList[count] ) ;
   }

   // query all the record in this collection
   // and return the result by the cursor handle
   rc = sdbQuery(collection, NULL, NULL, NULL, NULL, 0, -1, &cursor ) ;
   CHECK_RC ( rc, "Failed to query" ) ;

   // get all the qureied records
   bson_init(&obj);
   while( !( rc=sdbNext( cursor, &obj ) ) )
   {
      bson_print( &obj ) ;
      bson_destroy(&obj) ;
      bson_init(&obj);
   }
   bson_destroy(&obj) ;
   if( rc==SDB_DMS_EOC )
   {
      printf("All the record had been list." OSS_NEWLINE ) ;
   }
   else if( rc!=SDB_OK )
   {
      CHECK_RC ( rc, "Failed to get the record" ) ;
   }

   // drop the specified collection
   rc = sdbDropCollection( collectionspace,COLLECTION_NAME ) ;
   CHECK_RC ( rc, "Failed to drop the specified collection" ) ;

   // drop the specified collection space
   rc = sdbDropCollectionSpace( connection,COLLECTION_SPACE_NAME ) ;
   CHECK_RC ( rc, "Failed to drop the specified collection space" ) ;

done:
   // disconnect the connection
   sdbDisconnect ( connection ) ;
   // release the local variables
   sdbReleaseCursor ( cursor ) ;
   sdbReleaseCollection ( collection ) ;
   sdbReleaseCS ( collectionspace ) ;
   sdbReleaseConnection ( connection ) ;
   return 0;
error:
   goto done ;
}
   INT32 RecordSharding::init(const vector<Host>& hosts,
                              const string& user,
                              const string& password,
                              const string& csname,
                              const string& clname,
                              BOOLEAN useSSL)
   {
      INT32 rc = SDB_OK;
      sdbConnectionHandle conn = SDB_INVALID_HANDLE;
      sdbCursorHandle cursor = SDB_INVALID_HANDLE;
      bson cataObj;
      INT32 cataCount = 0;

      SDB_ASSERT(!_inited, "alreay inited");

      _hosts = &hosts;
      _user = user;
      _password = password;
      _csname = csname;
      _clname = clname;
      _useSSL = useSSL;
      bson_init(&cataObj);

      for (vector<Host>::const_iterator it = hosts.begin();
           it != hosts.end(); it++)
      {
         const Host& host = *it;

         if (SDB_INVALID_HANDLE != cursor)
         {
            sdbCloseCursor(cursor);
            sdbReleaseCursor(cursor);
            cursor = SDB_INVALID_HANDLE;
         }

         if (SDB_INVALID_HANDLE != conn)
         {
            sdbDisconnect(conn);
            sdbReleaseConnection(conn);
            conn = SDB_INVALID_HANDLE;
         }

         if (_useSSL)
         {
            rc = sdbSecureConnect(host.hostname.c_str(), host.svcname.c_str(),
                                  _user.c_str(), _password.c_str(), &conn);
         }
         else
         {
            rc = sdbConnect(host.hostname.c_str(), host.svcname.c_str(),
                            _user.c_str(), _password.c_str(), &conn);
         }

         if (SDB_OK != rc)
         {
            PD_LOG(PDWARNING, "failed to connect to server %s:%s, rc=%d, usessl=%d",
                   host.hostname.c_str(), host.svcname.c_str(), rc, _useSSL);
            rc = SDB_OK;
            continue;
         }

         rc = sdbGetSnapshot(conn, SDB_SNAP_CATALOG, NULL, NULL, NULL, &cursor);
         if (SDB_OK != rc)
         {
            if (SDB_INVALID_HANDLE != cursor)
            {
               sdbCloseCursor(cursor);
               sdbReleaseCursor(cursor);
               cursor = SDB_INVALID_HANDLE;
            }

            if (SDB_RTN_COORD_ONLY == rc)
            {
               PD_LOG(PDWARNING, "%s:%s is not coordinator",
                      host.hostname.c_str(), host.svcname.c_str());
               rc = SDB_OK;
               continue;
            }

            PD_LOG(PDWARNING, "failed to get coordinator group from %s:%s, rc = %d",
                   host.hostname.c_str(), host.svcname.c_str(), rc);
            rc = SDB_OK;
            continue;
         }

         break;
      }

      if (SDB_INVALID_HANDLE == cursor)
      {
         rc = SDB_OK;
         PD_LOG(PDWARNING, "failed to get coordinator group");
         goto done;
      }

      for(;;)
      {
         rc = sdbNext(cursor, &cataObj);
         if (SDB_OK != rc)
         {
            if (SDB_DMS_EOC == rc)
            {
               rc = SDB_OK;
               break;
            }

            PD_LOG(PDERROR, "failed to get cataObj from cursor, rc=%d", rc);
            goto error;
         }

         rc = _cataAgent.updateCatalog(bson_data(&cataObj));
         if (SDB_OK != rc)
         {
            PD_LOG(PDERROR, "failed to update catalog agent, rc=%d", rc);
            goto error;
         }

         cataCount++;
      }

      if (0 == cataCount)
      {
         _inited = TRUE;
         goto done;
      }

      _collectionName = _csname + "." + _clname;

      rc = _cataAgent.getCataInfo(_collectionName, _cataInfo);
      if (SDB_OK != rc)
      {
         PD_LOG(PDERROR, "failed to get catalog info, rc=%d", rc);
         goto error;
      }

      _isMainCL = _cataInfo.isMainCL();

      if (_cataInfo.isMainCL())
      {
         vector<string> subCLList;
         INT32 subGroupNum = 0;

         rc = _cataInfo.getSubCLList(subCLList);
         if (SDB_OK != rc)
         {
            PD_LOG(PDERROR, "failed to get group by record, rc=%d", rc);
            goto error;
         }

         for (vector<string>::iterator it = subCLList.begin();
              it != subCLList.end(); it++)
         {
            CataInfo cataInfo;
            rc = _cataAgent.getCataInfo(*it, cataInfo);
            if (SDB_OK != rc)
            {
               PD_LOG(PDERROR, "failed to get catalog info, rc=%d", rc);
               goto error;
            }

            subGroupNum += cataInfo.getGroupNum();
            _subCataInfo[*it] = cataInfo;
         }

         _groupNum = subGroupNum;
      }
      else
      {
         _groupNum = _cataInfo.getGroupNum();
      }

      _inited = TRUE;

   done:
      bson_destroy(&cataObj);
      if (SDB_INVALID_HANDLE != cursor)
      {
         sdbCloseCursor(cursor);
         sdbReleaseCursor(cursor);
         cursor = SDB_INVALID_HANDLE;
      }
      if (SDB_INVALID_HANDLE != conn)
      {
         sdbDisconnect(conn);
         sdbReleaseConnection(conn);
         conn = SDB_INVALID_HANDLE;
      }
      return rc;
   error:
      goto done;
   }