Skip to content

rethinkdb-export can time-out on count() #1984

Closed

Description

@danielmewes

drivers/python/rethinkdb/_export.py contains the following line:
table_size = r.db(db).table(table).count().run(conn)

Apparently the result is used for computing the relative progress.

There are two problems with this:

  1. count() on a large out-of-memory table can be slow.
  2. In extreme cases it can become so slow that it times out, and users cannot backup their tables anymore.

@wojons encountered this, but with an older version of RethinkDB that did the count() inefficiently. However in general it seems plausible that this could occur with a current version as well, if the table is just large enough.

Ideally, we would expose the approximate table count through ReQL and use that to get an approximate progress bar. Probably it should become part of r.table().info().

Another work-around could be to catch timeout errors during the count, print a message and ignore them, or add a command line option to disable count and progress bar, and on a timeout print a message mentioning that option.

Activity

  1. added this to the subsequent milestone on Feb 21, 2014
  2. danielmewes commented on Feb 21, 2014

    @danielmewes
    MemberAuthor

    Let's make this a ReQL proposal:

    Add an entry approximate_count to the result of r.table().info(). It would display the approximation which is used in the web ui.

  3. neumino commented on Feb 21, 2014

    @neumino
    Member

    #1118 would allow a constant count too. That may be a solution.

  4. wojons commented on Feb 21, 2014

    @wojons
    Contributor

    how about something like r.table().count({'appox': true}) and then in r.table().info({'count': appox}) would return appoxmant. and {'count': false} would return no count. i think the more felxable the better to avoid werid issues.

  5. danielmewes commented on Feb 21, 2014

    @danielmewes
    MemberAuthor

    r.table().count({approx: true}) is nice too. A problem with it is that it would only work on plain tables. For example if you have an array or a selection (something like r.table(t).between(a, b).count({approx: true})), count({approx: true}) would fail.
    Given that it is really an exclusive property of tables, I think I would prefer having it in info().

    @neumino: #1118 would do it, but it seems like it's pretty far away.

  6. wojons commented on Feb 21, 2014

    @wojons
    Contributor

    @danielmewes the cool think about appox is that it does not need to be anywhere near correct lets pretend you run it though sample. so you look at some random ones and then u get there data size and then you use the average size of that to "Guess" the size of the result set. its appoxmenat even if its really off its there choice to use an appoxmat count

  7. coffeemug commented on Feb 21, 2014

    @coffeemug
    Contributor

    I really think we should just do a constant time count. It's not that much harder than approximate count, and will fix a whole bunch of issues (we use count in the UI, etc.) I'll try to schedule it sooner rather than later.

  8. wojons commented on Feb 21, 2014

    @wojons
    Contributor

    @coffeemug when you say "constant time count" you mean O(n)?

  9. coffeemug commented on Feb 21, 2014

    @coffeemug
    Contributor

    No, I mean O(1).

  10. danielmewes commented on Feb 21, 2014

    @danielmewes
    MemberAuthor

    If we can make sure that it works, I'm on board with making count() always use the stats block when it's applied to a table. I.e. implementing O(1) r.table().count().

  11. wojons commented on Feb 21, 2014

    @wojons
    Contributor

    @coffeemug duh O(n) would be linear time. if it can be O(1) than i would be on board for that. i thought the way myisam does it is that it just keep track of how many records there are and some other intresting stuff. I thnk innodb still uses an appox for many things

  12. srh commented on Mar 5, 2014

    @srh
    Contributor

    I'm on board with making count() always use the stats block

    Don't assume that O(1) count would use the stats block.

  13. danielmewes commented on Mar 5, 2014

    @danielmewes
    MemberAuthor

    Don't assume that O(1) count would use the stats block.

    In fact I'll assume that right now (but will try not to assume that in general, fair enough).

    Assuming that we implement O(1) count using the stats block or a similar structure, the general problem is that we must not count documents twice if we have replicas in a cluster by the way. We would probably have to keep counts on a per-shard level, and that would require recomputing/adjusting the per-shard counts when resharding. It needs some thought.

  14. srh commented on Mar 5, 2014

    @srh
    Contributor

    the general problem is that we must not count documents twice if we have replicas in a cluster by the way

    How would having replicas in a cluster be a problem? That wouldn't cause any problems with count in a stats block.

  15. danielmewes commented on Mar 5, 2014

    @danielmewes
    MemberAuthor

    @srh: If we never had replicas, counting the number of documents in a table through the stats block would be very easy: Go to all nodes (yes nodes, not shards), let them get the current number of documents in the btree from the stats block, and sum all of those numbers up. That's the number of documents in the table.
    Because we can have replication, documents can be on multiple nodes at the same time. So they would be counted multiple times.
    Even worse if one of the replicas is currently backfilling. Then we don't even know how many documents of a shard are on the node being backfilled to (and we can't just ignore that node, because it might have the only consistent copy of some other shard at that time).

    To account for this, we would need one count per shard in the stat block. But then we have to maintain that when changing the shard boundaries.

  16. srh commented on Mar 5, 2014

    @srh
    Contributor

    We would probably have to keep counts on a per-shard level, and that would require recomputing/adjusting the per-shard counts when resharding. It needs some thought.

    This is why you shouldn't assume we'd have counts in the stats block. It's probably better to maintain them for subtrees in the LBA.

  17. danielmewes commented on Mar 6, 2014

    @danielmewes
    MemberAuthor

    This is why you shouldn't assume we'd have counts in the stats block. It's probably better to maintain them for subtrees in the LBA.

    Yeah I assumed that mostly because the count is already there (it's actually the only thing in there as far as I know). If we do it for subtrees, it probably shouldn't be in the LBA either. But we could certainly have a block_id -> subtree count map somewhere (it could just be a second btree).

  18. srh commented on Mar 8, 2014

    @srh
    Contributor

    If we do it for subtrees, it probably shouldn't be in the LBA either.

    It would have to be the LBA, because we don't want to go rewriting an entire spine of blocks every time an insertion happens.

  19. coffeemug commented on Jul 2, 2014

    @coffeemug
    Contributor

    Closing in favor of #152.

  20. modified the milestones: wontfix, subsequent, moved on Jul 2, 2014
  21. modified the milestones: duplicate, moved on Jul 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions