Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pager_open function optimization #68

Open
muxiaobao opened this issue Feb 23, 2021 · 0 comments
Open

pager_open function optimization #68

muxiaobao opened this issue Feb 23, 2021 · 0 comments

Comments

@muxiaobao
Copy link

After implementing B-tree, each node occupies exactly one page of the table, so there is no need to test whether db file is a whole number of pages in pager_open function.

Pager* pager_open(const char* filename) {

    .............

    off_t file_length = lseek(fd, 0, SEEK_END);

    Pager* pager = malloc(sizeof(Pager));
    pager->file_descriptor = fd;
    pager->file_length = file_length;
    pager->num_pages = (file_length / PAGE_SIZE);

    // if (file_length % PAGE_SIZE != 0) {
    //     printf("Db file is not a whole number of pages. Corrupt file.\n");
    //     exit(EXIT_FAILURE);
    // }

    for (uint32_t i = 0; i < TABLE_MAX_PAGES; i++) {
        pager->pages[i] = NULL;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant