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

Ask Your Question
0

Space iterator and FIFO order

I've been trying to get the the Space Iterator (GSIterator) feature working with FIFO ordering.

So far, I have not been successful.

My space class looks like this:

@SpaceClass(fifoSupport=FifoSupport.ALL)
public class MySpaceClass { . . . }

Here's my code to iterate over the instances:

     IteratorBuilder iteratorBuilder = new IteratorBuilder(gigaSpace).
            addTemplate(query).
            iteratorScope(IteratorScope.CURRENT);

      GSIterator gsIterator = iteratorBuilder.iterate();

      while(gsIterator.hasNext()) {
          MySpaceClass o =  (MySpaceClass)gsIterator.next();          
          System.out.println(o.toString());
       }

What I'm noticing is that the ordering on subsequent runs of the code above alternates between FIFO order and reverse order (LIFO).

It will flip-flop between FIFO and LIFO ordering !!!

I'm totally at a loss here.

I even tried this but it didn't work:

  EventSessionConfig sessionConfig = new EventSessionConfig();
  sessionConfig.setFifo(true);

  IteratorBuilder iteratorBuilder = new IteratorBuilder(gigaSpace).
            eventSessionConfig(sessionConfig).
            addTemplate(query).
            iteratorScope(IteratorScope.CURRENT);

Can somebody please assist.

asked 2013-08-21 15:13:28 -0600

Steve McCarthy gravatar image

updated 2013-08-21 23:21:44 -0600

edit retag flag offensive close merge delete

Comments

I found this using the google:

http://forum.openspaces.org/thread.js...

Apparently I'm doing everything that was suggested and still no luck.

Steve McCarthy gravatar imageSteve McCarthy ( 2013-08-21 16:27:42 -0600 )edit

4 Answers

Sort by ยป oldest newest most voted
0

We are checking this.________________________________________From: forum@ask.gigaspaces.org

answered 2013-08-22 02:41:33 -0600

shay hassidim gravatar image
edit flag offensive delete link more

Comments

Thank you.

Here's what my space class looks like in case it helps:

@SpaceClass(fifoSupport=FifoSupport.ALL)
public class MySpaceClass {
   int id;

   @SpaceId
   @SpaceRouting
   public int getId() {
      return id;
   }              

   . . .   // More fields not shown
}

When writing the class to the space, I set the ID myself. The ID value is increment on successive writes to the space.

I'm testing this in Eclipse currently but also see the same behavior when deployed normally.

Also interesting, if I get the iterator twice (instead of once) before using it, the behavior is consistent on subsequent runs (FIFO or LIFO) instead of alternating back and forth.

It sounds like bug with Gigaspaces to me.

Steve McCarthy gravatar imageSteve McCarthy ( 2013-08-22 12:25:58 -0600 )edit

This is my query in case it makes a difference:

query = new SQLQuery<MySpaceClass>(MySpaceClass.class, "id > 0")
Steve McCarthy gravatar imageSteve McCarthy ( 2013-08-22 17:01:06 -0600 )edit

Can anyone confirm that this is an XAP bug or not?

Steve McCarthy gravatar imageSteve McCarthy ( 2013-08-23 12:02:28 -0600 )edit
0

This issue has been very frustrating.

What I'm trying to do is summarized below:

Read current and future data in the order they are written without missing any data

That's what I'm trying to do !!

Sounds simple enough but it hasn't been due to issues with XAP.

Enough said. On to my work around.

In my space class, I'll increment the ID every time I write to the space. That way I know the correct order.

The first step is get the current data:

MySpaceClass[] dataArray = gigaSpace.readMultiple(query, Integer.MAX_VALUE, ReadModifiers.FIFO);

Next, we save the last ID that we have:

final int lastId = dataArray[dataArray.length -1].getId();

The next step is to use a polling notifier with FIFO enabled:

 SimpleNotifyEventListenerContainer notifyEventListenerContainer =
        new SimpleNotifyContainerConfigurer(gigaSpace).
           template(query).
           fifo(true).
           eventListenerAnnotation(new Object() {
        boolean boundaryChecked = false;
        SQLQuery<MySpaceClass> rangeQuery = new SQLQuery<MySpaceClass>(MySpaceClass.class, "id > ? AND id < ?");

        @SpaceDataEvent
        public void eventListener(MySpaceClass data) {
           if (!boundaryChecked) {
              if (data.getId() > lastId + 1) {
                 rangeQuery.setParameter(1, lastId);
                 rangeQuery.setParameter(2, data.getId());

                 MySpaceClass[] dataArray = gigaSpace.readMultiple(rangeQuery, Integer.MAX_VALUE, ReadModifiers.FIFO);

                 for (MySpaceClass data: dataArray) {
                     System.out.println(data);
                 }                   
              }

              boundaryChecked = true;
           }

           System.out.println(data);
        }
     }).notifyContainer();

The boundaryChecked condition is to catch anything that's been written in between the first readMutiple and when the notifier begins getting events. Yes, you can get new data written in that time period !!!!! If you don't check for it, you will miss them !!! For me it's important to get everything.

You'll see I'll make another readMultiply with a query that has a range from the last ID received (from the first readMultiply) to the ID of the first notification event (exclusive range).

That ensures we get any missing data.

I tested this solution and it seems to work though it's highly inelegant and much more complex than it should be.

Note this ugly solution is a work around for XAP issues I found.

And I'm still not 100% sure this solution is bulletproof. I suspect there may be some obscure edge cases where the work around may not work entirely properly.

So to conclude, I hope the issue gets fixed in XAP in a future release.

answered 2013-08-23 19:29:17 -0600

Steve McCarthy gravatar image

updated 2013-08-23 19:38:04 -0600

edit flag offensive delete link more

Comments

The issue been reported and will be resolved.Your solution might work with a single partition. If you have multiple partitions you will have to sort the result using order by.Shay________________________________________From: forum@ask.gigaspaces.org

shay hassidim gravatar imageshay hassidim ( 2013-08-24 03:37:44 -0600 )edit

Ok. Thank you. I look forwards to a fix for this issue in a future release. Thank you very much.

Steve McCarthy gravatar imageSteve McCarthy ( 2013-08-24 19:55:16 -0600 )edit
0

I still have no resolution for this issue.

Without a resolution, I will not be able to use Gigaspaces for my needs.

answered 2013-08-23 12:54:58 -0600

Steve McCarthy gravatar image
edit flag offensive delete link more
0

Steve ,

Would this works :

query = new SQLQuery<MySpaceClass>(MySpaceClass.class, "id > 0 order by id")

If it doesn't try this: - register for notifications. Use fifo mode. This will send you notifications for future write. - use readMultiple to read existing data. Since FIFO supported at the partition level , you will have to sort the result. have a SQLQuery and Order by id.

If the above does not work for you contact me : shay at gigaspaces.com

Shay

answered 2013-08-23 13:08:42 -0600

shay hassidim gravatar image

updated 2013-08-23 13:09:46 -0600

edit flag offensive delete link more

Comments

I'm afraid none of the solutions you mentioned works for me.

You can not use "ORDER BY" with the GSIterator. It is simply not permitted by XAP.

One of my requirements is that none of the data is skipped when reading.

How can I guarantee that I didn't miss anything when doing a readMultiply followed by notifications. I can't think of a way to do that in practical terms.

Getting back to the original issue with the GSIterator FIFO/LIFO issue, is that an XAP bug or not?

BTW, I work for a company that is a client of Gigaspaces.

Expect an email from me soon.

Thank you.

Steve McCarthy gravatar imageSteve McCarthy ( 2013-08-23 13:29:00 -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: 2013-08-21 15:13:28 -0600

Seen: 305 times

Last updated: Aug 23 '13