📄 tsbuf.c
字号:
/************************************************************************The test module for the file system and buffer manager(c) 1995 Innobase OyCreated 11/16/1995 Heikki Tuuri*************************************************************************/#include "string.h"#include "os0thread.h"#include "os0file.h"#include "ut0ut.h"#include "ut0byte.h"#include "sync0sync.h"#include "mem0mem.h"#include "fil0fil.h"#include "mtr0mtr.h"#include "mtr0log.h"#include "log0log.h"#include "mach0data.h"#include "..\buf0buf.h"#include "..\buf0flu.h"#include "..\buf0lru.h"os_file_t files[1000];mutex_t ios_mutex;ulint ios;ulint n[10];mutex_t incs_mutex;ulint incs;#define N_SPACES 1#define N_FILES 1#define FILE_SIZE 4000#define POOL_SIZE 1000#define COUNTER_OFFSET 1500#define LOOP_SIZE 150#define N_THREADS 5ulint zero = 0;buf_frame_t* bl_arr[POOL_SIZE];/************************************************************************Io-handler thread function. */ulinthandler_thread(/*===========*/ void* arg){ ulint segment; void* mess; ulint i; bool ret; segment = *((ulint*)arg); printf("Io handler thread %lu starts\n", segment); for (i = 0;; i++) { ret = fil_aio_wait(segment, &mess); ut_a(ret); buf_page_io_complete((buf_block_t*)mess); mutex_enter(&ios_mutex); ios++; mutex_exit(&ios_mutex); } return(0);}/*************************************************************************This thread reports the status of sync system. */ulintinfo_thread(/*========*/ void* arg){ ulint segment; segment = *((ulint*)arg); for (;;) { sync_print(); os_aio_print(); printf("Debug stop threads == %lu\n", ut_dbg_stop_threads); os_thread_sleep(30000000); } return(0);}/*************************************************************************Creates the files for the file system test and inserts them tothe file system. */voidcreate_files(void)/*==============*/{ bool ret; ulint i, k; char name[20]; os_thread_t thr[5]; os_thread_id_t id[5]; ulint err; printf("--------------------------------------------------------\n"); printf("Create or open database files\n"); strcpy(name, "tsfile00"); for (k = 0; k < N_SPACES; k++) { for (i = 0; i < N_FILES; i++) { name[9] = (char)((ulint)'0' + k); name[10] = (char)((ulint)'0' + i); files[i] = os_file_create(name, OS_FILE_CREATE, OS_FILE_TABLESPACE, &ret); if (ret == FALSE) { err = os_file_get_last_error(); if (err != OS_FILE_ALREADY_EXISTS) { printf("OS error %lu in file creation\n", err); ut_error; } files[i] = os_file_create( name, OS_FILE_OPEN, OS_FILE_TABLESPACE, &ret); ut_a(ret); } ret = os_file_close(files[i]); ut_a(ret); if (i == 0) { fil_space_create(name, k, OS_FILE_TABLESPACE); } ut_a(fil_validate()); fil_node_create(name, FILE_SIZE, k); } } ios = 0; mutex_create(&ios_mutex); for (i = 0; i < 5; i++) { n[i] = i; thr[i] = os_thread_create(handler_thread, n + i, id + i); }/* n[9] = 9; os_thread_create(info_thread, n + 9, id);*/}/************************************************************************Creates the test database files. */void create_db(void)/*===========*/{ ulint i; byte* frame; ulint j; ulint tm, oldtm; mtr_t mtr; printf("--------------------------------------------------------\n"); printf("Write database pages\n"); oldtm = ut_clock(); for (i = 0; i < N_SPACES; i++) { for (j = 0; j < FILE_SIZE * N_FILES; j++) { mtr_start(&mtr); mtr_set_log_mode(&mtr, MTR_LOG_NONE); frame = buf_page_create(i, j, &mtr); buf_page_get(i, j, RW_X_LATCH, &mtr); if (j > FILE_SIZE * N_FILES - 64 * 2 - 1) { mlog_write_ulint(frame + FIL_PAGE_PREV, j - 5, MLOG_4BYTES, &mtr); mlog_write_ulint(frame + FIL_PAGE_NEXT, j - 7, MLOG_4BYTES, &mtr); } else { mlog_write_ulint(frame + FIL_PAGE_PREV, j - 1, MLOG_4BYTES, &mtr); mlog_write_ulint(frame + FIL_PAGE_NEXT, j + 1, MLOG_4BYTES, &mtr); } mlog_write_ulint(frame + FIL_PAGE_OFFSET, j, MLOG_4BYTES, &mtr); mlog_write_ulint(frame + FIL_PAGE_SPACE, i, MLOG_4BYTES, &mtr); mlog_write_ulint(frame + COUNTER_OFFSET, 0, MLOG_4BYTES, &mtr); mtr_commit(&mtr); } } tm = ut_clock(); printf("Wall clock time for test %lu milliseconds\n", tm - oldtm); printf("--------------------------------------------------------\n"); printf("TEST 1 A. Test of page creation when page resides in buffer\n"); for (i = 0; i < N_SPACES; i++) { for (j = FILE_SIZE * N_FILES - 200; j < FILE_SIZE * N_FILES; j++) { mtr_start(&mtr); mtr_set_log_mode(&mtr, MTR_LOG_NONE); frame = buf_page_create(i, j, &mtr); buf_page_get(i, j, RW_X_LATCH, &mtr); mlog_write_ulint(frame + FIL_PAGE_PREV, j - 1, MLOG_4BYTES, &mtr); mlog_write_ulint(frame + FIL_PAGE_NEXT, j + 1, MLOG_4BYTES, &mtr); mlog_write_ulint(frame + FIL_PAGE_OFFSET, j, MLOG_4BYTES, &mtr); mlog_write_ulint(frame + FIL_PAGE_SPACE, i, MLOG_4BYTES, &mtr); mtr_commit(&mtr); } } printf("--------------------------------------------------------\n"); printf("TEST 1 B. Flush pages\n"); buf_flush_batch(BUF_FLUSH_LIST, POOL_SIZE / 2); buf_validate(); printf("--------------------------------------------------------\n"); printf("TEST 1 C. Allocate POOL_SIZE blocks to flush pages\n"); buf_validate(); /* Flush the pool of dirty pages */ for (i = 0; i < POOL_SIZE; i++) { bl_arr[i] = buf_frame_alloc(); } buf_validate(); buf_LRU_print(); for (i = 0; i < POOL_SIZE; i++) { buf_frame_free(bl_arr[i]); } buf_validate(); ut_a(buf_all_freed()); mtr_start(&mtr); frame = buf_page_get(0, 313, RW_S_LATCH, &mtr);#ifdef UNIV_ASYNC_IO ut_a(buf_page_io_query(buf_block_align(frame)) == TRUE);#endif mtr_commit(&mtr);} /************************************************************************Reads the test database files. */void test1(void)/*=======*/{ ulint i, j, k, c; byte* frame; ulint tm, oldtm; mtr_t mtr; printf("--------------------------------------------------------\n"); printf("TEST 1 D. Read linearly database files\n"); oldtm = ut_clock(); for (k = 0; k < 1; k++) { for (i = 0; i < N_SPACES; i++) { for (j = 0; j < N_FILES * FILE_SIZE; j++) { mtr_start(&mtr); frame = buf_page_get(i, j, RW_S_LATCH, &mtr); ut_a(mtr_read_ulint(frame + FIL_PAGE_OFFSET, MLOG_4BYTES, &mtr) == j); ut_a(mtr_read_ulint(frame + FIL_PAGE_SPACE, MLOG_4BYTES, &mtr) == i); mtr_commit(&mtr); } } } tm = ut_clock(); printf("Wall clock time for %lu pages %lu milliseconds\n", k * i * j, tm - oldtm); buf_validate(); printf("--------------------------------------------------------\n"); printf("TEST 1 E. Read linearly downward database files\n"); oldtm = ut_clock(); c = 0; for (k = 0; k < 1; k++) { for (i = 0; i < N_SPACES; i++) { for (j = ut_min(1000, FILE_SIZE - 1); j > 0; j--) { mtr_start(&mtr); frame = buf_page_get(i, j, RW_S_LATCH, &mtr); c++; ut_a(mtr_read_ulint(frame + FIL_PAGE_OFFSET, MLOG_4BYTES, &mtr) == j); ut_a(mtr_read_ulint(frame + FIL_PAGE_SPACE, MLOG_4BYTES, &mtr) == i); ut_a(buf_page_io_query(buf_block_align(frame)) == FALSE); mtr_commit(&mtr); } } } tm = ut_clock(); printf("Wall clock time for %lu pages %lu milliseconds\n", c, tm - oldtm); buf_validate();}/************************************************************************Reads the test database files. */void test2(void)/*=======*/{ ulint i, j, k; byte* frame; ulint tm, oldtm; mtr_t mtr; printf("--------------------------------------------------------\n"); printf("TEST 2. Read randomly database files\n"); oldtm = ut_clock(); for (k = 0; k < 100; k++) { i = ut_rnd_gen_ulint() % N_SPACES; j = ut_rnd_gen_ulint() % (N_FILES * FILE_SIZE); mtr_start(&mtr); frame = buf_page_get(i, j, RW_S_LATCH, &mtr); ut_a(mtr_read_ulint(frame + FIL_PAGE_OFFSET, MLOG_4BYTES, &mtr) == j); ut_a(mtr_read_ulint(frame + FIL_PAGE_SPACE, MLOG_4BYTES, &mtr) == i); mtr_commit(&mtr); } tm = ut_clock(); printf("Wall clock time for random %lu read %lu milliseconds\n", k, tm - oldtm);}/************************************************************************Reads the test database files. */void test3(void)/*=======*/{ ulint i, j, k; byte* frame; ulint tm, oldtm; ulint rnd; mtr_t mtr; if (FILE_SIZE < POOL_SIZE + 3050 + ut_dbg_zero) { return; } printf("Flush the pool of high-offset pages\n"); /* Flush the pool of high-offset pages */ for (i = 0; i < POOL_SIZE; i++) { mtr_start(&mtr); frame = buf_page_get(0, i, RW_S_LATCH, &mtr); mtr_commit(&mtr); } buf_validate(); printf("--------------------------------------------------------\n"); printf("TEST 3. Read randomly database pages, no read-ahead\n"); oldtm = ut_clock(); rnd = 123; for (k = 0; k < 400; k++) { rnd += 23477; i = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -