Re: How cache invalidations work (and hack to listen in) (was Re: Applause for ZODB! And a question: How do you get pending change info from a transaction object?)
David Pesta <[email protected]> Sat, 5 May 2018 19:16:27 -0700 (PDT)
| Newsgroups | gmane.comp.web.zope.zodb |
|---|---|
| Message-ID | <[email protected]> |
Thanks for that response!
I may have found a way to reproduce the problem I am having with my odd
test results, but not quite sure how to fix the issue yet. I must be
missing something important somewhere. (Unless maybe something about this
doesn't quite work yet?)
============ Toys/Toy.py ==========
import persistent
class Toy(persistent.Persistent):
def __init__(self, size: int, color: str, fun: int):
self.size = size
self.color = color
self.fun = fun
===================================
========== zeo.config ============
<zeo>
address localhost:8090
</zeo>
<filestorage>
path /path/to/data.fs
</filestorage>
<eventlog>
<logfile>
path /path/to/zeo.log
format %(asctime)s %(message)s
</logfile>
</eventlog>
==================================
Terminal 1:
$ runzeo --version
4.2.0
$ runzeo -C zeo.config
Terminal 2:
$ python
>>> import ZEO
>>> import transaction
>>> from Toys.Toy import Toy
>>> connection = ZEO.connection(8090)
>>> root = connection.root
>>> root.toy2.color
'test17'
Terminal 3:
$ python
>>> import ZEO
>>> import transaction
>>> from Toys.Toy import Toy
>>> connection = ZEO.connection(8090)
>>> root = connection.root
>>> root.toy2.color
'test17'
Terminal 2:
>>> root.toy2.color = "green"
>>> transaction.commit()
>>> root.toy2.color
'green'
Terminal 3:
>>> root.toy2.color
'test17'
Terminal 2:
>>> root.toy2._p_oid
b'\x00\x00\x00\x00\x00\x00\x00\x05'
>>> toy = connection.get(b'\x00\x00\x00\x00\x00\x00\x00\x05')
>>> toy.color
'green'
Terminal 3:
>>> toy = connection.get(b'\x00\x00\x00\x00\x00\x00\x00\x05')
>>> toy.color
'test17'
???
Why doesn't the toy color in Terminal 3 change to green?
???
Terminal 2:
>>> exit()
Terminal 3:
>>> exit()
============ script.py ============
import time
import ZODB
import ZEO
import transaction
from Toys.Toy import Toy
connection = ZEO.connection(8090)
root = connection.root
def objects_updated(oids):
for oid in oids:
print(oid)
print("Sleeping for 5 seconds.")
time.sleep(5)
print("Getting oid from connection.")
print(connection)
toy = connection.get(oid)
print("toy:")
print(toy)
print("toy.color:")
print(toy.color)
print("toy.__dict__:")
print(toy.__dict__)
invalidate_orig = ZODB.mvccadapter.MVCCAdapter.invalidate
def invalidate(self, transaction_id, oids):
print("INVALIDATING")
objects_updated(oids)
invalidate_orig(self, transaction_id, oids)
ZODB.mvccadapter.MVCCAdapter.invalidate = invalidate
==================================
Terminal 2:
$ python
>>> import script
>>> import time
>>> import ZODB
>>> import ZEO
>>> import transaction
>>> from Toys.Toy import Toy
>>> connection = ZEO.connection(8090)
>>> root = connection.root
Terminal 3:
$ python
>>> import script
>>> import time
>>> import ZODB
>>> import ZEO
>>> import transaction
>>> from Toys.Toy import Toy
>>> connection = ZEO.connection(8090)
>>> root = connection.root
Terminal 2:
>>> root = connection.root
>>> root.toy2.color
'green'
>>> root.toy2.color = "blue"
>>> transaction.commit()
INVALIDATING
b'\x00\x00\x00\x00\x00\x00\x00\x05'
Sleeping for 5 seconds.
>>> Getting oid from connection.
<Connection at 7f523ee3dfd0>
Terminal 3:
>>> INVALIDATING
b'\x00\x00\x00\x00\x00\x00\x00\x05'
Sleeping for 5 seconds.
INVALIDATING
b'\x00\x00\x00\x00\x00\x00\x00\x05'
Sleeping for 5 seconds.
Getting oid from connection.
Getting oid from connection.
<Connection at 7f9336656128>
<Connection at 7f9336656128>
As you can see, the custom invalidate function does trigger automatically
when transaction.commit() happens in the other terminal. But why does
invalidate get called twice in Terminal 3? Also, on both terminals, it
hangs right after "print(connection)" and never finishes executing "toy =
connection.get(oid)".
It's like the connection cannot get the oid and it stalls.
It feels like this is getting closer though.
--
You received this message because you are subscribed to the Google Groups "zodb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.