# Java Plugin: Data update correctly implemented?

**URL:** <https://discuss.elastic.co/t/java-plugin-data-update-correctly-implemented/13561>\
**Category:** Elasticsearch\
**Created:** [September 11, 2013, 7:13pm UTC](https://discuss.elastic.co/t/java-plugin-data-update-correctly-implemented/13561 "2013-09-11T19:13:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jan\_Hendrik\_Lendholt](https://avatars.discourse-cdn.com/v4/letter/j/b4bc9f/32.png) [@Jan\_Hendrik\_Lendholt](https://discuss.elastic.co/u/Jan_Hendrik_Lendholt)\
**Post date:** [September 11, 2013, 7:13pm UTC](https://discuss.elastic.co/t/java-plugin-data-update-correctly-implemented/13561/1 "2013-09-11T19:13:18Z")

</div>

Hi,

I am relatively new to ES. We are currently running an ES cluster with 3  
Nodes and the default sharding strategy.

I started now to write a Plugin which will do some basic maintenance,  
update some data here and there and set a flag to true or false.  
I created a service and registered it. The constructor gets a Client object  
injected.

Then I regularly fetch data, process them and eventually put them back to  
index.

My question: Is this okay for the whole cluster? I mean, will the changes  
that I make with the Client object get propagated to the other nodes and  
the replica shards or do I have to make my plugin shard- and cluster  
agnostic?

Thanks for a short reply 🙂

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [September 12, 2013, 11:32am UTC](https://discuss.elastic.co/t/java-plugin-data-update-correctly-implemented/13561/2 "2013-09-12T11:32:49Z")

</div>

If you work with a Client object, whatever implementation it is, you are  
sending normal requests that affect the whole cluster. What happens is that  
you don't need to send your requests to a node, since your code is running  
already within an elasticsearch node, which will decide where your requests  
need to be sent and what to do with those.

Cheers  
Luca

On Wednesday, September 11, 2013 9:13:18 PM UTC+2, Jan-Hendrik Lendholt  
wrote:

> Hi,
> 
> I am relatively new to ES. We are currently running an ES cluster with 3  
> Nodes and the default sharding strategy.
> 
> I started now to write a Plugin which will do some basic maintenance,  
> update some data here and there and set a flag to true or false.  
> I created a service and registered it. The constructor gets a Client  
> object injected.
> 
> Then I regularly fetch data, process them and eventually put them back to  
> index.
> 
> My question: Is this okay for the whole cluster? I mean, will the changes  
> that I make with the Client object get propagated to the other nodes and  
> the replica shards or do I have to make my plugin shard- and cluster  
> agnostic?
> 
> Thanks for a short reply 🙂

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Jan\_Hendrik\_Lendholt](https://avatars.discourse-cdn.com/v4/letter/j/b4bc9f/32.png) [@Jan\_Hendrik\_Lendholt](https://discuss.elastic.co/u/Jan_Hendrik_Lendholt)\
**Post date:** [September 13, 2013, 5:53am UTC](https://discuss.elastic.co/t/java-plugin-data-update-correctly-implemented/13561/3 "2013-09-13T05:53:54Z")

</div>

Hi Luca,

thanks for your answer 🙂 That sounds good.

I got another question you might be able to answer:

Let's say I've got 3 machines, one of them being master and 2 being  
replicas.  
I install my plugin on all three machines. The plugin code gets executed  
once every 60 seconds.

If the plugin gets called on the replica first (and on the master second)  
and updates data, will it be propagated to the other replica and to the  
master as well?  
I am afraid loosing data or doing the work twice.

Thanks 🙂

Jan

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [September 13, 2013, 7:14am UTC](https://discuss.elastic.co/t/java-plugin-data-update-correctly-implemented/13561/4 "2013-09-13T07:14:33Z")

</div>

Hey,

you might be doing the work thrice in this setup. You could check, if the  
plugin is called on the master node, and if not, simply do nothing (this is  
a simple solution and might put some additional load on your master, not  
sure how big your maintenance tasks are, you might need to find a different  
solution in your case).

Sample code might be here:

> <https://github.com/spinscale/elasticsearch-graphite-plugin/blob/master/src/main/java/org/elasticsearch/service/graphite/GraphiteService.java#L78-L94>

--Alex

On Fri, Sep 13, 2013 at 7:53 AM, Jan-Hendrik Lendholt \<  
[jan.lendholt@gmail.com](mailto:jan.lendholt@gmail.com)\> wrote:

> Hi Luca,
> 
> thanks for your answer 🙂 That sounds good.
> 
> I got another question you might be able to answer:
> 
> Let's say I've got 3 machines, one of them being master and 2 being  
> replicas.  
> I install my plugin on all three machines. The plugin code gets executed  
> once every 60 seconds.
> 
> If the plugin gets called on the replica first (and on the master second)  
> and updates data, will it be propagated to the other replica and to the  
> master as well?  
> I am afraid loosing data or doing the work twice.
> 
> Thanks 🙂
> 
> Jan
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Jan\_Hendrik\_Lendholt](https://avatars.discourse-cdn.com/v4/letter/j/b4bc9f/32.png) [@Jan\_Hendrik\_Lendholt](https://discuss.elastic.co/u/Jan_Hendrik_Lendholt)\
**Post date:** [September 13, 2013, 9:10am UTC](https://discuss.elastic.co/t/java-plugin-data-update-correctly-implemented/13561/5 "2013-09-13T09:10:39Z")

</div>

Hi Alex,

thanks for the quick reply 🙂

I managed it a little bit different:

I implemented LocalNodeMasterListener which makes sure, that the plugin  
only executes the maintenance tasks on the master node.  
If the master not gets degraded and another node gets promoted, the plugin  
will start to work on the new master node.

One short question: The maintenance task selects & updates several  
documents, up to a few thousands. Which ExecutorName should I take from ThreadPool.Name?  
I choose .INDEX, or should I rather choose SEARCH?

Thank you guys!

Jan

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:16am UTC](https://discuss.elastic.co/t/java-plugin-data-update-correctly-implemented/13561/6 "2017-07-06T02:16:39Z")

</div>


