You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by yy lee <so...@gmail.com> on 2018/06/10 15:11:02 UTC

Get replica status in solrj

hi all,

I am try to get the replica status from solrj,
but I found out that the status I get is not correct.
I still get the state of the replica as "active", although I have stop my
solr.
Is there any way I can get the correct replica state from solrj?

regards,
yy

Re: Get replica status in solrj

Posted by y y <so...@gmail.com>.
after I close down one of the solr without using the stop command, I can
get the correct replica state as "down" in the command prompt using this
code:
solr.cmd healthcheck -c test1 -z
localhost:2181,localhost:2182,localhost:2183
but I cannot get the correct replica state in solrj even when I add this
additional test code :
" if (reader..getClusterState().getLiveNodes().contains(
replica.getNodeName())
== false) ----state is down."
it is because of ".... live_nodes and the clusterstate will not be updated
immediately...." as mentioned above?

regards,
yy

On Mon, Jun 11, 2018 at 11:03 PM, Erick Erickson <er...@gmail.com>
wrote:

> bq. how can I get the correct replica state?
>
> something like add this additional test.
>
> if (reader..getClusterState().getLiveNodes().contains(
> replica.getNodeName())
> == false) ----state is down.
>
> Best,
> Erick
>
> On Mon, Jun 11, 2018 at 6:59 AM, Shawn Heisey <el...@elyograg.org>
> wrote:
> > On 6/11/2018 3:29 AM, y y wrote:
> >>
> >> question is I can manage to get the correct replica state if I start and
> >> stop solr using command line.
> >>   how if solr failure or crashed, how can I get the correct replica
> state?
> >
> >
> > As I have stated elsewhere on this mailing list, actual Solr crashes are
> > extremely rare.  The most common reason for Solr to die suddenly is the
> > intentional death that happens when OutOfMemoryError is thrown.  Other
> > causes are possible, but normally indicate serious problems with the
> system
> > itself.
> >
> > If Solr is ungracefully killed due to OOME or some other reason, then as
> > Erick mentioned, live_nodes and the clusterstate will not be updated
> > immediately.  Eventually, when attempts to use those replicas fail, the
> > remaining Solr servers will notice that the node is down and update the
> > clusterstate.  But it won't happen as soon as the node dies.
> >
> > Thanks,
> > Shawn
> >
>

Re: Get replica status in solrj

Posted by Erick Erickson <er...@gmail.com>.
bq. how can I get the correct replica state?

something like add this additional test.

if (reader..getClusterState().getLiveNodes().contains(replica.getNodeName())
== false) ----state is down.

Best,
Erick

On Mon, Jun 11, 2018 at 6:59 AM, Shawn Heisey <el...@elyograg.org> wrote:
> On 6/11/2018 3:29 AM, y y wrote:
>>
>> question is I can manage to get the correct replica state if I start and
>> stop solr using command line.
>>   how if solr failure or crashed, how can I get the correct replica state?
>
>
> As I have stated elsewhere on this mailing list, actual Solr crashes are
> extremely rare.  The most common reason for Solr to die suddenly is the
> intentional death that happens when OutOfMemoryError is thrown.  Other
> causes are possible, but normally indicate serious problems with the system
> itself.
>
> If Solr is ungracefully killed due to OOME or some other reason, then as
> Erick mentioned, live_nodes and the clusterstate will not be updated
> immediately.  Eventually, when attempts to use those replicas fail, the
> remaining Solr servers will notice that the node is down and update the
> clusterstate.  But it won't happen as soon as the node dies.
>
> Thanks,
> Shawn
>

Re: Get replica status in solrj

Posted by Shawn Heisey <el...@elyograg.org>.
On 6/11/2018 3:29 AM, y y wrote:
> question is I can manage to get the correct replica state if I start and
> stop solr using command line.
>   how if solr failure or crashed, how can I get the correct replica state?

As I have stated elsewhere on this mailing list, actual Solr crashes are 
extremely rare.  The most common reason for Solr to die suddenly is the 
intentional death that happens when OutOfMemoryError is thrown.  Other 
causes are possible, but normally indicate serious problems with the 
system itself.

If Solr is ungracefully killed due to OOME or some other reason, then as 
Erick mentioned, live_nodes and the clusterstate will not be updated 
immediately.  Eventually, when attempts to use those replicas fail, the 
remaining Solr servers will notice that the node is down and update the 
clusterstate.  But it won't happen as soon as the node dies.

Thanks,
Shawn


Re: Get replica status in solrj

Posted by y y <so...@gmail.com>.
Hi all,

I am using the code below to get the replica state:

    ZkStateReader reader = cloudSolrClient.getZkStateReader();
    ClusterState slices22 = reader.getClusterState();
    DocCollection slices =
reader.getClusterState().getCollection(collection);
    Iterator<Slice> iter = slices.iterator();

    while (iter.hasNext()) {
        Slice slice = iter.next();
        for(Replica replica:slice.getReplicas()) {
            System.out.println(replica.getStr( "state" ));
        }
    }

question is I can manage to get the correct replica state if I start and
stop solr using command line.
 how if solr failure or crashed, how can I get the correct replica state?

regards,
yy

On Mon, Jun 11, 2018 at 4:28 AM, Erick Erickson <er...@gmail.com>
wrote:

> You have to cross check with live_nodes. This is especially true if
> you stop Solr un-gracefully, i.e. "kill -9" or the like (which is
> _not_ recommended).
>
> During graceful shutdown, the Solr instance has a chance to change all
> replica's states correctly. There's no chance to do that if you kill
> Solr though. At that point, Zookeeper will eventually tryto contact
> the Solr node and, if the Solr node is unavailable, remove it's
> ephemeral node from the live_nodes znode. It does _not_, however,
> change any replica's states that are hosted on that Solr instance,
> thus you must check live_nodes too.
>
> Or shut Solr down gracefully. This may require that you lengthen
> "SOLR_STOP_WAIT" in solr.in.sh (Solr 6.3). If your version is earlier
> than 6.3, you'll have to modify your local copy of bin/solr.
>
> Best,
> Erick.
>
> On Sun, Jun 10, 2018 at 8:11 AM, yy lee <so...@gmail.com> wrote:
> > hi all,
> >
> > I am try to get the replica status from solrj,
> > but I found out that the status I get is not correct.
> > I still get the state of the replica as "active", although I have stop my
> > solr.
> > Is there any way I can get the correct replica state from solrj?
> >
> > regards,
> > yy
>

Re: Get replica status in solrj

Posted by Erick Erickson <er...@gmail.com>.
You have to cross check with live_nodes. This is especially true if
you stop Solr un-gracefully, i.e. "kill -9" or the like (which is
_not_ recommended).

During graceful shutdown, the Solr instance has a chance to change all
replica's states correctly. There's no chance to do that if you kill
Solr though. At that point, Zookeeper will eventually tryto contact
the Solr node and, if the Solr node is unavailable, remove it's
ephemeral node from the live_nodes znode. It does _not_, however,
change any replica's states that are hosted on that Solr instance,
thus you must check live_nodes too.

Or shut Solr down gracefully. This may require that you lengthen
"SOLR_STOP_WAIT" in solr.in.sh (Solr 6.3). If your version is earlier
than 6.3, you'll have to modify your local copy of bin/solr.

Best,
Erick.

On Sun, Jun 10, 2018 at 8:11 AM, yy lee <so...@gmail.com> wrote:
> hi all,
>
> I am try to get the replica status from solrj,
> but I found out that the status I get is not correct.
> I still get the state of the replica as "active", although I have stop my
> solr.
> Is there any way I can get the correct replica state from solrj?
>
> regards,
> yy