|
| 1 | +/* Update layestattype to include new columns and fix ordering of columns as its used in update statement in trigger*/ |
| 2 | + |
| 3 | +DROP TYPE public.layerstattype; |
| 4 | + |
| 5 | +CREATE TYPE public.layerstattype AS |
| 6 | +( |
| 7 | + int_cores_min bigint, |
| 8 | + int_mem_min bigint, |
| 9 | + int_core_time_success bigint, |
| 10 | + int_core_time_fail bigint, |
| 11 | + int_gpu_time_success bigint, |
| 12 | + int_gpu_time_fail bigint, |
| 13 | + int_total_count bigint, |
| 14 | + int_waiting_count bigint, |
| 15 | + int_dead_count bigint, |
| 16 | + int_depend_count bigint, |
| 17 | + int_eaten_count bigint, |
| 18 | + int_succeeded_count bigint, |
| 19 | + int_running_count bigint, |
| 20 | + int_max_rss bigint, |
| 21 | + int_gpu_mem_max bigint |
| 22 | +); |
| 23 | + |
| 24 | +/* update trigger to include new columns in update for layer_history */ |
| 25 | +-- FUNCTION: public.trigger__after_job_finished() |
| 26 | + |
| 27 | +-- DROP FUNCTION IF EXISTS public.trigger__after_job_finished(); |
| 28 | + |
| 29 | +CREATE OR REPLACE FUNCTION public.trigger__after_job_finished() |
| 30 | + RETURNS trigger |
| 31 | + LANGUAGE 'plpgsql' |
| 32 | + COST 100 |
| 33 | + VOLATILE NOT LEAKPROOF |
| 34 | +AS $BODY$ |
| 35 | +DECLARE |
| 36 | + ts INT := cast(epoch(current_timestamp) as integer); |
| 37 | + js JobStatType; |
| 38 | + ls LayerStatType; |
| 39 | + one_layer RECORD; |
| 40 | +BEGIN |
| 41 | + SELECT |
| 42 | + job_usage.int_core_time_success, |
| 43 | + job_usage.int_core_time_fail, |
| 44 | + job_usage.int_gpu_time_success, |
| 45 | + job_usage.int_gpu_time_fail, |
| 46 | + job_stat.int_waiting_count, |
| 47 | + job_stat.int_dead_count, |
| 48 | + job_stat.int_depend_count, |
| 49 | + job_stat.int_eaten_count, |
| 50 | + job_stat.int_succeeded_count, |
| 51 | + job_stat.int_running_count, |
| 52 | + job_mem.int_max_rss, |
| 53 | + job_mem.int_gpu_mem_max |
| 54 | + INTO |
| 55 | + js |
| 56 | + FROM |
| 57 | + job_mem, |
| 58 | + job_usage, |
| 59 | + job_stat |
| 60 | + WHERE |
| 61 | + job_usage.pk_job = job_mem.pk_job |
| 62 | + AND |
| 63 | + job_stat.pk_job = job_mem.pk_job |
| 64 | + AND |
| 65 | + job_mem.pk_job = NEW.pk_job; |
| 66 | + |
| 67 | + UPDATE |
| 68 | + job_history |
| 69 | + SET |
| 70 | + pk_dept = NEW.pk_dept, |
| 71 | + int_core_time_success = js.int_core_time_success, |
| 72 | + int_core_time_fail = js.int_core_time_fail, |
| 73 | + int_gpu_time_success = js.int_gpu_time_success, |
| 74 | + int_gpu_time_fail = js.int_gpu_time_fail, |
| 75 | + int_frame_count = NEW.int_frame_count, |
| 76 | + int_layer_count = NEW.int_layer_count, |
| 77 | + int_waiting_count = js.int_waiting_count, |
| 78 | + int_dead_count = js.int_dead_count, |
| 79 | + int_depend_count = js.int_depend_count, |
| 80 | + int_eaten_count = js.int_eaten_count, |
| 81 | + int_succeeded_count = js.int_succeeded_count, |
| 82 | + int_running_count = js.int_running_count, |
| 83 | + int_max_rss = js.int_max_rss, |
| 84 | + int_gpu_mem_max = js.int_gpu_mem_max, |
| 85 | + int_ts_stopped = ts |
| 86 | + WHERE |
| 87 | + pk_job = NEW.pk_job; |
| 88 | + |
| 89 | + FOR one_layer IN (SELECT pk_layer from layer where pk_job = NEW.pk_job) |
| 90 | + LOOP |
| 91 | + SELECT |
| 92 | + layer.int_cores_min, |
| 93 | + layer.int_mem_min, |
| 94 | + layer_usage.int_core_time_success, |
| 95 | + layer_usage.int_core_time_fail, |
| 96 | + layer_usage.int_gpu_time_success, |
| 97 | + layer_usage.int_gpu_time_fail, |
| 98 | + layer_stat.int_total_count, |
| 99 | + layer_stat.int_waiting_count, |
| 100 | + layer_stat.int_dead_count, |
| 101 | + layer_stat.int_depend_count, |
| 102 | + layer_stat.int_eaten_count, |
| 103 | + layer_stat.int_succeeded_count, |
| 104 | + layer_stat.int_running_count, |
| 105 | + layer_mem.int_max_rss, |
| 106 | + layer_mem.int_gpu_mem_max |
| 107 | + INTO |
| 108 | + ls |
| 109 | + FROM |
| 110 | + layer, |
| 111 | + layer_mem, |
| 112 | + layer_usage, |
| 113 | + layer_stat |
| 114 | + WHERE |
| 115 | + layer_mem.pk_layer = layer.pk_layer |
| 116 | + AND |
| 117 | + layer_usage.pk_layer = layer.pk_layer |
| 118 | + AND |
| 119 | + layer_stat.pk_layer = layer.pk_layer |
| 120 | + AND |
| 121 | + layer.pk_layer = one_layer.pk_layer; |
| 122 | + UPDATE |
| 123 | + layer_history |
| 124 | + SET |
| 125 | + int_cores_min = ls.int_cores_min, |
| 126 | + int_mem_min = ls.int_mem_min, |
| 127 | + int_core_time_success = ls.int_core_time_success, |
| 128 | + int_core_time_fail = ls.int_core_time_fail, |
| 129 | + int_gpu_time_success = ls.int_gpu_time_success, |
| 130 | + int_gpu_time_fail = ls.int_gpu_time_fail, |
| 131 | + int_frame_count = ls.int_total_count, |
| 132 | + int_waiting_count = ls.int_waiting_count, |
| 133 | + int_dead_count = ls.int_dead_count, |
| 134 | + int_depend_count = ls.int_depend_count, |
| 135 | + int_eaten_count = ls.int_eaten_count, |
| 136 | + int_succeeded_count = ls.int_succeeded_count, |
| 137 | + int_running_count = ls.int_running_count, |
| 138 | + int_max_rss = ls.int_max_rss, |
| 139 | + int_gpu_mem_max = ls.int_gpu_mem_max |
| 140 | + WHERE |
| 141 | + pk_layer = one_layer.pk_layer; |
| 142 | + END LOOP; |
| 143 | + |
| 144 | + /** |
| 145 | + * Delete any local core assignments from this job. |
| 146 | + **/ |
| 147 | + DELETE FROM job_local WHERE pk_job=NEW.pk_job; |
| 148 | + |
| 149 | + RETURN NEW; |
| 150 | +END; |
| 151 | +$BODY$; |
| 152 | + |
| 153 | +-- FUNCTION: public.trigger__before_delete_layer() |
| 154 | + |
| 155 | +-- DROP FUNCTION IF EXISTS public.trigger__before_delete_layer(); |
| 156 | + |
| 157 | +CREATE OR REPLACE FUNCTION public.trigger__before_delete_layer() |
| 158 | + RETURNS trigger |
| 159 | + LANGUAGE 'plpgsql' |
| 160 | + COST 100 |
| 161 | + VOLATILE NOT LEAKPROOF |
| 162 | +AS $BODY$ |
| 163 | +DECLARE |
| 164 | + ls LayerStatType; |
| 165 | +BEGIN |
| 166 | + SELECT |
| 167 | + layer.int_cores_min, |
| 168 | + layer.int_mem_min, |
| 169 | + layer_usage.int_core_time_success, |
| 170 | + layer_usage.int_core_time_fail, |
| 171 | + layer_usage.int_gpu_time_success, |
| 172 | + layer_usage.int_gpu_time_fail, |
| 173 | + layer_stat.int_total_count, |
| 174 | + layer_stat.int_waiting_count, |
| 175 | + layer_stat.int_dead_count, |
| 176 | + layer_stat.int_depend_count, |
| 177 | + layer_stat.int_eaten_count, |
| 178 | + layer_stat.int_succeeded_count, |
| 179 | + layer_stat.int_running_count, |
| 180 | + layer_mem.int_max_rss, |
| 181 | + layer_mem.int_gpu_mem_max |
| 182 | + INTO |
| 183 | + ls |
| 184 | + FROM |
| 185 | + layer, |
| 186 | + layer_mem, |
| 187 | + layer_usage, |
| 188 | + layer_stat |
| 189 | + WHERE |
| 190 | + layer_mem.pk_layer = layer.pk_layer |
| 191 | + AND |
| 192 | + layer_usage.pk_layer = layer.pk_layer |
| 193 | + AND |
| 194 | + layer_stat.pk_layer = layer.pk_layer |
| 195 | + AND |
| 196 | + layer.pk_layer = OLD.pk_layer; |
| 197 | + UPDATE |
| 198 | + layer_history |
| 199 | + SET |
| 200 | + int_cores_min = ls.int_cores_min, |
| 201 | + int_mem_min = ls.int_mem_min, |
| 202 | + int_core_time_success = ls.int_core_time_success, |
| 203 | + int_core_time_fail = ls.int_core_time_fail, |
| 204 | + int_gpu_time_success = ls.int_gpu_time_success, |
| 205 | + int_gpu_time_fail = ls.int_gpu_time_fail, |
| 206 | + int_frame_count = ls.int_total_count, |
| 207 | + int_waiting_count = ls.int_waiting_count, |
| 208 | + int_dead_count = ls.int_dead_count, |
| 209 | + int_depend_count = ls.int_depend_count, |
| 210 | + int_eaten_count = ls.int_eaten_count, |
| 211 | + int_succeeded_count = ls.int_succeeded_count, |
| 212 | + int_running_count = ls.int_running_count, |
| 213 | + int_max_rss = ls.int_max_rss, |
| 214 | + int_gpu_mem_max = ls.int_gpu_mem_max, |
| 215 | + b_archived = true |
| 216 | + WHERE |
| 217 | + pk_layer = OLD.pk_layer; |
| 218 | + |
| 219 | + DELETE FROM layer_resource where pk_layer=OLD.pk_layer; |
| 220 | + DELETE FROM layer_stat where pk_layer=OLD.pk_layer; |
| 221 | + DELETE FROM layer_usage where pk_layer=OLD.pk_layer; |
| 222 | + DELETE FROM layer_env where pk_layer=OLD.pk_layer; |
| 223 | + DELETE FROM layer_mem where pk_layer=OLD.pk_layer; |
| 224 | + DELETE FROM layer_output where pk_layer=OLD.pk_layer; |
| 225 | + |
| 226 | + RETURN OLD; |
| 227 | +END; |
| 228 | +$BODY$; |
0 commit comments