Commit ed194a6d authored by Sean McGivern's avatar Sean McGivern

Merge branch 'feature/migrate-wiki-write-page-to-gitaly' into 'master'

Migrate Gitlab::Git::Wiki#write_page to Gitaly

Closes gitaly#638

See merge request gitlab-org/gitlab-ce!14870
parents 1d72952d fa5eeaec
...@@ -398,7 +398,7 @@ group :ed25519 do ...@@ -398,7 +398,7 @@ group :ed25519 do
end end
# Gitaly GRPC client # Gitaly GRPC client
gem 'gitaly-proto', '~> 0.42.0', require: 'gitaly' gem 'gitaly-proto', '~> 0.45.0', require: 'gitaly'
gem 'toml-rb', '~> 0.3.15', require: false gem 'toml-rb', '~> 0.3.15', require: false
......
...@@ -273,7 +273,7 @@ GEM ...@@ -273,7 +273,7 @@ GEM
po_to_json (>= 1.0.0) po_to_json (>= 1.0.0)
rails (>= 3.2.0) rails (>= 3.2.0)
gherkin-ruby (0.3.2) gherkin-ruby (0.3.2)
gitaly-proto (0.42.0) gitaly-proto (0.45.0)
google-protobuf (~> 3.1) google-protobuf (~> 3.1)
grpc (~> 1.0) grpc (~> 1.0)
github-linguist (4.7.6) github-linguist (4.7.6)
...@@ -1030,7 +1030,7 @@ DEPENDENCIES ...@@ -1030,7 +1030,7 @@ DEPENDENCIES
gettext (~> 3.2.2) gettext (~> 3.2.2)
gettext_i18n_rails (~> 1.8.0) gettext_i18n_rails (~> 1.8.0)
gettext_i18n_rails_js (~> 1.2.0) gettext_i18n_rails_js (~> 1.2.0)
gitaly-proto (~> 0.42.0) gitaly-proto (~> 0.45.0)
github-linguist (~> 4.7.0) github-linguist (~> 4.7.0)
gitlab-flowdock-git-hook (~> 1.0.1) gitlab-flowdock-git-hook (~> 1.0.1)
gitlab-markup (~> 1.6.2) gitlab-markup (~> 1.6.2)
......
...@@ -23,14 +23,14 @@ module Gitlab ...@@ -23,14 +23,14 @@ module Gitlab
end end
def write_page(name, format, content, commit_details) def write_page(name, format, content, commit_details)
assert_type!(format, Symbol) @repository.gitaly_migrate(:wiki_write_page) do |is_enabled|
assert_type!(commit_details, CommitDetails) if is_enabled
gitaly_write_page(name, format, content, commit_details)
gollum_wiki.write_page(name, format, content, commit_details.to_h) gollum_wiki.clear_cache
else
nil gollum_write_page(name, format, content, commit_details)
rescue Gollum::DuplicatePageError => e end
raise Gitlab::Git::Wiki::DuplicatePageError, e.message end
end end
def delete_page(page_path, commit_details) def delete_page(page_path, commit_details)
...@@ -110,6 +110,25 @@ module Gitlab ...@@ -110,6 +110,25 @@ module Gitlab
raise ArgumentError, "expected a #{klass}, got #{object.inspect}" raise ArgumentError, "expected a #{klass}, got #{object.inspect}"
end end
end end
def gitaly_wiki_client
@gitaly_wiki_client ||= Gitlab::GitalyClient::WikiService.new(@repository)
end
def gollum_write_page(name, format, content, commit_details)
assert_type!(format, Symbol)
assert_type!(commit_details, CommitDetails)
gollum_wiki.write_page(name, format, content, commit_details.to_h)
nil
rescue Gollum::DuplicatePageError => e
raise Gitlab::Git::Wiki::DuplicatePageError, e.message
end
def gitaly_write_page(name, format, content, commit_details)
gitaly_wiki_client.write_page(name, format, content, commit_details)
end
end end
end end
end end
require 'stringio'
module Gitlab
module GitalyClient
class WikiService
MAX_MSG_SIZE = 128.kilobytes.freeze
def initialize(repository)
@gitaly_repo = repository.gitaly_repository
@repository = repository
end
def write_page(name, format, content, commit_details)
request = Gitaly::WikiWritePageRequest.new(
repository: @gitaly_repo,
name: GitalyClient.encode(name),
format: format.to_s,
commit_details: Gitaly::WikiCommitDetails.new(
name: GitalyClient.encode(commit_details.name),
email: GitalyClient.encode(commit_details.email),
message: GitalyClient.encode(commit_details.message)
)
)
strio = StringIO.new(content)
enum = Enumerator.new do |y|
until strio.eof?
chunk = strio.read(MAX_MSG_SIZE)
request.content = GitalyClient.encode(chunk)
y.yield request
request = Gitaly::WikiWritePageRequest.new
end
end
response = GitalyClient.call(@repository.storage, :wiki_service, :wiki_write_page, enum)
if error = response.duplicate_error.presence
raise Gitlab::Git::Wiki::DuplicatePageError, error
end
end
end
end
end
...@@ -180,6 +180,7 @@ describe ProjectWiki do ...@@ -180,6 +180,7 @@ describe ProjectWiki do
end end
describe "#create_page" do describe "#create_page" do
shared_examples 'creating a wiki page' do
after do after do
destroy_page(subject.pages.first.page) destroy_page(subject.pages.first.page)
end end
...@@ -214,6 +215,15 @@ describe ProjectWiki do ...@@ -214,6 +215,15 @@ describe ProjectWiki do
end end
end end
context 'when Gitaly wiki_write_page is enabled' do
it_behaves_like 'creating a wiki page'
end
context 'when Gitaly wiki_write_page is disabled', :skip_gitaly_mock do
it_behaves_like 'creating a wiki page'
end
end
describe "#update_page" do describe "#update_page" do
before do before do
create_page("update-page", "some content") create_page("update-page", "some content")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment