irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

rsDataObjTrim.cpp
Go to the documentation of this file.
1 
3 /* See dataObjTrim.h for a description of this API call.*/
4 
5 #include "dataObjTrim.h"
6 #include "dataObjUnlink.h"
7 #include "dataObjOpr.hpp"
8 #include "rodsLog.h"
9 #include "objMetaOpr.hpp"
10 #include "specColl.hpp"
11 #include "rsDataObjTrim.hpp"
12 #include "icatDefines.h"
13 #include "getRemoteZoneResc.h"
14 #include "rsDataObjUnlink.hpp"
15 
16 // =-=-=-=-=-=-=-
19 
20 /* rsDataObjTrim - The Api handler of the rcDataObjTrim call - trim down
21  * the number of replicas of a data object
22  * Input -
23  * rsComm_t *rsComm
24  * dataObjInp_t *dataObjInp - The trim input
25  *
26  * Returned val - return 1 if a copy is trimmed. 0 if nothing trimmed.
27  */
28 int rsDataObjTrim( rsComm_t *rsComm, dataObjInp_t *dataObjInp )
29 {
30  // Deprecation messages must be handled by doing the following.
31  // The native rule engine may erase all messages in the rError array.
32  // The only way to guarantee that messages are received by the client
33  // is to add them to the rError array when the function returns.
34  irods::at_scope_exit at_scope_exit{[&] {
35  // itrim -N
36  if (getValByKey(&dataObjInp->condInput, COPIES_KW)) {
37  addRErrorMsg(&rsComm->rError, DEPRECATED_PARAMETER, "Specifying a minimum number of replicas to keep is deprecated.");
38  }
39  }};
40 
41  if (getValByKey(&dataObjInp->condInput, RESC_NAME_KW) && // -S
42  getValByKey(&dataObjInp->condInput, REPL_NUM_KW)) // -n
43  {
45  }
46 
47  int status;
48  dataObjInfo_t *dataObjInfoHead = NULL;
49  dataObjInfo_t *tmpDataObjInfo;
50  char *accessPerm;
51  int retVal = 0;
52  int remoteFlag;
54  specCollCache_t *specCollCache = NULL;
55  int myTime = 0;
56  char *tmpStr;
57  int myAge;
58 
59  resolveLinkedPath( rsComm, dataObjInp->objPath, &specCollCache,
60  &dataObjInp->condInput );
61  remoteFlag = getAndConnRemoteZone( rsComm, dataObjInp, &rodsServerHost,
62  REMOTE_OPEN );
63 
64  if ( remoteFlag < 0 ) {
65  return remoteFlag;
66  }
67  else if ( remoteFlag == REMOTE_HOST ) {
68  status = rcDataObjTrim( rodsServerHost->conn, dataObjInp );
69  return status;
70  }
71 
72  // =-=-=-=-=-=-=-
73  // working on the "home zone", determine if we need to redirect to a different
74  // server in this zone for this operation. if there is a RESC_HIER_STR_KW then
75  // we know that the redirection decision has already been made
76  std::string hier;
77  int local = LOCAL_HOST;
79  char* hier_char = getValByKey( &dataObjInp->condInput, RESC_HIER_STR_KW );
80  if ( hier_char == NULL ) {
81  // set a repl keyword here so resources can respond accordingly
82  addKeyVal( &dataObjInp->condInput, IN_REPL_KW, "" );
84  dataObjInp, hier, host, local );
85  if ( !ret.ok() ) {
86  std::stringstream msg;
87  msg << __FUNCTION__;
88  msg << " :: failed in irods::resource_redirect for [";
89  msg << dataObjInp->objPath << "]";
90  irods::log( PASSMSG( msg.str(), ret ) );
91  return ret.code();
92  }
93  // =-=-=-=-=-=-=-
94  // we resolved the redirect and have a host, set the hier str for subsequent
95  // api calls, etc.
96  addKeyVal( &dataObjInp->condInput, RESC_HIER_STR_KW, hier.c_str() );
97 
98  } // if keyword
99 
100  if ( getValByKey( &dataObjInp->condInput, ADMIN_KW ) != NULL ) {
103  }
104  accessPerm = NULL;
105  }
106  else {
107  accessPerm = ACCESS_DELETE_OBJECT;
108  }
109 
110  status = getDataObjInfo( rsComm, dataObjInp, &dataObjInfoHead,
111  accessPerm, 1 );
112 
113  if ( status < 0 ) {
115  "rsDataObjTrim: getDataObjInfo for %s", dataObjInp->objPath );
116  return status;
117  }
118  status = resolveInfoForTrim( &dataObjInfoHead, &dataObjInp->condInput );
119 
120  if ( status < 0 ) {
121  return status;
122  }
123 
124  if ( ( tmpStr = getValByKey( &dataObjInp->condInput, AGE_KW ) ) != NULL ) {
125  myAge = atoi( tmpStr );
126  /* age value is in minutes */
127  if ( myAge > 0 ) {
128  myTime = time( 0 ) - myAge * 60;
129  }
130  }
131 
132  tmpDataObjInfo = dataObjInfoHead;
133  while ( tmpDataObjInfo != NULL ) {
134  if ( myTime == 0 || atoi( tmpDataObjInfo->dataModify ) <= myTime ) {
135  if ( getValByKey( &dataObjInp->condInput, DRYRUN_KW ) == NULL ) {
136  status = dataObjUnlinkS( rsComm, dataObjInp, tmpDataObjInfo );
137  if ( status < 0 ) {
138  if ( retVal == 0 ) {
139  retVal = status;
140  }
141  }
142  else {
143  retVal = 1;
144  }
145  }
146  else {
147  retVal = 1;
148  }
149  }
150  tmpDataObjInfo = tmpDataObjInfo->next;
151  }
152 
153  freeAllDataObjInfo( dataObjInfoHead );
154 
155  return retVal;
156 }
157 
158 
160  rsComm_t* rsComm,
161  dataObjInfo_t* dataObjInfo ) {
162 
163  dataObjInp_t dataObjInp;
164  char tmpStr[NAME_LEN];
165  int status;
166 
167  // =-=-=-=-=-=-=-
168  // add the hier to a parser to get the leaf
170  parser.set_string( dataObjInfo->rescHier );
171  std::string cache_resc;
172  parser.last_resc( cache_resc );
173 
174  bzero( &dataObjInp, sizeof( dataObjInp ) );
175  rstrcpy( dataObjInp.objPath, dataObjInfo->objPath, MAX_NAME_LEN );
176  snprintf( tmpStr, NAME_LEN, "1" );
177  addKeyVal( &dataObjInp.condInput, COPIES_KW, tmpStr );
178 
179  // =-=-=-=-=-=-=-
180  // specify the cache repl num to trim just the cache
181  std::stringstream str;
182  str << dataObjInfo->replNum;
183  addKeyVal( &dataObjInp.condInput, REPL_NUM_KW, str.str().c_str() );
184  addKeyVal( &dataObjInp.condInput, RESC_HIER_STR_KW, dataObjInfo->rescHier );
185 
186  status = rsDataObjTrim( rsComm, &dataObjInp );
187  clearKeyVal( &dataObjInp.condInput );
188  if ( status < 0 ) {
190  "trimDataObjInfo: rsDataObjTrim of %s error", dataObjInfo->objPath );
191  }
192  return status;
193 }
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
getValByKey
char * getValByKey(const keyValPair_t *condInput, const char *keyWord)
Definition: rcMisc.cpp:675
DataObjInp::objPath
char objPath[(1024+64)]
Definition: dataObjInpOut.h:66
RESC_NAME_KW
#define RESC_NAME_KW
Definition: rodsKeyWdDef.h:19
NULL
#define NULL
Definition: rodsDef.h:70
irods::at_scope_exit
Definition: irods_at_scope_exit.hpp:10
rsComm_t
Definition: rcConnect.h:145
addKeyVal
int addKeyVal(keyValPair_t *condInput, const char *keyWord, const char *value)
Definition: rcMisc.cpp:789
getRemoteZoneResc.h
DataObjInfo::dataModify
char dataModify[32]
Definition: objInfo.h:151
specColl.hpp
rodsServerHost::conn
rcComm_t * conn
Definition: rodsConnect.h:64
REMOTE_HOST
#define REMOTE_HOST
Definition: rodsConnect.h:45
REMOTE_OPEN
#define REMOTE_OPEN
Definition: getRemoteZoneResc.h:5
irods::hierarchy_parser
Definition: irods_hierarchy_parser.hpp:14
DataObjInfo::rescHier
char rescHier[(1024+64)]
Definition: objInfo.h:132
LOCAL_HOST
#define LOCAL_HOST
Definition: rodsConnect.h:44
irods::resource_redirect
error resource_redirect(const std::string &, rsComm_t *, dataObjInp_t *, std::string &, rodsServerHost_t *&, int &, dataObjInfo_t **_data_obj_info=0)
Definition: irods_resource_redirect.cpp:786
REPL_NUM_KW
#define REPL_NUM_KW
Definition: rodsKeyWdDef.h:30
PASSMSG
#define PASSMSG(message_, prev_error_)
Definition: irods_error.hpp:119
deploy_schemas_locally.parser
parser
Definition: deploy_schemas_locally.py:59
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
irods_resource_redirect.hpp
rsDataObjTrim.hpp
DataObjInfo::next
struct DataObjInfo * next
Definition: objInfo.h:163
resolveLinkedPath
int resolveLinkedPath(rsComm_t *rsComm, char *objPath, specCollCache_t **specCollCache, keyValPair_t *condInput)
Definition: specColl.cpp:711
COPIES_KW
#define COPIES_KW
Definition: rodsKeyWdDef.h:11
rsComm_t::rError
rError_t rError
Definition: rcConnect.h:158
irods::error::code
long long code() const
Definition: irods_error.cpp:194
RESC_HIER_STR_KW
#define RESC_HIER_STR_KW
Definition: rodsKeyWdDef.h:225
rsDataObjTrim
int rsDataObjTrim(rsComm_t *rsComm, dataObjInp_t *dataObjInp)
Definition: rsDataObjTrim.cpp:28
freeAllDataObjInfo
int freeAllDataObjInfo(dataObjInfo_t *dataObjInfoHead)
Definition: rcMisc.cpp:561
CAT_INSUFFICIENT_PRIVILEGE_LEVEL
@ CAT_INSUFFICIENT_PRIVILEGE_LEVEL
Definition: rodsErrorTable.h:445
DRYRUN_KW
#define DRYRUN_KW
Definition: rodsKeyWdDef.h:106
DataObjInp
Definition: dataObjInpOut.h:65
IN_REPL_KW
#define IN_REPL_KW
Definition: rodsKeyWdDef.h:230
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
ADMIN_KW
#define ADMIN_KW
Definition: rodsKeyWdDef.h:62
addRErrorMsg
int addRErrorMsg(rError_t *myError, int status, const char *msg)
Definition: rcMisc.cpp:121
DataObjInfo::replNum
int replNum
Definition: objInfo.h:140
LOCAL_PRIV_USER_AUTH
#define LOCAL_PRIV_USER_AUTH
Definition: rodsUser.h:36
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
rodsLog.h
irods::log
void log(const error &)
Definition: irods_log.cpp:13
icatDefines.h
rsComm_t::clientUser
userInfo_t clientUser
Definition: rcConnect.h:153
getDataObjInfo
int getDataObjInfo(rsComm_t *rsComm, dataObjInp_t *dataObjInp, dataObjInfo_t **dataObjInfoHead, char *accessPerm, int ignoreCondInput)
Definition: dataObjOpr.cpp:87
irods::error
Definition: irods_error.hpp:23
AGE_KW
#define AGE_KW
Definition: rodsKeyWdDef.h:221
rcDataObjTrim
int rcDataObjTrim(rcComm_t *conn, dataObjInp_t *dataObjInp)
Definition: rcDataObjTrim.cpp:73
DEPRECATED_PARAMETER
@ DEPRECATED_PARAMETER
Definition: rodsErrorTable.h:856
irods_hierarchy_parser.hpp
rodsServerHost
Definition: rodsConnect.h:62
rodsLogError
void rodsLogError(int level, int errCode, char *formatStr,...)
Definition: rodsLog.cpp:422
getAndConnRemoteZone
int getAndConnRemoteZone(rsComm_t *rsComm, dataObjInp_t *dataObjInp, rodsServerHost_t **rodsServerHost, char *remotZoneOpr)
Definition: rodsConnect.cpp:784
generate_iadmin_commands_for_41_to_42_upgrade.host
host
Definition: generate_iadmin_commands_for_41_to_42_upgrade.py:23
USER_INCOMPATIBLE_PARAMS
@ USER_INCOMPATIBLE_PARAMS
Definition: rodsErrorTable.h:288
trimDataObjInfo
int trimDataObjInfo(rsComm_t *rsComm, dataObjInfo_t *dataObjInfo)
Definition: rsDataObjTrim.cpp:159
DataObjInfo::objPath
char objPath[(1024+64)]
Definition: objInfo.h:130
userInfo_t::authInfo
authInfo_t authInfo
Definition: rodsUser.h:70
rstrcpy
char * rstrcpy(char *dest, const char *src, int maxLen)
Definition: stringOpr.cpp:51
dataObjOpr.hpp
DataObjInp::condInput
keyValPair_t condInput
Definition: dataObjInpOut.h:74
ACCESS_DELETE_OBJECT
#define ACCESS_DELETE_OBJECT
Definition: icatDefines.h:60
NAME_LEN
#define NAME_LEN
Definition: rodsDef.h:55
authInfo_t::authFlag
int authFlag
Definition: rodsUser.h:42
clearKeyVal
int clearKeyVal(keyValPair_t *condInput)
Definition: rcMisc.cpp:1047
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
DataObjInfo
Definition: objInfo.h:129
dataObjTrim.h
irods::UNLINK_OPERATION
const std::string UNLINK_OPERATION("UNLINK")
resolveInfoForTrim
int resolveInfoForTrim(dataObjInfo_t **dataObjInfoHead, keyValPair_t *condInput)
Definition: dataObjOpr.cpp:1563
SpecCollCache
Definition: objInfo.h:102
objMetaOpr.hpp