You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by michael <mi...@citi.com> on 2018/04/18 15:13:10 UTC

Inconsistency reading cache from code and via REST?

My Setup in windows
 - all running locally pointing at same ignite xml config
 - 2 * ignite servers running ignite.bat 
 - Provided java sample code GridCacheTest (running in IntelliJ) to put 20
key value pairs in a cache

The sample code runs correctly and outputs the key/value pairs it reads back
from the cache (using cache.get(1) )

However, making a REST call from from a browser (IE) for key = 1 with:
http://127.0.0.1:8080/ignite?cmd=get&cacheName=GridCacheTest&key=*1*

gives null:
{"successStatus":0,"affinityNodeId":"44392174-5fc5-446a-ba31-05ab0c56552d","error":null,"sessionToken":null,"response":*null*}

So tried a bit of troubleshooting:

From the browser - check I really am looking/connect to the right place:
http://127.0.0.1:8080/ignite?cmd=size&cacheName=GridCacheTest

gives the size of the cache:
{"successStatus":0,"affinityNodeId":null,"error":null,"sessionToken":null,"response":*20*}

Now I tried adding an item using the REST API from the browser using cmd=put
and key = *100* and value = *101*
the cache size now correctly shows *21*
{"successStatus":0,"affinityNodeId":null,"error":null,"sessionToken":null,"response":*21*}

and
http://127.0.0.1:8080/ignite?cmd=get&cacheName=GridCacheTest&key=*100*
correctly gives
{"successStatus":0,"affinityNodeId":"9dbee249-d657-4097-b8be-0eeee8627382","error":null,"sessionToken":null,"response":"*101*"}

Even stranger back in the java code, some simple modifications to check the
size shows the cache is correctly 21 but cache.get(key) only give values for
1 to 20, for the newly added 100 it shows null.





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

Re: Inconsistency reading cache from code and via REST?

Posted by aealexsandrov <ae...@gmail.com>.
Hi,

qryexe doesn't work correct. At some reason it ignores _key and _value in
2.4. You can use qryfldexe as it was describe here:

http://apache-ignite-users.70518.x6.nabble.com/Example-of-SQL-query-td21427.html

BR,
Andrei





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

Re: Inconsistency reading cache from code and via REST?

Posted by michael <mi...@citi.com>.
Hi 

revisiting this now I am actually connecting to a data source and filling
the cache with data:

For simplicity the attached code 
cacheTableTest.java
<http://apache-ignite-users.70518.x6.nabble.com/file/t1696/cacheTableTest.java>  
only gets an update of a single string key value pair when in reality there
will be 100s of updates. I'm aware that creating the table MyData multiple
times will fail again this is so the code is a bit neater.

My problem is I am still unclear how to get data from a REST call. In
particular, whether I need the data in a cache or in a table, so the example
shows populating both.

A simple "get" by key works:
http://127.0.0.1:8080/ignite?cmd=get&cacheName=MyCache&key="key123"

{"successStatus":0,"affinityNodeId":"05f313de-6f41-47bb-856a-03a32a0fe467","error":null,"response":"value123","sessionToken":null}

but my guess on the cache:
http://127.0.0.1:8080/ignite?cmd=qryexe&cacheName=MyCache&pageSize=1&Type=String&arg1=key123&qry=_key%20%3D%20%3F

fails:
{"successStatus":1,"error":"class org.apache.ignite.IgniteException:
null","response":null,"sessionToken":null}

and I dont understand how to query the table

thanks
Michael






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

Re: Inconsistency reading cache from code and via REST?

Posted by michael <mi...@citi.com>.
ok that's great; wasn't too clear from the docs that I needed the
addQueryField



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

Re: Inconsistency reading cache from code and via REST?

Posted by aealexsandrov <ae...@gmail.com>.
Also I will check why it's not working in next case:

            CacheConfiguration<String, String> cfg = new
CacheConfiguration<>();

            cfg.setIndexedTypes(String.class, String.class);
            cfg.setName(CACHE_NAME);

            IgniteCache<String, String> cache = ignite.getOrCreateCache(cfg)

and 

http://127.0.0.1:8080/ignite?cmd=qryexe&cacheName=StartNode&pageSize=1&Type=String&arg1=2&qry=_key%20%3D%20%3F

Andrei



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

Re: Inconsistency reading cache from code and via REST?

Posted by aealexsandrov <ae...@gmail.com>.
Hi Michael,

You are trying to work with sql queries. Let me provide to you the example
how you can do it:

1) Start ingnite server node
2) Start ignite client node that will create the cache and put some values:

StartNode.java
<http://apache-ignite-users.70518.x6.nabble.com/file/t1704/StartNode.java>  

3)Run next command:

http://127.0.0.1:8080/ignite?cmd=qryexe&type=Value&pageSize=1&cacheName=mycache&arg1=15&qry=key%20%3D%20%3F

Here "key%20%3D%20%3F" is "key = ?"

where ? is a value from arg1.

It's not working without arg1_argN: e.g  key = 1. Looks like it depends of
parsing process. I will check.

The result should be like next:

{"successStatus":0,"error":null,"sessionToken":null,"response":{"items":[{"key":{"key":15},"value":{"value":"Value
15"}}],"last":true,"queryId":0,"fieldsMetadata":[]}}

All components of this query should be described here:

https://apacheignite.readme.io/docs/rest-api#section-sql-query-execute

Thank you,
Andrei



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

Re: Inconsistency reading cache from code and via REST?

Posted by michael <mi...@citi.com>.
Following on from his example of a simple cache with key value pairs (now
strings! IgniteCache<String, String>), how would I create a sql query on the
data:

http://127.0.0.1:8080/ignite?cmd=qryexe&cacheName=GridCacheTest&pageSize=1&Type=String&qry=_key+%3D+1

gives:
{"successStatus":1,"error":"class org.apache.ignite.IgniteException:
null","sessionToken":null,"response":null}

Does this only make sense if the value is a complex type/structure


Similarly how would I do a qryfldexe to see all values



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

Re: Inconsistency reading cache from code and via REST?

Posted by michael <mi...@citi.com>.
Hi Andrei

I simpler workaround for me for now is just to have keys a strings so REST

A few toString() tweaks to the sample code to put/get as strings instead of
integers shows this now works as expected both checking the cache in code
and from a browser.

thanks
Michael





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

Re: Inconsistency reading cache from code and via REST?

Posted by aealexsandrov <ae...@gmail.com>.
Hi Michael,

I reproduced your problem. It's a known issue. Please take a look at this
responce to find the workaround:

http://apache-ignite-users.70518.x6.nabble.com/How-to-use-rest-api-to-put-an-object-into-cache-td5897.html#a5955

Looks like this problem will be solved for basic types at next releases: 

https://issues.apache.org/jira/browse/IGNITE-3345 

Best regards,
Andrei



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

Re: Inconsistency reading cache from code and via REST?

Posted by michael <mi...@citi.com>.
Hi Andrei


1. Ignite version is 2.3.0
2. xml config -  attached.  Actually example-ignite.xml and imported
resource example-default.xml.
N.B. this is the deafult xml I got from install but with
peerClassLoadingEnabled set to true since I was also testing the broadcast
functionality.
3. GridCacheTest.java - attached. As I mentioned, pretty much as the
included example code with some additions:
- added some compute broadcast to test that functionality and also check
that the nodes can see each other
- cache.size() and cache.get(100) to check that the key/value (100,101)
added via REST from the browser gets added. When I do add an item using
REST, cache.size reports 21 but cache.get(100) gives null.

thank you

Michael

GridCacheTest.java
<http://apache-ignite-users.70518.x6.nabble.com/file/t1696/GridCacheTest.java>  
example-default.xml
<http://apache-ignite-users.70518.x6.nabble.com/file/t1696/example-default.xml>  
example-ignite.xml
<http://apache-ignite-users.70518.x6.nabble.com/file/t1696/example-ignite.xml>  



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

Re: Inconsistency reading cache from code and via REST?

Posted by aealexsandrov <ae...@gmail.com>.
Hi Michail,

Could you please provide next information:

1)Ignite version
2)your ignite xml config
3)your reproducer (GridCacheTest). Looks like it wasn't attached.

Also if you are using Ignite 2.4 then do you add your servers to baseline
topology using control.sh before cluster activation?

Thank you,
Andrei



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