@@ -40,7 +40,6 @@ def init(inconfig, inlog):
40
40
ctx ['lockasattr' ] = inconfig .getboolean ('cs3' , 'lockasattr' , fallback = False )
41
41
ctx ['locknotimpl' ] = False
42
42
ctx ['revagateway' ] = inconfig .get ('cs3' , 'revagateway' )
43
- ctx ['xattrcache' ] = {} # this is a map cs3ref -> arbitrary_metadata as returned by Stat()
44
43
ctx ['grpc_timeout' ] = inconfig .getint ('cs3' , "grpctimeout" , fallback = 10 )
45
44
ctx ['http_timeout' ] = inconfig .getint ('cs3' , "httptimeout" , fallback = 10 )
46
45
# prepare the gRPC channel and validate that the revagateway gRPC server is ready
@@ -97,11 +96,6 @@ def _getcs3reference(endpoint, fileref):
97
96
return ref
98
97
99
98
100
- def _hashedref (endpoint , fileref ):
101
- '''Returns an hashable key for the given endpoint and file reference'''
102
- return str (endpoint ) + str (fileref )
103
-
104
-
105
99
def authenticate_for_test (userid , userpwd ):
106
100
'''Use basic authentication against Reva for testing purposes'''
107
101
authReq = cs3gw .AuthenticateRequest (type = 'basic' , client_id = userid , client_secret = userpwd )
@@ -148,14 +142,14 @@ def stat(endpoint, fileref, userid, versioninv=1):
148
142
log .info ('msg="Invoked stat" fileref="%s" trace="%s" inode="%s" filepath="%s" elapsedTimems="%.1f"' %
149
143
(fileref , statInfo .status .trace , inode , filepath , (tend - tstart )* 1000 ))
150
144
# cache the xattrs map prior to returning; note we're never cleaning this cache and let it grow indefinitely
151
- ctx ['xattrcache' ][_hashedref (endpoint , fileref )] = statInfo .info .arbitrary_metadata .metadata
152
145
return {
153
146
'inode' : inode ,
154
147
'filepath' : filepath ,
155
148
'ownerid' : statInfo .info .owner .opaque_id + '@' + statInfo .info .owner .idp ,
156
149
'size' : statInfo .info .size ,
157
150
'mtime' : statInfo .info .mtime .seconds ,
158
151
'etag' : statInfo .info .etag ,
152
+ 'xattrs' : statInfo .info .arbitrary_metadata .metadata
159
153
}
160
154
161
155
@@ -169,11 +163,6 @@ def setxattr(endpoint, filepath, userid, key, value, lockmd):
169
163
ref = _getcs3reference (endpoint , filepath )
170
164
md = cs3spr .ArbitraryMetadata ()
171
165
md .metadata .update ({key : str (value )}) # pylint: disable=no-member
172
- try :
173
- ctx ['xattrcache' ][_hashedref (endpoint , filepath )][key ] = str (value )
174
- except KeyError :
175
- # we did not have this file in the cache, ignore
176
- pass
177
166
lockid = None
178
167
if lockmd :
179
168
_ , lockid = lockmd
@@ -192,38 +181,6 @@ def setxattr(endpoint, filepath, userid, key, value, lockmd):
192
181
log .debug (f'msg="Invoked setxattr" result="{ res } "' )
193
182
194
183
195
- def getxattr (endpoint , filepath , userid , key ):
196
- '''Get the extended attribute <key> using the given userid as access token'''
197
- ref = _getcs3reference (endpoint , filepath )
198
- statInfo = None
199
- href = _hashedref (endpoint , filepath )
200
- if href not in ctx ['xattrcache' ]:
201
- # cache miss, go for Stat and refresh cache
202
- tstart = time .time ()
203
- statInfo = ctx ['cs3gw' ].Stat (request = cs3sp .StatRequest (ref = ref ), metadata = [('x-access-token' , userid )])
204
- tend = time .time ()
205
- if statInfo .status .code == cs3code .CODE_NOT_FOUND :
206
- log .debug (f'msg="Invoked stat for getxattr on missing file" filepath="{ filepath } "' )
207
- return None
208
- if statInfo .status .code != cs3code .CODE_OK :
209
- log .error ('msg="Failed to stat" filepath="%s" userid="%s" trace="%s" key="%s" reason="%s"' %
210
- (filepath , userid [- 20 :], statInfo .status .trace , key , statInfo .status .message .replace ('"' , "'" )))
211
- raise IOError (statInfo .status .message )
212
- log .debug (f'msg="Invoked stat for getxattr" filepath="{ filepath } " elapsedTimems="{ (tend - tstart ) * 1000 :.1f} "' )
213
- ctx ['xattrcache' ][href ] = statInfo .info .arbitrary_metadata .metadata
214
- try :
215
- xattrvalue = ctx ['xattrcache' ][href ][key ]
216
- if xattrvalue == '' :
217
- raise KeyError
218
- if not statInfo :
219
- log .debug (f'msg="Returning cached attr on getxattr" filepath="{ filepath } " key="{ key } "' )
220
- return xattrvalue
221
- except KeyError :
222
- log .info ('msg="Empty value or key not found in getxattr" filepath="%s" key="%s" trace="%s" metadata="%s"' %
223
- (filepath , key , statInfo .status .trace if statInfo else 'N/A' , ctx ['xattrcache' ][href ]))
224
- return None
225
-
226
-
227
184
def rmxattr (endpoint , filepath , userid , key , lockmd ):
228
185
'''Remove the extended attribute <key> using the given userid as access token'''
229
186
ref = _getcs3reference (endpoint , filepath )
@@ -240,11 +197,6 @@ def rmxattr(endpoint, filepath, userid, key, lockmd):
240
197
log .error ('msg="Failed to rmxattr" filepath="%s" trace="%s" key="%s" reason="%s"' %
241
198
(filepath , key , res .status .trace , res .status .message .replace ('"' , "'" )))
242
199
raise IOError (res .status .message )
243
- try :
244
- del ctx ['xattrcache' ][_hashedref (endpoint , filepath )][key ]
245
- except KeyError :
246
- # we did not have this file in the cache, ignore
247
- pass
248
200
log .debug (f'msg="Invoked rmxattr" result="{ res .status } "' )
249
201
250
202
@@ -253,7 +205,8 @@ def setlock(endpoint, filepath, userid, appname, value):
253
205
if ctx ['lockasattr' ] and ctx ['locknotimpl' ]:
254
206
log .debug (f'msg="Using xattrs to execute setlock" filepath="{ filepath } " value="{ value } "' )
255
207
try :
256
- currvalue = getxattr (endpoint , filepath , userid , LOCK_ATTR_KEY )
208
+ filemd = stat (endpoint , filepath , userid )
209
+ currvalue = filemd ['xattrs' ][LOCK_ATTR_KEY ]
257
210
log .info ('msg="Invoked setlock on an already locked entity" filepath="%s" appname="%s" previouslock="%s"' %
258
211
(filepath , appname , currvalue ))
259
212
raise IOError (common .EXCL_ERROR )
@@ -287,7 +240,8 @@ def getlock(endpoint, filepath, userid):
287
240
if ctx ['lockasattr' ] and ctx ['locknotimpl' ]:
288
241
log .debug (f'msg="Using xattrs to execute getlock" filepath="{ filepath } "' )
289
242
try :
290
- currvalue = getxattr (endpoint , filepath , userid , LOCK_ATTR_KEY )
243
+ filemd = stat (endpoint , filepath , userid )
244
+ currvalue = filemd ['xattrs' ][LOCK_ATTR_KEY ]
291
245
return {
292
246
'lock_id' : currvalue .split ('!' )[1 ],
293
247
'type' : 2 , # LOCK_TYPE_WRITE, though this is advisory!
@@ -333,7 +287,8 @@ def refreshlock(endpoint, filepath, userid, appname, value, oldvalue=None):
333
287
if ctx ['lockasattr' ] and ctx ['locknotimpl' ]:
334
288
log .debug (f'msg="Using xattrs to execute setlock" filepath="{ filepath } " value="{ value } "' )
335
289
try :
336
- currvalue = getxattr (endpoint , filepath , userid , LOCK_ATTR_KEY )
290
+ filemd = stat (endpoint , filepath , userid )
291
+ currvalue = filemd ['xattrs' ][LOCK_ATTR_KEY ]
337
292
if currvalue .split ('!' )[0 ] == appname and (not oldvalue or currvalue .split ('!' )[1 ] == oldvalue ):
338
293
raise KeyError
339
294
log .info ('msg="Failed precondition on refreshlock" filepath="%s" appname="%s" previouslock="%s"' %
@@ -369,7 +324,8 @@ def unlock(endpoint, filepath, userid, appname, value):
369
324
if ctx ['lockasattr' ] and ctx ['locknotimpl' ]:
370
325
log .debug (f'msg="Using xattrs to execute unlock" filepath="{ filepath } " value="{ value } "' )
371
326
try :
372
- currvalue = getxattr (endpoint , filepath , userid , LOCK_ATTR_KEY )
327
+ filemd = stat (endpoint , filepath , userid )
328
+ currvalue = filemd ['xattrs' ][LOCK_ATTR_KEY ]
373
329
if currvalue .split ('!' )[0 ] == appname and currvalue .split ('!' )[1 ] == value :
374
330
raise KeyError
375
331
log .info ('msg="Failed precondition on unlock" filepath="%s" appname="%s" previouslock="%s"' %
0 commit comments