LCOV - code coverage report
Current view: top level - flamenco/accdb - fd_accdb_tile.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 99 0.0 %
Date: 2026-06-30 05:50:37 Functions: 0 8 0.0 %

          Line data    Source code
       1             : #include "../../disco/tiles.h"
       2             : 
       3             : #include "generated/fd_accdb_tile_seccomp.h"
       4             : 
       5             : #include "../../disco/metrics/fd_metrics.h"
       6             : #include "../../tango/fseq/fd_fseq.h"
       7             : 
       8             : #include "fd_accdb.h"
       9             : 
      10             : #include <fcntl.h>
      11             : 
      12             : /* Maximum number of read-only accdb consumer fseqs the accdb tile can
      13             :    bind external_epoch_slots[] to.  Bumped as new RO consumers are
      14             :    added.  Today: rpc tile (optional). */
      15             : #define FD_ACCDB_TILE_MAX_EXTERNAL_EPOCHS (8UL)
      16             : 
      17             : struct fd_accdb_tile_ctx {
      18             :   fd_accdb_t * accdb;
      19             : 
      20             :   ulong seed;
      21             : };
      22             : 
      23             : typedef struct fd_accdb_tile_ctx fd_accdb_tile_ctx_t;
      24             : 
      25             : FD_FN_CONST static inline ulong
      26           0 : scratch_align( void ) {
      27           0 :   return alignof( fd_accdb_tile_ctx_t );
      28           0 : }
      29             : 
      30             : FD_FN_PURE static inline ulong
      31           0 : scratch_footprint( fd_topo_tile_t const * tile ) {
      32           0 :   ulong l = FD_LAYOUT_INIT;
      33           0 :   l = FD_LAYOUT_APPEND( l, alignof( fd_accdb_tile_ctx_t ), sizeof( fd_accdb_tile_ctx_t )                    );
      34           0 :   l = FD_LAYOUT_APPEND( l, fd_accdb_align(),               fd_accdb_footprint( tile->accdb.max_live_slots ) );
      35           0 :   return FD_LAYOUT_FINI( l, scratch_align() );
      36           0 : }
      37             : 
      38             : static inline void
      39           0 : metrics_write( fd_accdb_tile_ctx_t * ctx ) {
      40           0 :   fd_accdb_shmem_metrics_t const * metrics = fd_accdb_shmetrics( ctx->accdb );
      41             : 
      42           0 :   FD_MGAUGE_SET( ACCDB, ACCOUNT_COUNT,          metrics->accounts_total );
      43           0 :   FD_MGAUGE_SET( ACCDB, ACCOUNT_CAPACITY,       metrics->accounts_capacity );
      44           0 :   FD_MCNT_SET( ACCDB, ACCOUNT_RELOCATED,        metrics->accounts_relocated );
      45           0 :   FD_MGAUGE_SET( ACCDB, DISK_ALLOCATED_BYTES,   metrics->disk_allocated_bytes );
      46           0 :   FD_MGAUGE_SET( ACCDB, DISK_CURRENT_BYTES,     metrics->disk_current_bytes );
      47           0 :   FD_MGAUGE_SET( ACCDB, DISK_USED_BYTES,        metrics->disk_used_bytes );
      48           0 :   FD_MGAUGE_SET( ACCDB, IN_COMPACTION,          (ulong)metrics->in_compaction );
      49           0 :   FD_MCNT_SET( ACCDB, COMPACTION_REQUESTED,     metrics->compactions_requested );
      50           0 :   FD_MCNT_SET( ACCDB, COMPACTION_COMPLETED,     metrics->compactions_completed );
      51           0 :   FD_MCNT_SET( ACCDB, ACCOUNT_RELOCATED_BYTES,  metrics->accounts_relocated_bytes );
      52             : 
      53           0 :   fd_accdb_metrics_t const * rt = fd_accdb_metrics( ctx->accdb );
      54           0 :   FD_MCNT_ENUM_COPY( ACCDB, ACCOUNT_PREEVICTED, rt->accounts_preevicted_per_class );
      55           0 :   FD_MCNT_SET( ACCDB, BYTES_READ,        rt->bytes_read        );
      56           0 :   FD_MCNT_SET( ACCDB, BYTES_WRITTEN,     rt->bytes_written     );
      57           0 :   FD_MCNT_SET( ACCDB, WRITE_OPERATION,   rt->write_ops         );
      58           0 :   FD_MCNT_SET( ACCDB, COPY_OPERATION,    rt->copy_ops          );
      59           0 :   FD_MCNT_SET( ACCDB, ACCOUNT_DELETED,   rt->accounts_deleted  );
      60             : 
      61           0 :   ulong cache_used    [ FD_ACCDB_CACHE_CLASS_CNT ];
      62           0 :   ulong cache_max     [ FD_ACCDB_CACHE_CLASS_CNT ];
      63           0 :   ulong cache_reserved[ FD_ACCDB_CACHE_CLASS_CNT ];
      64           0 :   fd_accdb_cache_class_occupancy( ctx->accdb, cache_used, cache_max, cache_reserved );
      65           0 :   FD_MGAUGE_ENUM_COPY( ACCDB, CACHE_CLASS_USED,     cache_used     );
      66           0 :   FD_MGAUGE_ENUM_COPY( ACCDB, CACHE_CLASS_MAX,      cache_max      );
      67           0 :   FD_MGAUGE_ENUM_COPY( ACCDB, CACHE_CLASS_RESERVED, cache_reserved );
      68             : 
      69           0 :   ulong cache_target_used[ FD_ACCDB_CACHE_CLASS_CNT ];
      70           0 :   ulong cache_lwm_used   [ FD_ACCDB_CACHE_CLASS_CNT ];
      71           0 :   fd_accdb_cache_class_thresholds( ctx->accdb, cache_target_used, cache_lwm_used );
      72           0 :   FD_MGAUGE_ENUM_COPY( ACCDB, CACHE_CLASS_TARGET_USED,    cache_target_used );
      73           0 :   FD_MGAUGE_ENUM_COPY( ACCDB, CACHE_CLASS_LOW_WATER_USED, cache_lwm_used    );
      74           0 : }
      75             : 
      76             : static inline void
      77             : before_credit( fd_accdb_tile_ctx_t * ctx,
      78             :                fd_stem_context_t *   stem FD_FN_UNUSED,
      79           0 :                int *                 charge_busy ) {
      80           0 :   fd_accdb_background( ctx->accdb, charge_busy );
      81           0 : }
      82             : 
      83             : static void
      84             : privileged_init( fd_topo_t const *      topo,
      85           0 :                  fd_topo_tile_t const * tile ) {
      86           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
      87             : 
      88           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
      89           0 :   fd_accdb_tile_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_accdb_tile_ctx_t ), sizeof( fd_accdb_tile_ctx_t ) );
      90           0 :   FD_TEST( fd_rng_secure( &ctx->seed, 8U ) );
      91           0 : }
      92             : 
      93             : static void
      94             : unprivileged_init( fd_topo_t const *      topo,
      95           0 :                    fd_topo_tile_t const * tile ) {
      96           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
      97             : 
      98           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
      99           0 :   fd_accdb_tile_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_accdb_tile_ctx_t ), sizeof( fd_accdb_tile_ctx_t ) );
     100           0 :   void * _accdb             = FD_SCRATCH_ALLOC_APPEND( l, fd_accdb_align(),               fd_accdb_footprint( tile->accdb.max_live_slots ) );
     101             : 
     102           0 :   void * _accdb_shmem = fd_topo_obj_laddr( topo, tile->accdb.accdb_obj_id );
     103           0 :   fd_accdb_shmem_t * accdb_shmem = fd_accdb_shmem_join( _accdb_shmem );
     104           0 :   FD_TEST( accdb_shmem );
     105             : 
     106             :   /* Gather per-RO-consumer epoch fseq pointers.  Each enabled RO
     107             :      consumer has a private fseq it owns RW; we map it RO and pass
     108             :      the pointer to fd_accdb_new so the compaction tile's
     109             :      deferred-free reclamation will wait on it. */
     110           0 :   static ulong const * external_epoch_slots[ FD_ACCDB_TILE_MAX_EXTERNAL_EPOCHS ];
     111           0 :   ulong external_epoch_cnt = 0UL;
     112           0 :   if( FD_LIKELY( tile->accdb.rpc_epoch_obj_id!=ULONG_MAX ) ) {
     113           0 :     ulong * fseq = fd_fseq_join( fd_topo_obj_laddr( topo, tile->accdb.rpc_epoch_obj_id ) );
     114           0 :     FD_TEST( fseq );
     115           0 :     FD_TEST( external_epoch_cnt<FD_ACCDB_TILE_MAX_EXTERNAL_EPOCHS );
     116           0 :     external_epoch_slots[ external_epoch_cnt++ ] = fseq;
     117           0 :   }
     118           0 :   for( ulong i=0UL; i<tile->accdb.resolv_epoch_obj_cnt; i++ ) {
     119           0 :     ulong * fseq = fd_fseq_join( fd_topo_obj_laddr( topo, tile->accdb.resolv_epoch_obj_ids[ i ] ) );
     120           0 :     FD_TEST( fseq );
     121           0 :     FD_TEST( external_epoch_cnt<FD_ACCDB_TILE_MAX_EXTERNAL_EPOCHS );
     122           0 :     external_epoch_slots[ external_epoch_cnt++ ] = fseq;
     123           0 :   }
     124             : 
     125           0 :   ctx->accdb = fd_accdb_join( fd_accdb_new( _accdb, accdb_shmem, FD_ACCDB_FD_RW, external_epoch_cnt, external_epoch_slots ) );
     126           0 :   FD_TEST( ctx->accdb );
     127             : 
     128           0 :   ulong scratch_top = FD_SCRATCH_ALLOC_FINI( l, 1UL );
     129           0 :   if( FD_UNLIKELY( scratch_top > (ulong)scratch + scratch_footprint( tile ) ) )
     130           0 :     FD_LOG_ERR(( "scratch overflow %lu %lu %lu", scratch_top - (ulong)scratch - scratch_footprint( tile ), scratch_top, (ulong)scratch + scratch_footprint( tile ) ));
     131           0 : }
     132             : 
     133             : static ulong
     134             : populate_allowed_seccomp( fd_topo_t const *      topo,
     135             :                           fd_topo_tile_t const * tile,
     136             :                           ulong                  out_cnt,
     137           0 :                           struct sock_filter *   out ) {
     138           0 :   (void)topo; (void)tile;
     139           0 :   populate_sock_filter_policy_fd_accdb_tile( out_cnt, out, (uint)fd_log_private_logfile_fd(), (uint)FD_ACCDB_FD_RW );
     140           0 :   return sock_filter_policy_fd_accdb_tile_instr_cnt;
     141           0 : }
     142             : 
     143             : static ulong
     144             : populate_allowed_fds( fd_topo_t const *      topo,
     145             :                       fd_topo_tile_t const * tile,
     146             :                       ulong                  out_fds_cnt,
     147           0 :                       int *                  out_fds ) {
     148           0 :   (void)topo; (void)tile;
     149             : 
     150           0 :   if( FD_UNLIKELY( out_fds_cnt<3UL ) ) FD_LOG_ERR(( "out_fds_cnt %lu", out_fds_cnt ));
     151             : 
     152           0 :   ulong out_cnt = 0UL;
     153           0 :   out_fds[ out_cnt++ ] = 2; /* stderr */
     154           0 :   if( FD_LIKELY( -1!=fd_log_private_logfile_fd() ) )
     155           0 :     out_fds[ out_cnt++ ] = fd_log_private_logfile_fd(); /* logfile */
     156           0 :   out_fds[ out_cnt++ ] = FD_ACCDB_FD_RW; /* accounts db fd */
     157           0 :   return out_cnt;
     158           0 : }
     159             : 
     160           0 : #define STEM_BURST (1UL)
     161           0 : #define STEM_LAZY  (128L*3000L)
     162             : 
     163           0 : #define STEM_CALLBACK_CONTEXT_TYPE  fd_accdb_tile_ctx_t
     164           0 : #define STEM_CALLBACK_CONTEXT_ALIGN alignof(fd_accdb_tile_ctx_t)
     165             : 
     166           0 : #define STEM_CALLBACK_METRICS_WRITE metrics_write
     167           0 : #define STEM_CALLBACK_BEFORE_CREDIT before_credit
     168             : 
     169             : #include "../../disco/stem/fd_stem.c"
     170             : 
     171             : fd_topo_run_tile_t fd_tile_accdb = {
     172             :   .name                     = "accdb",
     173             :   .populate_allowed_seccomp = populate_allowed_seccomp,
     174             :   .populate_allowed_fds     = populate_allowed_fds,
     175             :   .scratch_align            = scratch_align,
     176             :   .scratch_footprint        = scratch_footprint,
     177             :   .privileged_init          = privileged_init,
     178             :   .unprivileged_init        = unprivileged_init,
     179             :   .run                      = stem_run,
     180             : };

Generated by: LCOV version 1.14