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

« back to all changes in this revision

Viewing changes to storage/innobase/fil/fil0fil.c

  • 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:
966
966
        HASH_SEARCH(name_hash, system->name_hash, ut_fold_string(name), space,
967
967
                    0 == strcmp(name, space->name));
968
968
        if (space != NULL) {
 
969
                ibool   success;
 
970
 
969
971
                ut_print_timestamp(stderr);
970
972
                fprintf(stderr,
971
973
                        "  InnoDB: Warning: trying to init to the"
1002
1004
 
1003
1005
                namesake_id = space->id;
1004
1006
 
 
1007
                success = fil_space_free(namesake_id, FALSE);
 
1008
                ut_a(success);
 
1009
 
1005
1010
                mutex_exit(&(system->mutex));
1006
1011
 
1007
 
                fil_space_free(namesake_id);
1008
 
 
1009
1012
                goto try_again;
1010
1013
        }
1011
1014
 
1128
1131
}
1129
1132
 
1130
1133
/***********************************************************************
 
1134
Check if the space id exists in the cache, complain to stderr if the
 
1135
space id cannot be found. */
 
1136
static
 
1137
fil_space_t*
 
1138
fil_space_search(
 
1139
/*=============*/
 
1140
                        /* out: file space instance*/
 
1141
        ulint   id)     /* in: space id */
 
1142
{
 
1143
        fil_space_t*    space;
 
1144
 
 
1145
        ut_ad(mutex_own(&fil_system->mutex));
 
1146
 
 
1147
        HASH_SEARCH(hash, fil_system->spaces, id, space, space->id == id);
 
1148
 
 
1149
        if (space == NULL) {
 
1150
                ut_print_timestamp(stderr);
 
1151
                fprintf(stderr,
 
1152
                        "  InnoDB: Error: trying to remove tablespace %lu"
 
1153
                        " from the cache but\n"
 
1154
                        "InnoDB: it is not there.\n", (ulong) id);
 
1155
        }
 
1156
 
 
1157
        return(space);
 
1158
}
 
1159
 
 
1160
/***********************************************************************
1131
1161
Frees a space object from the tablespace memory cache. Closes the files in
1132
1162
the chain but does not delete them. There must not be any pending i/o's or
1133
1163
flushes on the files. */
1135
1165
ibool
1136
1166
fil_space_free(
1137
1167
/*===========*/
1138
 
                        /* out: TRUE if success */
1139
 
        ulint   id)     /* in: space id */
 
1168
                                /* out: TRUE if success */
 
1169
        ulint   id,             /* in: space id */
 
1170
        ibool   x_latched)      /* in: TRUE if caller has space->latch
 
1171
                                in X mode */
1140
1172
{
1141
1173
        fil_system_t*   system = fil_system;
1142
1174
        fil_space_t*    space;
1143
1175
        fil_space_t*    namespace;
1144
1176
        fil_node_t*     fil_node;
1145
1177
 
1146
 
        mutex_enter(&(system->mutex));
1147
 
 
1148
 
        HASH_SEARCH(hash, system->spaces, id, space, space->id == id);
1149
 
 
1150
 
        if (!space) {
1151
 
                ut_print_timestamp(stderr);
1152
 
                fprintf(stderr,
1153
 
                        "  InnoDB: Error: trying to remove tablespace %lu"
1154
 
                        " from the cache but\n"
1155
 
                        "InnoDB: it is not there.\n", (ulong) id);
1156
 
 
1157
 
                mutex_exit(&(system->mutex));
1158
 
 
 
1178
        ut_ad(mutex_own(&fil_system->mutex));
 
1179
 
 
1180
        space = fil_space_search(id);
 
1181
 
 
1182
        if (space == NULL) {
1159
1183
                return(FALSE);
1160
1184
        }
1161
1185
 
1191
1215
 
1192
1216
        ut_a(0 == UT_LIST_GET_LEN(space->chain));
1193
1217
 
1194
 
        mutex_exit(&(system->mutex));
 
1218
        if (x_latched) {
 
1219
                rw_lock_x_unlock(&space->latch);
 
1220
        }
1195
1221
 
1196
1222
        rw_lock_free(&(space->latch));
1197
1223
 
2048
2074
        path = mem_strdup(space->name);
2049
2075
 
2050
2076
        mutex_exit(&(system->mutex));
 
2077
 
 
2078
        /* Important: We rely on the data dictionary mutex to ensure
 
2079
        that a race is not possible here. It should serialize the tablespace
 
2080
        drop/free. We acquire an X latch only to avoid a race condition
 
2081
        when accessing the tablespace instance via:
 
2082
 
 
2083
          fsp_get_available_space_in_free_extents().
 
2084
 
 
2085
        There our main motivation is to reduce the contention on the
 
2086
        dictionary mutex and not correctness. */
 
2087
 
 
2088
        rw_lock_x_lock(&space->latch);
 
2089
 
2051
2090
#ifndef UNIV_HOTBACKUP
2052
2091
        /* Invalidate in the buffer pool all pages belonging to the
2053
2092
        tablespace. Since we have set space->is_being_deleted = TRUE, readahead
2060
2099
#endif
2061
2100
        /* printf("Deleting tablespace %s id %lu\n", space->name, id); */
2062
2101
 
2063
 
        success = fil_space_free(id);
 
2102
        mutex_enter(&system->mutex);
 
2103
 
 
2104
        success = fil_space_free(id, TRUE);
 
2105
 
 
2106
        mutex_exit(&system->mutex);
2064
2107
 
2065
2108
        if (success) {
2066
2109
                success = os_file_delete(path);
2068
2111
                if (!success) {
2069
2112
                        success = os_file_delete_if_exists(path);
2070
2113
                }
 
2114
        } else {
 
2115
                rw_lock_x_unlock(&space->latch);
2071
2116
        }
2072
2117
 
2073
2118
        if (success) {
4569
4614
 
4570
4615
        return(mach_read_from_2(page + FIL_PAGE_TYPE));
4571
4616
}
 
4617
 
 
4618
/***********************************************************************
 
4619
Returns TRUE if a single-table tablespace is being deleted. */
 
4620
 
 
4621
ibool
 
4622
fil_tablespace_is_being_deleted(
 
4623
/*============================*/
 
4624
                                /* out: TRUE if space is being deleted */
 
4625
        ulint           id)     /* in: space id */
 
4626
{
 
4627
        fil_space_t*    space;
 
4628
        ibool           is_being_deleted;
 
4629
 
 
4630
        mutex_enter(&fil_system->mutex);
 
4631
 
 
4632
        HASH_SEARCH(hash, fil_system->spaces, id, space, space->id == id);
 
4633
 
 
4634
        ut_a(space != NULL);
 
4635
 
 
4636
        is_being_deleted = space->is_being_deleted;
 
4637
 
 
4638
        mutex_exit(&fil_system->mutex);
 
4639
 
 
4640
        return(is_being_deleted);
 
4641
}