5

Google Cloud Datastore是一個非關係數據庫,建立在eventual consistency的概念之上。它還提供了通過ancestor queries and entity groups獲得強一致性的方法。但是,在transaction中使用祖先查詢時,我沒有獲得強大的一致性。Google Cloud Datastore在交易中的一致性很高

考慮一下:

class Child(ndb.Model): 

    @classmethod 
    def create(cls): 
     child = cls() 
     child.put() 
     print Child.query().fetch() 

Child.create() 

因爲這沒有用的實體組,它與最終一致性操作。正如預期的那樣,我們得到:

[] 

讓我們試一下用實體組和祖先查詢:

class Parent(ndb.Model): 

    pass 


class Child(ndb.Model): 

    @classmethod 
    def create(cls, parent): 
     child = cls(parent=parent) 
     child.put() 
     print Child.query(ancestor=parent).fetch() 


parent = Parent().put() 
Child.create(parent) 

在這裏我們得到了很強的一致性,因此輸出是:

[Child(key=Key('Parent', <id>, 'Child', <id>))] 

然而,當我們將交易投入混合時:

class Parent(ndb.Model): 

    pass 


class Child(ndb.Model): 

    @classmethod 
    @ndb.transactional 
    def create(cls, parent): 
     child = cls(parent=parent) 
     child.put() 
     print Child.query(ancestor=parent).fetch() 


parent = Parent().put() 
Child.create(parent) 

輸出是:

[] 

鑑於翻譯是爲了主要與祖先查詢(跨組標記,甚至存在只是爲了得到這個費用),爲什麼丟失一個事務中強一致性工作?

回答

3

谷歌的文檔here不解決您的最後一個例子:

不像大多數數據庫,查詢並得到一個雲存儲 事務中沒有看到 事務中先前寫入的結果。具體而言,如果某個實體在 事務中被修改或刪除,則查詢或獲取會在交易開始時返回原始版本的 實體,或者如果 實體不存在,則返回該實體。

我不能解釋這比谷歌文檔更好,但這是基於谷歌如何實現事務隔離的交易的預期行爲。

+0

按照慣例,我多次閱讀Google的文檔,但似乎錯過了我正在尋找的關鍵信息。我認爲對祖先查詢的文檔提及事務隔離以避免我遇到的困惑/沮喪會有幫助。感謝您指點我正確的方向! – redhotvengeance

相關問題