Browse Source

HUE-8319 [editor] Silence background SQL refresh errors

This takes care of an issue where "Failed to invalidate" messages occasionally appear in the UI. Users will still be notified on manual refresh.
Johan Ahlen 7 years ago
parent
commit
931c867513

+ 3 - 3
apps/metastore/src/metastore/static/metastore/js/metastore.ko.js

@@ -201,7 +201,7 @@ var MetastoreViewModel = (function () {
     if (!self.reloading() && self.catalogEntry()) {
       self.reloading(true);
       // Clear will publish when done
-      self.catalogEntry().clear(self.catalogEntry().getSourceType() === 'impala' ? 'invalidate' : 'cache');
+      self.catalogEntry().clearCache({ invalidate: self.catalogEntry().getSourceType() === 'impala' ? 'invalidate' : 'cache' });
     }
   };
 
@@ -255,7 +255,7 @@ var MetastoreViewModel = (function () {
             self.loadingTable(false);
             self.database().setTable(foundTables[0], callback);
           } else if (clearDbCacheOnMissing) {
-            self.database().catalogEntry.clear('invalidate').done(function () {
+            self.database().catalogEntry.clearCache({ invalidate: 'invalidate', silenceErrors: true }).done(function () {
               self.database().load(function () {
                 setTableAfterLoad(false);
               });
@@ -298,7 +298,7 @@ var MetastoreViewModel = (function () {
       if (foundDatabases.length === 1) {
         self.setDatabase(foundDatabases[0], callback);
       } else if (clearCacheOnMissing) {
-        self.catalogEntry().clear('invalidate').done(function () {
+        self.catalogEntry().clearCache({ invalidate: 'invalidate', silenceErrors: true }).done(function () {
           self.loadDatabases().done(function () {
             whenLoaded(false)
           })

+ 2 - 2
apps/metastore/src/metastore/static/metastore/js/metastore.model.js

@@ -83,7 +83,7 @@ var MetastoreDatabase = (function () {
   MetastoreDatabase.prototype.reload = function () {
     var self = this;
     // Clear will publish when done
-    self.catalogEntry.clear(self.catalogEntry.getSourceType() === 'impala' ? 'invalidate' : 'cache');
+    self.catalogEntry.clearCache({ invalidate: self.catalogEntry.getSourceType() === 'impala' ? 'invalidate' : 'cache' });
   };
 
   MetastoreDatabase.prototype.load = function (callback, optimizerEnabled, navigatorEnabled) {
@@ -649,7 +649,7 @@ var MetastoreTable = (function () {
     self.samples.loaded(false);
     self.partitions.loaded(false);
     // Clear will publish when done
-    self.catalogEntry.clear(self.catalogEntry.getSourceType() === 'impala' ? 'invalidate' : 'cache');
+    self.catalogEntry.clearCache({ invalidate: self.catalogEntry.getSourceType() === 'impala' ? 'invalidate' : 'cache' });
   };
 
   MetastoreTable.prototype.showImportData = function () {

+ 1 - 1
apps/metastore/src/metastore/templates/metastore.mako

@@ -1233,7 +1233,7 @@ ${ components.menubar(is_embeddable) }
 
       if (location.getParameter('refresh') === 'true') {
         DataCatalog.getEntry({ sourceType: viewModel.sourceType(), path: [], definition: { type: 'source' }}).done(function (entry) {
-          huePubSub.publish('data.catalog.refresh.entry', { invalidate: sourceType() === 'impala' ? 'invalidate' : 'cache', catalogEntry: entry });
+          entry.clearCache({ invalidate: sourceType() === 'impala' ? 'invalidate' : 'cache', silenceErrors: true });
           hueUtils.replaceURL('?');
         });
       }

+ 1 - 1
desktop/core/src/desktop/static/desktop/js/assist/assistDbEntry.js

@@ -243,7 +243,7 @@ var AssistDbEntry = (function () {
 
   AssistDbEntry.prototype.triggerRefresh = function () {
     var self = this;
-    self.catalogEntry.clear(self.invalidateOnRefresh(), true);
+    self.catalogEntry.clearCache({ invalidate: self.invalidateOnRefresh(), cascade: true });
   };
 
   AssistDbEntry.prototype.highlightInside = function (path) {

+ 1 - 1
desktop/core/src/desktop/static/desktop/js/assist/assistDbSource.js

@@ -348,7 +348,7 @@ var AssistDbSource = (function () {
   AssistDbSource.prototype.triggerRefresh = function (data, event) {
     var self = this;
     if (self.catalogEntry) {
-      self.catalogEntry.clear(self.invalidateOnRefresh());
+      self.catalogEntry.clearCache({ invalidate: self.invalidateOnRefresh() });
     }
   };
 

+ 15 - 19
desktop/core/src/desktop/static/desktop/js/dataCatalog.js

@@ -656,19 +656,22 @@ var DataCatalog = (function () {
     /**
      * Resets the entry and clears the cache
      *
-     * @param {string} [invalidate] - 'cache', 'invalidate' or 'invalidateAndFlush', default 'cache', only used for Impala
-     * @param {boolean} [cascade] - Default false, only used when the entry is for the source
+     * @param {Object} options
+     * @param {string} [options.invalidate] - 'cache', 'invalidate' or 'invalidateAndFlush', default 'cache', only used for Impala
+     * @param {boolean} [options.cascade] - Default false, only used when the entry is for the source
+     * @param {boolean [options.silenceErrors] - Default false
      * @return {CancellablePromise}
      */
-    DataCatalogEntry.prototype.clear = function (invalidate, cascade) {
+    DataCatalogEntry.prototype.clearCache = function (options) {
       var self = this;
 
-      var invalidatePromise;
-
-      if (!invalidate) {
-        invalidate = 'cache';
+      if (!options) {
+        options = {}
       }
 
+      var invalidatePromise;
+      var invalidate = options.invalidate || 'cache';
+
       if (invalidate !== 'cache' && self.getSourceType() === 'impala') {
         if (self.dataCatalog.invalidatePromise) {
           invalidatePromise = self.dataCatalog.invalidatePromise;
@@ -676,7 +679,8 @@ var DataCatalog = (function () {
           invalidatePromise = ApiHelper.getInstance().invalidateSourceMetadata({
             sourceType: self.getSourceType(),
             invalidate: invalidate,
-            path: self.path
+            path: self.path,
+            silenceErrors: options.silenceErrors
           });
           self.dataCatalog.invalidatePromise = invalidatePromise;
           invalidatePromise.always(function () {
@@ -692,15 +696,15 @@ var DataCatalog = (function () {
       }
 
       self.reset();
-      var saveDeferred = cascade ? self.dataCatalog.clearStorageCascade(self.path) : self.save();
+      var saveDeferred = options.cascade ? self.dataCatalog.clearStorageCascade(self.path) : self.save();
 
       var clearPromise = $.when(invalidatePromise, saveDeferred);
 
       clearPromise.always(function () {
-        huePubSub.publish('data.catalog.entry.refreshed', { entry: self, cascade: cascade });
+        huePubSub.publish('data.catalog.entry.refreshed', { entry: self, cascade: !!options.cascade });
       });
 
-      return new CancellablePromise(clearPromise, undefined, [invalidatePromise]);
+      return new CancellablePromise(clearPromise, undefined, [ invalidatePromise ]);
     };
 
     /**
@@ -2105,14 +2109,6 @@ var DataCatalog = (function () {
       return sourceBoundCatalogs[sourceType] || (sourceBoundCatalogs[sourceType] = new DataCatalog(sourceType));
     };
 
-    huePubSub.subscribe('data.catalog.refresh.entry', function (options) {
-      options.catalogEntry.clear(options.invalidate).always(function () {
-        if (options.callback) {
-          options.callback();
-        }
-      });
-    });
-
     return {
 
       /**

+ 3 - 3
desktop/core/src/desktop/templates/assist.mako

@@ -1119,7 +1119,7 @@ from desktop.views import _ko
 
         huePubSub.subscribe('assist.collections.refresh', function() {
           DataCatalog.getEntry({ sourceType: 'solr', path: [] }).done(function (entry) {
-            entry.clear('cache', true);
+            entry.clearCache({ cascade: true });
           });
         });
 
@@ -2632,13 +2632,13 @@ from desktop.views import _ko
                                    // Clear the database first if it exists without cascade
                                   var hasDb = dbEntries.some(function (dbEntry) {
                                     if (dbEntry.name.toLowerCase() === self.path[0].toLowerCase()) {
-                                      clearPromise = dbEntry.clear('invalidate', false);
+                                      clearPromise = dbEntry.clearCache({ invalidate: 'invalidate', cascade: false });
                                       return true;
                                     }
                                   });
                                   if (!hasDb) {
                                     // If the database is missing clear the source without cascade
-                                    clearPromise = sourceEntry.clear('invalidate', false);
+                                    clearPromise = sourceEntry.clearCache({ invalidate: 'invalidate', cascade: false });
                                   }
                                   clearPromise.fail(function () {
                                     self.reloading(false);

+ 1 - 1
desktop/core/src/desktop/templates/ko_components/ko_context_popover.mako

@@ -545,7 +545,7 @@ from metadata.conf import has_navigator
 
       DataCatalogContext.prototype.refresh = function () {
         var self = this;
-        self.catalogEntry().clear('invalidate', true).always(self.load.bind(self));
+        self.catalogEntry().clearCache({ invalidate: 'invalidate', cascade: true }).always(self.load.bind(self));
       };
 
       DataCatalogContext.prototype.load = function () {

+ 1 - 1
desktop/core/src/desktop/templates/ko_components/ko_history_panel.mako

@@ -237,7 +237,7 @@ from desktop.views import _ko
 
                   if (notebook.onSuccessUrl() === 'assist.db.refresh') {
                     DataCatalog.getEntry({ sourceType: snippet.type(), path: [] }).done(function (entry) {
-                      entry.clear('cache', true);
+                      entry.clearCache({ invalidate: 'cache', cascade: true, silenceErrors: true });
                     });
                   } else if (notebook.onSuccessUrl()) {
                     huePubSub.publish(notebook.pubSubUrl());

+ 2 - 2
desktop/libs/indexer/src/indexer/templates/importer.mako

@@ -2315,13 +2315,13 @@ ${ assist.assistPanel() }
                       if (match) {
                         var db = match[1];
                         DataCatalog.getEntry({ sourceType: snippet.type(), path: [ db ]}).done(function (dbEntry) {
-                          dbEntry.clear('invalidate').done(function () {
+                          dbEntry.clearCache({ invalidate: 'invalidate', silenceErrors: true }).done(function () {
                             window.location.href = self.editorVM.selectedNotebook().onSuccessUrl();
                           })
                         });
                       } else {
                         DataCatalog.getEntry({ sourceType: snippet.type(), path: []}).done(function (sourceEntry) {
-                          sourceEntry.clear().done(function () {
+                          sourceEntry.clearCache({ silenceErrors: true }).done(function () {
                             window.location.href = self.editorVM.selectedNotebook().onSuccessUrl();
                           })
                         });

+ 1 - 1
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -908,7 +908,7 @@ var EditorViewModel = (function() {
         }
         ignoreNextAssistDatabaseUpdate = true;
         DataCatalog.getEntry({ sourceType: self.type(), path: path }).done(function (entry) {
-          entry.clear('invalidate', true);
+          entry.clearCache({ invalidate: 'invalidate', cascade: true, silenceErrors: true });
         });
       });
     }, 0);