Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split the alias update call in two calls #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
27 changes: 21 additions & 6 deletions lib/searchyll/indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,21 +241,36 @@ def finalize_replication(http)
# hot swap the index into the canonical alias
def finalize_aliases(http)
update_aliases = http_post('/_aliases')

# perform removal and addition in two different calls so that
# the second one is performed even if the first one fails
if !old_indices.empty?
update_aliases.body = {
actions: [
{ remove: {
index: old_indices.join(','),
alias: configuration.elasticsearch_index_base_name
} }
]
}.to_json
res = http.request(update_aliases)
unless res.kind_of?(Net::HTTPSuccess)
Jekyll.logger.error("Elasticsearch returned an error when removing old aliases: #{res.message} #{res.body}")
exit
end
end

update_aliases.body = {
actions: [
{ remove: {
index: old_indices.join(','),
alias: configuration.elasticsearch_index_base_name
} },
{ add: {
index: elasticsearch_index_name,
alias: configuration.elasticsearch_index_base_name
} }
]
}.to_json
res = http.request(update_aliases)
if !res.kind_of?(Net::HTTPSuccess)
$stderr.puts "Elasticsearch returned an error when updating aliases: " + res.message + " " + res.body
unless res.kind_of?(Net::HTTPSuccess)
Jekyll.logger.error("Elasticsearch returned an error when assigning the new alias: #{res.message} #{res.body}")
exit
end
end
Expand Down