Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Improve logging and recovery around errors in reindexing and create-table! (#64897)

Nathan Voxlandac22d632bced
diff --git a/src/metabase/search/appdb/core.clj b/src/metabase/search/appdb/core.clj
index 81a3f0b8360..ad241c805f8 100644
--- a/src/metabase/search/appdb/core.clj
+++ b/src/metabase/search/appdb/core.clj
@@ -178,14 +178,18 @@
(defmethod search.engine/reindex! :search.engine/appdb
[_ {:keys [in-place?]}]
- (search.index/ensure-ready!)
- (if in-place?
- (when-let [table (search.index/active-table)]
- ;; keep the current table, just delete its contents
- (t2/delete! table))
- (search.index/maybe-create-pending!))
- (u/prog1 (populate-index! (if in-place? :search/updating :search/reindexing))
- (search.index/activate-table!)))
+ (try
+ (search.index/ensure-ready!)
+ (if in-place?
+ (when-let [table (search.index/active-table)]
+ ;; keep the current table, just delete its contents
+ (t2/delete! table))
+ (search.index/maybe-create-pending!))
+ (u/prog1 (populate-index! (if in-place? :search/updating :search/reindexing))
+ (search.index/activate-table!))
+ (catch Throwable e
+ (log/error e "Error during reindexing")
+ (throw e))))
(derive :event/setting-update ::settings-changed-event)
diff --git a/src/metabase/search/appdb/index.clj b/src/metabase/search/appdb/index.clj
index b8d39fdecd8..51e2f2bca4f 100644
--- a/src/metabase/search/appdb/index.clj
+++ b/src/metabase/search/appdb/index.clj
@@ -200,7 +200,12 @@
(log/infof "Creating pending index %s for lang %s" table-name (i18n/site-locale-string))
;; We may fail to insert a new metadata row if we lose a race with another instance.
(when (search-index-metadata/create-pending! :appdb *index-version-id* table-name)
- (create-table! table-name))
+ (try
+ (create-table! table-name)
+ (catch Exception e
+ (log/error e "Error creating pending index table, cleaning up metadata")
+ (t2/delete! :model/SearchIndexMetadata :index_name (name table-name))
+ (sync-tracking-atoms!))))
(let [pending (:pending (sync-tracking-atoms!))]
(log/infof "New pending index %s" pending)
pending))))))