BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
db464758
Commit
db464758
authored
May 15, 2017
by
Robert Speicher
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'gitaly-reuse-stubs' into 'master'
Reuse gRPC stubs instead of channels Closes #31991 and gitaly#187 See merge request !11244
parents
53a9f6a0
60106c1e
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
58 additions
and
65 deletions
+58
-65
repository.rb
app/models/repository.rb
+0
-2
8_gitaly.rb
config/initializers/8_gitaly.rb
+4
-2
repository.rb
lib/gitlab/git/repository.rb
+6
-8
gitaly_client.rb
lib/gitlab/gitaly_client.rb
+24
-38
commit.rb
lib/gitlab/gitaly_client/commit.rb
+2
-2
notifications.rb
lib/gitlab/gitaly_client/notifications.rb
+1
-1
ref.rb
lib/gitlab/gitaly_client/ref.rb
+1
-1
workhorse.rb
lib/gitlab/workhorse.rb
+1
-1
gitaly_client_spec.rb
spec/lib/gitlab/gitaly_client_spec.rb
+15
-6
workhorse_spec.rb
spec/lib/gitlab/workhorse_spec.rb
+1
-1
test_env.rb
spec/support/test_env.rb
+3
-2
backup_rake_spec.rb
spec/tasks/gitlab/backup_rake_spec.rb
+0
-1
No files found.
app/models/repository.rb
View file @
db464758
...
...
@@ -1163,8 +1163,6 @@ class Repository
@project
.
repository_storage_path
end
delegate
:gitaly_channel
,
:gitaly_repository
,
to: :raw_repository
def
initialize_raw_repository
Gitlab
::
Git
::
Repository
.
new
(
project
.
repository_storage
,
path_with_namespace
+
'.git'
)
end
...
...
config/initializers/8_gitaly.rb
View file @
db464758
require
'uri'
# Make sure we initialize our Gitaly channels before Sidekiq starts multi-threaded execution.
if
Gitlab
.
config
.
gitaly
.
enabled
||
Rails
.
env
.
test?
Gitlab
::
GitalyClient
.
configure_channels
Gitlab
.
config
.
repositories
.
storages
.
keys
.
each
do
|
storage
|
# Force validation of each address
Gitlab
::
GitalyClient
.
address
(
storage
)
end
end
lib/gitlab/git/repository.rb
View file @
db464758
...
...
@@ -27,13 +27,15 @@ module Gitlab
# Rugged repo object
attr_reader
:rugged
attr_reader
:storage
# 'path' must be the path to a _bare_ git repository, e.g.
# /path/to/my-repo.git
def
initialize
(
repository_
storage
,
relative_path
)
@
repository_storage
=
repository_
storage
def
initialize
(
storage
,
relative_path
)
@
storage
=
storage
@relative_path
=
relative_path
storage_path
=
Gitlab
.
config
.
repositories
.
storages
[
@
repository_
storage
][
'path'
]
storage_path
=
Gitlab
.
config
.
repositories
.
storages
[
@storage
][
'path'
]
@path
=
File
.
join
(
storage_path
,
@relative_path
)
@name
=
@relative_path
.
split
(
"/"
).
last
@attributes
=
Gitlab
::
Git
::
Attributes
.
new
(
path
)
...
...
@@ -965,11 +967,7 @@ module Gitlab
end
def
gitaly_repository
Gitlab
::
GitalyClient
::
Util
.
repository
(
@repository_storage
,
@relative_path
)
end
def
gitaly_channel
Gitlab
::
GitalyClient
.
get_channel
(
@repository_storage
)
Gitlab
::
GitalyClient
::
Util
.
repository
(
@storage
,
@relative_path
)
end
private
...
...
lib/gitlab/gitaly_client.rb
View file @
db464758
...
...
@@ -4,56 +4,42 @@ module Gitlab
module
GitalyClient
SERVER_VERSION_FILE
=
'GITALY_SERVER_VERSION'
.
freeze
# This function is not thread-safe because it updates Hashes in instance variables.
def
self
.
configure_channels
@addresses
=
{}
@channels
=
{}
Gitlab
.
config
.
repositories
.
storages
.
each
do
|
name
,
params
|
address
=
params
[
'gitaly_address'
]
unless
address
.
present?
raise
"storage
#{
name
.
inspect
}
is missing a gitaly_address"
end
MUTEX
=
Mutex
.
new
private_constant
:MUTEX
unless
URI
(
address
).
scheme
.
in?
(
%w(tcp unix)
)
raise
"Unsupported Gitaly address:
#{
address
.
inspect
}
does not use URL scheme 'tcp' or 'unix'"
def
self
.
stub
(
name
,
storage
)
MUTEX
.
synchronize
do
@stubs
||=
{}
@stubs
[
storage
]
||=
{}
@stubs
[
storage
][
name
]
||=
begin
klass
=
Gitaly
.
const_get
(
name
.
to_s
.
camelcase
.
to_sym
).
const_get
(
:Stub
)
addr
=
address
(
storage
)
addr
=
addr
.
sub
(
%r{^tcp://}
,
''
)
if
URI
(
addr
).
scheme
==
'tcp'
klass
.
new
(
addr
,
:this_channel_is_insecure
)
end
@addresses
[
name
]
=
address
@channels
[
name
]
=
new_channel
(
address
)
end
end
def
self
.
new_channel
(
address
)
address
=
address
.
sub
(
%r{^tcp://}
,
''
)
if
URI
(
address
).
scheme
==
'tcp'
# NOTE: When Gitaly runs on a Unix socket, permissions are
# handled using the file system and no additional authentication is
# required (therefore the :this_channel_is_insecure flag)
# TODO: Add authentication support when Gitaly is running on a TCP socket.
GRPC
::
Core
::
Channel
.
new
(
address
,
{},
:this_channel_is_insecure
)
def
self
.
clear_stubs!
MUTEX
.
synchronize
do
@stubs
=
nil
end
def
self
.
get_channel
(
storage
)
if
!
Rails
.
env
.
production?
&&
@channels
.
nil?
# In development mode the Rails auto-loader may reset the instance
# variables of this class. What we do here is not thread-safe. In normal
# circumstances (including production) these instance variables have
# been initialized from config/initializers.
configure_channels
end
@channels
[
storage
]
def
self
.
address
(
storage
)
params
=
Gitlab
.
config
.
repositories
.
storages
[
storage
]
raise
"storage not found:
#{
storage
.
inspect
}
"
if
params
.
nil?
address
=
params
[
'gitaly_address'
]
unless
address
.
present?
raise
"storage
#{
storage
.
inspect
}
is missing a gitaly_address"
end
def
self
.
get_address
(
storage
)
if
!
Rails
.
env
.
production?
&&
@addresses
.
nil?
# In development mode the Rails auto-loader may reset the instance
# variables of this class. What we do here is not thread-safe. In normal
# circumstances (including development) these instance variables have
# been initialized from config/initializers.
configure_channels
unless
URI
(
address
).
scheme
.
in?
(
%w(tcp unix)
)
raise
"Unsupported Gitaly address:
#{
address
.
inspect
}
does not use URL scheme 'tcp' or 'unix'"
end
@addresses
[
storage
]
address
end
def
self
.
enabled?
...
...
lib/gitlab/gitaly_client/commit.rb
View file @
db464758
...
...
@@ -11,7 +11,7 @@ module Gitlab
end
def
is_ancestor
(
ancestor_id
,
child_id
)
stub
=
Gitaly
::
Commit
::
Stub
.
new
(
nil
,
nil
,
channel_override:
@repository
.
gitaly_channel
)
stub
=
Gitaly
Client
.
stub
(
:commit
,
@repository
.
storage
)
request
=
Gitaly
::
CommitIsAncestorRequest
.
new
(
repository:
@gitaly_repo
,
ancestor_id:
ancestor_id
,
...
...
@@ -52,7 +52,7 @@ module Gitlab
end
def
diff_service_stub
Gitaly
::
Diff
::
Stub
.
new
(
nil
,
nil
,
channel_override:
@repository
.
gitaly_channel
)
Gitaly
Client
.
stub
(
:diff
,
@repository
.
storage
)
end
end
end
...
...
lib/gitlab/gitaly_client/notifications.rb
View file @
db464758
...
...
@@ -6,7 +6,7 @@ module Gitlab
# 'repository' is a Gitlab::Git::Repository
def
initialize
(
repository
)
@gitaly_repo
=
repository
.
gitaly_repository
@stub
=
Gitaly
::
Notifications
::
Stub
.
new
(
nil
,
nil
,
channel_override:
repository
.
gitaly_channel
)
@stub
=
Gitaly
Client
.
stub
(
:notifications
,
repository
.
storage
)
end
def
post_receive
...
...
lib/gitlab/gitaly_client/ref.rb
View file @
db464758
...
...
@@ -6,7 +6,7 @@ module Gitlab
# 'repository' is a Gitlab::Git::Repository
def
initialize
(
repository
)
@gitaly_repo
=
repository
.
gitaly_repository
@stub
=
Gitaly
::
Ref
::
Stub
.
new
(
nil
,
nil
,
channel_override:
repository
.
gitaly_channel
)
@stub
=
Gitaly
Client
.
stub
(
:ref
,
repository
.
storage
)
end
def
default_branch_name
...
...
lib/gitlab/workhorse.rb
View file @
db464758
...
...
@@ -26,7 +26,7 @@ module Gitlab
}
if
Gitlab
.
config
.
gitaly
.
enabled
address
=
Gitlab
::
GitalyClient
.
get_
address
(
project
.
repository_storage
)
address
=
Gitlab
::
GitalyClient
.
address
(
project
.
repository_storage
)
params
[
:Repository
]
=
repository
.
gitaly_repository
.
to_h
feature_enabled
=
case
action
.
to_s
...
...
spec/lib/gitlab/gitaly_client_spec.rb
View file @
db464758
require
'spec_helper'
describe
Gitlab
::
GitalyClient
,
lib:
true
do
describe
'.new_channel'
do
describe
'.stub'
do
before
{
described_class
.
clear_stubs!
}
context
'when passed a UNIX socket address'
do
it
'passes the address as-is to GRPC
::Core::Channel initializer
'
do
it
'passes the address as-is to GRPC'
do
address
=
'unix:/tmp/gitaly.sock'
allow
(
Gitlab
.
config
.
repositories
).
to
receive
(
:storages
).
and_return
({
'default'
=>
{
'gitaly_address'
=>
address
}
})
expect
(
G
RPC
::
Core
::
Channel
).
to
receive
(
:new
).
with
(
address
,
any_args
)
expect
(
G
italy
::
Commit
::
Stub
).
to
receive
(
:new
).
with
(
address
,
any_args
)
described_class
.
new_channel
(
address
)
described_class
.
stub
(
:commit
,
'default'
)
end
end
...
...
@@ -17,9 +22,13 @@ describe Gitlab::GitalyClient, lib: true do
address
=
'localhost:9876'
prefixed_address
=
"tcp://
#{
address
}
"
expect
(
GRPC
::
Core
::
Channel
).
to
receive
(
:new
).
with
(
address
,
any_args
)
allow
(
Gitlab
.
config
.
repositories
).
to
receive
(
:storages
).
and_return
({
'default'
=>
{
'gitaly_address'
=>
prefixed_address
}
})
expect
(
Gitaly
::
Commit
::
Stub
).
to
receive
(
:new
).
with
(
address
,
any_args
)
described_class
.
new_channel
(
prefixed_address
)
described_class
.
stub
(
:commit
,
'default'
)
end
end
end
...
...
spec/lib/gitlab/workhorse_spec.rb
View file @
db464758
...
...
@@ -202,7 +202,7 @@ describe Gitlab::Workhorse, lib: true do
context
'when Gitaly is enabled'
do
let
(
:gitaly_params
)
do
{
GitalyAddress
:
Gitlab
::
GitalyClient
.
get_
address
(
'default'
)
GitalyAddress
:
Gitlab
::
GitalyClient
.
address
(
'default'
)
}
end
...
...
spec/support/test_env.rb
View file @
db464758
...
...
@@ -120,7 +120,7 @@ module TestEnv
end
def
setup_gitaly
socket_path
=
Gitlab
::
GitalyClient
.
get_
address
(
'default'
).
sub
(
/\Aunix:/
,
''
)
socket_path
=
Gitlab
::
GitalyClient
.
address
(
'default'
).
sub
(
/\Aunix:/
,
''
)
gitaly_dir
=
File
.
dirname
(
socket_path
)
unless
File
.
directory?
(
gitaly_dir
)
||
system
(
'rake'
,
"gitlab:gitaly:install[
#{
gitaly_dir
}
]"
)
...
...
@@ -133,7 +133,8 @@ module TestEnv
def
start_gitaly
(
gitaly_dir
)
gitaly_exec
=
File
.
join
(
gitaly_dir
,
'gitaly'
)
gitaly_config
=
File
.
join
(
gitaly_dir
,
'config.toml'
)
@gitaly_pid
=
spawn
(
gitaly_exec
,
gitaly_config
,
[
:out
,
:err
]
=>
'/dev/null'
)
log_file
=
Rails
.
root
.
join
(
'log/gitaly-test.log'
).
to_s
@gitaly_pid
=
spawn
(
gitaly_exec
,
gitaly_config
,
[
:out
,
:err
]
=>
log_file
)
end
def
stop_gitaly
...
...
spec/tasks/gitlab/backup_rake_spec.rb
View file @
db464758
...
...
@@ -236,7 +236,6 @@ describe 'gitlab:app namespace rake task' do
'custom'
=>
{
'path'
=>
Settings
.
absolute
(
'tmp/tests/custom_storage'
),
'gitaly_address'
=>
gitaly_address
}
}
allow
(
Gitlab
.
config
.
repositories
).
to
receive
(
:storages
).
and_return
(
storages
)
Gitlab
::
GitalyClient
.
configure_channels
# Create the projects now, after mocking the settings but before doing the backup
project_a
...
...
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