11/*
2- Copyright (c) 2005, 2011 , Oracle and/or its affiliates. All rights reserved.
2+ Copyright (c) 2005, 2012 , Oracle and/or its affiliates. All rights reserved.
33
44 This program is free software; you can redistribute it and/or modify
55 it under the terms of the GNU General Public License as published by
@@ -135,9 +135,14 @@ bool Partition_share::init(uint num_parts)
135135 auto_inc_initialized= false ;
136136 partition_name_hash_initialized= false ;
137137 next_auto_inc_val= 0 ;
138- partitions_shares = new Parts_share_storage (num_parts) ;
139- if (!partitions_shares )
138+ partitions_share_refs = new Parts_share_refs ;
139+ if (!partitions_share_refs )
140140 DBUG_RETURN (true );
141+ if (partitions_share_refs->init (num_parts))
142+ {
143+ delete partitions_share_refs;
144+ DBUG_RETURN (true );
145+ }
141146 DBUG_RETURN (false );
142147}
143148
@@ -334,7 +339,7 @@ void ha_partition::init_handler_variables()
334339 m_is_clone_of= NULL ;
335340 m_clone_mem_root= NULL ;
336341 part_share= NULL ;
337- m_new_partitions_shares .empty ();
342+ m_new_partitions_share_refs .empty ();
338343
339344#ifdef DONT_HAVE_TO_BE_INITALIZED
340345 m_start_key.flag = 0 ;
@@ -363,8 +368,8 @@ const char *ha_partition::table_type() const
363368ha_partition::~ha_partition ()
364369{
365370 DBUG_ENTER (" ha_partition::~ha_partition()" );
366- if (m_new_partitions_shares .elements )
367- m_new_partitions_shares .delete_elements ();
371+ if (m_new_partitions_share_refs .elements )
372+ m_new_partitions_share_refs .delete_elements ();
368373 if (m_file != NULL )
369374 {
370375 uint i;
@@ -1707,16 +1712,18 @@ int ha_partition::change_partitions(HA_CREATE_INFO *create_info,
17071712 part_elem->part_state == PART_TO_BE_ADDED)
17081713 {
17091714 uint j= 0 ;
1710- Parts_share_storage *p_share_storage ;
1715+ Parts_share_refs *p_share_refs ;
17111716 /*
17121717 The Handler_shares for each partition's handler can be allocated
17131718 within this handler, since there will not be any more instances of the
17141719 new partitions, until the table is reopened after the ALTER succeeded.
17151720 */
1716- p_share_storage = new Parts_share_storage (num_subparts) ;
1717- if (!p_share_storage )
1721+ p_share_refs = new Parts_share_refs ;
1722+ if (!p_share_refs )
17181723 DBUG_RETURN (HA_ERR_OUT_OF_MEM);
1719- if (m_new_partitions_shares.push_back (p_share_storage))
1724+ if (p_share_refs->init (num_subparts))
1725+ DBUG_RETURN (HA_ERR_OUT_OF_MEM);
1726+ if (m_new_partitions_share_refs.push_back (p_share_refs))
17201727 DBUG_RETURN (HA_ERR_OUT_OF_MEM);
17211728 do
17221729 {
@@ -1729,7 +1736,7 @@ int ha_partition::change_partitions(HA_CREATE_INFO *create_info,
17291736 mem_alloc_error (sizeof (handler));
17301737 DBUG_RETURN (HA_ERR_OUT_OF_MEM);
17311738 }
1732- if ((*new_file)->set_ha_share_storage (&p_share_storage ->ha_shares [j]))
1739+ if ((*new_file)->set_ha_share_ref (&p_share_refs ->ha_shares [j]))
17331740 {
17341741 DBUG_RETURN (HA_ERR_OUT_OF_MEM);
17351742 }
@@ -2842,27 +2849,26 @@ bool ha_partition::populate_partition_name_hash()
28422849 @retval false Sucess
28432850*/
28442851
2845- bool ha_partition::set_ha_share_storage (Handler_share **ha_share_arg)
2852+ bool ha_partition::set_ha_share_ref (Handler_share **ha_share_arg)
28462853{
28472854 Handler_share **ha_shares;
28482855 uint i;
2849- DBUG_ENTER (" ha_partition::set_ha_share_storage " );
2856+ DBUG_ENTER (" ha_partition::set_ha_share_ref " );
28502857
2851- DBUG_ASSERT (!ha_share);
2852- DBUG_ASSERT (ha_share_arg);
28532858 DBUG_ASSERT (!part_share);
28542859 DBUG_ASSERT (table_share);
28552860 DBUG_ASSERT (!m_is_clone_of);
28562861 DBUG_ASSERT (m_tot_parts);
2857- ha_share= ha_share_arg;
2862+ if (handler::set_ha_share_ref (ha_share_arg))
2863+ DBUG_RETURN (true );
28582864 if (!(part_share= get_share ()))
28592865 DBUG_RETURN (true );
2860- DBUG_ASSERT (part_share->partitions_shares );
2861- DBUG_ASSERT (part_share->partitions_shares ->num_parts >= m_tot_parts);
2862- ha_shares= part_share->partitions_shares ->ha_shares ;
2866+ DBUG_ASSERT (part_share->partitions_share_refs );
2867+ DBUG_ASSERT (part_share->partitions_share_refs ->num_parts >= m_tot_parts);
2868+ ha_shares= part_share->partitions_share_refs ->ha_shares ;
28632869 for (i= 0 ; i < m_tot_parts; i++)
28642870 {
2865- if (m_file[i]->set_ha_share_storage (&ha_shares[i]))
2871+ if (m_file[i]->set_ha_share_ref (&ha_shares[i]))
28662872 DBUG_RETURN (true );
28672873 }
28682874 DBUG_RETURN (false );
@@ -2882,34 +2888,27 @@ bool ha_partition::set_ha_share_storage(Handler_share **ha_share_arg)
28822888
28832889Partition_share *ha_partition::get_share ()
28842890{
2885- Handler_share *tmp_ha_share;
2886- Partition_share *tmp_part_share;
2891+ Partition_share *tmp_share;
28872892 DBUG_ENTER (" ha_partition::get_share" );
28882893 DBUG_ASSERT (table_share);
28892894
2890- if (!(tmp_ha_share= get_ha_share_ptr ()))
2895+ lock_shared_ha_data ();
2896+ if (!(tmp_share= static_cast <Partition_share*>(get_ha_share_ptr ())))
28912897 {
2892- tmp_part_share = new Partition_share;
2893- if (!tmp_part_share )
2898+ tmp_share = new Partition_share;
2899+ if (!tmp_share )
28942900 goto err;
2895- if (tmp_part_share ->init (m_tot_parts))
2901+ if (tmp_share ->init (m_tot_parts))
28962902 {
2897- delete tmp_part_share;
2903+ delete tmp_share;
2904+ tmp_share= NULL ;
28982905 goto err;
28992906 }
2900- part_share= tmp_part_share;
2901-
2902- set_ha_share_ptr (static_cast <Handler_share*>(tmp_part_share));
2903- DBUG_RETURN (tmp_part_share);
2907+ set_ha_share_ptr (static_cast <Handler_share*>(tmp_share));
29042908 }
2905-
2906- DBUG_RETURN (static_cast <Partition_share*>(tmp_ha_share));
29072909err:
2908- /*
2909- LOCK_ha_data is taken in get_ha_share_ptr and not released if not found.
2910- */
29112910 unlock_shared_ha_data ();
2912- DBUG_RETURN (NULL );
2911+ DBUG_RETURN (tmp_share );
29132912}
29142913
29152914
@@ -3184,7 +3183,7 @@ handler *ha_partition::clone(const char *name, MEM_ROOT *mem_root)
31843183
31853184 /*
31863185 We will not clone each partition's handler here, it will be done in
3187- ha_partition::open() for clones. Also set_ha_share_storage is not needed
3186+ ha_partition::open() for clones. Also set_ha_share_ref is not needed
31883187 here, since 1) ha_share is copied in the constructor used above
31893188 2) each partition's cloned handler will set it from its original.
31903189 */
0 commit comments