获取一个集合,然后对其进行无间隙或重叠的更改
Get a collection and then changes to it without gaps or overlap
如何可靠地获取 table 的内容,然后对其进行更改,而不出现间隙或重叠?随着时间的推移,我试图对 table 形成一致的看法。
我可以先查询数据库,然后订阅更改提要,但这些查询之间可能存在修改发生的间隙。
或者我可以先订阅更改,然后查询 table,但随后可能会在查询中已处理的更改提要中发生修改。
这种情况的例子:
A subscribe 'messages'
B add 'messages' 'message'
A <- changed 'messages' 'message'
A run get 'messages'
A <- messages
此处 A 在发送其消息查询之前收到一条 'changed' 消息,并且消息查询的结果包括已更改的消息。可能 A 可以在收到查询结果之前简单地忽略任何更改的消息。是否保证查询后收到的更改(在同一连接上)尚未应用到先前的查询中,即在同一线程上处理?
推荐的方法是什么?我找不到有关此用例的任何文档。
我知道你说你想出了一个答案,但我已经做了很多次,这就是我一直在做的事情:
r.db('test').table('my_table').between(tsOne, tsTwo, {index: 'timestamp'});
所以在我的工作中,我 运行 一个索引 between
查询捕获最后 运行 时间和那个确切时刻之间的数据。您可以 运行 锁定配置 table,它会跟踪您的作业 last_run_time,这样您甚至可以使用多个处理器进行扩展!并且因为我们正在使用 between
等待锁完成的下一个作业将仅在第一个处理器 之后 获取数据 运行。希望对您有所帮助!
RethinkDB 的 Michael Lucy 写道:
For .get.changes
and .order_by.limit.changes
you should be fine because we already send the initial value of the query for those. For other queries, the only way to do that right now is to subscribe to changes on the query, execute the query, and then read from the changefeed and discard any changes from before the read (how to do this depends on what read you're executing and what legal changes to it are, but the easiest way to hack it would probably be to add a timestamp
field to your objects that you increment whenever you do an update).
In 2.1 we're planning to add an optional argument return_initial
that will do what I just described automatically and without any need to change your document schema.
如何可靠地获取 table 的内容,然后对其进行更改,而不出现间隙或重叠?随着时间的推移,我试图对 table 形成一致的看法。
我可以先查询数据库,然后订阅更改提要,但这些查询之间可能存在修改发生的间隙。
或者我可以先订阅更改,然后查询 table,但随后可能会在查询中已处理的更改提要中发生修改。
这种情况的例子:
A subscribe 'messages'
B add 'messages' 'message'
A <- changed 'messages' 'message'
A run get 'messages'
A <- messages
此处 A 在发送其消息查询之前收到一条 'changed' 消息,并且消息查询的结果包括已更改的消息。可能 A 可以在收到查询结果之前简单地忽略任何更改的消息。是否保证查询后收到的更改(在同一连接上)尚未应用到先前的查询中,即在同一线程上处理?
推荐的方法是什么?我找不到有关此用例的任何文档。
我知道你说你想出了一个答案,但我已经做了很多次,这就是我一直在做的事情:
r.db('test').table('my_table').between(tsOne, tsTwo, {index: 'timestamp'});
所以在我的工作中,我 运行 一个索引 between
查询捕获最后 运行 时间和那个确切时刻之间的数据。您可以 运行 锁定配置 table,它会跟踪您的作业 last_run_time,这样您甚至可以使用多个处理器进行扩展!并且因为我们正在使用 between
等待锁完成的下一个作业将仅在第一个处理器 之后 获取数据 运行。希望对您有所帮助!
RethinkDB 的 Michael Lucy 写道:
For
.get.changes
and.order_by.limit.changes
you should be fine because we already send the initial value of the query for those. For other queries, the only way to do that right now is to subscribe to changes on the query, execute the query, and then read from the changefeed and discard any changes from before the read (how to do this depends on what read you're executing and what legal changes to it are, but the easiest way to hack it would probably be to add atimestamp
field to your objects that you increment whenever you do an update).In 2.1 we're planning to add an optional argument
return_initial
that will do what I just described automatically and without any need to change your document schema.