summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/src/block/block_tiered.c
blob: b275ccd95a7e0d99c08d7cbcd8a5fd9702e263eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*-
 * Copyright (c) 2014-present MongoDB, Inc.
 * Copyright (c) 2008-2014 WiredTiger, Inc.
 *	All rights reserved.
 *
 * See the file LICENSE for redistribution information.
 */

#include "wt_internal.h"

/*
 * __wt_block_tiered_flush --
 *     Flush this file, start another file.
 */
int
__wt_block_tiered_flush(
  WT_SESSION_IMPL *session, WT_BLOCK *block, uint8_t **flush_cookie, size_t *cookie_size)
{
    /* TODO: tiered: fill in the cookie. */
    (void)flush_cookie;
    (void)cookie_size;

    return (__wt_block_tiered_newfile(session, block));
}

/*
 * __wt_block_tiered_load --
 *     Set up log-structured processing when loading a new root page.
 */
int
__wt_block_tiered_load(WT_SESSION_IMPL *session, WT_BLOCK *block, WT_BLOCK_CKPT *ci)
{
    /*
     * TODO: tiered: this call currently advances the object id, that's probably not appropriate for
     * readonly opens. Perhaps it's also not appropriate for opening at an older checkpoint?
     */
    if (block->has_objects) {
        block->objectid = ci->root_objectid;

        /* Advance to the next file for future changes. */
        WT_RET(__wt_block_tiered_newfile(session, block));
    }
    return (0);
}

/*
 * __wt_block_tiered_newfile --
 *     Switch a log-structured block object to a new file.
 */
int
__wt_block_tiered_newfile(WT_SESSION_IMPL *session, WT_BLOCK *block)
{
    WT_DECL_ITEM(tmp);
    WT_DECL_RET;
    const char *filename;

    /* Get the old file name again. */
    WT_ERR(__wt_scr_alloc(session, 0, &tmp));

    /*
     * TODO: tiered: We will get rid of the log id, and this name generation will be replaced by the
     * name generated by __tiered_switch.
     */
    WT_ERR(__wt_close(session, &block->fh));

    /* Bump to a new file ID. */
    ++block->objectid;
    WT_ERR(__wt_buf_fmt(session, tmp, "%s.%08" PRIu32, block->name, block->objectid));
    filename = tmp->data;

    WT_WITH_BUCKET_STORAGE(session->bucket_storage, session, {
        ret = __wt_open(session, filename, WT_FS_OPEN_FILE_TYPE_DATA,
          WT_FS_OPEN_CREATE | block->file_flags, &block->fh);
    });
    WT_ERR(ret);
    WT_ERR(__wt_desc_write(session, block->fh, block->allocsize));

    block->size = block->allocsize;
    __wt_block_ckpt_destroy(session, &block->live);
    WT_ERR(__wt_block_ckpt_init(session, &block->live, "live"));

err:
    __wt_scr_free(session, &tmp);
    return (ret);
}