Created
July 24, 2016 21:04
-
-
Save relwell/51aecaf7a435c68a1651872f0febbb5b to your computer and use it in GitHub Desktop.
Recover SolrCloud Replicas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This will restore replicas back to a node that has lost all of its data, | |
# running from the same hostname as the previous node | |
import sys | |
from solrcloudpy import SolrConnection | |
connection = SolrConnection(sys.argv[0], version='6.0.0') | |
health = connection.cluster_health | |
if health and health['status'] == 'NOT OK': | |
for detail in health['details']: | |
print '======= Recovering node %s | %s | %s ==========' % (detail['collection'], | |
detail['shard'], | |
detail['replica']) | |
print detail | |
# first delete the down shard | |
# this will result in a solrexception, but it will also remove the bad entry. | |
params = {'action': 'DELETEREPLICA', | |
'collection': detail['collection'], | |
'shard': detail['shard'], | |
'replica': detail['replica']} | |
result = connection.client.get(('/{webappdir}/admin/collections'.format(webappdir=connection.webappdir)), | |
params).result | |
print result.dict | |
# now add back that bad replica | |
params = {'action': 'ADDREPLICA', | |
'collection': detail['collection'], | |
'shard': detail['shard'], | |
'node': detail['info']['node_name']} | |
result = connection.client.get(('/{webappdir}/admin/collections'.format(webappdir=connection.webappdir)), | |
params).result | |
print result.dict | |
print '=============================================================' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment