Commit 3db51a89 authored by Mark Chao's avatar Mark Chao

ES: provide default version for class-level write operations

After project is converted to allow multiple schemas,
operations such as `delete_index!` will require version,
so provide a default version for now.
parent 0355e90a
......@@ -4,8 +4,7 @@ module Gitlab
module Elastic
class Helper
# rubocop: disable CodeReuse/ActiveRecord
def self.create_empty_index
index_name = Project.index_name
def self.create_empty_index(version = ::Elastic::MultiVersionUtil::TARGET_VERSION)
settings = {}
mappings = {}
......@@ -23,7 +22,9 @@ module Gitlab
mappings.deep_merge!(klass.__elasticsearch__.mappings.to_hash)
end
client = Project.__elasticsearch__.client
proxy = Project.__elasticsearch__.version(version)
client = proxy.client
index_name = proxy.index_name
# ES5.6 needs a setting enabled to support JOIN datatypes that ES6 does not support...
if Gitlab::VersionInfo.parse(client.info['version']['number']) < Gitlab::VersionInfo.new(6)
......@@ -42,16 +43,16 @@ module Gitlab
end
# rubocop: enable CodeReuse/ActiveRecord
def self.delete_index
Project.__elasticsearch__.delete_index!
def self.delete_index(version = ::Elastic::MultiVersionUtil::TARGET_VERSION)
Project.__elasticsearch__.version(version).delete_index!
end
def self.refresh_index
Project.__elasticsearch__.refresh_index!
end
def self.index_size
Project.__elasticsearch__.client.indices.stats['indices'][Project.__elasticsearch__.index_name]['total']
def self.index_size(version = ::Elastic::MultiVersionUtil::TARGET_VERSION)
Project.__elasticsearch__.version(version).client.indices.stats['indices'][Project.__elasticsearch__.index_name]['total']
end
end
end
......
......@@ -4,7 +4,7 @@ namespace :gitlab do
desc 'GitLab | Elasticsearch | Test | Measure space taken by ES indices'
task index_size: :environment do
puts "===== Size stats for index: #{Project.__elasticsearch__.index_name} ====="
pp Gitlab::Elastic::Helper.index_size.slice(*%w(docs store))
pp Gitlab::Elastic::Helper.index_size(::Elastic::MultiVersionUtil::TARGET_VERSION).slice(*%w(docs store))
end
desc 'GitLab | Elasticsearch | Test | Measure space taken by ES indices, reindex, and measure space taken again'
......
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