Commit Graph

8 Commits

Author SHA1 Message Date
Jun Wu
eab358c1b0 dag: implement descendants
Summary: The implemenation is based on `range`.

Reviewed By: sfilipco

Differential Revision: D17002967

fbshipit-source-id: f59e1686306b9fc08dbca9891c2b6d6c42be2717
2019-09-17 12:36:45 -07:00
Jun Wu
d10dab5342 dag: make sure Dag has complete high-level segments when SyncableDag gets dropped
Summary:
Previously, `SyncableDag` and `Dag` can co-exist. Dropping SyncableDag involves
error handling and is not panic-free. If we want to make sure `Dag` has complete
high-level segments, then it would have been implemented in `SyncableDag::drop`,
making it more sensitive to panic.

Change the API so `SyncableDag` is independent from `Dag`, so `Dag` always
has complete segments, and changes to `SyncableDag` are invisible to `Dag`,
so `SyncableDag` cannot mess up existing `Dag` structures.

Reviewed By: sfilipco

Differential Revision: D17000969

fbshipit-source-id: 1ceed4ea335d3d64848b7430d48076846b90695d
2019-09-17 12:36:44 -07:00
Jun Wu
b3eb5bf97d dag: refactor segment building APIs
Summary:
Previously, the `Dag` has 2 low-level `build_segemnts` APIs:

- Dag::build_flat_segments(..., last_threshold)
- Dag::build_high_level_segments(..., drop_last)

They allow customization about whether the segments are lagging or not.

However, certain algorithms (ex. children and range) now require the high level
segments to cover everything covered by the flat segments. The above APIs
wouldn't ensure that.

This diff refactors the segment building APIs so that:

- Make `build_flat_segments`, and `build_high_level_segments` private to
  prevent misuse.
- Ensure high level segments cover flat segments at `Dag::open` and
  `Dag::build_segments_volatile`, the only ways to change `Dag`.
- Provide different APIs suitable for different (one-time in-memory vs
  on-disk) use-cases. The on-disk `build_segments_persistent` API makes high
  level segments lagging to avoid fragmentation, while the in-memory
  `build_segments_volatile` does not.

To satisfy the existing test need, a `set_segment_size` API was added to
override the default segment size.

Most callsites become simpler because they no longer need to figure out
details about segment size, level, and lagging.

Reviewed By: sfilipco

Differential Revision: D17000965

fbshipit-source-id: 78bb0c7674c99e91be6011bb7e623cd4f63b1521
2019-09-13 19:31:03 -07:00
Jun Wu
00188de9fe dag: add parent_ids function
Summary:
Parents are ordered and the order can be important. The flat segments preserve
the order but there are no APIs exposing the parent order. Define one.

Reviewed By: markbt

Differential Revision: D17000966

fbshipit-source-id: 66beb53d9cef651a53391707c0b690a1e3b76ce2
2019-09-13 19:31:03 -07:00
Jun Wu
5bbc59aff0 dag: implement DAG range
Summary: Implement the "dag range" (aka. "x::y" in mercurial) query.

Reviewed By: sfilipco

Differential Revision: D16988046

fbshipit-source-id: 2733a1ec7831c5bace6056b9376dce53c6aafb0c
2019-09-13 19:31:01 -07:00
Jun Wu
f6deec39ec dag: implement roots
Summary: Similar to `heads(x) = x - parents(x)`, `roots(x) = x - children(x)`.

Reviewed By: markbt

Differential Revision: D16976381

fbshipit-source-id: 0606cc907951b49cbbd7b75ccd11a222bc9bd0fe
2019-09-13 19:31:01 -07:00
Jun Wu
1a32a56b82 dag: implement children
Summary:
The children operation is now O(flat segments) = O(merges). But it has
potential to be faster with more precalculated information in segments.
See added comments for details.

Reviewed By: markbt

Differential Revision: D16976383

fbshipit-source-id: 80bfd2cefa5aa5ceabfd7e40d46d06f7e2b64d34
2019-09-13 19:31:00 -07:00
Jun Wu
0181efeb2c dag: add dag_ops benchmark
Summary:
This will guide optimizations.

Right now, gca_one "large sets" can take forever to run.

The code to build the mozilla DAG was extracted to a single file to be sharable.

Reviewed By: sfilipco

Differential Revision: D16992730

fbshipit-source-id: 1538f5b0098cd06cb179bd556df285055e1d62b6
2019-09-13 19:30:59 -07:00