Skip to content

Commit de91d4f

Browse files
kbowers-jumpripatel-fd
authored andcommitted
Hashing and prefetching hints for fd_map_chain_para
By popular demand. This is nearly identical to the hinting support already in fd_map_slot_para. Also: - Support for hashless prefetching in fd_map_slot_para. - Some minor documentation clarifications in fd_map_slot_para. - Drive by cleanup to slight improve load balance for FD_FOR_ALL / FD_MAP_REDUCE.
1 parent 5cea668 commit de91d4f

File tree

12 files changed

+355
-186
lines changed

12 files changed

+355
-186
lines changed

src/flamenco/runtime/fd_blockstore.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,6 @@ fd_blockstore_shred_remove( fd_blockstore_t * blockstore, ulong slot, uint idx )
480480
// FD_TEST( fd_buf_shred_map_verify ( blockstore->shred_map ) == FD_MAP_SUCCESS );
481481
}
482482

483-
484483
void
485484
fd_blockstore_shred_insert( fd_blockstore_t * blockstore, fd_shred_t const * shred ) {
486485
// FD_LOG_NOTICE(( "[%s] slot %lu idx %u", __func__, shred->slot, shred->idx ));
@@ -511,7 +510,7 @@ fd_blockstore_shred_insert( fd_blockstore_t * blockstore, fd_shred_t const * shr
511510

512511
for(;;) {
513512
fd_buf_shred_map_query_t query[1] = { 0 };
514-
int err = fd_buf_shred_map_query_try( blockstore->shred_map, &key, NULL, query );
513+
int err = fd_buf_shred_map_query_try( blockstore->shred_map, &key, NULL, query, 0 );
515514
if( FD_UNLIKELY( err == FD_MAP_ERR_CORRUPT ) ) FD_LOG_ERR(( "[%s] %s. shred: (%lu, %u)", __func__, fd_buf_shred_map_strerror( err ), slot, shred->idx ));
516515
if( FD_UNLIKELY( err == FD_MAP_ERR_AGAIN ) ) continue;
517516
fd_buf_shred_t * buf_shred = fd_buf_shred_map_query_ele( query );
@@ -684,7 +683,7 @@ fd_blockstore_shred_test( fd_blockstore_t * blockstore, ulong slot, uint idx ) {
684683
fd_buf_shred_map_query_t query[1] = { 0 };
685684

686685
for(;;) {
687-
int err = fd_buf_shred_map_query_try( blockstore->shred_map, &key, NULL, query );
686+
int err = fd_buf_shred_map_query_try( blockstore->shred_map, &key, NULL, query, 0 );
688687
if( FD_UNLIKELY( err == FD_MAP_ERR_CORRUPT ) ) FD_LOG_ERR(( "[%s] slot: %lu idx: %u. %s", __func__, slot, idx, fd_buf_shred_map_strerror( err ) ));
689688
if( FD_LIKELY( !fd_buf_shred_map_query_test( query ) ) ) return err != FD_MAP_ERR_KEY;
690689
}
@@ -730,7 +729,7 @@ fd_buf_shred_query_copy_data( fd_blockstore_t * blockstore, ulong slot, uint idx
730729
int err = FD_MAP_ERR_AGAIN;
731730
while( err == FD_MAP_ERR_AGAIN ) {
732731
fd_buf_shred_map_query_t query[1] = { 0 };
733-
err = fd_buf_shred_map_query_try( blockstore->shred_map, &key, NULL, query );
732+
err = fd_buf_shred_map_query_try( blockstore->shred_map, &key, NULL, query, 0 );
734733
if( FD_UNLIKELY( err == FD_MAP_ERR_KEY ) ) return -1;
735734
if( FD_UNLIKELY( err == FD_MAP_ERR_CORRUPT ) ) FD_LOG_ERR(( "[%s] map corrupt. shred %lu %u", __func__, slot, idx ));
736735
if( FD_UNLIKELY( err == FD_MAP_ERR_AGAIN ) ) continue;
@@ -825,7 +824,7 @@ fd_blockstore_slice_query( fd_blockstore_t * blockstore,
825824
for(;;) { /* speculative copy one shred */
826825
fd_shred_key_t key = { slot, idx };
827826
fd_buf_shred_map_query_t query[1] = { 0 };
828-
int err = fd_buf_shred_map_query_try( blockstore->shred_map, &key, NULL, query );
827+
int err = fd_buf_shred_map_query_try( blockstore->shred_map, &key, NULL, query, 0 );
829828
if( FD_UNLIKELY( err == FD_MAP_ERR_CORRUPT ) ){
830829
FD_LOG_WARNING(( "[%s] key: (%lu, %u) %s", __func__, slot, idx, fd_buf_shred_map_strerror( err ) ));
831830
return FD_BLOCKSTORE_ERR_CORRUPT;
@@ -874,7 +873,6 @@ fd_blockstore_shreds_complete( fd_blockstore_t * blockstore, ulong slot ){
874873
}
875874
return complete;
876875

877-
878876
/* When replacing block_query( slot ) != NULL with this function:
879877
There are other things verified in a successful deshred & scan block that are not verified here.
880878
scan_block does a round of well-formedness checks like parsing txns, and no premature end of batch
@@ -889,7 +887,6 @@ fd_blockstore_shreds_complete( fd_blockstore_t * blockstore, ulong slot ){
889887

890888
}
891889

892-
893890
int
894891
fd_blockstore_block_data_query_volatile( fd_blockstore_t * blockstore,
895892
int fd,
@@ -1044,7 +1041,6 @@ fd_blockstore_block_data_query_volatile( fd_blockstore_t * blockstore,
10441041
#endif
10451042
}
10461043

1047-
10481044
int
10491045
fd_blockstore_block_map_query_volatile( fd_blockstore_t * blockstore,
10501046
int fd,

src/flamenco/runtime/fd_rocksdb.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ fd_rocksdb_init( fd_rocksdb_t * db,
3636
db->cfgs[ FD_ROCKSDB_CFIDX_OPTIMISTIC_SLOTS ] = "optimistic_slots";
3737
db->cfgs[ FD_ROCKSDB_CFIDX_MERKLE_ROOT_META ] = "merkle_root_meta";
3838

39-
4039
rocksdb_options_t const * cf_options[ FD_ROCKSDB_CF_CNT ];
4140
for( ulong i=0UL; i<FD_ROCKSDB_CF_CNT; i++ )
4241
cf_options[ i ] = db->opts;
@@ -178,7 +177,6 @@ ulong fd_rocksdb_find_last_slot(fd_rocksdb_t *db, char **err) {
178177
return max_slot;
179178
}
180179

181-
182180
ulong
183181
fd_rocksdb_first_slot( fd_rocksdb_t * db,
184182
char ** err ) {
@@ -672,7 +670,7 @@ deshred( fd_blockstore_t * blockstore, ulong slot ) {
672670
int err = FD_MAP_ERR_AGAIN;
673671
while( err == FD_MAP_ERR_AGAIN ) {
674672
fd_buf_shred_map_query_t query[1] = { 0 };
675-
err = fd_buf_shred_map_query_try( blockstore->shred_map, &key, NULL, query );
673+
err = fd_buf_shred_map_query_try( blockstore->shred_map, &key, NULL, query, 0 );
676674
if( FD_UNLIKELY( err == FD_MAP_ERR_KEY ) ) FD_LOG_ERR(( "[%s] map missing shred %lu %u while deshredding", __func__, slot, idx ));
677675
if( FD_UNLIKELY( err == FD_MAP_ERR_CORRUPT ) ) FD_LOG_ERR(( "[%s] map corrupt. shred %lu %u", __func__, slot, idx ));
678676
if( FD_UNLIKELY( err == FD_MAP_ERR_AGAIN ) ) continue;
@@ -723,7 +721,7 @@ deshred( fd_blockstore_t * blockstore, ulong slot ) {
723721
int err = FD_MAP_ERR_AGAIN;
724722
while( err == FD_MAP_ERR_AGAIN ) {
725723
fd_buf_shred_map_query_t query[1] = { 0 };;
726-
err = fd_buf_shred_map_query_try( blockstore->shred_map, &key, NULL, query );
724+
err = fd_buf_shred_map_query_try( blockstore->shred_map, &key, NULL, query, 0 );
727725
if( FD_UNLIKELY( err == FD_MAP_ERR_AGAIN ) ) continue;
728726
if( FD_UNLIKELY( err == FD_MAP_ERR_KEY ) ) FD_LOG_ERR(( "[%s] map missing shred %lu %u while deshredding", __func__, slot, idx ));
729727
if( FD_UNLIKELY( err == FD_MAP_ERR_CORRUPT ) ) FD_LOG_ERR(( "[%s] map corrupt. shred %lu %u", __func__, slot, idx ));
@@ -897,7 +895,6 @@ fd_rocksdb_import_block_blockstore( fd_rocksdb_t * db,
897895

898896
rocksdb_iter_destroy(iter);
899897

900-
901898
fd_wksp_t * wksp = fd_blockstore_wksp( blockstore );
902899
fd_block_info_t * block_info = fd_blockstore_block_map_query( blockstore, slot );
903900
if( FD_LIKELY( block_info && fd_blockstore_shreds_complete( blockstore, slot ) ) ) {

src/flamenco/runtime/test_blockstore.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@ main( int argc, char ** argv ) {
141141
}
142142
}
143143

144-
145-
146144
cnt++;
147145
} else {
148146
dup_cnt++;
@@ -169,7 +167,7 @@ main( int argc, char ** argv ) {
169167

170168
// fd_shred_key_t key = { slot, idx };
171169
// fd_buf_shred_map_query_t query;
172-
// int err = fd_buf_shred_map_query_try( blockstore->shred_map, &key, NULL, &query );
170+
// int err = fd_buf_shred_map_query_try( blockstore->shred_map, &key, NULL, &query, 0 );
173171
// FD_TEST( err != FD_MAP_ERR_INVAL && err != FD_MAP_ERR_CORRUPT && err != FD_MAP_ERR_KEY );
174172
// err = fd_buf_shred_map_query_test( &query );
175173
// FD_TEST( err == FD_MAP_SUCCESS );

src/funk/fd_funk_rec.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fd_funk_rec_query_try( fd_funk_t * funk,
4747
}
4848
fd_funk_rec_key_copy( pair->key, key );
4949
for(;;) {
50-
int err = fd_funk_rec_map_query_try( &rec_map, pair, NULL, query );
50+
int err = fd_funk_rec_map_query_try( &rec_map, pair, NULL, query, 0 );
5151
if( err == FD_MAP_SUCCESS ) break;
5252
if( err == FD_MAP_ERR_KEY ) return NULL;
5353
if( err == FD_MAP_ERR_AGAIN ) continue;
@@ -145,7 +145,7 @@ fd_funk_rec_query_copy( fd_funk_t * funk,
145145
ulong last_copy_sz = 0;
146146
for(;;) {
147147
fd_funk_rec_query_t query[1];
148-
int err = fd_funk_rec_map_query_try( &rec_map, pair, NULL, query );
148+
int err = fd_funk_rec_map_query_try( &rec_map, pair, NULL, query, 0 );
149149
if( err == FD_MAP_ERR_KEY ) {
150150
if( last_copy ) fd_valloc_free( valloc, last_copy );
151151
return NULL;
@@ -410,7 +410,7 @@ fd_funk_rec_remove( fd_funk_t * funk,
410410
fd_funk_rec_key_copy( pair->key, key );
411411
fd_funk_rec_query_t query[ 1 ];
412412
for(;;) {
413-
int err = fd_funk_rec_map_query_try( &rec_map, pair, NULL, query );
413+
int err = fd_funk_rec_map_query_try( &rec_map, pair, NULL, query, 0 );
414414
if( err == FD_MAP_SUCCESS ) break;
415415
if( err == FD_MAP_ERR_KEY ) return FD_FUNK_SUCCESS;
416416
if( err == FD_MAP_ERR_AGAIN ) continue;

src/funk/fd_funk_txn.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fd_funk_txn_prepare( fd_funk_t * funk,
7979
fd_funk_txn_pool_t txn_pool = fd_funk_txn_pool( funk, wksp );
8080

8181
fd_funk_txn_map_query_t query[1];
82-
if( FD_UNLIKELY( fd_funk_txn_map_query_try( &txn_map, xid, NULL, query ) != FD_MAP_ERR_KEY ) ) {
82+
if( FD_UNLIKELY( fd_funk_txn_map_query_try( &txn_map, xid, NULL, query, 0 ) != FD_MAP_ERR_KEY ) ) {
8383
if( FD_UNLIKELY( verbose ) ) FD_LOG_WARNING(( "xid in use" ));
8484
return NULL;
8585
}
@@ -987,7 +987,7 @@ fd_funk_txn_valid( fd_funk_t * funk, fd_funk_txn_t const * txn ) {
987987
if( txn_idx >= funk->txn_max || txn != txn_idx + txn_pool.ele ) return 0;
988988
fd_funk_txn_map_t txn_map = fd_funk_txn_map( funk, wksp );
989989
fd_funk_txn_map_query_t query[1];
990-
if( FD_UNLIKELY( fd_funk_txn_map_query_try( &txn_map, &txn->xid, NULL, query ) ) ) return 0;
990+
if( FD_UNLIKELY( fd_funk_txn_map_query_try( &txn_map, &txn->xid, NULL, query, 0 ) ) ) return 0;
991991
if( fd_funk_txn_map_query_ele( query ) != txn ) return 0;
992992
return 1;
993993
}

src/funk/fd_funk_txn.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ fd_funk_txn_query( fd_funk_txn_xid_t const * xid,
145145
fd_funk_txn_map_t * map ) {
146146
do {
147147
fd_funk_txn_map_query_t query[1];
148-
if( FD_UNLIKELY( fd_funk_txn_map_query_try( map, xid, NULL, query ) ) ) return NULL;
148+
if( FD_UNLIKELY( fd_funk_txn_map_query_try( map, xid, NULL, query, 0 ) ) ) return NULL;
149149
fd_funk_txn_t * ele = fd_funk_txn_map_query_ele( query );
150150
if( FD_LIKELY( !fd_funk_txn_map_query_test( query ) ) ) return ele;
151151
} while( 1 );

src/groove/test_groove_meta.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ tile_main( int argc,
8181
ulong memo = fd_groove_meta_map_key_hash( key, seed );
8282

8383
if( use_hint ) {
84-
fd_groove_meta_map_hint( map, key, query, flags );
84+
fd_groove_meta_map_hint( map, key, query, flags & (~FD_MAP_FLAG_USE_HINT) );
8585
FD_TEST( memo==fd_groove_meta_map_query_memo( query ) );
8686
}
8787

@@ -112,7 +112,7 @@ tile_main( int argc,
112112
ulong mod = 0UL;
113113

114114
if( use_hint ) {
115-
fd_groove_meta_map_hint( map, key, query, flags );
115+
fd_groove_meta_map_hint( map, key, query, flags & (~FD_MAP_FLAG_USE_HINT) );
116116
FD_TEST( memo==fd_groove_meta_map_query_memo( query ) );
117117
}
118118

@@ -146,7 +146,7 @@ tile_main( int argc,
146146
ulong memo = fd_groove_meta_map_key_hash( key, seed );
147147

148148
if( use_hint ) {
149-
fd_groove_meta_map_hint( map, key, query, flags );
149+
fd_groove_meta_map_hint( map, key, query, flags & (~FD_MAP_FLAG_USE_HINT) );
150150
FD_TEST( memo==fd_groove_meta_map_query_memo( query ) );
151151
}
152152

@@ -167,7 +167,7 @@ tile_main( int argc,
167167
ulong memo = fd_groove_meta_map_key_hash( key, seed );
168168

169169
if( use_hint ) {
170-
fd_groove_meta_map_hint( map, key, query, flags );
170+
fd_groove_meta_map_hint( map, key, query, flags & (~FD_MAP_FLAG_USE_HINT) );
171171
FD_TEST( memo==fd_groove_meta_map_query_memo( query ) );
172172
}
173173

@@ -189,7 +189,7 @@ tile_main( int argc,
189189
ulong memo = fd_groove_meta_map_key_hash( key, seed );
190190

191191
if( use_hint ) {
192-
fd_groove_meta_map_hint( map, key, query, flags );
192+
fd_groove_meta_map_hint( map, key, query, flags & (~FD_MAP_FLAG_USE_HINT) );
193193
FD_TEST( memo==fd_groove_meta_map_query_memo( query ) );
194194
}
195195

@@ -218,7 +218,7 @@ tile_main( int argc,
218218
ulong memo = fd_groove_meta_map_key_hash( key, seed );
219219

220220
if( use_hint ) {
221-
fd_groove_meta_map_hint( map, key, query, flags );
221+
fd_groove_meta_map_hint( map, key, query, flags & (~FD_MAP_FLAG_USE_HINT) );
222222
FD_TEST( memo==fd_groove_meta_map_query_memo( query ) );
223223
}
224224

@@ -254,7 +254,7 @@ tile_main( int argc,
254254
ulong memo = fd_groove_meta_map_key_hash( key, seed );
255255

256256
if( use_hint ) {
257-
fd_groove_meta_map_hint( map, key, query, flags );
257+
fd_groove_meta_map_hint( map, key, query, flags & (~FD_MAP_FLAG_USE_HINT) );
258258
FD_TEST( memo==fd_groove_meta_map_query_memo( query ) );
259259
}
260260

@@ -276,7 +276,7 @@ tile_main( int argc,
276276
ulong memo = fd_groove_meta_map_key_hash( key, seed );
277277

278278
if( use_hint ) {
279-
fd_groove_meta_map_hint( map, key, query, flags );
279+
fd_groove_meta_map_hint( map, key, query, flags & (~FD_MAP_FLAG_USE_HINT) );
280280
FD_TEST( memo==fd_groove_meta_map_query_memo( query ) );
281281
}
282282

0 commit comments

Comments
 (0)