Skip to content

ReQL proposal: allow changefeeds on specific documents #2542

Closed

Description

@coffeemug
r.table('foo').get(id).changes()

# { 'old_val': x, 'new_val': y }
# { 'old_val': x, 'new_val': y }
# ...

Activity

  1. added this to the 1.14 milestone on Jun 12, 2014
  2. modified the milestones: subsequent, 1.14 on Jun 12, 2014
  3. mlucy commented on Jun 12, 2014

    @mlucy
    Member

    +1

    I think this is really important, and arguably more useful than the existing changefeeds.

  4. mlucy commented on Jun 12, 2014

    @mlucy
    Member

    Also, I think it would be useful to have an optarg that makes r.table('foo').get(id).changes() return as its first change object the actual value of r.table('foo').get(id). I think the most common use case for this is "get me this row and tell me when it changes", which is hard to do by composing a get and a changes call because you might miss a change in-between.

  5. mlucy commented on Jun 12, 2014

    @mlucy
    Member

    But we can talk more about this when it's scheduled.

  6. srh commented on Jun 13, 2014

    @srh
    Contributor

    Is this any different from applying a .filter(r.row('id').eq(id))? Aside from getting the row.

    which is hard to do by composing a get and a changes call because you might miss a change in-between.

    You do the changes call first and then do a get.

  7. coffeemug commented on Jun 13, 2014

    @coffeemug
    ContributorAuthor

    Is this any different from applying a .filter(r.row('id').eq(id))?

    Scalability. If you filter, the changefeed has to look at every row, so you can't create millions of them. With a changefeed on get, you might be able to (at least theoretically).

    You do the changes call first and then do a get.

    You might lose documents in between. The flag would guarantee atomicity.

  8. mlucy commented on Jun 13, 2014

    @mlucy
    Member

    Is this any different from applying a .filter(r.row('id').eq(id))?

    Like Slava said, scalability. We could theoretically do this by just having a better query optimizer, but that's a whole thing.

    You do the changes call first and then do a get.

    Yes, but that's a pain, and still doesn't quite do what you want. What you really want is to know the most recent version of the document at any point in time. OK, so you've called changes and gotten back a stream, and done a get. Is the value of the get the most recent version of the document? Well, you'd have to look at what's in the stream, but that can block. So you have to set the value to the object you got back from get, then consume the stream and only start replacing the value with the objects in the stream when you see old_val:VALUE_RETURNED_FROM_GET. People can definitely do that, but it sucks.

    You can't set the value to get and then replace from the stream without checking old_val unless you're OK with the value maybe changing from a newer value to and older value and back (which might be confusing depending on the use case).

  9. neumino commented on Jun 13, 2014

    @neumino
    Member

    Can I miss some changes between the get() and the changes()?

    r.expr([r.table("foo").get(1)]).union(r.table("foo").filter({id: 1}).changes())
    
  10. mlucy commented on Jun 13, 2014

    @mlucy
    Member

    @neumino -- yes. But @srh was talking about opening a changefeed and then doing the get, which prevents you from missing changes at the cost of needing extra logic in your app to maintain ordering.

  11. srh commented on Jun 16, 2014

    @srh
    Contributor

    Scalability.

    What are you talking about? You don't get any scalability benefits by doing changefeeds on a specific document.

    If we implemented things such that you would, we could also implement things such that you also get the scalability benefits when applying a filter.

  12. srh commented on Jun 16, 2014

    @srh
    Contributor

    In particular, the most important performance improvement to look for right now is that of: not having to send every write to every single changefeed-listening parser in the cluster. Making btree nodes also not have to iterate through a list of changefeed listeners (by registering point-listeners with a map by key, on the store end?) is a relatively miniscule benefit.

  13. 9 remaining items

  14. srh commented on Jun 18, 2014

    @srh
    Contributor

    I don't see why you would expect it to be anything other than a changefeed that covers the exact set of documents provided by the initial filter at the changefeed's creation.

  15. coffeemug commented on Jun 18, 2014

    @coffeemug
    ContributorAuthor

    Ah, you're right. I don't think I should comment more on this until I get eight hours worth of sleep.

  16. srh commented on Jun 18, 2014

    @srh
    Contributor

    (Note that it covering the exact set of documents wouldn't be a great idea because (I think) it would require an up-front traversal of the entire table. Actually, maybe not, if we send exact per-row timestamps to the parser and use that detect which documents were part of the set, the first time they come through?) I still don't like that behavior either, because it doesn't seem like what people would want -- the set of documents as defined by a filter sounds like the sort of thing you'd want to include any new documents inserted into the database too, in most applications.

    I think maybe seq.filter(x).changes() might also want to be equivalent to seq.changes().filter(lambda row: x(row['new_val']).or(x(row['old_val']))) ???

    Or maybe, when x runs on new_val and old_val, and fails on one of them, that entry is null. If it fails on both of them, the document's not part of the changefeed at all. That way, the changefeed can see what enters and removes the given selection. I think this might be what you really want and it seems to generally make sense.

    But with that, things would get dicey with a .filter(...).map(...).changes(). We've got a general sort of query transformation in play.

    (On that note, it might not be so bad internally -- I think datum_stream_t should have its role replaced in much of query evaluation with selection_t or something that merely describes a table and the operations that have been attached to in in order to form a selection, without that dreadful state related to streaming actual data.)

  17. srh commented on Jun 18, 2014

    @srh
    Contributor

    Or maybe, when x runs on new_val and old_val, and fails on one of them, that entry is null.

    Also, combining that with return_all=True, you get the exact set and sequence of data you'd need to construct and maintain a per-parser view of some query on the table. Some kind of future .create_view(...) operation would be able to match the semantics of changes() quite nicely.

  18. mlucy commented on Jun 18, 2014

    @mlucy
    Member

    Or maybe, when x runs on new_val and old_val, and fails on one of them, that entry is null. If it fails on both of them, the document's not part of the changefeed at all. That way, the changefeed can see what enters and removes the given selection. I think this might be what you really want and it seems to generally make sense.

    That's what I would expect.

    On that note, it might not be so bad internally -- I think datum_stream_t should have its role replaced in much of query evaluation with selection_t or something that merely describes a table and the operations that have been attached to in in order to form a selection, without that dreadful state related to streaming actual data.

    This is basically how we do it now. A lazy_datum_stream_t (which is the only kind we'd need to support this on I think) has a reader_t which contains an std::vector<transform_variant_t>.

  19. srh commented on Jun 18, 2014

    @srh
    Contributor

    This is basically how we do it now.

    In other words, it's not how we do it now. datum_stream_t is a stateful object that streams.

  20. modified the milestones: 1.14, subsequent on Jun 19, 2014
  21. coffeemug commented on Jun 19, 2014

    @coffeemug
    ContributorAuthor

    Moving to 1.14 since it's relevant to #1118.

  22. coffeemug commented on Jun 24, 2014

    @coffeemug
    ContributorAuthor

    Talked to @mlucy in person. He's going to write up a proposal.

  23. mlucy commented on Jun 25, 2014

    @mlucy
    Member

    I'd like to fold this into #1118 if there are no objections.

  24. coffeemug commented on Jun 25, 2014

    @coffeemug
    ContributorAuthor

    Sounds good.

  25. modified the milestones: duplicate, 1.14 on Jun 25, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions