forked from taskcluster/taskcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0009.yml
292 lines (291 loc) · 11.6 KB
/
0009.yml
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
version: 9
description: purge-cache phase 2
migrationScript: 0009-migration.sql
downgradeScript: 0009-downgrade.sql
methods:
cache_purges_entities_load:
deprecated: true
description: See taskcluster-lib-entities
mode: read
serviceName: purge_cache
args: partition_key text, row_key text
returns: table (partition_key_out text, row_key_out text, value jsonb, version integer, etag uuid)
body: |-
declare
decoded_composite_key text[];
begin
decoded_composite_key := decode_composite_key(cache_purges_entities_load.partition_key);
return query
select
cache_purges_entities_load.partition_key,
cache_purges_entities_load.row_key,
jsonb_build_object(
'PartitionKey', cache_purges_entities_load.partition_key,
'RowKey', cache_purges_entities_load.row_key,
'provisionerId', provisioner_id,
'workerType', worker_type,
'cacheName', cache_name,
'before', before,
'expires', expires) as value,
1 as version,
cache_purges.etag as etag
from cache_purges
where
cache_purges.provisioner_id = decoded_composite_key[1] and cache_purges.worker_type = decoded_composite_key[2] and cache_purges.cache_name = decode_string_key(cache_purges_entities_load.row_key);
end
cache_purges_entities_create:
deprecated: true
serviceName: purge_cache
description: See taskcluster-lib-entities
mode: write
args: pk text, rk text, properties jsonb, overwrite boolean, version integer
returns: uuid
body: |-
declare
new_row cache_purges%ROWTYPE;
begin
select
(properties ->> 'provisionerId')::text as provisioner_id,
(properties ->> 'workerType')::text as worker_type,
(properties ->> 'cacheName')::text as cache_name,
(properties ->> 'before')::timestamptz as before,
(properties ->> 'expires')::timestamptz as expires,
public.gen_random_uuid() as etag
into new_row;
if overwrite then
raise exception 'overwrite not implemented';
else
execute 'insert into cache_purges select $1.*' using new_row;
end if;
return new_row.etag;
end
cache_purges_entities_remove:
deprecated: true
serviceName: purge_cache
description: See taskcluster-lib-entities
mode: write
args: partition_key text, row_key text
returns: table (etag uuid)
body: |-
declare
decoded_composite_key text[];
begin
decoded_composite_key := decode_composite_key(cache_purges_entities_remove.partition_key);
return query delete from cache_purges
where
cache_purges.provisioner_id = decoded_composite_key[1] and cache_purges.worker_type = decoded_composite_key[2] and cache_purges.cache_name = decode_string_key(cache_purges_entities_remove.row_key)
returning cache_purges.etag;
end
cache_purges_entities_modify:
deprecated: true
serviceName: purge_cache
description: See taskcluster-lib-entities
mode: write
args: partition_key text, row_key text, properties jsonb, version integer, old_etag uuid
returns: table (etag uuid)
body: |-
declare
new_row cache_purges%ROWTYPE;
decoded_composite_key text[];
begin
decoded_composite_key := decode_composite_key(cache_purges_entities_modify.partition_key);
select
(properties ->> 'provisionerId')::text as provisioner_id,
(properties ->> 'workerType')::text as worker_type,
(properties ->> 'cacheName')::text as cache_name,
(properties ->> 'before')::timestamptz as before,
(properties ->> 'expires')::timestamptz as expires,
public.gen_random_uuid() as etag
into new_row;
update cache_purges
set (
provisioner_id,
worker_type,
cache_name,
before,
expires,
etag
) = (
new_row.provisioner_id,
new_row.worker_type,
new_row.cache_name,
new_row.before,
new_row.expires,
new_row.etag
)
where
cache_purges.provisioner_id = decoded_composite_key[1] and
cache_purges.worker_type = decoded_composite_key[2] and
cache_purges.cache_name = decode_string_key(cache_purges_entities_modify.row_key) and
cache_purges.etag = cache_purges_entities_modify.old_etag;
if found then
return query select new_row.etag;
return;
end if;
perform cache_purges.etag from cache_purges
where
cache_purges.provisioner_id = decoded_composite_key[1] and
cache_purges.worker_type = decoded_composite_key[2] and
cache_purges.cache_name = decode_string_key(cache_purges_entities_modify.row_key);
if found then
raise exception 'unsuccessful update' using errcode = 'P0004';
else
raise exception 'no such row' using errcode = 'P0002';
end if;
end
cache_purges_entities_scan:
deprecated: true
description: See taskcluster-lib-entities
mode: read
serviceName: purge_cache
args: pk text, rk text, condition text, size integer, page integer
returns: table (partition_key text, row_key text, value jsonb, version integer, etag uuid)
body: |-
declare
cond text[];
exp_cond_operator text;
exp_cond_operand timestamptz;
partition_key_var text;
row_key_var text;
decoded_composite_key text[];
begin
decoded_composite_key := decode_composite_key(cache_purges_entities_scan.pk);
if not condition is null then
cond := regexp_split_to_array(condition, '\s+');
exp_cond_operator := cond[4];
exp_cond_operand := cond[5] :: timestamptz;
return query select
encode_composite_key(cache_purges.provisioner_id, cache_purges.worker_type) as partition_key,
encode_string_key(cache_purges.cache_name) as row_key,
jsonb_build_object(
'PartitionKey', encode_composite_key(cache_purges.provisioner_id, cache_purges.worker_type),
'RowKey', cache_name,
'provisionerId', provisioner_id,
'workerType', worker_type,
'cacheName', cache_name,
'before', before,
'expires', expires
) as value,
1 as version,
cache_purges.etag as etag from cache_purges
where
(cache_purges_entities_scan.pk is null or cache_purges_entities_scan.pk = decoded_composite_key[1] || '~' || decoded_composite_key[2]) and
(cache_purges_entities_scan.rk is null or cache_purges_entities_scan.rk = cache_name) and
case
when exp_cond_operator = '=' then expires = exp_cond_operand
when exp_cond_operator = '<' then expires < exp_cond_operand
when exp_cond_operator = '<=' then expires <= exp_cond_operand
when exp_cond_operator = '>' then expires > exp_cond_operand
when exp_cond_operator = '>=' then expires >= exp_cond_operand
else expires <> exp_cond_operand
end
order by cache_purges.provisioner_id, cache_purges.worker_type, cache_purges.cache_name
limit case
when (size is not null and size > 0) then size + 1
else null
end
offset case
when (page is not null and page > 0) then page
else 0
end;
else
return query select
encode_composite_key(cache_purges.provisioner_id, cache_purges.worker_type) as partition_key,
encode_string_key(cache_purges.cache_name) as row_key,
jsonb_build_object(
'PartitionKey', encode_composite_key(cache_purges.provisioner_id, cache_purges.worker_type),
'RowKey', encode_string_key(cache_name),
'provisionerId', provisioner_id,
'workerType', worker_type,
'cacheName', cache_name,
'before', before,
'expires', expires
) as value,
1 as version,
cache_purges.etag as etag from cache_purges
where
(cache_purges_entities_scan.pk is null or (cache_purges.provisioner_id = decoded_composite_key[1] and cache_purges.worker_type = decoded_composite_key[2])) and
(cache_purges_entities_scan.rk is null or cache_purges_entities_scan.rk = cache_name)
order by cache_purges.provisioner_id, cache_purges.worker_type, cache_purges.cache_name
limit case
when (size is not null and size > 0) then size + 1
else null
end
offset case
when (size is not null and size > 0 and page is not null and page > 0) then page
else 0
end;
end if;
end
purge_requests:
description: |-
List the caches for this `provisioner_id_in`/`worker_type_in`.
mode: read
serviceName: purge_cache
args: provisioner_id_in text, worker_type_in text
returns: table (provisioner_id text, worker_type text, cache_name text, before timestamptz)
body: |-
begin
return query
select cache_purges.provisioner_id, cache_purges.worker_type, cache_purges.cache_name, cache_purges.before from cache_purges
where cache_purges.provisioner_id = provisioner_id_in and cache_purges.worker_type = worker_type_in;
end
all_purge_requests:
description: |-
View all active purge requests.
mode: read
serviceName: purge_cache
args: page_size_in integer, page_offset_in integer
returns: table (provisioner_id text, worker_type text, cache_name text, before timestamptz)
body: |-
begin
return query select cache_purges.provisioner_id, cache_purges.worker_type, cache_purges.cache_name, cache_purges.before
from cache_purges
order by cache_purges.provisioner_id, cache_purges.worker_type, cache_purges.cache_name
limit get_page_limit(page_size_in)
offset get_page_offset(page_offset_in);
end
purge_cache:
serviceName: purge_cache
description: |-
Publish a request to purge caches with name `cache_name_in`
on `provisioner_id_in`/`worker_type_in` workers.
mode: write
args: provisioner_id_in text, worker_type_in text, cache_name_in text, before_in timestamptz, expires_in timestamptz
returns: void
body: |-
declare
new_etag uuid := public.gen_random_uuid();
begin
insert into cache_purges(provisioner_id, worker_type, cache_name, before, expires, etag)
values (
provisioner_id_in,
worker_type_in,
cache_name_in,
before_in,
expires_in,
new_etag
) on conflict (provisioner_id, worker_type, cache_name) do
update
set (before, expires, etag) = (before_in, expires_in, new_etag)
where cache_purges.provisioner_id = provisioner_id_in and cache_purges.worker_type = worker_type_in and cache_purges.cache_name = cache_name_in;
end
expire_cache_purges:
description: |-
Expire cache purges that come before `expires_in`.
Returns a count of rows that have been deleted.
mode: write
serviceName: purge_cache
args: expires_in timestamptz
returns: integer
body: |-
declare
count integer;
begin
delete from cache_purges where cache_purges.expires < expires_in;
if found then
get diagnostics count = row_count;
return count;
end if;
return 0;
end