]> git.pld-linux.org Git - packages/mysql.git/blob - mysql-innodb_fast_shutdown.patch
remove id expansion
[packages/mysql.git] / mysql-innodb_fast_shutdown.patch
1 # name       : innodb_fast_shutdown
2 # introduced : 13
3 # maintainer : Alexey
4 #
5 # Shutting down XtraDB takes uninterruptible sleep()s up to 10
6 # seconds, even when there is no actual work to do during shutdown.
7 #
8 # This patch removes most such delays during shutdown, as found using
9 # PMP. This makes standard test run very close in speed to with
10 # --loose-innodb-fast-shutdown=2, and greatly speeds up running the test
11 # suite.
12 #
13 # The patch also implements os_event_wait_time() for POSIX systems.
14 --- /dev/null
15 +++ b/COPYING.innodb_fast_shutdown
16 @@ -0,0 +1,10 @@
17 +Copyright (c) 2010, Kristian Nielsen
18 +All rights reserved.
19 +
20 +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
21 +
22 +    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
23 +    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
24 +    * Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
25 +
26 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 --- a/storage/innodb_plugin/include/os0sync.h
28 +++ b/storage/innodb_plugin/include/os0sync.h
29 @@ -189,14 +189,14 @@
30  
31  /**********************************************************//**
32  Waits for an event object until it is in the signaled state or
33 -a timeout is exceeded. In Unix the timeout is always infinite.
34 +a timeout is exceeded.
35  @return        0 if success, OS_SYNC_TIME_EXCEEDED if timeout was exceeded */
36  UNIV_INTERN
37  ulint
38  os_event_wait_time(
39  /*===============*/
40         os_event_t      event,  /*!< in: event to wait */
41 -       ulint           time);  /*!< in: timeout in microseconds, or
42 +       ulint           wtime); /*!< in: timeout in microseconds, or
43                                 OS_SYNC_INFINITE_TIME */
44  #ifdef __WIN__
45  /**********************************************************//**
46 --- a/storage/innodb_plugin/include/srv0srv.h
47 +++ b/storage/innodb_plugin/include/srv0srv.h
48 @@ -57,6 +57,9 @@
49  thread starts running */
50  extern os_event_t      srv_lock_timeout_thread_event;
51  
52 +/* This event is set at shutdown to wakeup threads from sleep */
53 +extern os_event_t      srv_shutdown_event;
54 +
55  /* If the last data file is auto-extended, we add this many pages to it
56  at a time */
57  #define SRV_AUTO_EXTEND_INCREMENT      \
58 --- a/storage/innodb_plugin/log/log0log.c
59 +++ b/storage/innodb_plugin/log/log0log.c
60 @@ -3103,6 +3103,7 @@
61         algorithm only works if the server is idle at shutdown */
62  
63         srv_shutdown_state = SRV_SHUTDOWN_CLEANUP;
64 +       os_event_set(srv_shutdown_event);
65  loop:
66         os_thread_sleep(100000);
67  
68 --- a/storage/innodb_plugin/os/os0sync.c
69 +++ b/storage/innodb_plugin/os/os0sync.c
70 @@ -31,6 +31,9 @@
71  
72  #ifdef __WIN__
73  #include <windows.h>
74 +#else
75 +#include <sys/time.h>
76 +#include <time.h>
77  #endif
78  
79  #include "ut0mem.h"
80 @@ -407,14 +410,14 @@
81  
82  /**********************************************************//**
83  Waits for an event object until it is in the signaled state or
84 -a timeout is exceeded. In Unix the timeout is always infinite.
85 +a timeout is exceeded.
86  @return        0 if success, OS_SYNC_TIME_EXCEEDED if timeout was exceeded */
87  UNIV_INTERN
88  ulint
89  os_event_wait_time(
90  /*===============*/
91         os_event_t      event,  /*!< in: event to wait */
92 -       ulint           time)   /*!< in: timeout in microseconds, or
93 +       ulint           wtime)  /*!< in: timeout in microseconds, or
94                                 OS_SYNC_INFINITE_TIME */
95  {
96  #ifdef __WIN__
97 @@ -422,8 +425,8 @@
98  
99         ut_a(event);
100  
101 -       if (time != OS_SYNC_INFINITE_TIME) {
102 -               err = WaitForSingleObject(event->handle, (DWORD) time / 1000);
103 +       if (wtime != OS_SYNC_INFINITE_TIME) {
104 +               err = WaitForSingleObject(event->handle, (DWORD) wtime / 1000);
105         } else {
106                 err = WaitForSingleObject(event->handle, INFINITE);
107         }
108 @@ -439,13 +442,47 @@
109                 return(1000000); /* dummy value to eliminate compiler warn. */
110         }
111  #else
112 -       UT_NOT_USED(time);
113 +       int             err;
114 +       int             ret = 0;
115 +       ulint           tmp;
116 +       ib_int64_t      old_count;
117 +       struct timeval  tv_start;
118 +       struct timespec timeout;
119 +
120 +       if (wtime == OS_SYNC_INFINITE_TIME) {
121 +               os_event_wait(event);
122 +               return 0;
123 +       }
124 +
125 +       /* Compute the absolute point in time at which to time out. */
126 +       gettimeofday(&tv_start, NULL);
127 +       tmp = tv_start.tv_usec + wtime;
128 +       timeout.tv_sec = tv_start.tv_sec + (tmp / 1000000);
129 +       timeout.tv_nsec = (tmp % 1000000) * 1000;
130 +
131 +       os_fast_mutex_lock(&(event->os_mutex));
132 +       old_count = event->signal_count;
133  
134 -       /* In Posix this is just an ordinary, infinite wait */
135 +       for (;;) {
136 +               if (event->is_set == TRUE || event->signal_count != old_count)
137 +                       break;
138 +
139 +               err = pthread_cond_timedwait(&(event->cond_var),
140 +                                            &(event->os_mutex), &timeout);
141 +               if (err == ETIMEDOUT) {
142 +                       ret = OS_SYNC_TIME_EXCEEDED;
143 +                       break;
144 +               }
145 +       }
146  
147 -       os_event_wait(event);
148 +       os_fast_mutex_unlock(&(event->os_mutex));
149 +
150 +       if (srv_shutdown_state == SRV_SHUTDOWN_EXIT_THREADS) {
151 +
152 +               os_thread_exit(NULL);
153 +       }
154  
155 -       return(0);
156 +       return ret;
157  #endif
158  }
159  
160 --- a/storage/innodb_plugin/srv/srv0srv.c
161 +++ b/storage/innodb_plugin/srv/srv0srv.c
162 @@ -722,6 +722,8 @@
163  
164  UNIV_INTERN os_event_t srv_lock_timeout_thread_event;
165  
166 +UNIV_INTERN os_event_t srv_shutdown_event;
167 +
168  UNIV_INTERN srv_sys_t* srv_sys = NULL;
169  
170  /* padding to prevent other memory update hotspots from residing on
171 @@ -1027,6 +1029,7 @@
172         }
173  
174         srv_lock_timeout_thread_event = os_event_create(NULL);
175 +       srv_shutdown_event = os_event_create(NULL);
176  
177         for (i = 0; i < SRV_MASTER + 1; i++) {
178                 srv_n_threads_active[i] = 0;
179 @@ -2256,7 +2259,7 @@
180         /* Wake up every 5 seconds to see if we need to print
181         monitor information. */
182  
183 -       os_thread_sleep(5000000);
184 +       os_event_wait_time(srv_shutdown_event, 5000000);
185  
186         current_time = time(NULL);
187  
188 @@ -2398,7 +2401,7 @@
189         /* When someone is waiting for a lock, we wake up every second
190         and check if a timeout has passed for a lock wait */
191  
192 -       os_thread_sleep(1000000);
193 +       os_event_wait_time(srv_shutdown_event, 1000000);
194  
195         srv_lock_timeout_active = TRUE;
196  
197 @@ -2602,7 +2605,7 @@
198  
199         fflush(stderr);
200  
201 -       os_thread_sleep(1000000);
202 +       os_event_wait_time(srv_shutdown_event, 1000000);
203  
204         if (srv_shutdown_state < SRV_SHUTDOWN_CLEANUP) {
205  
206 @@ -2648,7 +2651,7 @@
207         last_dump_time = time(NULL);
208  
209  loop:
210 -       os_thread_sleep(5000000);
211 +       os_event_wait_time(srv_shutdown_event, 5000000);
212  
213         if (srv_shutdown_state >= SRV_SHUTDOWN_CLEANUP) {
214                 goto exit_func;
215 @@ -2831,7 +2834,7 @@
216                 if (!skip_sleep) {
217                 if (next_itr_time > cur_time) {
218  
219 -                       os_thread_sleep(ut_min(1000000, (next_itr_time - cur_time) * 1000));
220 +                       os_event_wait_time(srv_shutdown_event, ut_min(1000000, (next_itr_time - cur_time) * 1000));
221                         srv_main_sleeps++;
222  
223                         /*
224 @@ -3538,9 +3541,10 @@
225                 mutex_exit(&kernel_mutex);
226  
227                 sleep_ms = 10;
228 +               os_event_reset(srv_shutdown_event);
229         }
230  
231 -       os_thread_sleep( sleep_ms * 1000 );
232 +       os_event_wait_time(srv_shutdown_event, sleep_ms * 1000);
233  
234         history_len = trx_sys->rseg_history_len;
235         if (history_len > 1000)
This page took 0.086665 seconds and 3 git commands to generate.