Commit 19407e2
Offload replication writes to IO threads (valkey-io#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:** valkey-io#761
---------
Signed-off-by: Uri Yagelnik <[email protected]>1 parent 2248705 commit 19407e2
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 | |
|---|---|---|---|
| |||
1544 | 1544 | | |
1545 | 1545 | | |
1546 | 1546 | | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
1547 | 1550 | | |
1548 | 1551 | | |
1549 | 1552 | | |
| |||
1953 | 1956 | | |
1954 | 1957 | | |
1955 | 1958 | | |
1956 | | - | |
1957 | | - | |
1958 | | - | |
1959 | | - | |
| 1959 | + | |
| 1960 | + | |
| 1961 | + | |
| 1962 | + | |
| 1963 | + | |
| 1964 | + | |
| 1965 | + | |
| 1966 | + | |
| 1967 | + | |
| 1968 | + | |
| 1969 | + | |
| 1970 | + | |
| 1971 | + | |
| 1972 | + | |
| 1973 | + | |
| 1974 | + | |
| 1975 | + | |
| 1976 | + | |
| 1977 | + | |
| 1978 | + | |
| 1979 | + | |
| 1980 | + | |
| 1981 | + | |
| 1982 | + | |
| 1983 | + | |
| 1984 | + | |
| 1985 | + | |
| 1986 | + | |
| 1987 | + | |
| 1988 | + | |
| 1989 | + | |
| 1990 | + | |
| 1991 | + | |
| 1992 | + | |
| 1993 | + | |
| 1994 | + | |
| 1995 | + | |
1960 | 1996 | | |
1961 | | - | |
1962 | | - | |
1963 | | - | |
1964 | | - | |
1965 | | - | |
1966 | | - | |
1967 | | - | |
1968 | | - | |
1969 | | - | |
1970 | | - | |
1971 | | - | |
1972 | | - | |
1973 | | - | |
| 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 | + | |
| 2037 | + | |
| 2038 | + | |
| 2039 | + | |
| 2040 | + | |
| 2041 | + | |
| 2042 | + | |
| 2043 | + | |
| 2044 | + | |
| 2045 | + | |
| 2046 | + | |
| 2047 | + | |
| 2048 | + | |
| 2049 | + | |
| 2050 | + | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
1974 | 2056 | | |
1975 | 2057 | | |
1976 | | - | |
1977 | | - | |
1978 | | - | |
1979 | | - | |
1980 | | - | |
1981 | | - | |
1982 | | - | |
1983 | | - | |
| 2058 | + | |
| 2059 | + | |
| 2060 | + | |
| 2061 | + | |
| 2062 | + | |
| 2063 | + | |
| 2064 | + | |
| 2065 | + | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
| 2070 | + | |
1984 | 2071 | | |
1985 | 2072 | | |
| 2073 | + | |
| 2074 | + | |
1986 | 2075 | | |
1987 | 2076 | | |
1988 | 2077 | | |
| |||
2181 | 2270 | | |
2182 | 2271 | | |
2183 | 2272 | | |
2184 | | - | |
| 2273 | + | |
2185 | 2274 | | |
2186 | 2275 | | |
2187 | 2276 | | |
| |||
2751 | 2840 | | |
2752 | 2841 | | |
2753 | 2842 | | |
2754 | | - | |
| 2843 | + | |
2755 | 2844 | | |
2756 | 2845 | | |
2757 | 2846 | | |
| |||
2828 | 2917 | | |
2829 | 2918 | | |
2830 | 2919 | | |
2831 | | - | |
| 2920 | + | |
2832 | 2921 | | |
2833 | 2922 | | |
2834 | 2923 | | |
| |||
5089 | 5178 | | |
5090 | 5179 | | |
5091 | 5180 | | |
5092 | | - | |
| 5181 | + | |
| 5182 | + | |
| 5183 | + | |
| 5184 | + | |
| 5185 | + | |
| 5186 | + | |
5093 | 5187 | | |
5094 | 5188 | | |
5095 | 5189 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4239 | 4239 | | |
4240 | 4240 | | |
4241 | 4241 | | |
4242 | | - | |
4243 | | - | |
4244 | 4242 | | |
4245 | 4243 | | |
4246 | 4244 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2647 | 2647 | | |
2648 | 2648 | | |
2649 | 2649 | | |
2650 | | - | |
| 2650 | + | |
2651 | 2651 | | |
2652 | 2652 | | |
2653 | 2653 | | |
| |||
0 commit comments