From 9b93ddf6af8d65450d835fb285bfb1879fabdfcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Vr=C3=A1til?= <daniel.vratil@kdab.com> Date: Wed, 4 Jan 2017 11:32:51 +0100 Subject: [PATCH 37/40] Break down the transaction in DELETE to multiple smaller trxs The recursive deletion of Collections triggers bunch of subqueries and also generates change notifications to clients, which in turn will try to query more details about the change, which can possibly lead to a transaction deadlock/lock timeout. This change replaces the one huge transaction that wrapped the whole deletion by smaller per-collection transactions. --- server/src/handler/delete.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/server/src/handler/delete.cpp b/server/src/handler/delete.cpp index de3ac4ef5..d601c7dcb 100644 --- a/server/src/handler/delete.cpp +++ b/server/src/handler/delete.cpp @@ -52,7 +52,14 @@ bool Delete::deleteRecursive( Collection &col ) } } DataStore *db = connection()->storageBackend(); - return db->cleanupCollection( col ); + Transaction transaction( db ); + if (!db->cleanupCollection( col )) { + return false; + } + if ( !transaction.commit() ) { + return failureResponse( "Unable to commit transaction" ); + } + return true; } bool Delete::parseStream() @@ -74,7 +81,6 @@ bool Delete::parseStream() // check if collection exists DataStore *db = connection()->storageBackend(); - Transaction transaction( db ); Collection collection = collections.first(); if ( !collection.isValid() ) { @@ -93,10 +99,6 @@ bool Delete::parseStream() return failureResponse( "Unable to delete collection" ); } - if ( !transaction.commit() ) { - return failureResponse( "Unable to commit transaction." ); - } - Response response; response.setTag( tag() ); response.setString( "DELETE completed" ); -- 2.14.1