Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
upgrade elasticsearch from 0.9.x to 0.10.0 script
/**
* An upgrade script from FS gateway indices version 0.9.0 to 0.10.
*
* The script uses groovy, you can get it from here: http://groovy.codehaus.org/Download.
*
* Upgrade Process:
*
* 1. Stop indexing operations against the cluster.
* 2. Issue a flush command: curl -XPOST host:port/_flush
* 3. Issue a snapshot command: curl -XPOST host:port/_gateway/snapshot
* 4. Shutdown the cluster: curl -XPOST host:port/_cluster/nodes/_shutdown
*
* Once its done, run this script as follows (in wet mode set to false):
*
* > groovy upgrade.groovy [path to gateway, including cluster_name]
*
* A commit file will be generated for each shard in each index. You can verify it. If all is well, run it in wet mode:
*
* > groovy upgrade.groovy [path to gateway, including cluster_name] --wet
*
* The above will upgrade the gateway to the new format. Now, you can start the cluster (and make sure to set
* recover_after_nodes to make full use of reusing local storage).
*/
if (args.length == 0) {
println "path to gateway is requried";
System.exit 1
}
def path = args[0]
println "using gateway path [$path]"
def wet = false;
if (args.length > 1) {
if ("--wet" == args[1]) {
wet = true
}
}
println "running in wet_mode $wet"
File base = new File(path);
File indices = new File(base, "indices")
if (!indices.exists()) {
println "failed to find indices location under $indices.absolutePath"
System.exit 1
}
indices.eachFile {
String indexName = it.name
println "--> processing index $indexName"
File indexFile = new File(indices, indexName)
indexFile.eachFile {
String shardId = it.name
println " --> processing shard $shardId"
File shardPath = new File(indexFile, shardId)
File shardIndexPath = new File(shardPath, "index")
File shardTranslogPath = new File(shardPath, "translog")
long generation = 0;
File commitPoint = new File(shardPath, "commit-0")
commitPoint.text = ""
commitPoint.append """{\n"""
commitPoint.append """ "version" : 0,\n"""
commitPoint.append """ "name" : "commit-0",\n"""
commitPoint.append """ "type" : "GENERATED", \n"""
commitPoint.append """ "index_files" : { \n"""
def first = true; // YUCK!!!!
shardIndexPath.eachFile {
String name = it.name;
if (!name.endsWith(".md5")) {
if (!first) {
commitPoint.append """,\n"""
} else {
first = false
}
File source = new File(shardIndexPath, name);
String genName = "__" + Long.toString(++generation, Character.MAX_RADIX)
commitPoint.append """ "$genName" : {\n"""
commitPoint.append """ "physical_name" : "$source.name",\n"""
commitPoint.append """ "length" : """ + source.length() + """\n"""
commitPoint.append """ }"""
File target = new File(shardPath, genName)
if (wet) println " moving file from $source.absolutePath to $target.absolutePath"
if (wet) source.renameTo(target)
}
}
commitPoint.append """\n },\n"""
commitPoint.append """ "translog_files" : { \n"""
def sortedTranslogs = shardTranslogPath.listFiles().findAll {it.file}.sort {it.lastModified}
if (!sortedTranslogs.isEmpty()) {
File translogFile = sortedTranslogs[0]
String genName = "__" + Long.toString(++generation, Character.MAX_RADIX)
commitPoint.append """ "$genName" : {\n"""
commitPoint.append """ "physical_name" : "$translogFile.name",\n"""
commitPoint.append """ "length" : """ + translogFile.length() + """\n"""
commitPoint.append """ }\n"""
File target = new File(shardPath, genName)
if (wet) println " moving file from $translogFile.absolutePath to $target.absolutePath"
if (wet) translogFile.renameTo(target)
}
commitPoint.append """ }\n"""
commitPoint.append """}\n"""
if (wet) {
shardIndexPath.deleteDir()
shardTranslogPath.deleteDir()
}
println " --> processed shard $shardId"
}
println "--> processed index $indexName"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment