RushOrm icon indicating copy to clipboard operation
RushOrm copied to clipboard

concurrency in rush orm

Open zean opened this issue 10 years ago • 5 comments

Hi there, When i try to read/write stuff at the same time, the orm doesnt have a stack of orders so some of the saves get lost, is there a way to do it?

zean avatar Aug 20 '15 11:08 zean

Oops comments as my build server a minuet ago...

Hi,

The intention is to be thread safe. Do you have an example of what your doing that does not work?

If you attempt a second operation while another one is not yet completed that thread should just wait until its notified when the last operation completes. Do you think your waiting thread is garbage collected or something along that nature?

Thanks

Stuart-campbell avatar Aug 21 '15 14:08 Stuart-campbell

im using a xmpp implementation, when i send a message to other device that device sends a receipt back, so in the object theres 2 boolean, one "send" and other "receive", this ones are changed each time this messages go and come around, so if i send a lot of them in a fast pace, some of the receipts are ignored, i can see the messages arriving, but the status doesnt change.

the actual methods im using are:

public static void revokeSendMessage(String messageId) {
    Chat_Msg chat = new RushSearch().whereEqual("message_id", messageId).findSingle(Chat_Msg.class);
    chat.setSend(false);
}

public static void setSendMessage(String messageId) {
    Chat_Msg chat = new RushSearch().whereEqual("message_id", messageId).findSingle(Chat_Msg.class);
    chat.setSend(true);
}

public static void revokeReceivedMessage(String messageId) {
    Chat_Msg chat = new RushSearch().whereEqual("message_id", messageId).findSingle(Chat_Msg.class);
    chat.setReceived(false);
    chat.save();
}

public static void setReceivedMessage(String messageId) {
    Chat_Msg chat = new RushSearch().whereEqual("message_id", messageId).findSingle(Chat_Msg.class);
    chat.setReceived(true);
    chat.save();
}
public static void setReceivedMedia(String chat_id, String media_id) {
    Chat_Object chat = new RushSearch().whereEqual("chat_id", chat_id).findSingle(Chat_Object.class);
    chat.getMessageByMediaId(media_id).setReceived(true);
    chat.save();
}

hope it was clear Cheers

zean avatar Aug 21 '15 14:08 zean

I'm guessing this is just a typo but you don't call save in either of the first two methods?

To better understand whats going on can you log before you load what is loaded then log again after the save call.

When save is called the first thing that happens is it should block till there is an available queue so that only one database read or write can happen at once. So if you can get a log before and after the save call it should have been written to the db.

This is the file in charge of concurrency.

https://github.com/Stuart-campbell/RushOrm/blob/master/RushORM/rushandroid/src/main/java/co/uk/rushorm/android/AndroidRushQueProvider.java

Thanks

Stuart-campbell avatar Aug 21 '15 15:08 Stuart-campbell

ah yeah, public void setSend(boolean send) { this.send = send; this.save(); } thats in Chat_Msg

im doing the changes in a service, can that be an issue?

zean avatar Aug 21 '15 15:08 zean

Hi again,

still didnt manage to fix this, is there a way to get e response when i use save(), so i can try again to save it?

Txs :D

zean avatar Aug 25 '15 14:08 zean