int printCollectionNat( rcComm_t *conn, char *collection, int flags ) { int status; //openCollInp_t openCollInp; collInp_t openCollInp; collEnt_t *collEnt; int handleInx; memset( &openCollInp, 0, sizeof( openCollInp ) ); rstrcpy( openCollInp.collName, collection, MAX_NAME_LEN ); openCollInp.flags = flags; handleInx = rcOpenCollection( conn, &openCollInp ); if ( handleInx < 0 ) { fprintf( stderr, "rcOpenCollection of %s error. status = %d\n", collection, handleInx ); return handleInx; } while ( ( status = rcReadCollection( conn, handleInx, &collEnt ) ) >= 0 ) { if ( collEnt->objType == DATA_OBJ_T ) { printf( "D - %s/%s\n", collEnt->collName, collEnt->dataName ); printf( " collName - %s\n", collEnt->collName ); printf( " dataName - %s\n", collEnt->dataName ); printf( " dataId - %s\n", collEnt->dataId ); if ( flags > 0 ) { printf( " ownerName - %s\n", collEnt->ownerName ); printf( " resource - %s\n", collEnt->resource ); printf( " replNum - %d\n", collEnt->replNum ); printf( " dataSize - %lld\n", collEnt->dataSize ); printf( " replStatus - %d\n", collEnt->replStatus ); printf( " modifyTime (UNIX clock in string) - %s\n", collEnt->modifyTime ); if ( ( flags & VERY_LONG_METADATA_FG ) != 0 ) { printf( " phyPath - %s\n", collEnt->phyPath ); printf( " chksum - %s\n", collEnt->chksum ); printf( " createTime (UNIX clock in string) - %s\n", collEnt->createTime ); } } } else if ( collEnt->objType == COLL_OBJ_T ) { printf( "C - %s\n", collEnt->collName ); printf( " collOwner %s\n", collEnt->ownerName ); /* recursive print */ printCollection( conn, collEnt->collName, flags ); } freeCollEnt( collEnt ); } rcCloseCollection( conn, handleInx ); if ( status < 0 && status != CAT_NO_ROWS_FOUND ) { return status; } else { return 0; } }
int _rsPhyBundleColl( rsComm_t* rsComm, structFileExtAndRegInp_t* phyBundleCollInp, const char *_resc_name ) { collInp_t collInp; bzero( &collInp, sizeof( collInp ) ); rstrcpy( collInp.collName, phyBundleCollInp->collection, MAX_NAME_LEN ); collInp.flags = RECUR_QUERY_FG | VERY_LONG_METADATA_FG | NO_TRIM_REPL_FG; char* srcRescName = getValByKey( &phyBundleCollInp->condInput, RESC_NAME_KW ); if ( srcRescName != NULL ) { collInp.flags |= INCLUDE_CONDINPUT_IN_QUERY; addKeyVal( &collInp.condInput, RESC_NAME_KW, srcRescName ); } int handleInx = rsOpenCollection( rsComm, &collInp ); if ( handleInx < 0 ) { rodsLog( LOG_ERROR, "_rsPhyBundleColl: rsOpenCollection of %s error. status = %d", collInp.collName, handleInx ); return handleInx; } if ( CollHandle[handleInx].rodsObjStat->specColl != NULL ) { rodsLog( LOG_ERROR, "_rsPhyBundleColl: unable to bundle special collection %s", collInp.collName ); rsCloseCollection( rsComm, &handleInx ); return 0; } /* create the bundle file */ char* dataType = getValByKey( &phyBundleCollInp->condInput, DATA_TYPE_KW ); // JMC - backport 4658 char* rescHier = getValByKey( &phyBundleCollInp->condInput, RESC_HIER_STR_KW ); dataObjInp_t dataObjInp; int l1descInx = createPhyBundleDataObj( rsComm, phyBundleCollInp->collection, _resc_name, rescHier, &dataObjInp, dataType ); // JMC - backport 4658 if ( l1descInx < 0 ) { return l1descInx; } // =-=-=-=-=-=-=- // JMC - backport 4528 int chksumFlag = -1; if ( getValByKey( &phyBundleCollInp->condInput, VERIFY_CHKSUM_KW ) != NULL ) { L1desc[l1descInx].chksumFlag = VERIFY_CHKSUM; chksumFlag = 1; } else { chksumFlag = 0; } // =-=-=-=-=-=-=- // JMC - backport 4771 int maxSubFileCnt = -1; // JMC - backport 4528, 4771 if ( getValByKey( &phyBundleCollInp->condInput, MAX_SUB_FILE_KW ) != NULL ) { maxSubFileCnt = atoi( getValByKey( &phyBundleCollInp->condInput, MAX_SUB_FILE_KW ) ); } else { maxSubFileCnt = MAX_SUB_FILE_CNT; } rodsLong_t maxBunSize; if ( getValByKey( &phyBundleCollInp->condInput, MAX_BUNDLE_SIZE_KW ) != NULL ) { maxBunSize = atoi( getValByKey( &phyBundleCollInp->condInput, MAX_BUNDLE_SIZE_KW ) ) * OneGig; } else { maxBunSize = MAX_BUNDLE_SIZE * OneGig; } // =-=-=-=-=-=-=- char phyBunDir[MAX_NAME_LEN]; createPhyBundleDir( rsComm, L1desc[l1descInx].dataObjInfo->filePath, phyBunDir, L1desc[l1descInx].dataObjInfo->rescHier ); curSubFileCond_t curSubFileCond; bunReplCacheHeader_t bunReplCacheHeader; bzero( &bunReplCacheHeader, sizeof( bunReplCacheHeader ) ); bzero( &curSubFileCond, sizeof( curSubFileCond ) ); int status = -1; int savedStatus = 0; collEnt_t* collEnt = NULL; while ( ( status = rsReadCollection( rsComm, &handleInx, &collEnt ) ) >= 0 ) { if ( collEnt->objType == DATA_OBJ_T ) { if ( curSubFileCond.collName[0] == '\0' ) { /* a new dataObj. */ rstrcpy( curSubFileCond.collName, collEnt->collName, MAX_NAME_LEN ); rstrcpy( curSubFileCond.dataName, collEnt->dataName, MAX_NAME_LEN ); curSubFileCond.dataId = strtoll( collEnt->dataId, 0, 0 ); } else if ( strcmp( curSubFileCond.collName, collEnt->collName ) != 0 || strcmp( curSubFileCond.dataName, collEnt->dataName ) != 0 ) { /* a new file, need to handle the old one */ if ( bunReplCacheHeader.numSubFiles >= maxSubFileCnt || // JMC - backport 4771 bunReplCacheHeader.totSubFileSize + collEnt->dataSize > maxBunSize ) { /* bundle is full */ status = bundleAndRegSubFiles( rsComm, l1descInx, phyBunDir, phyBundleCollInp->collection, &bunReplCacheHeader, chksumFlag ); // JMC - backport 4528 if ( status < 0 ) { rodsLog( LOG_ERROR, "_rsPhyBundleColl:bunAndRegSubFiles err for %s,stst=%d", phyBundleCollInp->collection, status ); savedStatus = status; } else { /* create a new bundle file */ l1descInx = createPhyBundleDataObj( rsComm, phyBundleCollInp->collection, _resc_name, rescHier, &dataObjInp, dataType ); // JMC - backport 4658 if ( l1descInx < 0 ) { rodsLog( LOG_ERROR, "_rsPhyBundleColl:createPhyBundleDataObj err for %s,stat=%d", phyBundleCollInp->collection, l1descInx ); freeCollEnt( collEnt ); return l1descInx; } createPhyBundleDir( rsComm, L1desc[l1descInx].dataObjInfo->filePath, phyBunDir, L1desc[l1descInx].dataObjInfo->rescHier ); /* need to reset subPhyPath since phyBunDir has * changed */ /* At this point subPhyPath[0] == 0 if it has gone * through replAndAddSubFileToDir below. != 0 if it has * not and already a good cache copy */ if ( curSubFileCond.subPhyPath[0] != '\0' ) setSubPhyPath( phyBunDir, curSubFileCond.dataId, curSubFileCond.subPhyPath ); } } /* end of new bundle file */ status = replAndAddSubFileToDir( rsComm, &curSubFileCond, _resc_name, phyBunDir, &bunReplCacheHeader ); if ( status < 0 ) { savedStatus = status; rodsLog( LOG_ERROR, "_rsPhyBundleColl:replAndAddSubFileToDir err for %s,sta=%d", curSubFileCond.subPhyPath, status ); } curSubFileCond.bundled = 0; curSubFileCond.subPhyPath[0] = curSubFileCond.cachePhyPath[0] = '\0'; rstrcpy( curSubFileCond.collName, collEnt->collName, MAX_NAME_LEN ); rstrcpy( curSubFileCond.dataName, collEnt->dataName, MAX_NAME_LEN ); curSubFileCond.dataId = strtoll( collEnt->dataId, 0, 0 ); } /* end of name compare */ if ( curSubFileCond.bundled > 0 ) { /* already bundled. skip */ } else if ( isDataObjBundled( collEnt ) ) { /* already bundled, skip */ curSubFileCond.bundled = 1; curSubFileCond.subPhyPath[0] = '\0'; curSubFileCond.cachePhyPath[0] = '\0'; /* XXXX there was a bug that if dataSize == 0, replStatus is 0. * This bug has been fixed since 3.1 */ } else if ( ( collEnt->replStatus > 0 || curSubFileCond.subPhyPath[0] == '\0' ) && // JMC - backport 4755 strcmp( collEnt->resource, _resc_name ) == 0 ) { /* have a good copy in cache resource */ setSubPhyPath( phyBunDir, curSubFileCond.dataId, curSubFileCond.subPhyPath ); rstrcpy( curSubFileCond.cachePhyPath, collEnt->phyPath, MAX_NAME_LEN ); curSubFileCond.cacheReplNum = collEnt->replNum; curSubFileCond.subFileSize = collEnt->dataSize; } } // if data obj free( collEnt ); /* just free collEnt but not content */ } // while /* handle any remaining */ status = replAndAddSubFileToDir( rsComm, &curSubFileCond, _resc_name, phyBunDir, &bunReplCacheHeader ); if ( status < 0 ) { savedStatus = status; rodsLog( LOG_ERROR, "_rsPhyBundleColl:replAndAddSubFileToDir err for %s,stat=%d", curSubFileCond.subPhyPath, status ); } status = bundleAndRegSubFiles( rsComm, l1descInx, phyBunDir, phyBundleCollInp->collection, &bunReplCacheHeader, chksumFlag ); // JMC - backport 4528 if ( status < 0 ) { rodsLog( LOG_ERROR, "_rsPhyBundleColl:bunAndRegSubFiles err for %s,stat=%d", phyBundleCollInp->collection, status ); } clearKeyVal( &collInp.condInput ); rsCloseCollection( rsComm, &handleInx ); if ( status >= 0 && savedStatus < 0 ) { return savedStatus; } else { return status; } }