From 71333299e94c4ad7c698fa0a6f8ddca099a17525 Mon Sep 17 00:00:00 2001 From: anton Date: Mon, 15 Jul 2024 18:40:47 +0200 Subject: [PATCH] Added env var to control materialized views refresh on Saturn start --- README.adoc | 2 +- charts/fairspace/templates/project/configmap-saturn.yaml | 1 + projects/saturn/application.yaml | 1 + .../src/main/java/io/fairspace/saturn/config/Config.java | 1 + .../saturn/services/views/ViewStoreClientFactory.java | 8 +++++--- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.adoc b/README.adoc index 8e195d789..cfd08f9f4 100644 --- a/README.adoc +++ b/README.adoc @@ -3320,7 +3320,7 @@ To address this issue, materialized views are used for enhanced performance. There are two types of materialized views: one for denormalized data, which includes the view ID and attribute data of Set/TermSet types, and another for joined views. For each joined view, there is one corresponding join materialized view (as specified in the views.yaml config). -Materialized views are refreshed during database reindexing, on Saturn initialization stage and metadata updates, provided that the doViewsUpdate flag is set to true in the metadata endpoints. The refresh is performed concurrently what allows for the system to be available during the update providing the old version of data until the new one is ready. +Materialized views are refreshed during database reindexing, on Saturn initialization stage and metadata updates, provided that the doViewsUpdate flag is set to true in the metadata endpoints. The refresh is performed concurrently what allows for the system to be available during the update providing the old version of data until the new one is ready. To skip materialized views refresh on Saturn initialization stage, update the Saturn ConfigMap setting false value to `viewDatabase.mvRefreshOnStartRequired`. ==== Extra file storage diff --git a/charts/fairspace/templates/project/configmap-saturn.yaml b/charts/fairspace/templates/project/configmap-saturn.yaml index da2609cde..514ad10d9 100644 --- a/charts/fairspace/templates/project/configmap-saturn.yaml +++ b/charts/fairspace/templates/project/configmap-saturn.yaml @@ -31,6 +31,7 @@ data: blobStorePath: "/data/saturn/files/blobs" viewDatabase: enabled: true + mvRefreshOnStartRequired: true features: {{ toYaml .Values.fairspace.features | indent 6 }} {{ if has "ExtraStorage" .Values.fairspace.features }} diff --git a/projects/saturn/application.yaml b/projects/saturn/application.yaml index c08cd1cd5..9dbebe53e 100644 --- a/projects/saturn/application.yaml +++ b/projects/saturn/application.yaml @@ -55,6 +55,7 @@ viewDatabase: autoCommit: false maxPoolSize: 50 connectionTimeout: 1000 + mvRefreshOnStartRequired: true search: pageRequestTimeout: 10000 countRequestTimeout: 60000 diff --git a/projects/saturn/src/main/java/io/fairspace/saturn/config/Config.java b/projects/saturn/src/main/java/io/fairspace/saturn/config/Config.java index d770ca93a..7eb428b60 100644 --- a/projects/saturn/src/main/java/io/fairspace/saturn/config/Config.java +++ b/projects/saturn/src/main/java/io/fairspace/saturn/config/Config.java @@ -115,6 +115,7 @@ public static class ViewDatabase { public int maxPoolSize = 50; public long connectionTimeout = 1000; public boolean autoCommit = false; + public boolean mvRefreshOnStartRequired = true; } public static class ExtraStorage { diff --git a/projects/saturn/src/main/java/io/fairspace/saturn/services/views/ViewStoreClientFactory.java b/projects/saturn/src/main/java/io/fairspace/saturn/services/views/ViewStoreClientFactory.java index 8ffdcce31..31bfc2a92 100644 --- a/projects/saturn/src/main/java/io/fairspace/saturn/services/views/ViewStoreClientFactory.java +++ b/projects/saturn/src/main/java/io/fairspace/saturn/services/views/ViewStoreClientFactory.java @@ -18,7 +18,6 @@ import com.zaxxer.hikari.HikariDataSource; import lombok.Builder; import lombok.Data; -import lombok.Getter; import lombok.extern.slf4j.Slf4j; import io.fairspace.saturn.config.Config; @@ -33,7 +32,6 @@ @Slf4j public class ViewStoreClientFactory { - @Getter private final MaterializedViewService materializedViewService; public ViewStoreClient build() throws SQLException { @@ -82,7 +80,11 @@ public ViewStoreClientFactory(ViewsConfig viewsConfig, Config.ViewDatabase viewD createOrUpdateView(view); } materializedViewService = new MaterializedViewService(dataSource, configuration, search.maxJoinItems); - materializedViewService.createOrUpdateAllMaterializedViews(); + if (viewDatabase.mvRefreshOnStartRequired) { + materializedViewService.createOrUpdateAllMaterializedViews(); + } else { + log.warn("Skipping materialized view refresh on start"); + } } public Connection getConnection() throws SQLException {