You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by "sergey.dolinkov" <se...@billing.ru> on 2018/07/30 16:47:57 UTC

entyproccessor dont locking entry

there is next code:

      counters.forEach((key, value) -> {
        TaskTicketsCounter outCounter = taskTicketCounterCache.invoke(key,
(entry, args) -> {
          TaskTicketsCounter counter = entry.getValue();          

          if (counter != null) {
            System.out.println(counter.getId());
            System.out.println(counter.getNotProcessedTicketCount());

            counter.setFailTicketCount(counter.getFailTicketCount() +
value.getRight());
            counter.setSuccessTicketCount(counter.getSuccessTicketCount() +
value.getMiddle());
           
counter.setNotProcessedTicketCount(counter.getNotProcessedTicketCount() -
value.getLeft());
          }
          System.out.println(counter.getNotProcessedTicketCount());
          return counter;
        }, value);

        System.out.println(outCounter.getNotProcessedTicketCount());

        if (outCounter != null && outCounter.getNotProcessedTicketCount() ==
0){
          Task task = taskCache.get(outCounter.getId());
          if (outCounter.getFailTicketCount() > 0){
            task.setStatus(TaskStatus.ERROR);
          } else {
            task.setStatus(TaskStatus.DONE);
          }
          taskCache.put(task.getId(), task);
        }
      });

when i run it concurently i never get 
outCounter.getNotProcessedTicketCount() == 0 

println out :
2
1
1

2
1
1

it look like what every entry proccessor get copy of one entry



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: entyproccessor dont locking entry

Posted by vkulichenko <va...@gmail.com>.
You're iterating through some collection of key-value pairs and then use
value from that pair within the entry processor, which is incorrect. You
should always use the one acquired via entry.getValue(); there.

I would actually recommend you to create a separate class instead of using
lambda for entry processor implementation. That would help you to avoid this
kind of errors, as well as various serialization issues (entry processors
are sent across the network which can cause unexpected behavior in case
lambdas or anonymous classes are used).

-Val



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/