Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_accdb_fd_accdb_user_h 2 : #define HEADER_fd_src_flamenco_accdb_fd_accdb_user_h 3 : 4 : #include "fd_accdb_base.h" 5 : #include "fd_accdb_ref.h" 6 : #include "fd_accdb_lineage.h" 7 : #include "../../funk/fd_funk_base.h" 8 : 9 259036 : #define FD_ACCDB_FLAG_CREATE (1) 10 129489 : #define FD_ACCDB_FLAG_TRUNCATE (2) 11 205861 : #define FD_ACCDB_FLAG_DONTZERO (4) 12 : 13 : /* FD_ACCDB_IMPL_FOOTPRINT sizes the inline impl[] buffer in 14 : fd_accdb_user_t and fd_accdb_admin_t. The main contributor to this 15 : footprint is fd_accdb_lineage_t. We add 2048 onto that to 16 : accommodate various vinyl pointers and etc. */ 17 : #define FD_ACCDB_IMPL_FOOTPRINT (FD_ACCDB_LINEAGE_FOOTPRINT+2048UL) 18 : 19 : /* fd_accdb_user_vt_t specifies the interface (vtable) for the account 20 : DB client. */ 21 : 22 : struct fd_accdb_user_vt { 23 : 24 : /* fini destroys the accdb_user object implementing this interface. 25 : It is assumed that all accdb_ref handles created by the object have 26 : been released before calling fini. */ 27 : 28 : void 29 : (* fini)( fd_accdb_user_t * accdb ); 30 : 31 : /* Config APIs */ 32 : 33 : /* batch_max returns the largest 'cnt' argument that is guaranteed to 34 : be accepted by open_ro_multi/close_ro_multi when no other refs are 35 : open. */ 36 : 37 : ulong 38 : (* batch_max)( fd_accdb_user_t * accdb ); 39 : 40 : /* Query APIs */ 41 : 42 : /* open_ro_multi opens a batch of accounts for read. ro[i] is 43 : initialized with an account handle. xid is the fork ID. 44 : address[i] gives the account address to query (conflicts are fine). 45 : cnt is the number of accounts to query. 46 : 47 : If account i is not found, ro[i] gives an account with zero 48 : lamports and no data. 49 : 50 : On return, the caller owns cnt accdb_ro database handles. */ 51 : 52 : void 53 : (* open_ro_multi)( fd_accdb_user_t * accdb, 54 : fd_accdb_ro_t * ro, /* array */ 55 : fd_funk_txn_xid_t const * xid, 56 : void const * address, /* array (stride 32) */ 57 : ulong cnt ); 58 : 59 : /* open_rw_multi opens a batch of accounts for read-write. rw[i] is 60 : either initialized with an account handle or marked as invalid (see 61 : below). xid is the fork ID. address[i] gives the account address 62 : to query (conflicts are forbidden). data_min[i] specifies the 63 : requested minimum account data byte capacity (grows account buffers 64 : if necessary). cnt is the number of accounts to query. 65 : 66 : Supported flags: 67 : 68 : CREATE: if set, and account i does not exist, rw[i] gives a valid 69 : handle with zero lamports and zero data length (but with 70 : requested buffer capacity). 71 : if not set, and account i does not exist, then sets 72 : rw[i]->ref->accdb_type=INVAL. 73 : 74 : TRUNCATE: reset the account's data length to zero (useful as a 75 : hint to the database engine to avoid copies) 76 : 77 : DONTZERO: do not zero unused account data buffer space (useful 78 : as a performance hint when the caller plans to 79 : overwrite all data bytes anyway) 80 : 81 : On return, the caller owns cnt accdb_rw database handles (some of 82 : which may be invalid). */ 83 : 84 : void 85 : (* open_rw_multi)( fd_accdb_user_t * accdb, 86 : fd_accdb_rw_t * rw, /* array */ 87 : fd_funk_txn_xid_t const * xid, 88 : void const * address, /* array (stride 32) */ 89 : ulong const * data_min, /* array */ 90 : int flags, 91 : ulong cnt ); 92 : 93 : /* close_ref_multi closes a batch of account handles. Handles that 94 : are invalid are silently ignored (such that a call to open_rw_multi 95 : without the CREATE flag set is still fine). It is U.B. to pass the 96 : same handle twice. */ 97 : 98 : void 99 : (* close_ref_multi)( fd_accdb_user_t * accdb, 100 : fd_accdb_ref_t * ref, /* array */ 101 : ulong cnt ); 102 : 103 : /* Resize APIs */ 104 : 105 : ulong 106 : (* rw_data_max)( fd_accdb_user_t * accdb, 107 : fd_accdb_rw_t const * rw ); 108 : 109 : void 110 : (* rw_data_sz_set)( fd_accdb_user_t * accdb, 111 : fd_accdb_rw_t * rw, 112 : ulong data_sz, 113 : int flags ); 114 : 115 : }; 116 : 117 : typedef struct fd_accdb_user_vt fd_accdb_user_vt_t; 118 : 119 : struct fd_accdb_user_base { 120 : fd_accdb_user_vt_t const * vt; 121 : uint accdb_type; 122 : 123 : ulong rw_active; 124 : ulong ro_active; 125 : ulong created_cnt; 126 : }; 127 : 128 : typedef struct fd_accdb_user_base fd_accdb_user_base_t; 129 : 130 : struct fd_accdb_user { 131 : fd_accdb_user_base_t base; 132 : 133 : uchar impl[ FD_ACCDB_IMPL_FOOTPRINT ] __attribute__((aligned(64))); 134 : }; 135 : 136 : FD_PROTOTYPES_BEGIN 137 : 138 : static inline ulong 139 0 : fd_accdb_user_align( void ) { 140 0 : return alignof(fd_accdb_user_t); 141 0 : } 142 : 143 : static inline ulong 144 0 : fd_accdb_user_footprint( void ) { 145 0 : return sizeof(fd_accdb_user_t); 146 0 : } 147 : 148 : static inline void 149 12 : fd_accdb_user_fini( fd_accdb_user_t * accdb ) { 150 12 : accdb->base.vt->fini( accdb ); 151 12 : accdb->base.accdb_type = 0; 152 12 : } 153 : 154 : FD_PROTOTYPES_END 155 : 156 : #endif /* HEADER_fd_src_flamenco_accdb_fd_accdb_user_h */