LTP GCOV extension - code coverage report
Current view: directory - storage/maria - ma_delete_table.c
Test: maria-mtr.html
Date: 2009-03-04 Instrumented lines: 17
Code covered: 64.7 % Executed lines: 11

       1                 : /* Copyright (C) 2006 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
       2                 : 
       3                 :    This program is free software; you can redistribute it and/or modify
       4                 :    it under the terms of the GNU General Public License as published by
       5                 :    the Free Software Foundation; version 2 of the License.
       6                 : 
       7                 :    This program is distributed in the hope that it will be useful,
       8                 :    but WITHOUT ANY WARRANTY; without even the implied warranty of
       9                 :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      10                 :    GNU General Public License for more details.
      11                 : 
      12                 :    You should have received a copy of the GNU General Public License
      13                 :    along with this program; if not, write to the Free Software
      14                 :    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
      15                 : 
      16                 : #include "ma_fulltext.h"
      17                 : #include "trnman_public.h"
      18                 : 
      19                 : /**
      20                 :    @brief drops (deletes) a table
      21                 : 
      22                 :    @param  name             table's name
      23                 : 
      24                 :    @return Operation status
      25                 :      @retval 0      ok
      26                 :      @retval 1      error
      27                 : */
      28                 : 
      29                 : int maria_delete_table(const char *name)
      30               9 : {
      31                 :   char from[FN_REFLEN];
      32                 : #ifdef USE_RAID
      33                 :   uint raid_type=0,raid_chunks=0;
      34                 : #endif
      35                 :   MARIA_HA *info;
      36                 :   myf sync_dir;
      37               9 :   DBUG_ENTER("maria_delete_table");
      38                 : 
      39                 : #ifdef EXTRA_DEBUG
      40               9 :   _ma_check_table_is_closed(name,"delete");
      41                 : #endif
      42                 :   /** @todo LOCK take X-lock on table */
      43                 :   /*
      44                 :     We need to know if this table is transactional.
      45                 :     When built with RAID support, we also need to determine if this table
      46                 :     makes use of the raid feature. If yes, we need to remove all raid
      47                 :     chunks. This is done with my_raid_delete(). Unfortunately it is
      48                 :     necessary to open the table just to check this. We use
      49                 :     'open_for_repair' to be able to open even a crashed table. If even
      50                 :     this open fails, we assume no raid configuration for this table
      51                 :     and try to remove the normal data file only. This may however
      52                 :     leave the raid chunks behind.
      53                 :   */
      54               9 :   if (!(info= maria_open(name, O_RDONLY, HA_OPEN_FOR_REPAIR)))
      55                 :   {
      56                 : #ifdef USE_RAID
      57                 :     raid_type= 0;
      58                 : #endif
      59               0 :     sync_dir= 0;
      60                 :   }
      61                 :   else
      62                 :   {
      63                 : #ifdef USE_RAID
      64                 :     raid_type=      info->s->base.raid_type;
      65                 :     raid_chunks=    info->s->base.raid_chunks;
      66                 : #endif
      67               9 :     sync_dir= (info->s->now_transactional && !info->s->temporary &&
      68                 :                !maria_in_recovery) ?
      69                 :       MY_SYNC_DIR : 0;
      70               9 :     maria_close(info);
      71                 :   }
      72                 : 
      73               9 :   if (sync_dir)
      74                 :   {
      75                 :     /*
      76                 :       For this log record to be of any use for Recovery, we need the upper
      77                 :       MySQL layer to be crash-safe in DDLs.
      78                 :       For now this record can serve when we apply logs to a backup, so we sync
      79                 :       it.
      80                 :     */
      81                 :     LSN lsn;
      82                 :     LEX_CUSTRING log_array[TRANSLOG_INTERNAL_PARTS + 1];
      83               0 :     log_array[TRANSLOG_INTERNAL_PARTS + 0].str= (uchar*)name;
      84               0 :     log_array[TRANSLOG_INTERNAL_PARTS + 0].length= strlen(name) + 1;
      85               0 :     if (unlikely(translog_write_record(&lsn, LOGREC_REDO_DROP_TABLE,
      86                 :                                        &dummy_transaction_object, NULL,
      87                 :                                        (translog_size_t)
      88                 :                                        log_array[TRANSLOG_INTERNAL_PARTS +
      89                 :                                                  0].length,
      90                 :                                        sizeof(log_array)/sizeof(log_array[0]),
      91                 :                                        log_array, NULL, NULL) ||
      92                 :                  translog_flush(lsn)))
      93               0 :       DBUG_RETURN(1);
      94                 :   }
      95                 : 
      96               9 :   fn_format(from,name,"",MARIA_NAME_IEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT);
      97               9 :   if (my_delete_with_symlink(from, MYF(MY_WME | sync_dir)))
      98               0 :     DBUG_RETURN(my_errno);
      99               9 :   fn_format(from,name,"",MARIA_NAME_DEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT);
     100                 : #ifdef USE_RAID
     101                 :   if (raid_type)
     102                 :     DBUG_RETURN(my_raid_delete(from, raid_chunks, MYF(MY_WME | sync_dir)) ?
     103                 :                 my_errno : 0);
     104                 : #endif
     105               9 :   DBUG_RETURN(my_delete_with_symlink(from, MYF(MY_WME | sync_dir)) ?
     106                 :               my_errno : 0);
     107                 : }

Generated by: LTP GCOV extension version 1.4