From 74124ec8ed088a2a345c812a55a16cbeb265ac52 Mon Sep 17 00:00:00 2001 From: bergquist Date: Thu, 27 Dec 2018 10:48:11 +0100 Subject: [PATCH 1/2] makes cache mode configurable this makes the cache mode in the sqlite connection string configurable. the default also changed from shared to private to solve #107272 but allow the user to use shared if performance is more important. ref #10727 --- conf/defaults.ini | 3 +++ conf/sample.ini | 3 +++ docs/sources/installation/configuration.md | 6 +++++ pkg/services/sqlstore/sqlstore.go | 29 ++++++++++++++-------- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/conf/defaults.ini b/conf/defaults.ini index 97c87edb8b2..7f61ac96870 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -103,6 +103,9 @@ server_cert_name = # For "sqlite3" only, path relative to data_path setting path = grafana.db +# For "sqlite3" only. cache mode setting used for connecting to the database +cache_mode = private + #################################### Session ############################# [session] # Either "memory", "file", "redis", "mysql", "postgres", "memcache", default is "file" diff --git a/conf/sample.ini b/conf/sample.ini index 473e4e8450c..014016d45bc 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -99,6 +99,9 @@ # Set to true to log the sql calls and execution times. log_queries = +# For "sqlite3" only. cache mode setting used for connecting to the database. (private, shared) +;cache_mode = private + #################################### Session #################################### [session] # Either "memory", "file", "redis", "mysql", "postgres", default is "file" diff --git a/docs/sources/installation/configuration.md b/docs/sources/installation/configuration.md index 30ef020a3de..0e5a55b3c0e 100644 --- a/docs/sources/installation/configuration.md +++ b/docs/sources/installation/configuration.md @@ -250,6 +250,12 @@ Sets the maximum amount of time a connection may be reused. The default is 14400 Set to `true` to log the sql calls and execution times. +### cache_mode + +For "sqlite3" only. [Shared cache](https://www.sqlite.org/sharedcache.html) setting used for connecting to the database. (private, shared) +Defaults to private. + +
## [security] diff --git a/pkg/services/sqlstore/sqlstore.go b/pkg/services/sqlstore/sqlstore.go index 95b53be9d4a..d0e93177d8b 100644 --- a/pkg/services/sqlstore/sqlstore.go +++ b/pkg/services/sqlstore/sqlstore.go @@ -243,7 +243,7 @@ func (ss *SqlStore) buildConnectionString() (string, error) { ss.dbCfg.Path = filepath.Join(ss.Cfg.DataPath, ss.dbCfg.Path) } os.MkdirAll(path.Dir(ss.dbCfg.Path), os.ModePerm) - cnnstr = "file:" + ss.dbCfg.Path + "?cache=shared&mode=rwc" + cnnstr = fmt.Sprintf("file:%s?cache=%s&mode=rwc", ss.dbCfg.Path, ss.dbCfg.CacheMode) default: return "", fmt.Errorf("Unknown database type: %s", ss.dbCfg.Type) } @@ -319,6 +319,8 @@ func (ss *SqlStore) readConfig() { ss.dbCfg.ClientCertPath = sec.Key("client_cert_path").String() ss.dbCfg.ServerCertName = sec.Key("server_cert_name").String() ss.dbCfg.Path = sec.Key("path").MustString("data/grafana.db") + + ss.dbCfg.CacheMode = sec.Key("cache_mode").MustString("private") } func InitTestDB(t *testing.T) *SqlStore { @@ -391,13 +393,20 @@ func IsTestDbPostgres() bool { } type DatabaseConfig struct { - Type, Host, Name, User, Pwd, Path, SslMode string - CaCertPath string - ClientKeyPath string - ClientCertPath string - ServerCertName string - ConnectionString string - MaxOpenConn int - MaxIdleConn int - ConnMaxLifetime int + Type string + Host string + Name string + User string + Pwd string + Path string + SslMode string + CaCertPath string + ClientKeyPath string + ClientCertPath string + ServerCertName string + ConnectionString string + MaxOpenConn int + MaxIdleConn int + ConnMaxLifetime int + CacheMode string } From 9895b1e6d00fb7358ce0e1a25b8818c115420e13 Mon Sep 17 00:00:00 2001 From: bergquist Date: Fri, 28 Dec 2018 10:49:00 +0100 Subject: [PATCH 2/2] adds orgId to user dto for provisioned dashboards --- pkg/services/dashboards/dashboard_service.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/services/dashboards/dashboard_service.go b/pkg/services/dashboards/dashboard_service.go index 7e334ff656f..6aa1276b093 100644 --- a/pkg/services/dashboards/dashboard_service.go +++ b/pkg/services/dashboards/dashboard_service.go @@ -175,7 +175,9 @@ func (dr *dashboardServiceImpl) SaveProvisionedDashboard(dto *SaveDashboardDTO, dto.User = &models.SignedInUser{ UserId: 0, OrgRole: models.ROLE_ADMIN, + OrgId: dto.OrgId, } + cmd, err := dr.buildSaveDashboardCommand(dto, true, false) if err != nil { return nil, err