mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-30 19:52:20 +01:00
fasten reindexing
This commit is contained in:
parent
3a92f7bb73
commit
0ed3fcd5e6
@ -190,7 +190,7 @@ ensure_initial_status_green()
|
|||||||
local indices=$(curl "$ES_IP:9200/_cat/indices" 2>/dev/null | awk '{print $3}')
|
local indices=$(curl "$ES_IP:9200/_cat/indices" 2>/dev/null | awk '{print $3}')
|
||||||
for index in $indices # do not surround $indices with quotes
|
for index in $indices # do not surround $indices with quotes
|
||||||
do
|
do
|
||||||
curl -XPUT "$ES_IP:9200/$index/_settings" -H 'Content-Type: application/json' -d '{
|
curl -XPUT "$ES_IP:9200/$index/_settings" 2>/dev/null -H 'Content-Type: application/json' -d '{
|
||||||
"index": {
|
"index": {
|
||||||
"number_of_replicas": 0
|
"number_of_replicas": 0
|
||||||
}
|
}
|
||||||
@ -214,19 +214,44 @@ wait_for_online()
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prepare_upgrade()
|
||||||
|
{
|
||||||
|
curl -XPUT "$ES_IP:9200/_cluster/settings?pretty" 2>/dev/null -H 'Content-Type: application/json' -d'{
|
||||||
|
"persistent": {
|
||||||
|
"cluster.routing.allocation.enable": "none"
|
||||||
|
},
|
||||||
|
"transient": {
|
||||||
|
"cluster.routing.allocation.enable": "none"
|
||||||
|
}
|
||||||
|
}'
|
||||||
|
curl -XPOST 2>/dev/null "$ES_IP:9200/_flush/synced?pretty"
|
||||||
|
}
|
||||||
|
|
||||||
|
reenable_allocation()
|
||||||
|
{
|
||||||
|
curl -XPUT "$ES_IP:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'{
|
||||||
|
"transient": {
|
||||||
|
"cluster.routing.allocation.enable": "all"
|
||||||
|
}
|
||||||
|
}'
|
||||||
|
}
|
||||||
|
|
||||||
upgrade_compose()
|
upgrade_compose()
|
||||||
{
|
{
|
||||||
local current=$1
|
local current=$1
|
||||||
local target=$2
|
local target=$2
|
||||||
echo -e "\nUpgrading docker-compose installation from $current to $target..."
|
echo -e "\nUpgrading docker-compose installation from $current to $target..."
|
||||||
|
prepare_upgrade
|
||||||
docker-compose stop elasticsearch
|
docker-compose stop elasticsearch
|
||||||
docker-compose rm -f elasticsearch
|
docker-compose rm -f elasticsearch
|
||||||
local image="elasticsearch:$target"
|
local image="elasticsearch:$target"
|
||||||
if [ $target = '6.2' ]; then image="docker.elastic.co/elasticsearch/elasticsearch-oss:$target"; fi
|
if [ $target = '6.2' ]; then image="docker.elastic.co\/elasticsearch\/elasticsearch-oss:6.2.3"; fi
|
||||||
sed -i.bak "s/image: elasticsearch:$current/image: $image/g" "$FM_PATH/docker-compose.yml"
|
sed -i.bak "s/image: elasticsearch:$current/image: $image/g" "$FM_PATH/docker-compose.yml"
|
||||||
docker-compose pull
|
docker-compose pull
|
||||||
docker-compose up -d
|
docker-compose up -d
|
||||||
wait_for_online
|
wait_for_online
|
||||||
|
reenable_allocation
|
||||||
|
# check status
|
||||||
local version=$(test_version)
|
local version=$(test_version)
|
||||||
if [ "$STATUS" = "ONLINE" ] && [ "$version" = "$target" ]; then
|
if [ "$STATUS" = "ONLINE" ] && [ "$version" = "$target" ]; then
|
||||||
echo "Migration to elastic $target was successful."
|
echo "Migration to elastic $target was successful."
|
||||||
@ -251,16 +276,23 @@ upgrade_docker()
|
|||||||
local network=$(docker inspect -f '{{.NetworkSettings.Networks}}' "$id" | sed 's/map\[\(.*\):0x[a-f0-9]*\]/\1/')
|
local network=$(docker inspect -f '{{.NetworkSettings.Networks}}' "$id" | sed 's/map\[\(.*\):0x[a-f0-9]*\]/\1/')
|
||||||
# get container mapping to data folder
|
# get container mapping to data folder
|
||||||
local mounts=$(docker inspect -f '{{.Mounts}}' "$id" | sed 's/} {/\n/g' | sed 's/^\[\?{\?bind[[:blank:]]*\([^[:blank:]]*\)[[:blank:]]*\([^[:blank:]]*\)[[:blank:]]*true \(rprivate\)\?}\?]\?$/-v \1:\2/g' | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/ /g')
|
local mounts=$(docker inspect -f '{{.Mounts}}' "$id" | sed 's/} {/\n/g' | sed 's/^\[\?{\?bind[[:blank:]]*\([^[:blank:]]*\)[[:blank:]]*\([^[:blank:]]*\)[[:blank:]]*true \(rprivate\)\?}\?]\?$/-v \1:\2/g' | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/ /g')
|
||||||
|
prepare_upgrade
|
||||||
# stop current elastic
|
# stop current elastic
|
||||||
docker stop "$name"
|
docker stop "$name"
|
||||||
docker rm -f "$name"
|
docker rm -f "$name"
|
||||||
# run target elastic
|
# run target elastic
|
||||||
local image="elasticsearch:$target"
|
local image="elasticsearch:$target"
|
||||||
if [ $target = '6.2' ]; then image="docker.elastic.co/elasticsearch/elasticsearch-oss:$target"; fi
|
local image_name="$image"
|
||||||
|
if [ $target = '6.2' ]
|
||||||
|
then
|
||||||
|
image_name="elasticsearch-oss:$target"
|
||||||
|
image="docker.elastic.co/elasticsearch/$image_name"
|
||||||
|
fi
|
||||||
docker pull "$image"
|
docker pull "$image"
|
||||||
echo docker run --restart=always -d --name="$name" --network="$network" --ip="$ES_IP" "$mounts" "$image" | bash
|
echo docker run --restart=always -d --name="$name" --network="$network" --ip="$ES_IP" "$mounts" "$image_name" | bash
|
||||||
# check status
|
|
||||||
wait_for_online
|
wait_for_online
|
||||||
|
reenable_allocation
|
||||||
|
# check status
|
||||||
local version=$(test_version)
|
local version=$(test_version)
|
||||||
if [ "$STATUS" = "ONLINE" ] && [ "$version" = "$target" ]; then
|
if [ "$STATUS" = "ONLINE" ] && [ "$version" = "$target" ]; then
|
||||||
echo "Migration to elastic $target was successful."
|
echo "Migration to elastic $target was successful."
|
||||||
@ -293,7 +325,15 @@ upgrade_classic()
|
|||||||
then
|
then
|
||||||
# Debian compatible
|
# Debian compatible
|
||||||
echo -e "\nUpdating ElasticSearch to $target"
|
echo -e "\nUpdating ElasticSearch to $target"
|
||||||
# TODO https://www.elastic.co/guide/en/elasticsearch/reference/2.4/restart-upgrade.html
|
prepare_upgrade
|
||||||
|
# stop elasticsearch
|
||||||
|
if command -v systemctl
|
||||||
|
then
|
||||||
|
sudo systemctl stop elasticsearch.service
|
||||||
|
else
|
||||||
|
sudo /etc/init.d/elasticsearch stop
|
||||||
|
fi
|
||||||
|
# process with package upgrade
|
||||||
wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
|
wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
|
||||||
case "$target" in
|
case "$target" in
|
||||||
"2.4")
|
"2.4")
|
||||||
@ -307,11 +347,12 @@ upgrade_classic()
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
sudo apt-get update && sudo apt-get install --only-upgrade elasticsearch
|
sudo apt-get update && sudo apt-get install --only-upgrade elasticsearch
|
||||||
|
# restart elasticsearch service
|
||||||
if command -v systemctl
|
if command -v systemctl
|
||||||
then
|
then
|
||||||
sudo systemctl restart elasticsearch.service
|
sudo systemctl start elasticsearch.service
|
||||||
else
|
else
|
||||||
sudo /etc/init.d/elasticsearch restart
|
sudo /etc/init.d/elasticsearch start
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
unsupported_message
|
unsupported_message
|
||||||
@ -320,6 +361,8 @@ upgrade_classic()
|
|||||||
;;
|
;;
|
||||||
Darwin*)
|
Darwin*)
|
||||||
# Mac OS X
|
# Mac OS X
|
||||||
|
echo -e "\nUpdating ElasticSearch to $target"
|
||||||
|
prepare_upgrade
|
||||||
brew update
|
brew update
|
||||||
case "$target" in
|
case "$target" in
|
||||||
"2.4")
|
"2.4")
|
||||||
@ -337,8 +380,9 @@ upgrade_classic()
|
|||||||
unsupported_message
|
unsupported_message
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
# check status
|
|
||||||
wait_for_online
|
wait_for_online
|
||||||
|
reenable_allocation
|
||||||
|
# check status
|
||||||
local version=$(test_version)
|
local version=$(test_version)
|
||||||
if [ "$STATUS" = "ONLINE" ] && [ "$version" = "$target" ]; then
|
if [ "$STATUS" = "ONLINE" ] && [ "$version" = "$target" ]; then
|
||||||
echo "Migration to elastic $target was successful."
|
echo "Migration to elastic $target was successful."
|
||||||
@ -368,9 +412,9 @@ reindex_indices()
|
|||||||
#
|
#
|
||||||
local migration_index="$index""_$1"
|
local migration_index="$index""_$1"
|
||||||
# create the temporary migration index with the previous mapping
|
# create the temporary migration index with the previous mapping
|
||||||
curl -XPUT "http://$ES_IP:9200/$migration_index/" -H 'Content-Type: application/json' -d "$definition"
|
curl -XPUT "http://$ES_IP:9200/$migration_index/" 2>/dev/null -H 'Content-Type: application/json' -d "$definition"
|
||||||
# reindex data content to the new migration index
|
# reindex data content to the new migration index
|
||||||
curl -XPOST "$ES_IP:9200/_reindex?pretty" -H 'Content-Type: application/json' -d '{
|
curl -XPOST "$ES_IP:9200/_reindex?pretty" 2>/dev/null -H 'Content-Type: application/json' -d '{
|
||||||
"source": {
|
"source": {
|
||||||
"index": "'"$index"'"
|
"index": "'"$index"'"
|
||||||
},
|
},
|
||||||
@ -401,8 +445,8 @@ reindex_final_indices()
|
|||||||
for index in $indices # do not surround $indices with quotes
|
for index in $indices # do not surround $indices with quotes
|
||||||
do
|
do
|
||||||
local final_index=$(echo "$index" | sed "s/\(.*\)_$previous$/\1/")
|
local final_index=$(echo "$index" | sed "s/\(.*\)_$previous$/\1/")
|
||||||
curl -XPUT "http://$ES_IP:9200/$final_index"
|
curl -XPUT "http://$ES_IP:9200/$final_index" 2>/dev/null
|
||||||
curl -XPOST "$ES_IP:9200/_reindex?pretty" -H 'Content-Type: application/json' -d '{
|
curl -XPOST "$ES_IP:9200/_reindex?pretty" 2>/dev/null -H 'Content-Type: application/json' -d '{
|
||||||
"source": {
|
"source": {
|
||||||
"index": "'"$index"'"
|
"index": "'"$index"'"
|
||||||
},
|
},
|
||||||
@ -421,7 +465,7 @@ reindex_final_indices()
|
|||||||
echo "Reindex completed, deleting previous index..."
|
echo "Reindex completed, deleting previous index..."
|
||||||
for index in $indices # do not surround $indices with quotes
|
for index in $indices # do not surround $indices with quotes
|
||||||
do
|
do
|
||||||
curl -XDELETE "$ES_IP:9200/$index?pretty"
|
curl -XDELETE "$ES_IP:9200/$index?pretty" 2>/dev/null
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user