Skip to content

Instantly share code, notes, and snippets.

@relwell
Created July 24, 2016 21:04
Show Gist options
  • Save relwell/51aecaf7a435c68a1651872f0febbb5b to your computer and use it in GitHub Desktop.
Save relwell/51aecaf7a435c68a1651872f0febbb5b to your computer and use it in GitHub Desktop.
Recover SolrCloud Replicas
# 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