Commit 525d2ec
committed
Use read lock after truncate checkpoint to prevent races
The previous implementation attempted to hold checkpoint locks during file copy by adding a keep_lock param to the checkpoint function.
However, checkpoint can have multiple early exit paths like empty WAL where no lock is acquired. Also, it clutters the checkpoint function.
This implementation executes TRUNCATE checkpoint and then acquires read lock on WAL before copying database file. This ensures new data is written
to WAL and new Checkpoint can not be taken before this read lock is released.
Signed-off-by: Prateek Singh Rathore <[email protected]>1 parent 510cb7b commit 525d2ec
2 files changed
+32
-52
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2025 | 2025 | | |
2026 | 2026 | | |
2027 | 2027 | | |
2028 | | - | |
2029 | | - | |
2030 | | - | |
| 2028 | + | |
| 2029 | + | |
| 2030 | + | |
| 2031 | + | |
| 2032 | + | |
2031 | 2033 | | |
2032 | | - | |
| 2034 | + | |
2033 | 2035 | | |
2034 | 2036 | | |
2035 | 2037 | | |
| |||
2064 | 2066 | | |
2065 | 2067 | | |
2066 | 2068 | | |
2067 | | - | |
2068 | | - | |
2069 | | - | |
2070 | | - | |
2071 | | - | |
2072 | | - | |
2073 | | - | |
2074 | | - | |
| 2069 | + | |
| 2070 | + | |
| 2071 | + | |
| 2072 | + | |
| 2073 | + | |
2075 | 2074 | | |
| 2075 | + | |
| 2076 | + | |
| 2077 | + | |
| 2078 | + | |
| 2079 | + | |
| 2080 | + | |
| 2081 | + | |
| 2082 | + | |
| 2083 | + | |
| 2084 | + | |
| 2085 | + | |
| 2086 | + | |
| 2087 | + | |
| 2088 | + | |
2076 | 2089 | | |
2077 | 2090 | | |
2078 | 2091 | | |
2079 | 2092 | | |
2080 | | - | |
2081 | | - | |
| 2093 | + | |
2082 | 2094 | | |
2083 | 2095 | | |
| 2096 | + | |
| 2097 | + | |
| 2098 | + | |
2084 | 2099 | | |
2085 | 2100 | | |
2086 | 2101 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2856 | 2856 | | |
2857 | 2857 | | |
2858 | 2858 | | |
2859 | | - | |
2860 | | - | |
2861 | | - | |
2862 | | - | |
2863 | | - | |
2864 | | - | |
2865 | | - | |
2866 | | - | |
2867 | | - | |
2868 | | - | |
2869 | | - | |
2870 | | - | |
2871 | | - | |
2872 | | - | |
2873 | | - | |
2874 | | - | |
2875 | | - | |
2876 | | - | |
2877 | | - | |
2878 | | - | |
2879 | | - | |
2880 | | - | |
2881 | 2859 | | |
2882 | 2860 | | |
2883 | 2861 | | |
2884 | 2862 | | |
2885 | 2863 | | |
2886 | 2864 | | |
2887 | | - | |
| 2865 | + | |
2888 | 2866 | | |
2889 | 2867 | | |
2890 | 2868 | | |
2891 | 2869 | | |
2892 | | - | |
2893 | 2870 | | |
2894 | 2871 | | |
2895 | 2872 | | |
| |||
3017 | 2994 | | |
3018 | 2995 | | |
3019 | 2996 | | |
3020 | | - | |
3021 | | - | |
3022 | | - | |
3023 | | - | |
| 2997 | + | |
| 2998 | + | |
3024 | 2999 | | |
3025 | 3000 | | |
3026 | 3001 | | |
| |||
3117 | 3092 | | |
3118 | 3093 | | |
3119 | 3094 | | |
3120 | | - | |
3121 | | - | |
3122 | | - | |
3123 | | - | |
3124 | | - | |
3125 | | - | |
3126 | | - | |
3127 | | - | |
3128 | | - | |
3129 | | - | |
3130 | 3095 | | |
3131 | 3096 | | |
3132 | 3097 | | |
| |||
0 commit comments