Skip to content

Exact timestamps for every row, no sindex post construction queues. #2134

Open

Description

@srh

A long time ago when implementing two-machine replication, in order to prevent costly memory overhead for rows, we decided to only store replication timestamps for the first few rows in a leaf node, under the idea that a replica would only be disconnected for a short amount of time.

Instead, we should store repli_timestamp_t values for every row. That will make backfilling do less work and it will make sindex post construction not have to queue writes -- we know which write "wins" in the secondary index by seeing which has the later timestamp.

Activity

  1. added this to the subsequent milestone on Mar 21, 2014
  2. srh commented on Apr 1, 2014

    @srh
    ContributorAuthor

    One problem here is that we do want to drop deletion entries (that are stored in the b-tree) at some point. We can't just store deletion entries for all these ancient documents. Fortunately, some of the benefits from exact timestamps -- such as more efficient secondary index post-construction, wouldn't require us to store all of our deletion entries.

  3. modified the milestones: 1.14, subsequent on Jun 14, 2014
  4. coffeemug commented on Jun 14, 2014

    @coffeemug
    Contributor

    Moving to 1.14, assigning to @srh.

  5. modified the milestones: , on Aug 13, 2014
  6. srh commented on Aug 16, 2014

    @srh
    ContributorAuthor

    How this will work:

    We will NOT have a long-running snapshot of the main b-tree while post-constructing a secondary index.

    The important timestamps are in the main b-tree. Secondary index entries need a different sort of metadata.

    • All new key/value pairs in the main b-tree are timestamped. Old ones, from version 1.14 and earlier, might not be, and that's OK, because the only question we'll need to answer, when looking at a timestamp, is whether it's before or after the time when the secondary index began post-constructing. (This differs from the existing implementation, where only some of the newest key/value pairs are timestamped. We will continue rapidly expiring deletion entries, which are always timestamped.)

    Define "old{t0} value" to mean a value whose timestamp is <= t0. And "new{t0} value" is one that is not old{t0}.

    When a post-construction begins with the latest value in the tree having timestamp t0, the post-constructing secondary index's entries will have metadata identifying it as a member of one of the following categories:

    1. An old{t0} value, that was inserted by the post-construction process.
    2. A new{t0} deletion entry.
    3. A new{t0} value: also, a deletion entry should be left behind when the value is removed.
    4. A new{t0} value: also, NO deletion entry should be left behind when the value is removed.

    The post-construction "process" that walks the b-tree does a series of small range traversals that covers the entire key range. When it comes across an old{t0} key/value pair, it throws it at the secondary index in a separate write transaction. In that write transaction, if a new{t0} value or deletion entry is present, it is untouched, except to say that if the value is removed, a deletion entry should be left behind. Otherwise, the old{t0} value gets inserted, if one isn't already present.

    When a new write comes in and modifies a value, it (naturally) updates the secondary indexes. Generally speaking, it has to remove the value from its old location (if an old value existed) and insert a value at the new location (if it's not a deletion). In a post-constructing index, the old value (which exists if the write is not a fresh insertion) and secondary index might be in one of several states:

    1. An old{t0} value, with no entry present in the secondary index: The post-construction process has not yet inserted it. We must leave behind a deletion entry for its key.
    2. An old{t0} value, that was inserted by the post-construction process: We must replace it with a deletion entry.
    3. A new{t0} value, and the entry says that a deletion entry should be left behind: We must replace it with a deletion entry.
    4. A new{t0} value, and the entry says that NO deletion entry should be left behind: We must remove it.
    5. We find a deletion entry already present: Crash, this is impossible.

    In a post-constructing index, the new value (which exists if the write is not a deletion) is always a new{t0} value. The secondary index, after removing the old value, might be in one of several states:

    1. Has a deletion entry for that value's key: Replace it with a new{t0} value, with the entry saying that a deletion entry should be left behind.
    2. Has nothing for the value's key: Insert a new{t0} value, with the entry saying that NO deletion entry should be left behind.

    It is permissible for the post-construction process to accidentally re-scan the same section of the b-tree and reprocess the same key/value pairs. If the post-construction process walks the b-tree from left to right, we could save the end of the last completed post-construction key range in the secondary index superblock (or somewhere) to allow post-construction to resume after a shutdown and restart.

  7. danielmewes commented on Aug 18, 2014

    @danielmewes
    Member

    👍 Sounds solid.

    Could we avoid having to add timestamps to the main btree if we instead introduced a guarantee that all writes update the secondary index even if it's still in post construction?

    In that case we could detect values that fall into the new{t0} category simply by the fact that they already have an entry (possibly a deletion entry) in the secondary index tree when post construction gets to them. Post construction would tag all pairs it inserts into the secondary index as old, and every sindex update caused by a regular write would be one of the three possible new{t0} entries.

  8. srh commented on Aug 18, 2014

    @srh
    ContributorAuthor

    We'd still use timestamps in the main btree for backfilling.

  9. danielmewes commented on Aug 18, 2014

    @danielmewes
    Member

    We'd still use timestamps in the main btree for backfilling.

    Sure, but we could keep timestamp deprecation and could leave the main btree format unchanged. Not sure how much that would save in terms of implementation costs.

  10. srh commented on Aug 18, 2014

    @srh
    ContributorAuthor

    Sure, but we could keep timestamp deprecation and could leave the main btree format unchanged. Not sure how much that would save in terms of implementation costs.

    If we did that, then if there's an active write workload the secondary index would need arbitrarily many deletion entries, instead of a number bounded by the size of the main b-tree. Unless post-construction exposed information about what it was currently looking at and we decided to get real clever about not leaving deletion entries most of the time.

  11. 14 remaining items

  12. modified the milestones: subsequent, 1.16 on Nov 24, 2014
  13. modified the milestones: 2.1, subsequent on Feb 3, 2015
  14. modified the milestones: , 2.1 on Apr 28, 2015
  15. modified the milestones: backlog, subsequent on Nov 3, 2015
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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions