LCOV - code coverage report
Current view: top level - flamenco/runtime - fd_rocksdb.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 22 0.0 %
Date: 2025-10-24 04:32:27 Functions: 0 0 -

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_runtime_fd_rocksdb_h
       2             : #define HEADER_fd_src_flamenco_runtime_fd_rocksdb_h
       3             : 
       4             : #include "../../ballet/block/fd_microblock.h"
       5             : #include "../types/fd_types.h"
       6             : 
       7             : /** allocations made for offline-replay in the blockstore */
       8             : struct fd_block {
       9             :   /* Used only in offline at the moment. Stored in the blockstore
      10             :      memory and used to iterate the block's contents.
      11             : 
      12             :    A block's data region is indexed to support iterating by shred,
      13             :    microblock/entry batch, microblock/entry, or transaction.
      14             :    This is done by iterating the headers for each, stored in allocated
      15             :    memory.
      16             :    To iterate shred payloads, for example, a caller should iterate the headers in tandem with the data region
      17             :    (offsetting by the bytes indicated in the shred header).
      18             : 
      19             :    Note random access of individual shred indices is not performant, due to the variable-length
      20             :    nature of shreds. */
      21             : 
      22             :   ulong data_gaddr;   /* ptr to the beginning of the block's allocated data region */
      23             :   ulong data_sz;      /* block size */
      24             :   ulong shreds_gaddr; /* ptr to the first fd_block_shred_t */
      25             :   ulong shreds_cnt;
      26             :   ulong batch_gaddr;  /* list of fd_block_entry_batch_t */
      27             :   ulong batch_cnt;
      28             :   ulong micros_gaddr; /* ptr to the list of fd_block_micro_t */
      29             :   ulong micros_cnt;
      30             : };
      31             : typedef struct fd_block fd_block_t;
      32             : 
      33             : #if FD_HAS_ROCKSDB
      34             : 
      35             : #include "../../ballet/shred/fd_shred.h"
      36             : #include <rocksdb/c.h>
      37             : 
      38           0 : #define FD_ROCKSDB_CF_CNT (21UL)
      39             : 
      40           0 : #define FD_ROCKSDB_CFIDX_DEFAULT                  (0UL)
      41           0 : #define FD_ROCKSDB_CFIDX_META                     (1UL)
      42           0 : #define FD_ROCKSDB_CFIDX_DEAD_SLOTS               (2UL)
      43           0 : #define FD_ROCKSDB_CFIDX_DUPLICATE_SLOTS          (3UL) /* Usually empty */
      44           0 : #define FD_ROCKSDB_CFIDX_ERASURE_META             (4UL)
      45           0 : #define FD_ROCKSDB_CFIDX_ORPHANS                  (5UL) /* Usually empty */
      46           0 : #define FD_ROCKSDB_CFIDX_BANK_HASHES              (6UL)
      47           0 : #define FD_ROCKSDB_CFIDX_ROOT                     (7UL)
      48           0 : #define FD_ROCKSDB_CFIDX_INDEX                    (8UL)
      49           0 : #define FD_ROCKSDB_CFIDX_DATA_SHRED               (9UL)
      50           0 : #define FD_ROCKSDB_CFIDX_CODE_SHRED               (10UL)
      51           0 : #define FD_ROCKSDB_CFIDX_TRANSACTION_STATUS       (11UL)
      52           0 : #define FD_ROCKSDB_CFIDX_ADDRESS_SIGNATURES       (12UL)
      53           0 : #define FD_ROCKSDB_CFIDX_TRANSACTION_MEMOS        (13UL)
      54           0 : #define FD_ROCKSDB_CFIDX_TRANSACTION_STATUS_INDEX (14UL)
      55           0 : #define FD_ROCKSDB_CFIDX_REWARDS                  (15UL)
      56           0 : #define FD_ROCKSDB_CFIDX_BLOCKTIME                (16UL)
      57           0 : #define FD_ROCKSDB_CFIDX_PERF_SAMPLES             (17UL)
      58           0 : #define FD_ROCKSDB_CFIDX_BLOCK_HEIGHT             (18UL)
      59           0 : #define FD_ROCKSDB_CFIDX_OPTIMISTIC_SLOTS         (19UL)
      60           0 : #define FD_ROCKSDB_CFIDX_MERKLE_ROOT_META         (20UL) /* Usually empty */
      61             : 
      62             : /* Solana rocksdb client */
      63             : struct fd_rocksdb {
      64             :   rocksdb_t *                     db;
      65             :   const char *                    db_name;
      66             :   const char *                    cfgs      [ FD_ROCKSDB_CF_CNT ];
      67             :   rocksdb_column_family_handle_t* cf_handles[ FD_ROCKSDB_CF_CNT ];
      68             :   rocksdb_options_t *             opts;
      69             :   rocksdb_readoptions_t *         ro;
      70             :   rocksdb_writeoptions_t *        wo;
      71             : };
      72             : typedef struct fd_rocksdb fd_rocksdb_t;
      73             : #define FD_ROCKSDB_FOOTPRINT sizeof(fd_rocksdb_t)
      74             : #define FD_ROCKSDB_ALIGN (8UL)
      75             : 
      76             : /* root column iterator */
      77             : struct fd_rocksdb_root_iter {
      78             :   fd_rocksdb_t *                  db;
      79             :   rocksdb_iterator_t*             iter;
      80             : };
      81             : typedef struct fd_rocksdb_root_iter fd_rocksdb_root_iter_t;
      82             : #define FD_ROCKSDB_ROOT_ITER_FOOTPRINT sizeof(fd_rocksdb_root_iter_t)
      83             : #define FD_ROCKSDB_ROOT_ITER_ALIGN (8UL)
      84             : 
      85             : FD_PROTOTYPES_BEGIN
      86             : 
      87             : void *
      88             : fd_rocksdb_root_iter_new( void * shiter );
      89             : 
      90             : fd_rocksdb_root_iter_t *
      91             : fd_rocksdb_root_iter_join( void * iter );
      92             : 
      93             : void *
      94             : fd_rocksdb_root_iter_leave( fd_rocksdb_root_iter_t * iter );
      95             : 
      96             : fd_slot_meta_t *
      97             : fd_rocksdb_root_iter_seek( fd_rocksdb_root_iter_t * iter,
      98             :                            fd_rocksdb_t *           db,
      99             :                            ulong                    slot );
     100             : 
     101             : fd_slot_meta_t *
     102             : fd_rocksdb_root_iter_next( fd_rocksdb_root_iter_t * iter );
     103             : 
     104             : int
     105             : fd_rocksdb_root_iter_slot( fd_rocksdb_root_iter_t * self,
     106             :                            ulong *                  slot );
     107             : 
     108             : void
     109             : fd_rocksdb_root_iter_destroy( fd_rocksdb_root_iter_t * iter );
     110             : 
     111             : /* fd_rocksdb_init: Returns a pointer to a description of the error on failure
     112             : 
     113             :   The provided db_name needs to point at the actual rocksdb directory
     114             :   as apposed to the directory above (like the solana ledger-tool) */
     115             : 
     116             : char *
     117             : fd_rocksdb_init( fd_rocksdb_t * db,
     118             :                  char const *   db_name );
     119             : 
     120             : /* fd_rocksdb_new: Creates a new rocksdb
     121             : 
     122             :    The provided db_name has to the be the full path where the directory
     123             :    will be created. The fd_rocksdb_t object will be initialized */
     124             : 
     125             : void
     126             : fd_rocksdb_new( fd_rocksdb_t * db,
     127             :                 char const *   db_name );
     128             : 
     129             : /* fd_rocksdb_destroy
     130             : 
     131             :    Frees up the internal data structures */
     132             : 
     133             : void
     134             : fd_rocksdb_destroy( fd_rocksdb_t * db );
     135             : 
     136             : /* fd_rocksdb_last_slot:  Returns the last slot in the db
     137             : 
     138             :    This uses the root column to discover the slot of the last root in
     139             :    the db.  If there is an error, this sets *err to a constant string
     140             :    describing the error.  There is no need to free that string. */
     141             : 
     142             : ulong
     143             : fd_rocksdb_last_slot( fd_rocksdb_t * db,
     144             :                       char **        err );
     145             : 
     146             : /* fd_rocksdb_first_slot:  Returns the first slot in the db
     147             : 
     148             :    This uses the root column to discover the slot of the first root in
     149             :    the db.  If there is an error, this sets *err to a constant string
     150             :    describing the error.  There is no need to free that string. */
     151             : 
     152             : ulong
     153             : fd_rocksdb_first_slot( fd_rocksdb_t * db,
     154             :                        char **        err );
     155             : 
     156             : fd_slot_meta_t * /* libc heap */
     157             : fd_rocksdb_get_meta( fd_rocksdb_t *   db,
     158             :                      ulong            slot );
     159             : 
     160             : /* fd_rocksdb_copy_over_slot_indexed_range copies over all entries for a
     161             :    given column family index into another rocksdb assuming that the key
     162             :    is prefixed with the slot number. This includes column families where
     163             :    the key is just the slot number but also ones where the key starts with
     164             :    the slot number. */
     165             : 
     166             : int
     167             : fd_rocksdb_copy_over_slot_indexed_range( fd_rocksdb_t * src,
     168             :                                          fd_rocksdb_t * dst,
     169             :                                          ulong          cf_idx,
     170             :                                          ulong          start_slot,
     171             :                                          ulong          end_slot );
     172             : /* fd_rocksdb_insert_entry inserts a key, value pair into a given rocksdb */
     173             : 
     174             : int
     175             : fd_rocksdb_insert_entry( fd_rocksdb_t * db,
     176             :                          ulong          cf_idx,
     177             :                          const char *   key,
     178             :                          ulong          key_len,
     179             :                          const char *   value,
     180             :                          ulong          value_len );
     181             : 
     182             : 
     183             : FD_PROTOTYPES_END
     184             : 
     185             : #endif
     186             : 
     187             : #endif // HEADER_fd_src_flamenco_runtime_fd_rocksdb_h

Generated by: LCOV version 1.14