Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
1c9b415d
Commit
1c9b415d
authored
Dec 10, 2018
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Rails.version to the Geo cache keys
parent
0067fe45
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
22 deletions
+71
-22
ee/lib/gitlab/geo.rb
ee/lib/gitlab/geo.rb
+25
-13
ee/spec/lib/gitlab/geo_spec.rb
ee/spec/lib/gitlab/geo_spec.rb
+46
-9
No files found.
ee/lib/gitlab/geo.rb
View file @
1c9b415d
# frozen_string_literal: true
module
Gitlab
module
Geo
OauthApplicationUndefinedError
=
Class
.
new
(
StandardError
)
...
...
@@ -6,22 +8,22 @@ module Gitlab
InvalidSignatureTimeError
=
Class
.
new
(
StandardError
)
CACHE_KEYS
=
%i(
geo_
primary_node
geo_
secondary_nodes
geo_
node_enabled
geo_
oauth_application
primary_node
secondary_nodes
node_enabled
oauth_application
)
.
freeze
def
self
.
current_node
self
.
cache_value
(
:
geo_node_current
)
{
GeoNode
.
current_node
}
self
.
cache_value
(
:
current_node
)
{
GeoNode
.
current_node
}
end
def
self
.
primary_node
self
.
cache_value
(
:
geo_
primary_node
)
{
GeoNode
.
primary_node
}
self
.
cache_value
(
:primary_node
)
{
GeoNode
.
primary_node
}
end
def
self
.
secondary_nodes
self
.
cache_value
(
:
geo_
secondary_nodes
)
{
GeoNode
.
secondary_nodes
}
self
.
cache_value
(
:secondary_nodes
)
{
GeoNode
.
secondary_nodes
}
end
def
self
.
connected?
...
...
@@ -29,7 +31,7 @@ module Gitlab
end
def
self
.
enabled?
cache_value
(
:
geo_
node_enabled
)
{
GeoNode
.
exists?
}
cache_value
(
:node_enabled
)
{
GeoNode
.
exists?
}
end
def
self
.
primary?
...
...
@@ -72,22 +74,32 @@ module Gitlab
def
self
.
oauth_authentication
return
false
unless
Gitlab
::
Geo
.
secondary?
self
.
cache_value
(
:
geo_
oauth_application
)
do
self
.
cache_value
(
:oauth_application
)
do
Gitlab
::
Geo
.
current_node
.
oauth_application
||
raise
(
OauthApplicationUndefinedError
)
end
end
def
self
.
cache_value
(
key
,
&
block
)
def
self
.
cache_key_for
(
key
)
"geo:
#{
key
}
:
#{
Rails
.
version
}
"
end
def
self
.
cache_value
(
raw_key
,
&
block
)
return
yield
unless
RequestStore
.
active?
# We need a short expire time as we can't manually expire on a secondary node
RequestStore
.
fetch
(
key
)
{
Rails
.
cache
.
fetch
(
key
,
expires_in:
15
.
seconds
)
{
yield
}
}
key
=
cache_key_for
(
raw_key
)
RequestStore
.
fetch
(
key
)
do
# We need a short expire time as we can't manually expire on a secondary node
Rails
.
cache
.
fetch
(
key
,
expires_in:
15
.
seconds
)
{
yield
}
end
end
def
self
.
expire_cache!
return
true
unless
RequestStore
.
active?
CACHE_KEYS
.
each
do
|
key
|
CACHE_KEYS
.
each
do
|
raw_key
|
key
=
cache_key_for
(
raw_key
)
Rails
.
cache
.
delete
(
key
)
RequestStore
.
delete
(
key
)
end
...
...
ee/spec/lib/gitlab/geo_spec.rb
View file @
1c9b415d
...
...
@@ -6,19 +6,36 @@ describe Gitlab::Geo, :geo do
set
(
:primary_node
)
{
create
(
:geo_node
,
:primary
)
}
set
(
:secondary_node
)
{
create
(
:geo_node
)
}
describe
'current_node'
do
shared_examples
'a Geo cached value'
do
|
method
,
key
|
it
'includes Rails.version in the cache key'
,
:request_store
do
expect
(
Rails
.
cache
).
to
receive
(
:fetch
)
.
with
(
"geo:
#{
key
}
:
#{
Rails
.
version
}
"
,
expires_in:
15
.
seconds
)
described_class
.
public_send
(
method
)
end
end
describe
'.current_node'
do
it
'returns a GeoNode instance'
do
expect
(
described_class
.
current_node
).
to
eq
(
primary_node
)
end
it_behaves_like
'a Geo cached value'
,
:current_node
,
:current_node
end
describe
'primary_node'
do
describe
'
.
primary_node'
do
it
'returns a GeoNode primary instance'
do
expect
(
described_class
.
primary_node
).
to
eq
(
primary_node
)
end
it_behaves_like
'a Geo cached value'
,
:primary_node
,
:primary_node
end
describe
'.secondary_nodes'
do
it_behaves_like
'a Geo cached value'
,
:secondary_nodes
,
:secondary_nodes
end
describe
'primary?'
do
describe
'
.
primary?'
do
context
'when current node is a primary node'
do
it
'returns true'
do
expect
(
described_class
.
primary?
).
to
be_truthy
...
...
@@ -32,7 +49,7 @@ describe Gitlab::Geo, :geo do
end
end
describe
'primary_node_configured?'
do
describe
'
.
primary_node_configured?'
do
context
'when current node is a primary node'
do
it
'returns true'
do
expect
(
described_class
.
primary_node_configured?
).
to
be_truthy
...
...
@@ -46,7 +63,7 @@ describe Gitlab::Geo, :geo do
end
end
describe
'secondary?'
do
describe
'
.
secondary?'
do
context
'when current node is a secondary node'
do
before
do
stub_current_geo_node
(
secondary_node
)
...
...
@@ -64,7 +81,9 @@ describe Gitlab::Geo, :geo do
end
end
describe
'enabled?'
do
describe
'.enabled?'
do
it_behaves_like
'a Geo cached value'
,
:enabled?
,
:node_enabled
context
'when any GeoNode exists'
do
it
'returns true'
do
expect
(
described_class
.
enabled?
).
to
be_truthy
...
...
@@ -92,7 +111,15 @@ describe Gitlab::Geo, :geo do
end
end
describe
'connected?'
do
describe
'.oauth_authentication'
do
before
do
stub_secondary_node
end
it_behaves_like
'a Geo cached value'
,
:oauth_authentication
,
:oauth_application
end
describe
'.connected?'
do
context
'when there is a database issue'
do
it
'returns false when database connection is down'
do
allow
(
GeoNode
).
to
receive
(
:connected?
)
{
false
}
...
...
@@ -114,7 +141,7 @@ describe Gitlab::Geo, :geo do
end
end
describe
'secondary?'
do
describe
'
.
secondary?'
do
context
'when current node is secondary'
do
it
'returns true'
do
stub_current_geo_node
(
secondary_node
)
...
...
@@ -129,7 +156,17 @@ describe Gitlab::Geo, :geo do
end
end
describe
'license_allows?'
do
describe
'.expire_cache!'
do
it
'clears the Geo cache keys'
,
:request_store
do
described_class
::
CACHE_KEYS
.
each
do
|
raw_key
|
expect
(
Rails
.
cache
).
to
receive
(
:delete
).
with
(
"geo:
#{
raw_key
}
:
#{
Rails
.
version
}
"
)
end
described_class
.
expire_cache!
end
end
describe
'.license_allows?'
do
it
'returns true if license has Geo addon'
do
stub_licensed_features
(
geo:
true
)
expect
(
described_class
.
license_allows?
).
to
be_truthy
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment