Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions docs/developer/adr/0013-follow-adds-the-rows-not-considered.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ intake.create('loki-iofq', title='Evening', source='sample-runs',
follow=True) # the batch 'afternoon' stops following
```

The earlier batch keeps its rows, also those from 60400 on, until a person removes them. It has considered the keys it has seen, and takes no row that arrives later, since it cannot follow again.
The earlier batch keeps its rows, also those from 60400 on, until a person removes them. It has considered the keys it has seen, and takes no row that arrives later while it does not follow.

A batch of only the rows that arrive later takes no row at making. Every row filled then is considered, so no row is reduced again:

Expand All @@ -130,22 +130,23 @@ intake.create('loki-iofq', title='Night', source='sample-runs',
choose=Range(later=True), follow=True)
```

### A batch follows from the time it is made, until it is stopped
### A batch follows from the time it is made or told to follow, until it is stopped

Follow is chosen when a batch is made. A batch that follows can be stopped. A batch that does not follow cannot be made to follow.
A batch made from a source follows from its making with Follow, or from `intake.follow(label)`. A batch that follows can be stopped.

```python
intake.create(..., source='sample-runs', follow=True) # follows; the batch that followed before stops
intake.following # its label
intake.stop() # none follows; that batch cannot follow again
intake.stop() # none follows
intake.follow('afternoon') # follows again; the batch that followed before stops
```

- At most one batch follows, as in ADR 0011: `Intake` keeps whether a batch follows in its `source.json`, a restart resumes, and removing that batch ends Follow. Since `considered` is kept, the first step after a restart adds the rows that arrived in between.
- A batch made without a source cannot follow: only `intake.create`, which takes a source, takes `follow=True`.
- A batch made without a source cannot follow: only `intake.create`, which takes a source, takes `follow=True`, and `intake.follow` refuses a batch without one.
- A batch that follows again adds at its next step every row of its source that is filled and not considered: those that arrived while it did not follow, also those that another batch took meanwhile. A row left out when it was made, or removed by a person, stays out, since its key is considered.
- A batch that follows has no last row. With one, the rows filled between the last row chosen and the making would be considered and never added, and the rows that arrive later would be. The range that a person picks is a value, `Range(first, last, later)`, which `Intake` reads: `create(follow=True)` with a `Range` that has a `last` is refused there. The page leaves the end of the range open while Follow is ticked, to say so before a person sends the form; the command does not follow. A `choose` that is a function may pick any rows, also with Follow: the rows were chosen in code, and the filled rows that it leaves out are considered, so Follow adds only the rows that arrive later.
- Nothing is kept that says a batch has followed. A batch is stopped when its `source.json` says that it does not follow, and no call writes that it follows again.
- So the next batch is one form, "New batch" with Follow, and a step never takes a row that another batch took since.
- On the page, Follow is a state with one action, "Stop following", not a switch.
- Nothing is kept that says a batch has followed. A batch made without Follow and a batch that was stopped are in the same state, and `intake.follow` writes `"follows": true` to either.
- On the page, the next batch is one form, "New batch" with Follow. Follow is a state with one action, "Stop following", not a switch: the page offers no action to let a batch follow again.

## Example

Expand All @@ -169,7 +170,7 @@ A batch made from `sample-runs` with the rows from run 60339 on, with Follow.
- **Add a row at once and fill its empty cells later.** It needs no memory of what waits. But it fills a cell again that a person emptied, and an empty cell of a parameter that takes `None` is a value (ADR 0012), so "not listed yet" and "none" cannot be told apart.
- **A step changes cells that have a value**, as today, so that a transmission run measured again reaches the earlier rows and they are reduced again. It needs to know who wrote each cell, and results change with nobody asking. A person can do it for the rows they choose.
- **A scope kept in the header** (ADR 0011): a slice of an index that a source gives each row. With `considered`, the start of the slice is the choice of rows at making, and it has no end: the next batch is made from the source and follows in its place. The index, its type, and the conversion of the ends go.
- **Follow turned on and off for a batch made before**, a switch on its page. A batch that follows again after another batch followed takes every row that arrived since, also the rows that the other batch took, and the next batch is two actions: make it, then turn Follow on.
- **Follow as a switch on the page of each batch**, in place of Follow in "New batch". The next batch would be two actions: make it, then turn Follow on. And a person who turns it on for an earlier batch may not expect that it takes the rows that another batch took since.
- **A row is added once it can be reduced**, in place of once the source has filled it. A column that the source does not fill would hold the row back for ever, and a parameter that takes `None` would let a row through before its file is listed.

## Consequences
Expand All @@ -178,7 +179,7 @@ A batch made from `sample-runs` with the rows from run 60339 on, with Follow.
- The rule of a step is "ready and without a record". `RowState.changed_by_hand`, the columns `at` of `Automatic`, and the exception for cells set by hand go.
- A row that only waits is not in the table. The page says how many rows wait, and a person can add them.
- A transmission run measured again reaches no earlier row, and a correction of a run changes no row that the table has.
- A stop by mistake cannot be undone. A person adds the later rows with "Add rows from the runs", or makes a batch from the source, with Follow, that starts at the first row the stopped batch lacks.
- A stop by mistake is undone in code with `intake.follow(label)`, not on the page. On the page, a person adds the later rows with "Add rows from the runs", or makes a batch from the source, with Follow, that starts at the first row the stopped batch lacks.
- A person who wants to try settings on a few rows first makes a batch without Follow, then the batch that follows with "Start with the settings of" the first. The rows tried are reduced again in the second batch.
- A batch made with Follow is stepped within seconds: the rows taken at making are reduced with the settings it was made with.
- `considered` grows by one key for each row that the source ever gave: some tens of bytes per row.
Expand Down
21 changes: 13 additions & 8 deletions packages/essapps/docs/batch.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Nothing in the batch layer imports the page or the command.
| row source | code of the application that makes rows from the files (a `RowSource`) |
| filled, waits | a row of the source is filled once it has a value in each of `RowSource.fills`; until then it waits |
| considered | the keys of the source that a batch made from it has taken or left out |
| Follow | a step every few seconds on one batch: add the rows of its source that are filled and not considered, then reduce the rows that are ready and have no result; chosen when the batch is made, until it is stopped |
| Follow | a step every few seconds on one batch: add the rows of its source that are filled and not considered, then reduce the rows that are ready and have no result; from the making of the batch or `intake.follow(label)`, until it is stopped |

`manager.create` and `intake.create` return the `Batch`, and `manager.batch(label)` gives it again.
Every other method that names a batch takes its label.
Expand Down Expand Up @@ -138,7 +138,7 @@ Other tables are always named with what they are of:
4. **A step never changes a row that the batch table has.** It adds rows, and reduces rows that have no result.
5. **A batch is shown without its source and without the files.** A file that is not found is a problem of its row.
6. **The rules are in the batch layer.** A refusal is a `ValueError`. The page and the command show it and copy no rule of the batch layer. The page refuses only a request that no call of the batch layer can express, such as Follow without a row source. The batch layer has no lock and no timer.
7. **Follow is chosen when a batch is made.** A batch follows from `intake.create(..., follow=True)` until `intake.stop()`, its removal, or the making of another batch that follows. A batch that does not follow cannot be made to follow.
7. **At most one batch follows.** It starts with `intake.create(..., follow=True)` or `intake.follow(label)`, and ends with `intake.stop()`, the removal of the batch, or another batch that starts to follow.

### What is kept on disk

Expand All @@ -155,6 +155,7 @@ Other tables are always named with what they are of:
A label is a batch if and only if `header.json` exists.
`manager.create` writes rows and settings, then the header.
`intake.create` then, if the batch follows, writes `"follows": false` to the `source.json` of the batch that followed, then writes the `source.json` of the batch; if the definitions refuse a write, it removes the batch again.
`intake.follow(label)` writes `"follows": false` to the `source.json` of the batch that followed, then `"follows": true` to that of `label`; a process that stops in between leaves no batch that follows.
So a batch of `intake.create` is not always made as asked or not at all: a process that stops between the header and the batch's `source.json` leaves a batch made without a source, which neither offers rows nor follows, and no batch that follows.
`manager.remove` deletes the header, then every other file of the label, `source.json` too.
So whether a batch follows goes with its label: a batch made again with the label does not follow unless made so.
Expand Down Expand Up @@ -260,11 +261,12 @@ They make it from the source, with the settings of the afternoon, and with Follo
evening = intake.create('loki-iofq', title='Evening', source='sample-runs',
choose=Range(first='60400'),
settings=manager.batch('afternoon').settings, label='evening',
follow=True) # 'afternoon' stops following, and cannot follow again
follow=True) # 'afternoon' stops following
```

No row moves between batches.
`afternoon` keeps its rows, also those from 60400 on that it added before, until a person removes them.
`intake.follow('afternoon')` would let it follow again, in place of `evening`: its next step would add every filled row it has not considered, also those that `evening` took.
A batch that follows has no last row: the rows filled between a last row and the making would never be added.
`intake.create` refuses `follow=True` with a `Range` that has a `last` (see [From a row source](#from-a-row-source)); a function as `choose` may pick any rows, and the filled rows it leaves out are considered.
For a batch of only the rows that arrive from now on, `choose` takes none: `choose=Range(later=True)`.
Expand Down Expand Up @@ -547,24 +549,26 @@ If the process stops while a batch that follows is made, the batch may be there

## Follow

At most one batch follows: the last one made with `follow=True`, until it is stopped.
The life of a batch; a batch made without Follow and a batch that stopped are in the same state:
At most one batch follows: the last one made with `follow=True` or given to `intake.follow(label)`, until it is stopped.
The life of a batch made from a source; a batch made without Follow and a batch that stopped are in the same state:

```mermaid
stateDiagram-v2
follows: follows
still: does not follow
[*] --> still: create(...)
[*] --> follows: intake.create(..., follow=True)
follows --> still: stop(), or another batch made with Follow
still --> follows: intake.follow(label)
follows --> still: stop(), or another batch starts to follow
still --> removed: remove()
follows --> removed: remove()
```

```python
intake.create(..., source='sample-runs', follow=True) # follows; the batch that followed stops
intake.following # its label, or None
intake.stop() # none follows; the batch that followed cannot follow again
intake.stop() # none follows
intake.follow(label) # this batch follows; the batch that followed stops
done = intake.step() # a Step, or None if none follows
intake.offered(label) # the rows of the source that the table lacks, with a boolean column `waits`
intake.take(label, keys) # put these rows as the source gives them now, then consider them
Expand Down Expand Up @@ -616,6 +620,7 @@ sequenceDiagram
- A row with a result is never reduced by a step, also when it is outdated, failed or cancelled.
- A row whose request is refused does not hold back the others; `done.refused` says why, and the next step tries again.
- A batch of the manager persists what it submits.
- A batch that follows again adds at its next step every row of its source that is filled and not considered: those that arrived while it did not follow, also those that another batch took meanwhile. A row left out when it was made, or removed by a person, stays out. `intake.follow` refuses a batch made without a source, or whose source is not registered.
- `manager.remove(label)` of the batch that follows ends Follow, since `source.json` goes with the label: `intake.following` is then `None`, and `intake.step()` does nothing. A batch made again with the label does not follow unless made so.

A source whose row grows, such as the runs of a sample so far, gives the grown list a new key:
Expand Down Expand Up @@ -728,5 +733,5 @@ Each action of the page is one call of the batch layer:
- A correction of a run changes no batch.
- No range of runs is kept: "from run 60339 on" is the choice of rows when the batch is made.
- No row moves between batches: the next batch is made from the source.
- One batch follows at a time, and a batch that stopped following never follows again. The command does no step.
- One batch follows at a time. The page offers no action to let a stopped batch follow again. The command does no step.
- The batch layer has no lock and no timer: whoever serves owns both.
Loading
Loading