From 5f7059219f0ef91854943fdeee51fb89dad18aee Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 4 Mar 2006 14:21:27 -0600 Subject: [PATCH] Bug #17720 Partition ALTER TABLE fails on rename of .MYI file Fix this by passing the HA_EXTRA_PREPARE_FOR_DELETE onto the newly added or about to be dropped partitions so they have an opportunity to close their OS file handle. client/mysqltest.c: prevent positive find of pattern when pattern has zero length (this has nothing to do with this bug fix) sql/ha_partition.cc: initialize m_new_file to NULL call new function prepare_for_delete for the HA_EXTRA_PREPARE_FOR_DELETE operation inside prepare_for_delete, loop over m_new_file and m_reorged_file if they are non-NULL sql/ha_partition.h: added decl for new prepare_for_delete function --- client/mysqltest.c | 1 + sql/ha_partition.cc | 41 ++++++++++++++++++++++++++++++++++++++++- sql/ha_partition.h | 1 + 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 46ec59e25c9..e6c84c18812 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -3736,6 +3736,7 @@ static void fix_win_paths(const char* val, int len) { const char** pattern= dynamic_element(&patterns, i, const char**); DBUG_PRINT("info", ("pattern: %s", *pattern)); + if (strlen(*pattern) == 0) continue; /* Search for the path in string */ while ((p= strstr(val, *pattern))) { diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index e7a324481db..059cc997e55 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -218,6 +218,7 @@ void ha_partition::init_handler_variables() m_engine_array= NULL; m_file= NULL; m_reorged_file= NULL; + m_new_file= NULL; m_reorged_parts= 0; m_added_file= NULL; m_tot_parts= 0; @@ -4680,11 +4681,13 @@ int ha_partition::extra(enum ha_extra_function operation) } /* Category 3), used by MyISAM handlers */ + case HA_EXTRA_PREPARE_FOR_DELETE: + DBUG_RETURN(prepare_for_delete()); + break; case HA_EXTRA_NORMAL: case HA_EXTRA_QUICK: case HA_EXTRA_NO_READCHECK: case HA_EXTRA_PREPARE_FOR_UPDATE: - case HA_EXTRA_PREPARE_FOR_DELETE: case HA_EXTRA_FORCE_REOPEN: case HA_EXTRA_FLUSH_CACHE: { @@ -4793,6 +4796,41 @@ void ha_partition::prepare_extra_cache(uint cachesize) } +/* + Prepares our new and reorged handlers for rename or delete + + SYNOPSIS + prepare_for_delete() + + RETURN VALUE + >0 Error code + 0 Success +*/ + +int ha_partition::prepare_for_delete() +{ + int result= 0, tmp; + handler **file; + DBUG_ENTER("ha_partition::prepare_for_delete()"); + + if (m_new_file != NULL) + { + for (file= m_new_file; *file; file++) + if ((tmp= (*file)->extra(HA_EXTRA_PREPARE_FOR_DELETE))) + result= tmp; + for (file= m_reorged_file; *file; file++) + if ((tmp= (*file)->extra(HA_EXTRA_PREPARE_FOR_DELETE))) + result= tmp; + } + else + { + for (file= m_file; *file; file++) + if ((tmp= (*file)->extra(HA_EXTRA_PREPARE_FOR_DELETE))) + result= tmp; + } + DBUG_RETURN(result); +} + /* Call extra on all partitions @@ -4810,6 +4848,7 @@ int ha_partition::loop_extra(enum ha_extra_function operation) int result= 0, tmp; handler **file; DBUG_ENTER("ha_partition::loop_extra()"); + /* TODO, 5.2: this is where you could possibly add optimisations to add the bitmap _if_ a SELECT. diff --git a/sql/ha_partition.h b/sql/ha_partition.h index 40306ba7da8..f828cc65ed3 100644 --- a/sql/ha_partition.h +++ b/sql/ha_partition.h @@ -197,6 +197,7 @@ public: DBUG_RETURN(0); } private: + int prepare_for_delete(); int copy_partitions(ulonglong *copied, ulonglong *deleted); void cleanup_new_partition(uint part_count); int prepare_new_partition(TABLE *table, HA_CREATE_INFO *create_info,