Skip to content
This repository was archived by the owner on Jul 12, 2023. It is now read-only.

Implement offset/limit for workflow instance executions #18

Merged
merged 2 commits into from
Dec 9, 2016
Merged

Conversation

rouzwawi
Copy link
Member

@rouzwawi rouzwawi commented Dec 4, 2016

No description provided.

@rouzwawi rouzwawi force-pushed the paginate branch 4 times, most recently from f68f103 to 1bd090f Compare December 4, 2016 16:42

return workflowInstanceDataList;
return workflowInstancesSet.parallelStream()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did the parallelStream() make any discernible difference?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, on a local run on request that took 9 seconds it went down to about 3.

final WorkflowId workflowId = WorkflowId.create(componentId, endpointId);
final List<WorkflowInstanceExecutionData> data;
final String offset = request.parameter("offset").orElse("");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just semantics and I can't really find anything useful on google right now, but isn't this more of a cursor than an offset? At least in the SQL sense, an offset to me is the number of items to skip while this is the element to start from.

@@ -48,8 +56,12 @@
import com.spotify.styx.model.Workflow;
import com.spotify.styx.model.WorkflowInstance;
import com.spotify.styx.model.WorkflowState;
import com.spotify.styx.storage.InMemStorage;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@@ -382,6 +426,26 @@ public void shouldReturnWorkflowInstanceData() throws Exception {
assertJson(response, "triggers.[0].executions.[0].statuses.[1].timestamp", is("2016-08-10T07:00:02Z"));
}

@Test
public void shouldPaginateWorkflowInstancesData() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test where the offset parameter is set as well? I kind of get the feeling that there could be an off-by-one error in there.

scan.setStartRow(Bytes.toBytes(offsetInstance.toKey() + '#'));

workflowInstancesSet.add(wfi);
if (!Strings.isNullOrEmpty(offset)) {
final WorkflowInstance offsetInstance = WorkflowInstance.create(workflowId, offset);
scan.setStartRow(Bytes.toBytes(offsetInstance.toKey() + '#'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this include the item named in offset or start from the next one? It's not immediately obvious to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The startRow is inclusive

return workflowInstancesSet.parallelStream()
.map(workflowInstance -> {
try {
return executionData(workflowInstance);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only partly related since it wasn't changed in this commit, but this function will call readEvents which in turns reads from the same table we just read from to get this list. Is there a point to that? Why not just use that data in the first scan?

@@ -73,7 +73,7 @@
/**
* Removes a workflow definition.
*
* @param workflowId The workflowid to remove.
* @param workflowId The workflow id to remove.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use the type instead?

* @param workflowId The workflowId to get execution information for
* @param offset The offset parameter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The id of the last item from previous fetch. Or something to that effect.

storage.writeEvent(SequenceEvent.create(Event.triggerExecution(WFI3, "triggerId3"), 0L, 3L));

List<WorkflowInstanceExecutionData> workflowInstanceExecutionData =
storage.executionData(WORKFLOW_ID1, WFI2.parameter(), 100);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! So the offset parameter is inclusive. This is unexpected to me and not how pagination works to me. You would have to guess the next ID to not get duplicates between pages.

@rouzwawi rouzwawi closed this Dec 6, 2016
@rouzwawi rouzwawi reopened this Dec 6, 2016
@rouzwawi rouzwawi force-pushed the paginate branch 3 times, most recently from 4660521 to 09ec0a8 Compare December 8, 2016 16:22
@rouzwawi
Copy link
Member Author

rouzwawi commented Dec 9, 2016

Discussion offline: we'll merge this for now and iterate on the details.

@rouzwawi rouzwawi merged commit e100d37 into master Dec 9, 2016
@rouzwawi rouzwawi deleted the paginate branch December 9, 2016 12:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants