Commit e9393c2
authored
Executing GraphQL and REST Mutations in a transaction (#1451)
## Why make this change?
Closes #814
When two update mutations act on the same item, the responses returned
back to these mutations are misleading.
Update Mutation that was run:
```graphql
mutation updateNotebook($id: Int!, $item: UpdateNotebookInput!) {
updateNotebook(id: $id, item: $item) {
id
color
}
}
```
When two graphQL mutations were executed in parallel with the following
variables,
```json
{
"id": 3,
"item": {
"color": "cyan"
}
}
```
```json
{
"id": 3,
"item": {
"color": "magenta"
}
}
```
the responses for both the mutations were either
```json
{"data":{"updateNotebook":{"id":3,"color":"magenta"}}}
```
or
```json
{"data":{"updateNotebook":{"id":3,"color":"cyan"}}}
```
Within the same mutation, the data read back from the database should be
the same as that of the updated value.
## What is this change?
- For a single graphQL mutation, there are 2 database queries performed.
Both these DB queries are run within a single transaction to ensure
consistency during concurrent updates.
- [Implicit Transactions
docs](https://learn.microsoft.com/en-us/dotnet/framework/data/transactions/implementing-an-implicit-transaction-using-transaction-scope).
- The transaction isolation level is chosen based on the database type
and the value chosen is the default isolation level for each database
type.
- In the database query constructed for REST upsert scenario, the
explicit creation of a transaction using T-SQL statements such as `SET
TRANSACTION ISOLATION LEVEL SERIALIZABLE;BEGIN TRANSACTION;..` is
removed. Since, the entire `PerformMutation()` block executes within a
transactionscope, creation of another transaction with a different
isolation level should not be done.
- Integration tests to validate that responses are consistent when there
are concurrent requests are added
## How was this tested?
- [x] Existing Unit Tests
- [x] Integration Tests
- k6 test suite:
> The concurrent test suite written using k6 -
[link](https://github.com/Azure/data-api-builder/tree/main/src/Service.Tests/ConcurrentTests/SqlTests)
was run in local against each of the database types.
>
> Scenarios covered by the Concurrent Test suite:
>
> > Parallel Read Operations on different items
> > Parallel CRUD Operations on different items
> > Parallel Update and Read Operations on the same item using GraphQL
> > Parallel Update and Read Operations on the same item using REST
> > Parallel Create Operations when the PK is auto-generated
> > Parallel Create Operations when the PK is not auto-generated
> > Parallel Delete Operations on the same item
>
- Jmeter:
> Tested concurrent updates with two mutations trying to update the same
row
> Concurrent graphQL mutation and query updating/reading the same row
> Concurrent REST PATCH requests updating the same row
> Concurrent REST PATCH and REST GET requests updating/reading the same
row
> Concurrent graphQL mutation and REST GET acting on the same row.
Performed all the scenarios with 100 threads (50 threads of each request
type) to see if there were any occurrences of errors related to
transactions when the volume of requests trying to update the same row
is high.1 parent bcc1e04 commit e9393c2
File tree
3 files changed
+373
-77
lines changed- src
- Service.Tests/SqlTests/GraphQLMutationTests
- Service/Resolvers
3 files changed
+373
-77
lines changedLines changed: 179 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
677 | 677 | | |
678 | 678 | | |
679 | 679 | | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
680 | 859 | | |
681 | 860 | | |
682 | 861 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
| 108 | + | |
114 | 109 | | |
115 | 110 | | |
116 | 111 | | |
| |||
125 | 120 | | |
126 | 121 | | |
127 | 122 | | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
| 123 | + | |
| 124 | + | |
132 | 125 | | |
133 | 126 | | |
134 | 127 | | |
| |||
137 | 130 | | |
138 | 131 | | |
139 | 132 | | |
140 | | - | |
141 | | - | |
| 133 | + | |
| 134 | + | |
142 | 135 | | |
143 | 136 | | |
144 | 137 | | |
| |||
172 | 165 | | |
173 | 166 | | |
174 | 167 | | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | 168 | | |
179 | 169 | | |
180 | 170 | | |
| |||
0 commit comments