~ubuntu-branches/ubuntu/maverick/mysql-5.1/maverick-proposed

« back to all changes in this revision

Viewing changes to storage/archive/ha_archive.cc

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 14:16:05 UTC
  • mto: This revision was merged to the branch mainline in revision 20.
  • Revision ID: package-import@ubuntu.com-20120222141605-nxlu9yzc6attylc2
Tags: upstream-5.1.61
ImportĀ upstreamĀ versionĀ 5.1.61

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2003 MySQL 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 */
 
1
/*
 
2
   Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
 
3
 
 
4
   This program is free software; you can redistribute it and/or
 
5
   modify it under the terms of the GNU General Public License
 
6
   as published by the Free Software Foundation; version 2 of
 
7
   the License.
 
8
 
 
9
   This program is distributed in the hope that it will be useful,
 
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
12
   GNU General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU General Public License
 
15
   along with this program; if not, write to the Free Software
 
16
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
 
17
*/
15
18
 
16
19
#ifdef USE_PRAGMA_IMPLEMENTATION
17
20
#pragma implementation        // gcc: Class implementation
757
760
       ptr != end ;
758
761
       ptr++)
759
762
  {
 
763
    if (!table->field[*ptr]->is_null())
760
764
      length += 2 + ((Field_blob*)table->field[*ptr])->get_length();
761
765
  }
762
766
 
864
868
       */
865
869
      azflush(&(share->archive_write), Z_SYNC_FLUSH);
866
870
      /*
867
 
        Set the position of the local read thread to the beginning postion.
 
871
        Set the position of the local read thread to the beginning position.
868
872
      */
869
873
      if (read_data_header(&archive))
870
874
      {
1107
1111
 
1108
1112
  /* Copy null bits */
1109
1113
  const uchar *ptr= record_buffer->buffer;
 
1114
  /*
 
1115
    Field::unpack() is not called when field is NULL. For VARCHAR
 
1116
    Field::unpack() only unpacks as much bytes as occupied by field
 
1117
    value. In these cases respective memory area on record buffer is
 
1118
    not initialized.
 
1119
 
 
1120
    These uninitialized areas may be accessed by CHECKSUM TABLE or
 
1121
    by optimizer using temporary table (BUG#12997905). We may remove
 
1122
    this memset() when they're fixed.
 
1123
  */
 
1124
  memset(record, 0, table->s->reclength);
1110
1125
  memcpy(record, ptr, table->s->null_bytes);
1111
1126
  ptr+= table->s->null_bytes;
1112
1127
  for (Field **field=table->field ; *field ; field++)
1113
1128
  {
1114
 
    if (!((*field)->is_null()))
 
1129
    if (!((*field)->is_null_in_record(record)))
1115
1130
    {
1116
1131
      ptr= (*field)->unpack(record + (*field)->offset(table->record[0]), ptr);
1117
1132
    }
1575
1590
{
1576
1591
  int rc= 0;
1577
1592
  const char *old_proc_info;
1578
 
  ha_rows count= share->rows_recorded;
 
1593
  ha_rows count;
1579
1594
  DBUG_ENTER("ha_archive::check");
1580
1595
 
1581
1596
  old_proc_info= thd_proc_info(thd, "Checking table");
 
1597
  pthread_mutex_lock(&share->mutex);
 
1598
  count= share->rows_recorded;
1582
1599
  /* Flush any waiting data */
1583
 
  pthread_mutex_lock(&share->mutex);
1584
 
  azflush(&(share->archive_write), Z_SYNC_FLUSH);
 
1600
  if (share->archive_write_open)
 
1601
    azflush(&(share->archive_write), Z_SYNC_FLUSH);
1585
1602
  pthread_mutex_unlock(&share->mutex);
1586
1603
 
 
1604
  if (init_archive_reader())
 
1605
    DBUG_RETURN(HA_ADMIN_CORRUPT);
1587
1606
  /*
1588
1607
    Now we will rewind the archive file so that we are positioned at the 
1589
1608
    start of the file.
1590
1609
  */
1591
 
  init_archive_reader();
1592
1610
  read_data_header(&archive);
 
1611
  for (ha_rows cur_count= count; cur_count; cur_count--)
 
1612
  {
 
1613
    if ((rc= get_row(&archive, table->record[0])))
 
1614
      goto error;
 
1615
  }
 
1616
  /*
 
1617
    Now read records that may have been inserted concurrently.
 
1618
    Acquire share->mutex so tail of the table is not modified by
 
1619
    concurrent writers.
 
1620
  */
 
1621
  pthread_mutex_lock(&share->mutex);
 
1622
  count= share->rows_recorded - count;
 
1623
  if (share->archive_write_open)
 
1624
    azflush(&(share->archive_write), Z_SYNC_FLUSH);
1593
1625
  while (!(rc= get_row(&archive, table->record[0])))
1594
1626
    count--;
1595
 
 
1596
 
  thd_proc_info(thd, old_proc_info);
 
1627
  pthread_mutex_unlock(&share->mutex);
1597
1628
 
1598
1629
  if ((rc && rc != HA_ERR_END_OF_FILE) || count)  
1599
 
  {
1600
 
    share->crashed= FALSE;
1601
 
    DBUG_RETURN(HA_ADMIN_CORRUPT);
1602
 
  }
 
1630
    goto error;
1603
1631
 
 
1632
  thd_proc_info(thd, old_proc_info);
1604
1633
  DBUG_RETURN(HA_ADMIN_OK);
 
1634
 
 
1635
error:
 
1636
  thd_proc_info(thd, old_proc_info);
 
1637
  share->crashed= FALSE;
 
1638
  DBUG_RETURN(HA_ADMIN_CORRUPT);
1605
1639
}
1606
1640
 
1607
1641
/*