【问题标题】:OrientDB issue creating vertex in transactionOrientDB 问题在事务中创建顶点
【发布时间】:2015-08-16 18:35:23
【问题描述】:

我认为使用事务在图表中创建记录时存在问题。 在事务期间创建的顶点始终存储在集群 #3 中,当我在 studio webapp 上检查时,在 tx 中创建的顶点具有类“未知”

代码如下:

client = pyorient.OrientDB("localhost", 2424)
client.connect("xxx", "xxx")
client.db_open("admin", "admin")

people_cluster = client.command("create class People extends V")
client.command("create vertex People content {'name': 'dummy', 'age': 21}")

attrs = {'@People': {'name': 'another_me', 'age': 31}}
res = client.record_create(people_cluster[0], attrs)

attrs2 = {'@People': {'name': 'me', 'age': 30}}
create_rec_cmd = ( client.get_message(pyorient.RECORD_CREATE) ).prepare((people_cluster[0], attrs2))

tx = tx.commit()
tx.begin()
tx.attach(create_rec_cmd)
tx.commit()

# This returns 'dummy' and 'another_me', but the people created in the tx is not present
res = client.command("select from People")

print(res[0]) => {'@People':{'age': 21, 'name': 'dummy', 'version':2,'rid':'#13:0'}
print(res[1]) => {'@People':{'age': 31, 'name': 'another_me'},'version':1,'rid':'#13:1'}

# The ones created in the transaction are found in the cluster #3, but with no class
print(client.command("select from #3:0")[0]) => {{'name': 'me', 'age': 30},'version':1,'rid':'#3:0'}

我已经激活了xml配置中的debug选项,日志并没有给出太多信息:

2015-08-16 17:59:46:992 INFO {db=test} /192.168.10.1:41317 - 读取字节:60 [OChannelBinaryServer]

2015-08-16 17:59:46:994 INFO {db=test} /192.168.10.1:41317 - 读取 int(4 个字节)... [OChannelBinaryServer]

2015-08-16 17:59:46:995 INFO {db=test} /192.168.10.1:41317 - 读取 int:6 [OChannelBinaryServer]

2015-08-16 17:59:47:000 INFO {db=test} /192.168.10.1:41317 - 读取 int (4 字节)... [OChannelBinaryServer]

2015-08-16 17:59:47:002 INFO {db=test} /192.168.10.1:41317 - 读取 int:2113677732 [OChannelBinaryServer]

2015-08-16 17:59:47:003 INFO {db=test} /192.168.10.1:41317 - 读取字节(1 个字节)... [OChannelBinaryServer]

2015-08-16 17:59:47:004 INFO {db=test} /192.168.10.1:41317 - 读取字节:1 [OChannelBinaryServer]

2015-08-16 17:59:47:005 INFO {db=test} /192.168.10.1:41317 - 读取字节(1 个字节)... [OChannelBinaryServer]

2015-08-16 17:59:47:006 INFO {db=test} /192.168.10.1:41317 - 读取字节:1 [OChannelBinaryServer]

2015-08-16 17:59:47:006 INFO {db=test} /192.168.10.1:41317 - 读取字节(1 个字节)... [OChannelBinaryServer]

2015-08-16 17:59:47:007 INFO {db=test} /192.168.10.1:41317 - 读取字节:3 [OChannelBinaryServer]

2015-08-16 17:59:47:007 INFO {db=test} /192.168.10.1:41317 - 读短(2 个字节)... [OChannelBinaryServer]

2015-08-16 17:59:47:007 信息 {db=test} /192.168.10.1:41317 - 简短阅读:-1 [OChannelBinaryServer]

2015-08-16 17:59:47:008 INFO {db=test} /192.168.10.1:41317 - 读取长(8 字节)... [OChannelBinaryServer]

2015-08-16 17:59:47:008 INFO {db=test} /192.168.10.1:41317 - 长读:-2 [OChannelBinaryServer]

2015-08-16 17:59:47:009 INFO {db=test} /192.168.10.1:41317 - 读取字节(1 个字节)... [OChannelBinaryServer]

2015-08-16 17:59:47:009 INFO {db=test} /192.168.10.1:41317 - 读取字节:100 [OChannelBinaryServer]

2015-08-16 17:59:47:010 INFO {db=test} /192.168.10.1:41317 - 读取字节块。读取块长度为 int(4 字节)... [OChannelBinaryServer]

2015-08-16 17:59:47:010 INFO {db=test} /192.168.10.1:41317 - 读取块长度:18 [OChannelBinaryServer]

2015-08-16 17:59:47:011 INFO {db=test} /192.168.10.1:41317 - 读取 18 个字节... [OChannelBinaryServer]

2015-08-16 17:59:47:011 INFO {db=test} /192.168.10.1:41317 - 读取 18 个字节:age:30,name:"me" [OChannelBinaryServer]

2015-08-16 17:59:47:016 INFO {db=test} /192.168.10.1:41317 - 读取字节(1 个字节)... [OChannelBinaryServer]

2015-08-16 17:59:47:017 INFO {db=test} /192.168.10.1:41317 - 读取字节:0 [OChannelBinaryServer]

2015-08-16 17:59:47:017 INFO {db=test} /192.168.10.1:41317 - 读取字节块。读取块长度为 int(4 字节)... [OChannelBinaryServer]

【问题讨论】:

    标签: python orientdb


    【解决方案1】:

    pyorient docs 有以下示例(为清楚起见,删除了几行)...

    tx = client.tx_commit()
    tx.begin()
    
    # create a new record
    rec1 = { 'accommodation': 'home', 'work': 'some work', 'holiday': 'surf' }
    rec_position1 = client.record_create( -1, rec1 )
    
    tx.attach( rec_position1 )
    

    record_create的源码如下...

    def record_create(self, *args):
    return self.get_message("RecordCreateMessage") \
        .prepare(args).send().fetch_response()
    

    您的代码只运行get_messageprepare 函数,而不是sendfetch_response。我怀疑这就是你的问题所在。

    【讨论】:

    • 感谢您的回复,但我不必调整发送和获取响应,因为这会立即将味精发送到服务器。事务处理在提交时发送附加的命令。记录已创建,只是事务中的记录存储在没有类的不同集群中。在测试文件夹中,您可以看到他们使用 msgs 执行此操作,就像我也在执行此操作一样。在基本消息类中,有一个丑陋的“如果”检查是否在事务中然后不发送。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多