Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions app/models/concerns/indexable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1187,9 +1187,16 @@ def create_template
alias_name = index_name

body =
if name == "Doi" || name == "DataciteDoi" || name == "OtherDoi"
if name == "DataciteDoi" || name == "Doi"
{
index_patterns: %w[dois*],
# Avoid "dois*" — it also matches dois-other*
index_patterns: [alias_name, "#{alias_name}_v1", "#{alias_name}_v2"],
settings: name == "DataciteDoi" ? settings.to_hash : DataciteDoi.settings.to_hash,
mappings: Doi.mappings.to_hash,
}
elsif name == "OtherDoi"
{
index_patterns: ["#{alias_name}*"],
settings: Doi.settings.to_hash,
mappings: Doi.mappings.to_hash,
}
Expand Down
4 changes: 4 additions & 0 deletions app/models/datacite_doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class DataciteDoi < Doi
index_name "dois"
end

settings index: Doi.settings.to_hash.fetch(:index, {}).merge(
number_of_shards: ENV["NUMBER_OF_SHARDS_DATACITE_DOI"].to_i,
)

def self.index_all_by_client(options = {})
client_to_doi_count = DataciteDoi.where(type: "DataciteDoi").group(:datacentre).count
# throw out id 0
Expand Down
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
ENV["ES_SCHEME"] ||= "http"
ENV["ES_PORT"] ||= "80"
ENV["ES_PREFIX"] ||= ""
ENV["NUMBER_OF_SHARDS_DATACITE_DOI"] ||= "1"
ENV["TRUSTED_IP"] ||= "10.0.40.1"
ENV["MG_FROM"] ||= "support@datacite.org"
ENV["MG_DOMAIN"] ||= "mg.datacite.org"
Expand Down
45 changes: 45 additions & 0 deletions spec/models/datacite_doi_shard_settings_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

require "rails_helper"

describe "Datacite DOI number_of_shards" do
it "defaults to 1 on DataciteDoi settings" do
expect(ENV.fetch("NUMBER_OF_SHARDS_DATACITE_DOI")).to eq("1")
expect(DataciteDoi.settings.to_hash.dig(:index, :number_of_shards)).to eq(1)
end

it "does not apply the shard setting to OtherDoi or shared Doi settings" do
expect(Doi.settings.to_hash.dig(:index, :number_of_shards)).to be_nil
expect(OtherDoi.settings.to_hash.dig(:index, :number_of_shards)).to be_nil
end

it "uses DataciteDoi.settings when building the Datacite template" do
indices = Elasticsearch::Model.client.indices
allow(indices).to receive(:exists_template?).and_return(false)
expect(indices).to receive(:put_template) do |args|
expect(args[:name]).to eq(DataciteDoi.index_name)
expect(args[:body][:index_patterns]).to eq(
[DataciteDoi.index_name, "#{DataciteDoi.index_name}_v1", "#{DataciteDoi.index_name}_v2"],
)
expect(args[:body][:settings]).to eq(DataciteDoi.settings.to_hash)
expect(args[:body][:settings][:index][:number_of_shards]).to eq(1)
{ "acknowledged" => true }
end

DataciteDoi.create_template
end

it "keeps OtherDoi templates free of the Datacite shard setting" do
indices = Elasticsearch::Model.client.indices
allow(indices).to receive(:exists_template?).and_return(false)
expect(indices).to receive(:put_template) do |args|
expect(args[:name]).to eq(OtherDoi.index_name)
expect(args[:body][:index_patterns]).to eq(["#{OtherDoi.index_name}*"])
expect(args[:body][:settings]).to eq(Doi.settings.to_hash)
expect(args[:body][:settings].dig(:index, :number_of_shards)).to be_nil
{ "acknowledged" => true }
end

OtherDoi.create_template
end
end
Loading