Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cs_comments_service
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
cs_comments_service
Commits
384fb61b
Commit
384fb61b
authored
May 08, 2014
by
jsa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add migrate-index.sh for simplified reindexing.
parent
f7375bb2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
96 additions
and
0 deletions
+96
-0
scripts/es/migrate-index.sh
+96
-0
No files found.
scripts/es/migrate-index.sh
0 → 100644
View file @
384fb61b
# USAGE
# 1). Use `bundle exec rake db:create_search_indexes` to generate
# new indexes with the appropriate mappings as declared in application
# model code.
# 2). Run this script for each of the two indexes created in the above
# step. For example, if db:create_search_indexes outputs the following:
#
# comment_threads_1234567890
# comments_1234567890
#
# Then you need to run the following two commands (setting the
# elasticsearch url as needed):
#
# ./migrate-index.sh http://my-es-host:9200 comment_threads comment_threads_1234567890
# ./migrate-index.sh http://my-es-host:9200 comments comments_1234567890
# HOW IT WORKS
# ---T1---(W1)---T2---(W2)---T3--------->
# \ \ \
# \ \ incremental-copy-index completes
# \ \
# \ copy-index completes
# \ alias moves
# \ incremental-copy-index begins
# \
# copy-index begins
#
# During W1, the new index is created but is not yet live. The current
# index's documents are copied into the new index, as of T1 (see
# copy-index.sh).
# At T2, when this initial copy finishes, the new index is made live and
# requests to the application begin using it (though it is still missing
# changes from W1).
# During W2, all documents in the old (previously live) index that were
# created or modified during W1 are copied into the newly-live index
# (see incremental-copy-index.sh).
# At T3, when the second copy finishes, the new (newly-live) index is up
# to date and the old index can be discarded.
# WARNING
# When performed while the application is online, the migration process
# is prone to a race condition, whose likelihood increases with the
# amount of write traffic against the application.
# Specifically, if a document is created or modified during W1, and the
# same document is modified (or deleted) during W2, the two
# modifications *may* be applied out of sequence, resulting in either a
# lost update or a reverted deletion.
# Therefore, manual steps must be taken to ensure the index and the
# source database are fully synchronized, if these tools are used for an
# online index migration. Otherwise, consider closing your application
# instance for maintenance while migrating your indexes.
ES_URL
=
$1
ALIAS
=
$2
NEW_INDEX
=
$3
# determine the existing alias and set OLD_INDEX
OLD_INDEX
=
`
curl
-X
GET
$ES_URL
/_alias/
$ALIAS
| jq
-r
'keys[0]'
`
echo
old index:
$OLD_INDEX
echo
new index:
$NEW_INDEX
if
[
$OLD_INDEX
=
$NEW_INDEX
]
;
then
echo
"Alias
${
ALIAS
}
already points to the new index. Nothing to do."
exit
0
fi
# regenerate presently existing documents in new index
./copy-index.sh
$ES_URL
$OLD_INDEX
$ES_URL
$NEW_INDEX
# move alias atomically to new index
BODY
=
"
{
\"
actions
\"
: [
{
\"
remove
\"
: {
\"
index
\"
:
\"
${
OLD_INDEX
}
\"
,
\"
alias
\"
:
\"
${
ALIAS
}
\"
} },
{
\"
add
\"
: {
\"
index
\"
:
\"
${
NEW_INDEX
}
\"
,
\"
alias
\"
:
\"
${
ALIAS
}
\"
} }
]
}
"
curl
-X
POST
"
${
ES_URL
}
/_aliases"
-d
"
${
BODY
}
"
# pick up any missed updates since the first copy
./incremental-copy-index.sh
$ES_URL
$OLD_INDEX
$ES_URL
$NEW_INDEX
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment