~raghavendra-prabhu/percona-xtrabackup/Bug-1182995

« back to all changes in this revision

Viewing changes to src/fil_cur.cc

  • Committer: Alexey Kopytov
  • Date: 2013-05-16 18:03:01 UTC
  • mfrom: (595.1.1 2.1)
  • Revision ID: akopytov@gmail.com-20130516180301-c23mooyxyglif3wh
MergedĀ lp:~akopytov/percona-xtrabackup/bug1079700-2.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
 
75
75
}
76
76
 
 
77
/**********************************************************************//**
 
78
Closes a file. */
 
79
static
 
80
void
 
81
xb_fil_node_close_file(
 
82
/*===================*/
 
83
        fil_node_t*     node)   /*!< in: file node */
 
84
{
 
85
        ibool   ret;
 
86
 
 
87
        mutex_enter(&fil_system->mutex);
 
88
 
 
89
        ut_ad(node);
 
90
        ut_a(node->n_pending == 0);
 
91
        ut_a(node->n_pending_flushes == 0);
 
92
#if MYSQL_VERSION_ID >= 50600
 
93
        ut_a(!node->being_extended);
 
94
#endif
 
95
 
 
96
        if (!node->open) {
 
97
 
 
98
                mutex_exit(&fil_system->mutex);
 
99
 
 
100
                return;
 
101
        }
 
102
 
 
103
        ret = os_file_close(node->handle);
 
104
        ut_a(ret);
 
105
 
 
106
        node->open = FALSE;
 
107
 
 
108
        ut_a(fil_system->n_open > 0);
 
109
        fil_system->n_open--;
 
110
#if MYSQL_VERSION_ID >= 50600
 
111
        fil_n_file_opened--;
 
112
#endif
 
113
 
 
114
        if (node->space->purpose == FIL_TABLESPACE &&
 
115
            !trx_sys_sys_space(node->space->id)) {
 
116
 
 
117
                ut_a(UT_LIST_GET_LEN(fil_system->LRU) > 0);
 
118
 
 
119
                /* The node is in the LRU list, remove it */
 
120
                UT_LIST_REMOVE(LRU, fil_system->LRU, node);
 
121
        }
 
122
 
 
123
        mutex_exit(&fil_system->mutex);
 
124
}
 
125
 
77
126
/************************************************************************
78
127
Open a source file cursor and initialize the associated read filter.
79
128
 
90
139
        ulint   page_size;
91
140
        ulint   page_size_shift;
92
141
        ulint   zip_size;
 
142
        ibool   success;
93
143
 
94
144
        /* Initialize these first so xb_fil_cur_close() handles them correctly
95
145
        in case of error */
96
146
        cursor->orig_buf = NULL;
97
 
        cursor->file = XB_FILE_UNDEFINED;
 
147
        cursor->node = NULL;
98
148
 
99
149
        cursor->space_id = node->space->id;
100
150
        cursor->is_system = trx_sys_sys_space(node->space->id);
109
159
                xb_get_relative_path(cursor->abs_path, cursor->is_system),
110
160
                sizeof(cursor->rel_path));
111
161
 
112
 
        /* Open the file */
113
 
 
114
 
        if (my_stat(node->name, &cursor->statinfo, MYF(MY_WME)) == NULL) {
115
 
                msg("[%02u] xtrabackup: Warning: cannot stat %s\n",
116
 
                    thread_n, node->name);
117
 
                return(XB_FIL_CUR_SKIP);
118
 
        }
119
 
 
120
 
        ibool success;
121
 
 
122
 
        cursor->file =
123
 
                xb_file_create_no_error_handling(node->name,
 
162
        /* In the backup mode we should already have a tablespace handle created
 
163
        by fil_load_single_table_tablespace() unless it is a system
 
164
        tablespace. Otherwise we open the file here. */
 
165
        if (cursor->is_system || !srv_backup_mode) {
 
166
                node->handle =
 
167
                        xb_file_create_no_error_handling(node->name,
124
168
                                                 OS_FILE_OPEN,
125
169
                                                 OS_FILE_READ_ONLY,
126
170
                                                 &success);
127
 
        if (!success) {
128
 
                /* The following call prints an error message */
129
 
                os_file_get_last_error(TRUE);
130
 
 
131
 
                msg("[%02u] xtrabackup: Warning: cannot open %s\n"
132
 
                    "[%02u] xtrabackup: Warning: We assume the "
133
 
                    "table was dropped or renamed during "
134
 
                    "xtrabackup execution and ignore the file.\n",
135
 
                    thread_n, node->name, thread_n);
136
 
                return(XB_FIL_CUR_SKIP);
 
171
                if (!success) {
 
172
                        /* The following call prints an error message */
 
173
                        os_file_get_last_error(TRUE);
 
174
 
 
175
                        msg("[%02u] xtrabackup: error: cannot open "
 
176
                            "tablespace %s\n",
 
177
                            thread_n, cursor->abs_path);
 
178
 
 
179
                        return(XB_FIL_CUR_ERROR);
 
180
                }
 
181
                mutex_enter(&fil_system->mutex);
 
182
 
 
183
                node->open = TRUE;
 
184
 
 
185
                fil_system->n_open++;
 
186
#if MYSQL_VERSION_ID >= 50600
 
187
                fil_n_file_opened++;
 
188
#endif
 
189
 
 
190
                if (node->space->purpose == FIL_TABLESPACE &&
 
191
                    !trx_sys_sys_space(node->space->id)) {
 
192
 
 
193
                        /* Put the node to the LRU list */
 
194
                        UT_LIST_ADD_FIRST(LRU, fil_system->LRU, node);
 
195
                }
 
196
 
 
197
                mutex_exit(&fil_system->mutex);
 
198
        }
 
199
 
 
200
        ut_ad(node->open);
 
201
 
 
202
        cursor->node = node;
 
203
        cursor->file = node->handle;
 
204
 
 
205
        if (my_fstat(cursor->file, &cursor->statinfo, MYF(MY_WME))) {
 
206
                msg("[%02u] xtrabackup: error: cannot stat %s\n",
 
207
                    thread_n, cursor->abs_path);
 
208
 
 
209
                xb_fil_cur_close(cursor);
 
210
 
 
211
                return(XB_FIL_CUR_ERROR);
137
212
        }
138
213
 
139
214
        xb_file_set_nocache(cursor->file, node->name, "OPEN");
142
217
        /* Determine the page size */
143
218
        zip_size = xb_get_zip_size(cursor->file);
144
219
        if (zip_size == ULINT_UNDEFINED) {
145
 
                os_file_close(cursor->file);
 
220
                xb_fil_cur_close(cursor);
146
221
                return(XB_FIL_CUR_SKIP);
147
222
        } else if (zip_size) {
148
223
                page_size = zip_size;
230
305
        cursor->buf_offset = offset;
231
306
        cursor->buf_page_no = (ulint) (offset >> cursor->page_size_shift);
232
307
 
233
 
        success = xb_os_file_read(cursor->file, cursor->buf, offset, to_read);
 
308
        success = xb_os_file_read(cursor->file, cursor->buf, offset,
 
309
                                  to_read);
234
310
        if (!success) {
235
311
                return(XB_FIL_CUR_ERROR);
236
312
        }
294
370
        if (cursor->orig_buf != NULL) {
295
371
                ut_free(cursor->orig_buf);
296
372
        }
297
 
        if (cursor->file != XB_FILE_UNDEFINED) {
298
 
                os_file_close(cursor->file);
 
373
        if (cursor->node != NULL) {
 
374
                xb_fil_node_close_file(cursor->node);
 
375
                cursor->file = XB_FILE_UNDEFINED;
299
376
        }
300
377
}