Welcome to the new Gigaspaces XAP forum. To recover your account, please follow these instructions.

Ask Your Question
0

SpaceIndexing at runtime

Hello,

I have a question on how to dynamically add SpaceIndexes using the API instead on Nested Properties for a Map. Take the following example where the key that I want the index on in the map is “ExternalId”

package com.myclass

public class MyBaseClass {

  private Map<String, String> nestedMap;

  // getter/setters

}

public class MyNextParentClass extends MyBaseClass {

}

public class MyChildClass extends MyNextParentClass { }

Now when I use the following SpaceIndex annotation

@SpaceIndex (path=nestedMap.ExternalId)

Any searches I do on MyChildClass on key “ExternalId” use the index. I can see the from the new logging that was added to 10.x release, all is good.

However, using the annotation really isn't an option for me because the key that I am searching on could be different depending on the context. Instead, I want to use the GigaSpaceTypeManager api to allow me to customize the indexes at runtime. However when I use the following code, searching never hits the index

gigaspace.getTypeManager().asyncAddIndex("com.myclass.MyChildClass", SpaceIndexFactory.createPropertyIndex("ExternalId", SpaceIndexType.BASIC));

I can see in the GS GUI that the index shows up, but looking at the logging I can clearly see the index doesn't work (I can tell by the search times too). I also tried using “com.myclass.MyBaseClass” instead but that also didn't work.

Can someone point me to better documentation or an example of how to make this work using the API? The documentation is very limited on this

http://docs.gigaspaces.com/xap102/ind...

Thanks

Rich

asked 2016-03-10 08:44:02 -0600

rich gravatar image
edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted
0

Hi John,

Yea I waited about 1 min, I had about 125K objects in the map of which about 20% of those were the key I was looking for (the rest were other keys).

So you are saying my test case worked for you? I even tried it from GS Gui and got the same result. My test case was simplified some. I have many other classes that inherit from the same hierarchy but none of those objects were in the space.

So you are saying the API calls I am making are correct? The test case I gave you was just a simplified version of my real case so I never tried it. I used it more for explanation, never actually tried it. I wanted to make sure I was suppose to use the child class on the API call even though the map is on a parent.

Rich

answered 2016-03-10 14:43:27 -0600

rich gravatar image
edit flag offensive delete link more
0

Rich

It doesn't take long, but the index can take a second or more to be built. Are you waiting for the process to complete? We can't reproduce this with a simple test using a three-class hierarchy such as you described. Here are the results (2,000,000 objects - 200,000 of type = 5):

read multiple took 1883 milliseconds unindexed read multiple for type = 5 took 322 milliseconds waiting for index completion . indexed read multiple for type = 5 took 31 milliseconds

Regards

John

answered 2016-03-10 14:27:42 -0600

jb gravatar image
edit flag offensive delete link more

Comments

Hi John,

Yea I waited about 1 min, I had about 125K objects in the map of which about 20% of those were the key I was looking for (the rest were other keys).

So you are saying my test case worked for you? I even tried it from GS Gui and got the same result. My test case was simplified some. I have many other classes that inherit from the same hierarchy but none of those objects were in the space.

So you are saying the API calls I am making are correct? The test case I gave you was just a simplified version of my real case so I never tried it. I used it more for explanation, never actually tried it. I wanted to make sure I was suppose to use the child class on the API call even though the map is on a parent.

Rich

rich gravatar imagerich ( 2016-03-10 15:31:57 -0600 )edit

One other question. Did you create the indexes before the data was inserted or can it be done either way. What i noticed about the annotations, it added that index to every level of the hierarchy. How is that done with the API? Do you have to invoke the API at every level of the hierarchy? If so, does order matter (i.e. leaf to parent or parent to leaf)?

rich gravatar imagerich ( 2016-03-10 15:34:13 -0600 )edit
0

Rich

Here is the actual code used for an _exact_ reproduction. The map<string, string=""> class 'nestedMap' is a member variable of the base class 'IndexBase', with an intermediate class 'IndexClass'. Output is at the bottom.

    start = System.currentTimeMillis();
    SQLQuery query = new SQLQuery<IndexChild>(IndexChild.class, "nestedMap.Zero = 'number'");
    space.readMultiple(query);
    stop =  System.currentTimeMillis();
    System.out.println("unindexed read multiple took " + (stop-start) + " milliseconds");

    GigaSpaceTypeManager manager = space.getTypeManager(); 
    SpaceIndex index = SpaceIndexFactory.createPropertyIndex("nestedMap.Zero", SpaceIndexType.BASIC);
    AsyncFuture<AddTypeIndexesResult> result = manager.asyncAddIndex(IndexChild.class.getName(), index);

    System.out.print("waiting for index completion ");
    while (! result.isDone()) {
        System.out.print(".");
        try {
            Thread.sleep(1000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    System.out.println();

    start = System.currentTimeMillis();
    space.readMultiple(query);
    stop =  System.currentTimeMillis();
    System.out.println("indexed read multiple took " + (stop-start) + " milliseconds");

read multiple took 423 milliseconds
unindexed read multiple took 601 milliseconds
waiting for index completion .
indexed read multiple took 160 milliseconds

answered 2016-03-10 16:06:32 -0600

jb gravatar image
edit flag offensive delete link more

Comments

One thing I forgot to mention, the SQLQuery is actually being done on MyBaseClass not the leaf. Would that make a difference?

rich gravatar imagerich ( 2016-03-10 16:32:20 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-03-10 08:44:02 -0600

Seen: 148 times

Last updated: Mar 10 '16