forked from rucio/rucio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_clean_staging_areas
executable file
·56 lines (51 loc) · 2.3 KB
/
check_clean_staging_areas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
# Copyright European Organization for Nuclear Research (CERN) 2013
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Authors:
# - Cedric Serfon, <cedric.serfon@cern.ch>, 2015
'''
Probe to clean expired replicas on STAGING areas
'''
import sys
import traceback
from rucio.db.sqla.session import get_session
# Exit statuses
OK, WARNING, CRITICAL, UNKNOWN = 0, 1, 2, 3
if __name__ == "__main__":
query = """
declare
type staging_rses is table of number(6) index by varchar(64);
l_staging_rses staging_rses;
begin
for loc in (select id from atlas_rucio.rses where rse like '%STAGING%' and staging_area=1)
loop
l_staging_rses(atlas_rucio.id2rse(loc.id)) := 0;
end loop;
for idx in 1..40
loop
for rep in (select /*+ INDEX(replicas REPLICAS_TOMBSTONE_IDX) */ scope, name, bytes, rse_id from atlas_rucio.replicas where
(case when tombstone is not null then rse_id END) in (select id from atlas_rucio.rses where rse like '%STAGING%' and staging_area=1) and lock_cnt=0 and rownum<10000)
loop
delete from atlas_rucio.replicas where scope=rep.scope and name=rep.name and rse_id=rep.rse_id;
insert into atlas_rucio.updated_rse_counters (id, rse_id, files, bytes, updated_at, created_at) values (sys_guid(), rep.rse_id, -1, -rep.bytes, sysdate, sysdate);
l_staging_rses(atlas_rucio.id2rse(rep.rse_id)) := l_staging_rses(atlas_rucio.id2rse(rep.rse_id)) + 1;
end loop;
commit;
end loop;
for loc in (select id from atlas_rucio.rses where rse like '%STAGING%')
loop
dbms_output.put_line(atlas_rucio.id2rse(loc.id) || ' ' || l_staging_rses(atlas_rucio.id2rse(loc.id)));
end loop;
end;
"""
try:
session = get_session()
session.execute(query)
except:
print traceback.format_exc()
sys.exit(CRITICAL)
sys.exit(OK)