Yair Zaslavsky has uploaded a new change for review.

Change subject: setup: checking if command_entities table exist
......................................................................

setup: checking if command_entities table exist

oVirt 3.5 has introduced command_entities table.
In addition to adding some new functions related to this
table to the task clenaer utility, some functions got changed,
but as it is run during setup and might run on top of version which
preceeds oVirt 3.5, it should be checked in the relevant SPs that
the table exists.

Bug-Url: https://bugzilla.redhat.com/1161012
Change-Id: I3152c4d3f6e02915053ada5019abeea7cb356751
Signed-off-by: Yair Zaslavsky <yzasl...@redhat.com>
---
M packaging/setup/dbutils/taskcleaner.sh
M packaging/setup/dbutils/taskcleaner_sp.sql
2 files changed, 33 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/47/37847/1

diff --git a/packaging/setup/dbutils/taskcleaner.sh 
b/packaging/setup/dbutils/taskcleaner.sh
index 3494c36..56078ef 100755
--- a/packaging/setup/dbutils/taskcleaner.sh
+++ b/packaging/setup/dbutils/taskcleaner.sh
@@ -124,6 +124,7 @@
        VERSION="3.5"
 else
        VERSION="3.4"
+        dbfunc_psql_die --command="create table command_entities ();"
 fi
 
 if [ "${TASK_ID}" != "" -o "${COMMAND_ID}" != "" -o -n "${CLEAR_ALL}" -o -n 
"${CLEAR_COMPENSATION}" -o -n "${CLEAR_JOB_STEPS}" ]; then #delete operations 
block
@@ -295,3 +296,8 @@
 # Execute
 
 dbfunc_psql_die --command="${CMD1}${CMD2}"
+
+if [[ $VERSION = "3.4" ]]; then
+    dbfunc_psql_die --command="drop table command_entities cascade;"
+fi
+
diff --git a/packaging/setup/dbutils/taskcleaner_sp.sql 
b/packaging/setup/dbutils/taskcleaner_sp.sql
index f958bc7..a3fac13 100644
--- a/packaging/setup/dbutils/taskcleaner_sp.sql
+++ b/packaging/setup/dbutils/taskcleaner_sp.sql
@@ -31,15 +31,29 @@
    AS $procedure$
 DECLARE
 deleted_rows int;
+root_command_id_of_deleted_cmds UUID;
 BEGIN
-    IF EXISTS (SELECT 1 FROM GetAsyncTasksZombies() WHERE command_id = 
v_command_id) THEN
-        DELETE FROM async_tasks WHERE command_id = v_command_id;
+    IF (fn_db_is_table_exists ('command_entities')) THEN
+        DELETE FROM command_entities c WHERE
+        c.command_id IN (
+            SELECT command_id FROM GetAsyncTasksZombies() t WHERE t.command_id 
= v_command_id
+        );
+
+        DELETE FROM command_entities c WHERE
+        c.command_id IN (
+            SELECT root_command_id FROM GetAsyncTasksZombies() t WHERE 
t.root_command_id = v_command_id
+        );
     END IF;
-    DELETE FROM command_entities where command_id = v_command_id;
-    GET DIAGNOSTICS deleted_rows = ROW_COUNT;
-    IF deleted_rows > 0 THEN
-        DELETE FROM command_entities C WHERE command_id = 
root_command_id_of_deleted_cmds AND NOT EXISTS (SELECT * from COMMAND_ENTITIES 
WHERE root_command_id = C.command_id);
-    END IF;
+
+    DELETE FROM async_tasks WHERE
+    root_command_id IN (
+        SELECT root_command_id FROM GetAsyncTasksZombies() t WHERE 
t.root_command_id = v_command_id
+    );
+
+    DELETE FROM async_tasks WHERE
+    root_command_id IN (
+        SELECT root_command_id FROM GetAsyncTasksZombies() t WHERE 
t.command_id = v_command_id
+    );
 END; $procedure$
 LANGUAGE plpgsql;
 
@@ -50,11 +64,13 @@
 root_command_id_of_deleted_cmds UUID;
 BEGIN
         DELETE FROM async_tasks WHERE command_id = v_command_id;
-        SELECT root_command_id  into root_command_id_of_deleted_cmds FROM 
COMMAND_entities WHERE command_id = v_command_id;
-        DELETE FROM command_entities where command_id = v_command_id;
-        GET DIAGNOSTICS deleted_rows = ROW_COUNT;
-        IF deleted_rows > 0 THEN
+        IF (fn_db_is_table_exists ('command_entities')) THEN
+            SELECT root_command_id  into root_command_id_of_deleted_cmds FROM 
COMMAND_entities WHERE command_id = v_command_id;
+            DELETE FROM command_entities where command_id = v_command_id;
+            GET DIAGNOSTICS deleted_rows = ROW_COUNT;
+            IF deleted_rows > 0 THEN
                 DELETE FROM command_entities C WHERE command_id = 
root_command_id_of_deleted_cmds AND NOT EXISTS (SELECT * from COMMAND_ENTITIES 
WHERE root_command_id = C.command_id);
+            END IF;
         END IF;
 END; $procedure$
 LANGUAGE plpgsql;


-- 
To view, visit http://gerrit.ovirt.org/37847
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3152c4d3f6e02915053ada5019abeea7cb356751
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.5
Gerrit-Owner: Yair Zaslavsky <yzasl...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to