From f21fd3c0fe9459fcfe1757892143f00bf28be151 Mon Sep 17 00:00:00 2001 From: Michael Hackstein Date: Tue, 25 Apr 2017 15:56:39 +0200 Subject: [PATCH] Made dropping of graphs more resilient to errors --- js/common/modules/@arangodb/general-graph.js | 73 ++++++-------------- 1 file changed, 22 insertions(+), 51 deletions(-) diff --git a/js/common/modules/@arangodb/general-graph.js b/js/common/modules/@arangodb/general-graph.js index 2064054250..219858fdcf 100644 --- a/js/common/modules/@arangodb/general-graph.js +++ b/js/common/modules/@arangodb/general-graph.js @@ -2012,67 +2012,38 @@ exports._drop = function (graphId, dropCollections) { if (dropCollections === true) { graphs = exports._listObjects(); - var initialCollections = new Set(); // Here we collect the initial collection(s) + // Here we collect all collections + // that are leading for distribution + var initialCollections = new Set(); + let dropColCB = (name) => { + if (checkIfMayBeDropped(name, graph._key, graphs)) { + try { + let colObj = db[name]; + if (colObj !== undefined) { + // If it is undefined the collection is gone already + if (colObj.properties().distributeShardsLike !== undefined) { + db._drop(name); + } else { + initialCollections.add(name); + } + } + } catch (ignore) {} + } + }; // drop orphans if (!graph.orphanCollections) { graph.orphanCollections = []; } - graph.orphanCollections.forEach( - function (oC) { - if (checkIfMayBeDropped(oC, graph._key, graphs)) { - try { - let colObj = db[oC]; - if (colObj.properties().distributeShardsLike !== undefined) { - db._drop(oC); - } else { - initialCollections.add(oC); - } - } catch (ignore) {} - } - } - ); + graph.orphanCollections.forEach(dropColCB); var edgeDefinitions = graph.edgeDefinitions; edgeDefinitions.forEach( function (edgeDefinition) { var from = edgeDefinition.from; var to = edgeDefinition.to; var collection = edgeDefinition.collection; - if (checkIfMayBeDropped(collection, graph._key, graphs)) { - let colObj = db[collection]; - if (colObj.properties().distributeShardsLike !== undefined) { - db._drop(collection); - } else { - initialCollections.add(collection); - } - } - from.forEach( - function (col) { - if (checkIfMayBeDropped(col, graph._key, graphs)) { - try { - let colObj = db[col]; - if (colObj.properties().distributeShardsLike !== undefined) { - db._drop(col); - } else { - initialCollections.add(col); - } - } catch (ignore) {} - } - } - ); - to.forEach( - function (col) { - if (checkIfMayBeDropped(col, graph._key, graphs)) { - try { - let colObj = db[col]; - if (colObj.properties().distributeShardsLike !== undefined) { - db._drop(col); - } else { - initialCollections.add(col); - } - } catch (ignore2) {} - } - } - ); + dropColCB(edgeDefinition.collection); + from.forEach(dropColCB); + to.forEach(dropColCB); } ); for (let c of initialCollections) {