diff options
author | John Cai <jcai@gitlab.com> | 2019-06-15 04:22:26 +0300 |
---|---|---|
committer | John Cai <jcai@gitlab.com> | 2019-07-05 20:31:47 +0300 |
commit | 8152e1aa4a039056d3010180051e6935b20d3656 (patch) | |
tree | d039df3af3556e12005541b87930b54c6a04e3e5 /lib/gitlab/gitaly_client.rb | |
parent | 50441577f0d24fe66ad1d59879f10315b54946c4 (diff) |
Use Rugged if we detect storage is NFS and we can access the disk
Add a module we use as a singleton to determine whether or not rails is
able to access the disk
Diffstat (limited to 'lib/gitlab/gitaly_client.rb')
-rw-r--r-- | lib/gitlab/gitaly_client.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb index 47976389af6..71ff1f74798 100644 --- a/lib/gitlab/gitaly_client.rb +++ b/lib/gitlab/gitaly_client.rb @@ -30,6 +30,7 @@ module Gitlab SERVER_VERSION_FILE = 'GITALY_SERVER_VERSION' MAXIMUM_GITALY_CALLS = 30 CLIENT_NAME = (Sidekiq.server? ? 'gitlab-sidekiq' : 'gitlab-web').freeze + GITALY_METADATA_FILENAME = '.gitaly-metadata' MUTEX = Mutex.new @@ -387,6 +388,45 @@ module Gitlab 0 end + def self.storage_metadata_file_path(storage) + Gitlab::GitalyClient::StorageSettings.allow_disk_access do + File.join( + Gitlab.config.repositories.storages[storage].legacy_disk_path, GITALY_METADATA_FILENAME + ) + end + end + + def self.can_use_disk?(storage) + cached_value = MUTEX.synchronize do + @can_use_disk ||= {} + @can_use_disk[storage] + end + + return cached_value unless cached_value.nil? + + gitaly_filesystem_id = filesystem_id(storage) + direct_filesystem_id = filesystem_id_from_disk(storage) + + MUTEX.synchronize do + @can_use_disk[storage] = gitaly_filesystem_id.present? && + gitaly_filesystem_id == direct_filesystem_id + end + end + + def self.filesystem_id(storage) + response = Gitlab::GitalyClient::ServerService.new(storage).info + storage_status = response.storage_statuses.find { |status| status.storage_name == storage } + storage_status.filesystem_id + end + + def self.filesystem_id_from_disk(storage) + metadata_file = File.read(storage_metadata_file_path(storage)) + metadata_hash = JSON.parse(metadata_file) + metadata_hash['gitaly_filesystem_id'] + rescue Errno::ENOENT, JSON::ParserError + nil + end + def self.timeout(timeout_name) Gitlab::CurrentSettings.current_application_settings[timeout_name] end |