LCOV - code coverage report
Current view: top level - flamenco/runtime - fd_rocksdb.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 23 0.0 %
Date: 2024-11-13 11:58:15 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             : #if FD_HAS_ROCKSDB
       5             : 
       6             : #include "../../ballet/shred/fd_shred.h"
       7             : #include "../../ballet/block/fd_microblock.h"
       8             : #include "fd_blockstore.h"
       9             : #include <rocksdb/c.h>
      10             : 
      11           0 : #define FD_ROCKSDB_CF_CNT (22UL)
      12             : 
      13           0 : #define FD_ROCKSDB_CFIDX_DEFAULT                  (0UL)
      14           0 : #define FD_ROCKSDB_CFIDX_META                     (1UL)
      15           0 : #define FD_ROCKSDB_CFIDX_DEAD_SLOTS               (2UL)
      16           0 : #define FD_ROCKSDB_CFIDX_DUPLICATE_SLOTS          (3UL) /* Usually empty */
      17           0 : #define FD_ROCKSDB_CFIDX_ERASURE_META             (4UL)
      18           0 : #define FD_ROCKSDB_CFIDX_ORPHANS                  (5UL) /* Usually empty */
      19           0 : #define FD_ROCKSDB_CFIDX_BANK_HASHES              (6UL)
      20           0 : #define FD_ROCKSDB_CFIDX_ROOT                     (7UL)
      21           0 : #define FD_ROCKSDB_CFIDX_INDEX                    (8UL)
      22           0 : #define FD_ROCKSDB_CFIDX_DATA_SHRED               (9UL)
      23           0 : #define FD_ROCKSDB_CFIDX_CODE_SHRED               (10UL)
      24           0 : #define FD_ROCKSDB_CFIDX_TRANSACTION_STATUS       (11UL)
      25           0 : #define FD_ROCKSDB_CFIDX_ADDRESS_SIGNATURES       (12UL)
      26           0 : #define FD_ROCKSDB_CFIDX_TRANSACTION_MEMOS        (13UL)
      27           0 : #define FD_ROCKSDB_CFIDX_TRANSACTION_STATUS_INDEX (14UL)
      28           0 : #define FD_ROCKSDB_CFIDX_REWARDS                  (15UL)
      29           0 : #define FD_ROCKSDB_CFIDX_BLOCKTIME                (16UL)
      30           0 : #define FD_ROCKSDB_CFIDX_PERF_SAMPLES             (17UL)
      31           0 : #define FD_ROCKSDB_CFIDX_BLOCK_HEIGHT             (18UL)
      32           0 : #define FD_ROCKSDB_CFIDX_PROGRAM_COSTS            (19UL) /* Usually empty */
      33           0 : #define FD_ROCKSDB_CFIDX_OPTIMISTIC_SLOTS         (20UL)
      34           0 : #define FD_ROCKSDB_CFIDX_MERKLE_ROOT_META         (21UL) /* Usually empty */
      35             : 
      36             : /* Solana rocksdb client */
      37             : struct fd_rocksdb {
      38             :   rocksdb_t *                     db;
      39             :   const char *                    db_name;
      40             :   const char *                    cfgs      [ FD_ROCKSDB_CF_CNT ];
      41             :   rocksdb_column_family_handle_t* cf_handles[ FD_ROCKSDB_CF_CNT ];
      42             :   rocksdb_options_t *             opts;
      43             :   rocksdb_readoptions_t *         ro;
      44             :   rocksdb_writeoptions_t *        wo;
      45             : };
      46             : typedef struct fd_rocksdb fd_rocksdb_t;
      47             : #define FD_ROCKSDB_FOOTPRINT sizeof(fd_rocksdb_t)
      48             : #define FD_ROCKSDB_ALIGN (8UL)
      49             : 
      50             : /* root column iterator */
      51             : struct fd_rocksdb_root_iter {
      52             :   fd_rocksdb_t *                  db;
      53             :   rocksdb_iterator_t*             iter;
      54             : };
      55             : typedef struct fd_rocksdb_root_iter fd_rocksdb_root_iter_t;
      56             : #define FD_ROCKSDB_ROOT_ITER_FOOTPRINT sizeof(fd_rocksdb_root_iter_t)
      57             : #define FD_ROCKSDB_ROOT_ITER_ALIGN (8UL)
      58             : 
      59             : FD_PROTOTYPES_BEGIN
      60             : 
      61             : void *
      62             : fd_rocksdb_root_iter_new( void * shiter );
      63             : 
      64             : fd_rocksdb_root_iter_t *
      65             : fd_rocksdb_root_iter_join( void * iter );
      66             : 
      67             : void *
      68             : fd_rocksdb_root_iter_leave( fd_rocksdb_root_iter_t * iter );
      69             : 
      70             : /* fd_rocksdb_root_iter_seek
      71             : 
      72             :     0 = success
      73             :    -1 = seek for supplied slot failed
      74             :    -2 = seek succeeded but slot did not match what we seeked for
      75             :    -3 = seek succeeded but points at an empty slot */
      76             : 
      77             : int
      78             : fd_rocksdb_root_iter_seek( fd_rocksdb_root_iter_t * iter,
      79             :                            fd_rocksdb_t *           db,
      80             :                            ulong                    slot,
      81             :                            fd_slot_meta_t *         m,
      82             :                            fd_valloc_t              valloc );
      83             : 
      84             : /*  fd_rocksdb_root_iter_next
      85             : 
      86             :     0 = success
      87             :    -1 = not properly initialized with a seek
      88             :    -2 = invalid starting iterator
      89             :    -3 = next returned an invalid iterator state
      90             :    -4 = seek succeeded but points at an empty slot */
      91             : 
      92             : int
      93             : fd_rocksdb_root_iter_next( fd_rocksdb_root_iter_t * iter,
      94             :                            fd_slot_meta_t *         m,
      95             :                            fd_valloc_t              valloc );
      96             : 
      97             : int
      98             : fd_rocksdb_root_iter_slot( fd_rocksdb_root_iter_t * self,
      99             :                            ulong *                  slot );
     100             : 
     101             : void
     102             : fd_rocksdb_root_iter_destroy( fd_rocksdb_root_iter_t * iter );
     103             : 
     104             : /* fd_rocksdb_init: Returns a pointer to a description of the error on failure
     105             : 
     106             :   The provided db_name needs to point at the actual rocksdb directory
     107             :   as apposed to the directory above (like the solana ledger-tool) */
     108             : 
     109             : char *
     110             : fd_rocksdb_init( fd_rocksdb_t * db,
     111             :                  char const *   db_name );
     112             : 
     113             : /* fd_rocksdb_new: Creates a new rocksdb
     114             : 
     115             :    The provided db_name has to the be the full path where the directory
     116             :    will be created. The fd_rocksdb_t object will be initialized */
     117             : 
     118             : void
     119             : fd_rocksdb_new( fd_rocksdb_t * db, 
     120             :                 char const *   db_name );
     121             : 
     122             : /* fd_rocksdb_destroy
     123             : 
     124             :    Frees up the internal data structures */
     125             : 
     126             : void
     127             : fd_rocksdb_destroy( fd_rocksdb_t * db );
     128             : 
     129             : /* fd_rocksdb_last_slot:  Returns the last slot in the db
     130             : 
     131             :    This uses the root column to discover the slot of the last root in
     132             :    the db.  If there is an error, this sets *err to a constant string
     133             :    describing the error.  There is no need to free that string. */
     134             : 
     135             : ulong
     136             : fd_rocksdb_last_slot( fd_rocksdb_t * db,
     137             :                       char **        err );
     138             : 
     139             : /* fd_rocksdb_first_slot:  Returns the first slot in the db
     140             : 
     141             :    This uses the root column to discover the slot of the first root in
     142             :    the db.  If there is an error, this sets *err to a constant string
     143             :    describing the error.  There is no need to free that string. */
     144             : 
     145             : ulong
     146             : fd_rocksdb_first_slot( fd_rocksdb_t * db,
     147             :                        char **        err );
     148             : 
     149             : ulong
     150             : fd_rocksdb_find_last_slot( fd_rocksdb_t * db,
     151             :                            char **        err );
     152             : 
     153             : /* fd_rocksdb_get_meta
     154             : 
     155             :    Retrieves the meta structure associated with the supplied slot.  If
     156             :    there is an error, *err is set to a string describing the error.
     157             :    It is expected that you should free() the error once done with it
     158             : 
     159             :    returns a 0 if there is no obvious error */
     160             : int
     161             : fd_rocksdb_get_meta( fd_rocksdb_t *   db,
     162             :                      ulong            slot,
     163             :                      fd_slot_meta_t * m,
     164             :                      fd_valloc_t      valloc );
     165             : 
     166             : /* fd_rocksdb_get_txn_status_raw queries transaction status metadata.
     167             :    slot is the slot number of the block that contains the txn.  sig
     168             :    points to the first signature of the txn.  Returns data==NULL if
     169             :    record not found.  On success, creates a malloc-backed buffer to hold
     170             :    return value, copies raw serialized status into buffer, sets *psz to
     171             :    the byte size of the status and returns pointer to buffer.  Caller
     172             :    must free() non-NULL returned region.  On failure, returns NULL and
     173             :    content of *psz is undefined.  Value is Protobuf-encoded
     174             :    TransactionStatusMeta.  Use fd_solblock nanopb API to deserialize
     175             :    value. */
     176             : 
     177             : void *
     178             : fd_rocksdb_get_txn_status_raw( fd_rocksdb_t * self,
     179             :                                ulong          slot,
     180             :                                void const *   sig,
     181             :                                ulong *        psz );
     182             : 
     183             : /* fd_rocksdb_copy_over_slot_indexed_range copies over all entries for a
     184             :    given column family index into another rocksdb assuming that the key
     185             :    is prefixed with the slot number. This includes column families where
     186             :    the key is just the slot number but also ones where the key starts with
     187             :    the slot number. */
     188             : 
     189             : int
     190             : fd_rocksdb_copy_over_slot_indexed_range( fd_rocksdb_t * src,
     191             :                                          fd_rocksdb_t * dst,
     192             :                                          ulong          cf_idx,
     193             :                                          ulong          start_slot,
     194             :                                          ulong          end_slot );
     195             : 
     196             : /* fd_rocksdb_copy_over_txn_status_range copies over all transaction statuses 
     197             :    within a block range assuming the blockstore contains relevant pointers to
     198             :    the transactions within the range. The blockstore object must be populated
     199             :    with the relevant block range. */
     200             : 
     201             : int
     202             : fd_rocksdb_copy_over_txn_status_range( fd_rocksdb_t *    src,
     203             :                                        fd_rocksdb_t *    dst,
     204             :                                        fd_blockstore_t * blockstore,
     205             :                                        ulong             start_slot,
     206             :                                        ulong             end_slot );
     207             : 
     208             : /* fd_rocksdb_copy_over_txn_status constructs a key to query a transaction 
     209             :    status and copies over the entry into another rocksdb. The index is used
     210             :    to specify which transaction. */
     211             : 
     212             : void
     213             : fd_rocksdb_copy_over_txn_status( fd_rocksdb_t * src,
     214             :                                  fd_rocksdb_t * dst,
     215             :                                  ulong          slot,
     216             :                                  void const *   sig );
     217             : 
     218             : /* fd_rocksdb_insert_entry inserts a key, value pair into a given rocksdb */
     219             : 
     220             : int
     221             : fd_rocksdb_insert_entry( fd_rocksdb_t * db,
     222             :                          ulong          cf_idx,
     223             :                          const char *   key, 
     224             :                          ulong          key_len,
     225             :                          const char *   value,
     226             :                          ulong          value_len );
     227             : 
     228             : /* Import from rocksdb into blockstore */
     229             : 
     230             : int
     231             : fd_rocksdb_import_block_blockstore( fd_rocksdb_t *    db,
     232             :                                     fd_slot_meta_t *  m,
     233             :                                     fd_blockstore_t * blockstore,
     234             :                                     int txnstatus,
     235             :                                     const uchar *hash_override );
     236             : 
     237             : int
     238             : fd_rocksdb_import_block_shredcap( fd_rocksdb_t *             db,
     239             :                                   fd_slot_meta_t *           metadata,
     240             :                                   fd_io_buffered_ostream_t * ostream,
     241             :                                   fd_io_buffered_ostream_t * bank_hash_ostream );
     242             : 
     243             : FD_PROTOTYPES_END
     244             : 
     245             : #endif
     246             : 
     247             : #endif // HEADER_fd_src_flamenco_runtime_fd_rocksdb_h

Generated by: LCOV version 1.14