岳帅杰
2009-Nov-12 05:33 UTC
[Xapian-discuss] Why the Database object cannot see changes made by other WritableDatabase object which has been flushed?
Hi, All: I was using xapian with python. But I didn't understand the following code: (The "db_path" and "docid" are both valid variable.) """ reader1 = xapian.Database(db_path) writter = xapian.WritableDatabase(db_path, xapian.DB_CREATE_OR_OPEN) writter.delete_document(docid) writter.flush() print '*' * 30, reader1.get_document(docid).get_data() reader2 = xapian.Database(db_path) print '*' * 30, reader2.get_document(tempid).get_data() """ I think this piece of code is quite simple for understanding. I don't understand why reader1 cannot see the changes make by writter. I see the document says: "From the point of view of a separate process (or a separate database object in the same process) reading the database, all modifications made to a database are invisible until the modifications is committed." But the writter had committed its change( by calling flush()) And why reader2 can see the change? -- Best wishes from Ray ...
Tom
2009-Nov-12 09:08 UTC
[Xapian-discuss] Why the Database object cannot see changes made by other WritableDatabase object which has been flushed?
2009/11/12 ??? <ysj.ray at gmail.com>:> Hi, All: > > ? ?I was using xapian with python. But I didn't understand the following > code: > ... > ? ?I think this piece of code is quite simple for understanding. > > ? ?I don't understand why reader1 cannot see the changes make by writter. > ? ?I see the document says: > ? ?"From the point of view of a separate process (or a separate database > object in the same process) reading the database, all modifications made to > a database are invisible until the modifications is committed." > ? ?But the writter had committed its change( by calling flush()) > > ? ?And why reader2 can see the change?Hi Ray, Database readers continue to see the version of the database that existed when they opened it, even if the database is changed. That's why reader2 sees changes that are invisible to reader1. (It's implemented by multiple, versioned paths through the B-trees). To make a reader see the latest flushed version of the database, you can call Database::reopen(). cheers, Tom