Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
b701c337
Unverified
Commit
b701c337
authored
6 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
MySQL fixes
parent
3d85a8d6
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/models/setting.clj
+4
-5
4 additions, 5 deletions
src/metabase/models/setting.clj
test/metabase/models/setting_test.clj
+14
-4
14 additions, 4 deletions
test/metabase/models/setting_test.clj
with
18 additions
and
9 deletions
src/metabase/models/setting.clj
+
4
−
5
View file @
b701c337
...
...
@@ -39,12 +39,12 @@
[
environ.core
:as
env
]
[
honeysql.core
:as
hsql
]
[
metabase
[
db
:as
mdb
]
[
events
:as
events
]
[
util
:as
u
]]
[
metabase.util.honeysql-extensions
:as
hx
]
[
puppetlabs.i18n.core
:refer
[
trs
tru
]]
[
schema.core
:as
s
]
[
metabase.db
:as
mdb
]
[
toucan
[
db
:as
db
]
[
models
:as
models
]]))
...
...
@@ -124,8 +124,7 @@
(
let
[
current-timestamp-as-string-honeysql
(
hx/cast
(
if
(
=
(
mdb/db-type
)
:mysql
)
:char
:text
)
(
hsql/raw
"current_timestamp"
))]
;; attempt to UPDATE the existing row. If no row exists, `update-where!` will return false...
(
or
(
db/debug-print-queries
; NOCOMMIT
(
db/update-where!
Setting
{
:key
settings-last-updated-key
}
:value
current-timestamp-as-string-honeysql
))
(
or
(
db/update-where!
Setting
{
:key
settings-last-updated-key
}
:value
current-timestamp-as-string-honeysql
)
;; ...at which point we will try to INSERT a new row. Note that it is entirely possible two instances can both
;; try to INSERT it at the same time; one instance would fail because it would violate the PK constraint on
;; `key`, and throw a SQLException. As long as one instance updates the value, we are fine, so we can go ahead
...
...
@@ -157,11 +156,11 @@
;; if not, get the cached value of `settings-last-updated`, and if it exists...
(
when-let
[
last-known-update
(
core/get
@
cache
settings-last-updated-key
)]
;; compare it to the value in the DB. This is done be seeing whether a row exists
;; WHERE
CAST(value AS TIMESTAMP) > CAST(<local-value> AS TIMESTAMP)
;; WHERE
value > <local-value>
(
db/select-one
Setting
{
:where
[
:and
[
:=
:key
settings-last-updated-key
]
[
:>
(
hx/cast
:timestamp
:value
)
(
hx/cast
:timestamp
last-known-update
)
]]})))))
[
:>
:value
last-known-update
]]})))))
(
def
^
:private
cache-update-check-interval-ms
"How often we should check whether the Settings cache is out of date (which requires a DB call)?"
...
...
This diff is collapsed.
Click to expand it.
test/metabase/models/setting_test.clj
+
14
−
4
View file @
b701c337
...
...
@@ -2,13 +2,14 @@
(
:require
[
clojure.core.memoize
:as
memoize
]
[
expectations
:refer
:all
]
[
honeysql.core
:as
hsql
]
[
metabase
[
db
:as
mdb
]
[
util
:as
u
]]
[
metabase.models.setting
:as
setting
:refer
[
defsetting
Setting
]]
[
metabase.test.util
:refer
:all
]
[
metabase.util
:as
u
]
[
metabase.util
[
encryption
:as
encryption
]
[
encryption-test
:as
encryption-test
]
[
honeysql-extensions
:as
hx
]]
[
encryption-test
:as
encryption-test
]]
[
puppetlabs.i18n.core
:refer
[
tru
]]
[
toucan.db
:as
db
]))
...
...
@@ -342,7 +343,13 @@
"Simulate a different instance updating the value of `settings-last-updated` in the DB by updating its value without
updating our locally cached value.."
[]
(
db/update-where!
Setting
{
:key
settings-last-updated-key
}
:value
(
hx/cast
:text
(
hsql/raw
"current_timestamp"
))))
(
db/update-where!
Setting
{
:key
settings-last-updated-key
}
:value
(
hsql/raw
(
case
(
mdb/db-type
)
;; make it one second in the future so we don't end up getting an exact match when we try to test
;; to see if things update below
:h2
"cast(dateadd('second', 1, current_timestamp) AS text)"
:mysql
"cast((current_timestamp + interval 1 second) AS char)"
:postgres
"cast((current_timestamp + interval '1 second') AS text)"
))))
(
defn-
simulate-another-instance-updating-setting!
[
setting-name
new-value
]
(
db/update-where!
Setting
{
:key
(
name
setting-name
)}
:value
new-value
)
...
...
@@ -374,6 +381,9 @@
(
clear-settings-last-updated-value-in-db!
)
(
toucan-name
"Bird Can"
)
(
let
[
first-value
(
settings-last-updated-value-in-db
)]
;; MySQL only has the resolution of one second on the timestamps here so we should wait that long to make sure
;; the second-value actually ends up being greater than the first
(
Thread/sleep
1200
)
(
toucan-name
"Bird Can"
)
(
let
[
second-value
(
settings-last-updated-value-in-db
)]
;; first & second values should be different, and first value should be "less than" the second value
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment