[infinispan-dev] Need to understand, ClusteredCacheWithElasticsearchIndexManagerIT

Katia Aresti karesti at redhat.com
Tue May 9 09:21:07 EDT 2017


Hi all,

I'm really struggling with something in order to finish the compute methods.

I added a test in *ClusteredCacheWithElasticsearchIndexManagerIT*

public void testToto() throws Exception {
    SearchManager searchManager = Search.getSearchManager(cache2);
    QueryBuilder queryBuilder = searchManager
          .buildQueryBuilderForClass(Person.class)
          .get();
    Query allQuery = queryBuilder.all().createQuery();

    String key = "newGoat";
    Person person4 = new Person(key, "eats something", 42);

    cache2.putIfAbsent(key, person4);
    StaticTestingErrorHandler.assertAllGood(cache1, cache2);

    List<Person> found = searchManager.<Person>getQuery(allQuery,
Person.class).list();
    assertEquals(1, found.size());
    assertTrue(found.contains(person4));
}

I put some logs in the processPutKeyValueCommand method in the
*QueryInterceptor* to explain what is happening.

*2 threads*
Sometimes two threads get involved.

= Thread 72 First (or second) call
It happens from a non local Node. The so the shouldModifyIndexes says "no,
you should not modify any index" because the IndexModificationStrategy is
set to "LOCAL ONLY". [1]

72 ctx.getOrigin() =
ClusteredCacheWithElasticsearchIndexManagerIT-NodeB-19565
72 should modify false
72 previousValue null
72 putValue Person{name='newGoat', blurb='eats something', age=42,
dateOfGraduation=null} // value in the command
72 contextValue Person{name='newGoat', blurb='eats something', age=42,
dateOfGraduation=null} //value in the invocation context

= Thread 48 Second (or first) call
the origin is null, and this is considered as a LOCAL in the
SingleKeyNonTxInvocationContext.
[2] In this case, the index is modified correctly, the value in the context
has already been set up by the PutKeyValueCommand and the index get's
correctly updated.

48 ctx.getOrigin() = null
48 should modify true
48 previousValue null
48 putValue Person{name='newGoat', blurb='eats something', age=42,
dateOfGraduation=null}
48 contextValue Person{name='newGoat', blurb='eats something', age=42,
dateOfGraduation=null}

And everything is ok. Everything is fine too in the case of a compute
method instead of the put method.

But sometimes, this is not executed like that.

*3 threads*

What is a bit more weird to me is this second scenario where the commands
are executed both from non local nodes (A and B). And so the index is not
updated.
But  just later, another thread get's involved and calls the
QueryInterceptor with a invocation context where the command has not been
executed (the value is not inside the context and the debugger does not
enter in the perform method, this has happened just twice before). This
call is coming like from a callback? in the QueueAsyncInvocationStage.

80 ctx.getOrigin() =
ClusteredCacheWithElasticsearchIndexManagerIT-NodeA-65110
80 should modify false
80 prev null
80 putValue Person{name='newGoat', blurb='eats something', age=42,
dateOfGraduation=null}
80 contextValue Person{name='newGoat', blurb='eats something', age=42,
dateOfGraduation=null}

38 ctx.getOrigin() =
ClusteredCacheWithElasticsearchIndexManagerIT-NodeB-35919
38 should modify false
38 prev null
38 putValue Person{name='newGoat', blurb='eats something', age=42,
dateOfGraduation=null}
38 contextValue Person{name='newGoat', blurb='eats something', age=42,
dateOfGraduation=null}

48 ctx.getOrigin() = null
48 should modify true
48 prev null
48 putValue Person{name='newGoat', blurb='eats something', age=42,
dateOfGraduation=null}
48 contextValue null


This execution works perfectly with PutKeyValueCommand. But don't work wth
compute.

The "computed value" is not inside the Command like put, replace or others.
It is computed in the perform method (if needed). So, the first time the
command is executed in A, the computed value is in the context, but the
index is not updated. Second call, executed in B, value in context, but the
index is not updated. The magic callback is executed, but the computed
value is nowhere because the command is not executed a third time, so the
context is null.

Can somebody please give me some light on this and explain to me what am I
missing ? Other tests are failing for the same problem,
like org.infinispan.query.blackbox.ClusteredCacheWithInfinispanDirectoryTest

Thank you very much for your help !

Katia

[1]
https://github.com/infinispan/infinispan/blob/master/query/src/main/java/org/infinispan/query/backend/IndexModificationStrategy.java#L50
[2]
https://github.com/infinispan/infinispan/blob/master/core/src/main/java/org/infinispan/context/SingleKeyNonTxInvocationContext.java#L39
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/infinispan-dev/attachments/20170509/b059956e/attachment-0001.html 


More information about the infinispan-dev mailing list