Line data Source code
1 : #ifndef HEADER_fd_discof_restore_fd_snapwm_tile_private_h 2 : #define HEADER_fd_discof_restore_fd_snapwm_tile_private_h 3 : 4 : /* fd_snapwm_tile_private.h contains private APIs for the "snapwm" tile, 5 : which is the tile responsible for directing vinyl database writes. */ 6 : 7 : #include "utils/fd_slot_delta_parser.h" 8 : #include "utils/fd_ssparse.h" 9 : #include "../../ballet/lthash/fd_lthash.h" 10 : #include "../../ballet/lthash/fd_lthash_adder.h" 11 : #include "../../disco/stem/fd_stem.h" 12 : #include "../../disco/topo/fd_topo.h" 13 : #include "../../vinyl/io/fd_vinyl_io.h" 14 : #include "../../vinyl/meta/fd_vinyl_meta.h" 15 : 16 0 : #define FD_SNAPWM_WR_MTU (16UL<<20) 17 0 : #define FD_SNAPWM_PAIR_BATCH_CNT_MAX (FD_SSPARSE_ACC_BATCH_MAX) 18 0 : #define FD_SNAPWM_PAIR_SZ_MAX (fd_vinyl_bstream_pair_sz(FD_RUNTIME_ACC_SZ_MAX)) 19 0 : #define FD_SNAPWM_PAIR_BATCH_SZ_MAX (FD_SNAPWM_PAIR_BATCH_CNT_MAX*FD_SNAPWM_PAIR_SZ_MAX) 20 : 21 0 : #define FD_SNAPWM_DUP_META_BATCH_CNT_MAX (FD_SNAPWM_PAIR_BATCH_CNT_MAX) 22 0 : #define FD_SNAPWM_DUP_META_SZ (sizeof(ulong)+sizeof(fd_vinyl_bstream_phdr_t)) 23 0 : #define FD_SNAPWM_DUP_META_BATCH_SZ (FD_SNAPWM_DUP_META_BATCH_CNT_MAX*FD_SNAPWM_DUP_META_SZ) 24 : 25 0 : #define FD_SNAPWM_DUP_BATCH_CREDIT_MIN (1UL) 26 0 : #define FD_SNAPWM_DUP_LTHASH_CREDIT_MIN ((FD_LTHASH_LEN_BYTES+(ctx->hash_out.mtu-1))/ctx->hash_out.mtu) 27 : 28 : struct fd_snapwm_out_link { 29 : ulong idx; 30 : fd_wksp_t * mem; 31 : ulong chunk0; 32 : ulong wmark; 33 : ulong chunk; 34 : ulong mtu; 35 : ulong depth; 36 : ulong const * consumer_fseq; 37 : }; 38 : typedef struct fd_snapwm_out_link fd_snapwm_out_link_t; 39 : 40 : struct fd_snapwm_tile { 41 : int state; 42 : uint full : 1; /* loading a full snapshot? */ 43 : uint lthash_disabled : 1; /* disable lthash checking? */ 44 : 45 : ulong seed; 46 : long boot_timestamp; 47 : 48 : fd_sstxncache_entry_t * txncache_entries; 49 : ulong const * txncache_entries_len_ptr; 50 : 51 : struct { 52 : /* Account counters (full + incremental) */ 53 : ulong accounts_loaded; 54 : ulong accounts_replaced; 55 : ulong accounts_ignored; 56 : 57 : /* Account counters (snapshot taken for full snapshot only) */ 58 : ulong full_accounts_loaded; 59 : ulong full_accounts_replaced; 60 : ulong full_accounts_ignored; 61 : } metrics; 62 : 63 : struct { 64 : fd_wksp_t * wksp; 65 : ulong chunk0; 66 : ulong wmark; 67 : ulong mtu; 68 : ulong pos; 69 : } in; 70 : 71 : ulong out_ct_idx; 72 : fd_snapwm_out_link_t hash_out; 73 : 74 : struct { 75 : uchar * bstream_mem; 76 : ulong bstream_sz; 77 : 78 : ulong pair_cnt; 79 : 80 : /* Vinyl in either io_wd or io_mm mode */ 81 : fd_vinyl_io_t * io; 82 : fd_vinyl_io_t * io_wd; 83 : fd_vinyl_io_t * io_mm; 84 : ulong io_seed; 85 : 86 : fd_vinyl_meta_t map[1]; 87 : 88 : ulong txn_seq; /* bstream seq of first txn record (in [seq_past,seq_present]) */ 89 : uint txn_active : 1; 90 : 91 : ulong duplicate_accounts_batch_sz; 92 : ulong duplicate_accounts_batch_cnt; 93 : 94 : fd_lthash_adder_t adder; 95 : fd_lthash_value_t running_lthash; 96 : } vinyl; 97 : }; 98 : 99 : typedef struct fd_snapwm_tile fd_snapwm_tile_t; 100 : 101 : FD_PROTOTYPES_BEGIN 102 : 103 0 : #define FD_SNAPWM_IO_SPAD_MAX (64UL<<20) /* 64 MiB of I/O scratch space */ 104 : 105 : /* fd_snapwm_vinyl_privileged_init performs administrative tasks, such 106 : as opening and mapping the bstream file descriptor. */ 107 : 108 : void 109 : fd_snapwm_vinyl_privileged_init( fd_snapwm_tile_t * ctx, 110 : fd_topo_t * topo, 111 : fd_topo_tile_t * tile ); 112 : 113 : /* fd_snapwm_vinyl_unprivileged_init performs setup tasks after being 114 : sandboxed. (anything that might be exposed to untrusted data) */ 115 : 116 : void 117 : fd_snapwm_vinyl_unprivileged_init( fd_snapwm_tile_t * ctx, 118 : fd_topo_t * topo, 119 : fd_topo_tile_t * tile, 120 : void * io_mm_mem, 121 : void * io_wd_mem ); 122 : 123 : /* fd_snapwm_vinyl_seccomp returns a seccomp sandbox policy suitable 124 : for vinyl operation. */ 125 : 126 : ulong 127 : fd_snapwm_vinyl_seccomp( ulong out_cnt, 128 : struct sock_filter * out ); 129 : 130 : /* fd_snapwm_vinyl_reset pauses the snapwr tile (waits for the snapwr 131 : tile to ack) and formats a bstream file to be empty. THIS IS A 132 : DESTRUCTIVE ACTION. */ 133 : 134 : void 135 : fd_snapwm_vinyl_reset( fd_snapwm_tile_t * ctx ); 136 : 137 : /* fd_snapwm_vinyl_txn_begin starts a transactional burst write. 138 : Assumes vinyl uses the io_mm backend. The write can then either be 139 : committed or cancelled. There is no practical limit on the size of 140 : this burst. */ 141 : 142 : void 143 : fd_snapwm_vinyl_txn_begin( fd_snapwm_tile_t * ctx ); 144 : 145 : /* fd_snapwm_vinyl_txn_commit finishes a transactional burst write. 146 : Assumes vinyl uses the io_mm backend. Reads through bstream records 147 : written since txn_begin was called and updates the vinyl_meta index. */ 148 : 149 : void 150 : fd_snapwm_vinyl_txn_commit( fd_snapwm_tile_t * ctx, fd_stem_context_t * stem ); 151 : 152 : /* fd_snapwm_vinyl_txn_cancel abandons a transactional burst write. 153 : Assumes vinyl uses the io_mm backend. Reverts the bstream state to 154 : when txn_begin was called. */ 155 : 156 : void 157 : fd_snapwm_vinyl_txn_cancel( fd_snapwm_tile_t * ctx ); 158 : 159 : /* fd_snapwm_vinyl_wd_init transitions the vinyl backend from generic 160 : vinyl accessor (io_mm) to fast dumb direct account insertion (io_wd). 161 : This must be called before calling fd_snapwm_process_account_*. 162 : Starts the snapwr tile (waits for the snapwr tile to ack). */ 163 : 164 : void 165 : fd_snapwm_vinyl_wd_init( fd_snapwm_tile_t * ctx ); 166 : 167 : /* fd_snapwm_vinyl_wd_fini transitions the vinyl backend from fast dumb 168 : direct account insertion (io_wd) back to generic mode (io_mm). 169 : Pauses the snapwr tile (waits for the snapwr to ack). */ 170 : 171 : void 172 : fd_snapwm_vinyl_wd_fini( fd_snapwm_tile_t * ctx ); 173 : 174 : /* fd_snapwm_vinyl_shutdown instructs vinyl-related tiles of the loader 175 : to shut down. Blocks until all affected tiles have acknowledged the 176 : shutdown signal. */ 177 : 178 : void 179 : fd_snapwm_vinyl_shutdown( fd_snapwm_tile_t * ctx ); 180 : 181 : /* fd_snapwm_vinyl_process_account reads a set of pre-generated bstream 182 : pairs and decides whether to actually add then to the vinyl database. 183 : It supports batch mode as well as single account (pair). */ 184 : 185 : void 186 : fd_snapwm_vinyl_process_account( fd_snapwm_tile_t * ctx, 187 : ulong chunk, 188 : ulong acc_cnt, 189 : fd_stem_context_t * stem ); 190 : 191 : /* fd_snapwm_vinyl_read_account retrieves an account from the vinyl 192 : database. */ 193 : 194 : void 195 : fd_snapwm_vinyl_read_account( fd_snapwm_tile_t * ctx, 196 : void const * acct_addr, 197 : fd_account_meta_t * meta, 198 : uchar * data, 199 : ulong data_max ); 200 : 201 : /* fd_snapwm_vinyl_duplicate_accounts_batch_{init,append,fini} handle 202 : duplicate accounts batching when lthash computation is enabled. 203 : The batch is needed to minimize the STEM_BURST, and make the stem 204 : credit handling possible. _fini is responsible for sending the 205 : message downstream. 206 : 207 : Typical usage: 208 : fd_snapwm_vinyl_duplicate_accounts_batch_init( ctx, stem ); 209 : for(...) { 210 : ... 211 : fd_snapwm_vinyl_duplicate_accounts_batch_append( ctx, phdr, seq ); 212 : } 213 : fd_snapwm_vinyl_duplicate_accounts_batch_fini( ctx, stem ); 214 : 215 : They all return 1 on success, and 0 otherwise. 216 : 217 : IMPORTANT: there is an fseq check inside init, since every append 218 : modifies the output link's dcache directly. However, there is no 219 : fseq check inside fini. This is a performance optimization, which 220 : requires no fd_stem_publish between init and fini. */ 221 : int 222 : fd_snapwm_vinyl_duplicate_accounts_batch_init( fd_snapwm_tile_t * ctx, 223 : fd_stem_context_t * stem ); 224 : int 225 : fd_snapwm_vinyl_duplicate_accounts_batch_append( fd_snapwm_tile_t * ctx, 226 : fd_vinyl_bstream_phdr_t * phdr, 227 : ulong seq ); 228 : int 229 : fd_snapwm_vinyl_duplicate_accounts_batch_fini( fd_snapwm_tile_t * ctx, 230 : fd_stem_context_t * stem ); 231 : 232 : /* fd_snapwm_vinyl_duplicate_accounts_lthash_{init,append,fini} handle 233 : duplicate accounts lthash local calculation when lthash computation 234 : is enabled. This is typically only needed when the account is an 235 : "old" duplicate (meaning that it corresponds to an older slot than 236 : what is currently in the database). _fini is responsible for 237 : sending the message downstream. 238 : 239 : Typical usage: 240 : fd_snapwm_vinyl_duplicate_accounts_lthash_init( ctx, stem ); 241 : for(...) { 242 : ... 243 : fd_snapwm_vinyl_duplicate_accounts_lthash_append( ctx, pair ); 244 : } 245 : fd_snapwm_vinyl_duplicate_accounts_lthash_fini( ctx, stem ); 246 : 247 : They all return 1 on success, and 0 otherwise. 248 : 249 : IMPORTANT: the fseq check happens only inside fini, since append 250 : only operates on internal variables. Therefore, it is safe to have 251 : fd_stem_publish in between init and fini. */ 252 : int 253 : fd_snapwm_vinyl_duplicate_accounts_lthash_init( fd_snapwm_tile_t * ctx, 254 : fd_stem_context_t * stem ); 255 : int 256 : fd_snapwm_vinyl_duplicate_accounts_lthash_append( fd_snapwm_tile_t * ctx, 257 : uchar * pair ); 258 : int 259 : fd_snapwm_vinyl_duplicate_accounts_lthash_fini( fd_snapwm_tile_t * ctx, 260 : fd_stem_context_t * stem ); 261 : 262 : FD_PROTOTYPES_END 263 : 264 : #endif /* HEADER_fd_discof_restore_fd_snapwm_tile_private_h */