Commit de3672a
authored
Offload replication writes to IO threads (#1485)
This PR offloads the write to replica clients to IO threads.
## Main Changes
* Replica writes will be offloaded but only after the replica is in
online mode..
* Replica reads will still be done in the main thread to reduce
complexity and because read traffic from replicas is negligible.
### Implementation Details
In order to offload the writes, `writeToReplica` has been split into 2
parts:
1. The write itself made by the IO thread or by the main thread
2. The post write where we update the replication buffers refcount will
be done in the main-thread after the write-job is done in the IO thread
(similar to what we do with a regular client)
### Additional Changes
* In `writeToReplica` we now use `writev` in case more than 1 buffer
exists.
* Changed client `nwritten` field to `ssize_t` since with a replica the
`nwritten` can theoretically exceed `int` size (not subject to
`NET_MAX_WRITES_PER_EVENT` limit).
* Changed parsing code to use `memchr` instead of `strchr`:
* During parsing command, ASAN got stuck for unknown reason when called
to `strchr` to look for the next `\r`
* Adding assert for null-terminated querybuf didn't resolve the issue.
* Switched to `memchr` as it's more secure and resolves the issue
### Testing
* Added integration tests
* Added unit tests
**Related issue:** #761
---------
Signed-off-by: Uri Yagelnik <[email protected]>1 parent 7fa784a commit de3672a
File tree
8 files changed
+493
-47
lines changed- src
- unit
- tests/unit
8 files changed
+493
-47
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
321 | 321 | | |
322 | 322 | | |
323 | 323 | | |
324 | | - | |
| 324 | + | |
325 | 325 | | |
326 | 326 | | |
327 | 327 | | |
| |||
364 | 364 | | |
365 | 365 | | |
366 | 366 | | |
367 | | - | |
368 | | - | |
| 367 | + | |
| 368 | + | |
369 | 369 | | |
370 | 370 | | |
371 | 371 | | |
| |||
392 | 392 | | |
393 | 393 | | |
394 | 394 | | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
402 | 400 | | |
403 | | - | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
404 | 411 | | |
405 | | - | |
| 412 | + | |
| 413 | + | |
406 | 414 | | |
407 | 415 | | |
408 | 416 | | |
409 | | - | |
| 417 | + | |
410 | 418 | | |
411 | 419 | | |
412 | 420 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1534 | 1534 | | |
1535 | 1535 | | |
1536 | 1536 | | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
1537 | 1540 | | |
1538 | 1541 | | |
1539 | 1542 | | |
| |||
1934 | 1937 | | |
1935 | 1938 | | |
1936 | 1939 | | |
1937 | | - | |
1938 | | - | |
1939 | | - | |
1940 | | - | |
| 1940 | + | |
| 1941 | + | |
| 1942 | + | |
| 1943 | + | |
| 1944 | + | |
| 1945 | + | |
| 1946 | + | |
| 1947 | + | |
| 1948 | + | |
| 1949 | + | |
| 1950 | + | |
| 1951 | + | |
| 1952 | + | |
| 1953 | + | |
| 1954 | + | |
| 1955 | + | |
| 1956 | + | |
| 1957 | + | |
| 1958 | + | |
| 1959 | + | |
| 1960 | + | |
| 1961 | + | |
| 1962 | + | |
| 1963 | + | |
| 1964 | + | |
| 1965 | + | |
| 1966 | + | |
| 1967 | + | |
| 1968 | + | |
| 1969 | + | |
| 1970 | + | |
| 1971 | + | |
| 1972 | + | |
| 1973 | + | |
| 1974 | + | |
| 1975 | + | |
| 1976 | + | |
1941 | 1977 | | |
1942 | | - | |
1943 | | - | |
1944 | | - | |
1945 | | - | |
1946 | | - | |
1947 | | - | |
1948 | | - | |
1949 | | - | |
1950 | | - | |
1951 | | - | |
1952 | | - | |
1953 | | - | |
1954 | | - | |
| 1978 | + | |
| 1979 | + | |
| 1980 | + | |
| 1981 | + | |
| 1982 | + | |
| 1983 | + | |
| 1984 | + | |
| 1985 | + | |
| 1986 | + | |
| 1987 | + | |
| 1988 | + | |
| 1989 | + | |
| 1990 | + | |
| 1991 | + | |
| 1992 | + | |
| 1993 | + | |
| 1994 | + | |
| 1995 | + | |
| 1996 | + | |
| 1997 | + | |
| 1998 | + | |
| 1999 | + | |
| 2000 | + | |
| 2001 | + | |
| 2002 | + | |
| 2003 | + | |
| 2004 | + | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
| 2008 | + | |
| 2009 | + | |
| 2010 | + | |
| 2011 | + | |
| 2012 | + | |
| 2013 | + | |
| 2014 | + | |
| 2015 | + | |
| 2016 | + | |
| 2017 | + | |
| 2018 | + | |
| 2019 | + | |
| 2020 | + | |
| 2021 | + | |
| 2022 | + | |
| 2023 | + | |
| 2024 | + | |
| 2025 | + | |
| 2026 | + | |
| 2027 | + | |
| 2028 | + | |
| 2029 | + | |
| 2030 | + | |
| 2031 | + | |
| 2032 | + | |
| 2033 | + | |
| 2034 | + | |
| 2035 | + | |
| 2036 | + | |
1955 | 2037 | | |
1956 | 2038 | | |
1957 | | - | |
1958 | | - | |
1959 | | - | |
1960 | | - | |
1961 | | - | |
1962 | | - | |
1963 | | - | |
1964 | | - | |
| 2039 | + | |
| 2040 | + | |
| 2041 | + | |
| 2042 | + | |
| 2043 | + | |
| 2044 | + | |
| 2045 | + | |
| 2046 | + | |
| 2047 | + | |
| 2048 | + | |
| 2049 | + | |
| 2050 | + | |
| 2051 | + | |
1965 | 2052 | | |
1966 | 2053 | | |
| 2054 | + | |
| 2055 | + | |
1967 | 2056 | | |
1968 | 2057 | | |
1969 | 2058 | | |
| |||
2158 | 2247 | | |
2159 | 2248 | | |
2160 | 2249 | | |
2161 | | - | |
| 2250 | + | |
2162 | 2251 | | |
2163 | 2252 | | |
2164 | 2253 | | |
| |||
2718 | 2807 | | |
2719 | 2808 | | |
2720 | 2809 | | |
2721 | | - | |
| 2810 | + | |
2722 | 2811 | | |
2723 | 2812 | | |
2724 | 2813 | | |
| |||
2795 | 2884 | | |
2796 | 2885 | | |
2797 | 2886 | | |
2798 | | - | |
| 2887 | + | |
2799 | 2888 | | |
2800 | 2889 | | |
2801 | 2890 | | |
| |||
5042 | 5131 | | |
5043 | 5132 | | |
5044 | 5133 | | |
5045 | | - | |
| 5134 | + | |
| 5135 | + | |
| 5136 | + | |
| 5137 | + | |
| 5138 | + | |
| 5139 | + | |
5046 | 5140 | | |
5047 | 5141 | | |
5048 | 5142 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4238 | 4238 | | |
4239 | 4239 | | |
4240 | 4240 | | |
4241 | | - | |
4242 | | - | |
4243 | 4241 | | |
4244 | 4242 | | |
4245 | 4243 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2633 | 2633 | | |
2634 | 2634 | | |
2635 | 2635 | | |
2636 | | - | |
| 2636 | + | |
2637 | 2637 | | |
2638 | 2638 | | |
2639 | 2639 | | |
| |||
0 commit comments