标签:
/*******************************************************************//** Creates a space memory object and puts it to the tablespace memory cache. If there is an error, prints an error message to the .err log. @return TRUE if success */ UNIV_INTERN ibool fil_space_create( /*=============*/ const char* name, /*!< in: space name */ ulint id, /*!< in: space id */ ulint flags, /*!< in: compressed page size and file format, or 0 */ ulint purpose)/*!< in: FIL_TABLESPACE, or FIL_LOG if log */ { fil_space_t* space; /* The tablespace flags (FSP_SPACE_FLAGS) should be 0 for ROW_FORMAT=COMPACT ((table->flags & ~(~0 << DICT_TF_BITS)) == DICT_TF_COMPACT) and ROW_FORMAT=REDUNDANT (table->flags == 0). For any other format, the tablespace flags should equal (table->flags & ~(~0 << DICT_TF_BITS)). */ ut_a(flags != DICT_TF_COMPACT); ut_a(!(flags & (~0UL << DICT_TF_BITS))); try_again: /*printf( "InnoDB: Adding tablespace %lu of name %s, purpose %lu\n", id, name, purpose);*/ ut_a(fil_system); ut_a(name); mutex_enter(&fil_system->mutex); space = fil_space_get_by_name(name); if (UNIV_LIKELY_NULL(space)) { goto try_again; } space = fil_space_get_by_id(id); if (UNIV_LIKELY_NULL(space)) { return(FALSE); }
/**
*结构体详见
*/ space = mem_alloc(sizeof(fil_space_t)); space->name = mem_strdup(name); space->id = id; fil_system->tablespace_version++; space->tablespace_version = fil_system->tablespace_version; space->mark = FALSE; if (UNIV_LIKELY(purpose == FIL_TABLESPACE && !recv_recovery_on) && UNIV_UNLIKELY(id > fil_system->max_assigned_id)) { if (!fil_system->space_id_reuse_warned) { } fil_system->max_assigned_id = id; } space->stop_ios = FALSE; space->stop_new_ops = FALSE; space->purpose = purpose; space->size = 0; space->flags = flags; space->n_reserved_extents = 0; space->n_pending_flushes = 0; space->n_pending_ops = 0;
//初始化chain链表 UT_LIST_INIT(space->chain); space->magic_n = FIL_SPACE_MAGIC_N; rw_lock_create(fil_space_latch_key, &space->latch, SYNC_FSP);
//分别以id和name作为哈希值,放入fil_system相应哈希表中 HASH_INSERT(fil_space_t, hash, fil_system->spaces, id, space); HASH_INSERT(fil_space_t, name_hash, fil_system->name_hash,ut_fold_string(name), space);
space->is_in_unflushed_spaces = FALSE;
//放入lru中 UT_LIST_ADD_LAST(space_list, fil_system->space_list, space); mutex_exit(&fil_system->mutex); return(TRUE); }
/*******************************************************************//** Returns the table space by a given name, NULL if not found. */ UNIV_INLINE fil_space_t* fil_space_get_by_name( /*==================*/ const char* name) /*!< in: space name */ { fil_space_t* space; ulint fold; ut_ad(mutex_own(&fil_system->mutex)); fold = ut_fold_string(name); HASH_SEARCH(name_hash, fil_system->name_hash, fold, fil_space_t*, space, ut_ad(space->magic_n == FIL_SPACE_MAGIC_N), !strcmp(name, space->name)); return(space); }
标签:
原文地址:http://www.cnblogs.com/taek/p/5073986.html