Cool! Thanks for the answers!

Norbert mentions something interesting about references. 
I have found that even though on each query mongo get the up-to-date version of 
the objects, it does not install the proxies to look for the up-to-date 
versions of the references of the queried object.

I made the following experiment:
Having two images 1 and 2 and two classes A and B, each of them having one 
instance variable.
—————————
Image 1 (Create two objects, “a” referencing “b”)
[ |a b|
a := A new.
b := B new
a setInstVar: b.
b setInstVar: ‘foo'.
b save.
a save.
]

Image 2 (Mutates the second object, but the first is not changed)
[
b := (repository selectAll: A) first instVar.
b setInstVar: ‘bar’.
b save.
]

Image 1 (Query the first object and access to the referenced object)
[
b := (repository selectAll: A) first instVar.
b instVar. “-> foo”
b := (repository selectAll: B) first.
b instVar. “-> bar"
]

This little experiment showed me that I cannot trust on the state of other 
objects that I have not explicitly queried for. 

Is there any way of solving this without creating new instances of voyage 
repositories for each request?

Thanks!
Alejandro

> On Jan 25, 2017, at 7:27 AM, Esteban Lorenzano <esteba...@gmail.com> wrote:
> 
>> 
>> On 25 Jan 2017, at 01:30, Alejandro Infante <alejandroinfant...@gmail.com> 
>> wrote:
>> 
>> Hi!
>> 
>> I’m close to deploy a web service using Pharo with Voyage and MongoDB. I 
>> have been playing with it and everything works ok with a single Pharo image.
>> 
>> Couple of days ago I started questioning myself about how voyage behaves 
>> when you have multiple pharo images using the same mongo database 
>> (horizontal scaling). I want to know how the cache of voyage behaves in a 
>> scenario with object updates.
>> 
>> Example: —————————————— 
>> Imagine I have two images A and B.
>> 
>> - Image A query for object o and voyage put it in the cache.
>> - Image B query for object o and voyage put it in the cache.
>> - Image A updates object o and push it into the database calling #save.
>> - Image B query for object o that should be already in the cache.
>> 
>> In this case, does Image B see the changes performed by image A?
>> —————————————— 
> 
> yes. 
> Voyage will always verify the version on the mongodb, no matter the cache, 
> because in fact, the cache of Voyage is meant just to keep object identity 
> (there has been discussions on if this is a real cache… I think it is, but 
> with a different purpose than usual). 
> Recently Martin enhanced that part by adding 
> VMMongoRepository>>saveEnsuringCurrent: protocol who will also check your 
> version is correct when writing (to avoid overwrite before update).  
> 
> So, this should be Ok :)
> 
> Esteban
> 
>> 
>> All ideas are welcome :)
>> 
>> Thanks and cheers!
>> Alejandro

Reply via email to