diff --recursive -u orig5037/innobase/include/srv0srv.h mysql-5.0.37/innobase/include/srv0srv.h --- orig5037/innobase/include/srv0srv.h 2007-03-05 11:21:39.000000000 -0800 +++ mysql-5.0.37/innobase/include/srv0srv.h 2008-10-02 06:10:22.000000000 -0700 @@ -79,6 +79,10 @@ extern ulint srv_log_buffer_size; extern ulong srv_flush_log_at_trx_commit; +/* When this event is reset we do not allow any file writes to +take place. */ +extern os_event_t srv_allow_writes_event; + extern byte srv_latin1_ordering[256];/* The sort order table of the latin1 character set */ extern ulint srv_pool_size; diff --recursive -u orig5037/innobase/os/os0file.c mysql-5.0.37/innobase/os/os0file.c --- orig5037/innobase/os/os0file.c 2007-03-05 11:21:03.000000000 -0800 +++ mysql-5.0.37/innobase/os/os0file.c 2008-10-02 06:10:22.000000000 -0700 @@ -518,6 +518,7 @@ /*========================*/ /* out: temporary file handle, or NULL on error */ { + os_event_wait(srv_allow_writes_event); #ifdef __NETWARE__ FILE* file = tmpfile(); #else /* __NETWARE__ */ @@ -832,6 +833,7 @@ ibool fail_if_exists) /* in: if TRUE, pre-existing directory is treated as an error. */ { + os_event_wait(srv_allow_writes_event); #ifdef __WIN__ BOOL rcode; @@ -883,6 +885,8 @@ OS_FILE_READ_WRITE */ ibool* success)/* out: TRUE if succeed, FALSE if error */ { + if (create_mode != OS_FILE_OPEN && create_mode != OS_FILE_OPEN_RAW) + os_event_wait(srv_allow_writes_event); #ifdef __WIN__ os_file_t file; DWORD create_flag; @@ -1024,6 +1028,8 @@ used by a backup program reading the file */ ibool* success)/* out: TRUE if succeed, FALSE if error */ { + if (create_mode != OS_FILE_OPEN && create_mode != OS_FILE_OPEN_RAW) + os_event_wait(srv_allow_writes_event); #ifdef __WIN__ os_file_t file; DWORD create_flag; @@ -1145,6 +1151,8 @@ ulint type, /* in: OS_DATA_FILE or OS_LOG_FILE */ ibool* success)/* out: TRUE if succeed, FALSE if error */ { + if (create_mode != OS_FILE_OPEN && create_mode != OS_FILE_OPEN_RAW) + os_event_wait(srv_allow_writes_event); #ifdef __WIN__ os_file_t file; DWORD share_mode = FILE_SHARE_READ; @@ -1359,6 +1367,7 @@ /* out: TRUE if success */ const char* name) /* in: file path as a null-terminated string */ { + os_event_wait(srv_allow_writes_event); #ifdef __WIN__ BOOL ret; ulint count = 0; @@ -1420,6 +1429,7 @@ /* out: TRUE if success */ const char* name) /* in: file path as a null-terminated string */ { + os_event_wait(srv_allow_writes_event); #ifdef __WIN__ BOOL ret; ulint count = 0; @@ -1485,6 +1495,7 @@ string */ const char* newpath)/* in: new file path */ { + os_event_wait(srv_allow_writes_event); #ifdef __WIN__ BOOL ret; @@ -1755,6 +1766,7 @@ /* out: TRUE if success */ FILE* file) /* in: file to be truncated */ { + os_event_wait(srv_allow_writes_event); #ifdef __WIN__ HANDLE h = (HANDLE) _get_osfhandle(fileno(file)); return(SetEndOfFile(h)); @@ -1772,6 +1784,7 @@ /* out: TRUE if success */ os_file_t file) /* in, own: handle to a file */ { + os_event_wait(srv_allow_writes_event); #ifdef __WIN__ BOOL ret; @@ -2317,6 +2330,7 @@ offset */ ulint n) /* in: number of bytes to write */ { + os_event_wait(srv_allow_writes_event); #ifdef __WIN__ BOOL ret; DWORD len; diff --recursive -u orig5037/innobase/srv/srv0srv.c mysql-5.0.37/innobase/srv/srv0srv.c --- orig5037/innobase/srv/srv0srv.c 2007-03-05 11:21:12.000000000 -0800 +++ mysql-5.0.37/innobase/srv/srv0srv.c 2008-10-02 06:10:28.000000000 -0700 @@ -115,6 +115,8 @@ ulint srv_log_buffer_size = ULINT_MAX; /* size in database pages */ ulong srv_flush_log_at_trx_commit = 1; +os_event_t srv_allow_writes_event; + byte srv_latin1_ordering[256] /* The sort order table of the latin1 character set. The following table is the MySQL order as of Feb 10th, 2002 */ @@ -951,8 +953,17 @@ conc_slot->reserved = FALSE; conc_slot->event = os_event_create(NULL); ut_a(conc_slot->event); - } -} + } + + /* + Writes have to be enabled on init or else we hang. Thus, we + always set the event here regardless of innobase_disallow_writes. + That flag will always be 0 at this point because it isn't settable + via my.cnf or command line arg. + */ + srv_allow_writes_event = os_event_create(NULL); + os_event_set(srv_allow_writes_event); +} /************************************************************************* Frees the OS fast mutex created in srv_init(). */ diff --recursive -u orig5037/sql/ha_innodb.cc mysql-5.0.37/sql/ha_innodb.cc --- orig5037/sql/ha_innodb.cc 2007-03-05 11:21:41.000000000 -0800 +++ mysql-5.0.37/sql/ha_innodb.cc 2008-10-02 06:10:28.000000000 -0700 @@ -174,6 +174,7 @@ my_bool innobase_locks_unsafe_for_binlog = FALSE; my_bool innobase_rollback_on_timeout = FALSE; my_bool innobase_create_status_file = FALSE; +my_bool innobase_disallow_writes = FALSE; /* Must always init to FALSE. */ static char *internal_innobase_data_file_path = NULL; @@ -7322,4 +7323,17 @@ (cursor_view_t*) curview); } +/************************************************************************** +Controls whether InnoDB is in no-write mode. */ + +void +innobase_set_disallow_writes(my_bool disallow_writes) +{ + ut_a(srv_allow_writes_event); + if (disallow_writes) + os_event_reset(srv_allow_writes_event); + else + os_event_set(srv_allow_writes_event); +} + #endif /* HAVE_INNOBASE_DB */ diff --recursive -u orig5037/sql/ha_innodb.h mysql-5.0.37/sql/ha_innodb.h --- orig5037/sql/ha_innodb.h 2007-03-05 11:21:41.000000000 -0800 +++ mysql-5.0.37/sql/ha_innodb.h 2008-10-02 06:10:22.000000000 -0700 @@ -216,7 +216,8 @@ innobase_use_native_aio, innobase_file_per_table, innobase_locks_unsafe_for_binlog, innobase_rollback_on_timeout, - innobase_create_status_file; + innobase_create_status_file, + innobase_disallow_writes; extern my_bool innobase_very_fast_shutdown; /* set this to 1 just before calling innobase_end() if you want InnoDB to shut down without @@ -334,3 +335,11 @@ innobase_set_cursor_view( /*=====================*/ void* curview); /* in: Consistent read view to be set */ + +/*********************************************************************** +Toggle the dynamic option of putting InnoDB into no-write mode. */ + +void +innobase_set_disallow_writes( +/*=========================*/ + my_bool disallow_writes); /* in: True to turn off writing */ diff --recursive -u orig5037/sql/set_var.cc mysql-5.0.37/sql/set_var.cc --- orig5037/sql/set_var.cc 2007-03-05 11:21:24.000000000 -0800 +++ mysql-5.0.37/sql/set_var.cc 2008-10-02 06:10:22.000000000 -0700 @@ -116,6 +116,7 @@ static void fix_thd_mem_root(THD *thd, enum_var_type type); static void fix_trans_mem_root(THD *thd, enum_var_type type); static void fix_server_id(THD *thd, enum_var_type type); +static void after_update_disallow_writes(THD *thd, enum_var_type type); static KEY_CACHE *create_key_cache(const char *name, uint length); void fix_sql_mode_var(THD *thd, enum_var_type type); static byte *get_error_count(THD *thd); @@ -431,6 +432,9 @@ &SV::net_wait_timeout); #ifdef HAVE_INNOBASE_DB +sys_var_bool_ptr sys_innodb_disallow_writes("innodb_disallow_writes", + &innobase_disallow_writes, + after_update_disallow_writes); sys_var_long_ptr sys_innodb_fast_shutdown("innodb_fast_shutdown", &innobase_fast_shutdown); sys_var_long_ptr sys_innodb_max_dirty_pages_pct("innodb_max_dirty_pages_pct", @@ -777,6 +781,7 @@ &sys_version_compile_machine, &sys_version_compile_os, #ifdef HAVE_INNOBASE_DB + &sys_innodb_disallow_writes, &sys_innodb_fast_shutdown, &sys_innodb_max_dirty_pages_pct, &sys_innodb_max_purge_lag, @@ -894,6 +899,8 @@ {sys_innodb_concurrency_tickets.name, (char*) &sys_innodb_concurrency_tickets, SHOW_SYS}, {"innodb_data_file_path", (char*) &innobase_data_file_path, SHOW_CHAR_PTR}, {"innodb_data_home_dir", (char*) &innobase_data_home_dir, SHOW_CHAR_PTR}, + {sys_innodb_disallow_writes.name, (char*) &sys_innodb_disallow_writes, + SHOW_SYS}, {"innodb_doublewrite", (char*) &innobase_use_doublewrite, SHOW_MY_BOOL}, {sys_innodb_fast_shutdown.name,(char*) &sys_innodb_fast_shutdown, SHOW_SYS}, {"innodb_file_io_threads", (char*) &innobase_file_io_threads, SHOW_LONG }, @@ -1426,6 +1433,17 @@ server_id_supplied = 1; } +#ifdef HAVE_INNOBASE_DB +static void after_update_disallow_writes(THD *thd, enum_var_type type) +{ + DBUG_ENTER("after_update_disallow_writes"); + DBUG_PRINT("info",("innobase_disallow_writes=%d", innobase_disallow_writes)); + + innobase_set_disallow_writes(innobase_disallow_writes); + + DBUG_VOID_RETURN; +} +#endif sys_var_long_ptr:: sys_var_long_ptr(const char *name_arg, ulong *value_ptr, diff --recursive -u orig5037/sql/set_var.h mysql-5.0.37/sql/set_var.h --- orig5037/sql/set_var.h 2007-03-05 11:21:22.000000000 -0800 +++ mysql-5.0.37/sql/set_var.h 2008-10-02 06:10:22.000000000 -0700 @@ -142,8 +142,9 @@ { public: my_bool *value; - sys_var_bool_ptr(const char *name_arg, my_bool *value_arg) - :sys_var(name_arg),value(value_arg) + sys_var_bool_ptr(const char *name_arg, my_bool *value_arg, + sys_after_update_func after_update_arg= NULL) + :sys_var(name_arg, after_update_arg),value(value_arg) {} bool check(THD *thd, set_var *var) {