Skip to content

Commit df323bc

Browse files
riptlripatel-fd
authored andcommitted
funk: remove unused APIs
- Remove rec_hard_remove Previously used to track hashing work, obsolete after #5581 - Remove erase_data tagging Previously planned to be used for LRU / garbage collection logic, currently unused - Remove rec_forget Unused and untested
1 parent 54bd852 commit df323bc

File tree

6 files changed

+19
-189
lines changed

6 files changed

+19
-189
lines changed

src/flamenco/runtime/fd_runtime.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,30 +1207,23 @@ fd_runtime_finalize_account( fd_funk_t * funk,
12071207
uchar const * record_data = (uchar *)fd_txn_account_get_meta( acc );
12081208
ulong record_sz = fd_account_meta_get_record_sz( acc->meta );
12091209

1210-
/* Remove the previous incarnation of the account's record from the
1211-
transaction, so that we don't hash it twice. */
1212-
fd_funk_rec_key_t funk_key = fd_funk_acc_key( key );
1213-
fd_funk_rec_hard_remove( funk, funk_txn, &funk_key );
1214-
12151210
int err = FD_FUNK_SUCCESS;
12161211

1212+
fd_funk_rec_key_t funk_key = fd_funk_acc_key( key );
12171213
fd_funk_rec_prepare_t prepare[1];
12181214
fd_funk_rec_t * rec = fd_funk_rec_prepare( funk, funk_txn, &funk_key, prepare, &err );
1219-
if( FD_UNLIKELY( !rec ) ) {
1220-
FD_LOG_CRIT(( "fd_runtime_finalize_account: failed to prepare record" ));
1221-
}
1222-
if( FD_UNLIKELY( err!=FD_FUNK_SUCCESS ) ) {
1223-
FD_LOG_CRIT(( "fd_runtime_finalize_account: failed to prepare record" ));
1215+
if( FD_UNLIKELY( !rec || err!=FD_FUNK_SUCCESS ) ) {
1216+
FD_LOG_ERR(( "fd_runtime_finalize_account: failed to prepare record (%i-%s)", err, fd_funk_strerror( err ) ));
12241217
}
12251218

1226-
if( fd_funk_val_truncate(
1219+
if( FD_UNLIKELY( !fd_funk_val_truncate(
12271220
rec,
12281221
fd_funk_alloc( funk ),
12291222
fd_funk_wksp( funk ),
12301223
0UL,
12311224
record_sz,
1232-
&err ) == NULL ) {
1233-
FD_LOG_CRIT(( "fd_funk_val_truncate(sz=%lu) for account failed (%i-%s)", record_sz, err, fd_funk_strerror( err ) ));
1225+
&err ) ) ) {
1226+
FD_LOG_ERR(( "fd_funk_val_truncate(sz=%lu) for account failed (%i-%s)", record_sz, err, fd_funk_strerror( err ) ));
12341227
}
12351228

12361229
fd_memcpy( fd_funk_val( rec, fd_funk_wksp( funk ) ), record_data, record_sz );

src/funk/fd_funk_rec.c

Lines changed: 1 addition & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -494,62 +494,11 @@ fd_funk_rec_clone( fd_funk_t * funk,
494494
}
495495
}
496496

497-
void
498-
fd_funk_rec_hard_remove( fd_funk_t * funk,
499-
fd_funk_txn_t * txn,
500-
fd_funk_rec_key_t const * key ) {
501-
fd_funk_xid_key_pair_t pair[1];
502-
fd_funk_rec_key_set_pair( pair, txn, key );
503-
504-
uchar * lock = NULL;
505-
if( txn==NULL ) {
506-
lock = &funk->shmem->lock;
507-
} else {
508-
lock = &txn->lock;
509-
}
510-
511-
while( FD_ATOMIC_CAS( lock, 0, 1 ) ) FD_SPIN_PAUSE();
512-
513-
fd_funk_rec_t * rec = NULL;
514-
for(;;) {
515-
fd_funk_rec_map_query_t rec_query[1];
516-
int err = fd_funk_rec_map_remove( funk->rec_map, pair, NULL, rec_query, FD_MAP_FLAG_BLOCKING );
517-
if( FD_UNLIKELY( err == FD_MAP_ERR_AGAIN ) ) continue;
518-
if( err == FD_MAP_ERR_KEY ) {
519-
FD_VOLATILE( *lock ) = 0;
520-
return;
521-
}
522-
if( FD_UNLIKELY( err != FD_MAP_SUCCESS ) ) FD_LOG_CRIT(( "map corruption" ));
523-
rec = fd_funk_rec_map_query_ele( rec_query );
524-
break;
525-
}
526-
527-
uint prev_idx = rec->prev_idx;
528-
uint next_idx = rec->next_idx;
529-
if( txn == NULL ) {
530-
if( fd_funk_rec_idx_is_null( prev_idx ) ) funk->shmem->rec_head_idx = next_idx;
531-
else funk->rec_pool->ele[ prev_idx ].next_idx = next_idx;
532-
if( fd_funk_rec_idx_is_null( next_idx ) ) funk->shmem->rec_tail_idx = prev_idx;
533-
else funk->rec_pool->ele[ next_idx ].prev_idx = prev_idx;
534-
} else {
535-
if( fd_funk_rec_idx_is_null( prev_idx ) ) txn->rec_head_idx = next_idx;
536-
else funk->rec_pool->ele[ prev_idx ].next_idx = next_idx;
537-
if( fd_funk_rec_idx_is_null( next_idx ) ) txn->rec_tail_idx = prev_idx;
538-
else funk->rec_pool->ele[ next_idx ].prev_idx = prev_idx;
539-
}
540-
541-
FD_VOLATILE( *lock ) = 0;
542-
543-
fd_funk_val_flush( rec, funk->alloc, funk->wksp );
544-
fd_funk_rec_pool_release( funk->rec_pool, rec, 1 );
545-
}
546-
547497
int
548498
fd_funk_rec_remove( fd_funk_t * funk,
549499
fd_funk_txn_t * txn,
550500
fd_funk_rec_key_t const * key,
551-
fd_funk_rec_t ** rec_out,
552-
ulong erase_data ) {
501+
fd_funk_rec_t ** rec_out ) {
553502
#ifdef FD_FUNK_HANDHOLDING
554503
if( FD_UNLIKELY( funk==NULL || key==NULL ) ) {
555504
return FD_FUNK_ERR_INVAL;
@@ -598,72 +547,6 @@ fd_funk_rec_remove( fd_funk_t * funk,
598547

599548
fd_funk_val_flush( rec, funk->alloc, funk->wksp );
600549

601-
/* At this point, the 5 most significant bytes should store data about the
602-
transaction that the record was updated in. */
603-
604-
fd_funk_rec_set_erase_data( rec, erase_data );
605-
606-
return FD_FUNK_SUCCESS;
607-
}
608-
609-
void
610-
fd_funk_rec_set_erase_data( fd_funk_rec_t * rec, ulong erase_data ) {
611-
rec->flags |= ((erase_data & 0xFFFFFFFFFFUL) << (sizeof(unsigned long) * 8 - 40));
612-
}
613-
614-
ulong
615-
fd_funk_rec_get_erase_data( fd_funk_rec_t const * rec ) {
616-
return (rec->flags >> (sizeof(unsigned long) * 8 - 40)) & 0xFFFFFFFFFFUL;
617-
}
618-
619-
int
620-
fd_funk_rec_forget( fd_funk_t * funk,
621-
fd_funk_rec_t ** recs,
622-
ulong recs_cnt ) {
623-
#ifdef FD_FUNK_HANDHOLDING
624-
if( FD_UNLIKELY( !funk ) ) return FD_FUNK_ERR_INVAL;
625-
#endif
626-
627-
#ifdef FD_FUNK_HANDHOLDING
628-
ulong rec_max = funk->shmem->rec_max;
629-
#endif
630-
631-
for( ulong i = 0; i < recs_cnt; ++i ) {
632-
fd_funk_rec_t * rec = recs[i];
633-
634-
#ifdef FD_FUNK_HANDHOLDING
635-
ulong rec_idx = (ulong)(rec - funk->rec_pool->ele);
636-
if( FD_UNLIKELY( (rec_idx>=rec_max) /* Out of map (incl NULL) */ | (rec!=(funk->rec_pool->ele+rec_idx)) /* Bad alignment */ ) )
637-
return FD_FUNK_ERR_INVAL;
638-
#endif
639-
640-
ulong txn_idx = fd_funk_txn_idx( rec->txn_cidx );
641-
if( FD_UNLIKELY( !fd_funk_txn_idx_is_null( txn_idx ) || /* Must be published */
642-
!( rec->flags & FD_FUNK_REC_FLAG_ERASE ) ) ) { /* Must be removed */
643-
return FD_FUNK_ERR_KEY;
644-
}
645-
646-
for(;;) {
647-
fd_funk_rec_map_query_t rec_query[1];
648-
int err = fd_funk_rec_map_remove( funk->rec_map, fd_funk_rec_pair( rec ), NULL, rec_query, FD_MAP_FLAG_BLOCKING );
649-
if( FD_UNLIKELY( err == FD_MAP_ERR_AGAIN ) ) continue;
650-
if( err == FD_MAP_ERR_KEY ) return FD_FUNK_ERR_KEY;
651-
if( FD_UNLIKELY( err != FD_MAP_SUCCESS ) ) FD_LOG_CRIT(( "map corruption" ));
652-
if( rec != fd_funk_rec_map_query_ele( rec_query ) ) FD_LOG_CRIT(( "map corruption" ));
653-
break;
654-
}
655-
656-
uint prev_idx = rec->prev_idx;
657-
uint next_idx = rec->next_idx;
658-
if( fd_funk_rec_idx_is_null( prev_idx ) ) funk->shmem->rec_head_idx = next_idx;
659-
else funk->rec_pool->ele[ prev_idx ].next_idx = next_idx;
660-
if( fd_funk_rec_idx_is_null( next_idx ) ) funk->shmem->rec_tail_idx = prev_idx;
661-
else funk->rec_pool->ele[ next_idx ].prev_idx = prev_idx;
662-
663-
fd_funk_val_flush( rec, funk->alloc, funk->wksp );
664-
fd_funk_rec_pool_release( funk->rec_pool, rec, 1 );
665-
}
666-
667550
return FD_FUNK_SUCCESS;
668551
}
669552

src/funk/fd_funk_rec.h

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -389,53 +389,7 @@ int
389389
fd_funk_rec_remove( fd_funk_t * funk,
390390
fd_funk_txn_t * txn,
391391
fd_funk_rec_key_t const * key,
392-
fd_funk_rec_t ** rec_out,
393-
ulong erase_data );
394-
395-
/*
396-
fd_funk_rec_hard_remove completely removes the record from Funk,
397-
and leaves no tombstone behind.
398-
399-
This is a dangerous API. An older version of the record in a
400-
parent transaction might be exposed. In other words, the record may
401-
appear to go backwards in time. We are effectively reverting an
402-
update. Any information in an removed record is lost.
403-
404-
Always succeeds.
405-
*/
406-
void
407-
fd_funk_rec_hard_remove( fd_funk_t * funk,
408-
fd_funk_txn_t * txn,
409-
fd_funk_rec_key_t const * key );
410-
411-
/* When a record is erased there is metadata stored in the five most
412-
significant bytes of record flags. These are helpers to make setting
413-
and getting these values simple. The caller is responsible for doing
414-
a check on the flag of the record before using the value of the erase
415-
data. The 5 least significant bytes of the erase data parameter will
416-
be used and set into the erase flag. */
417-
418-
void
419-
fd_funk_rec_set_erase_data( fd_funk_rec_t * rec, ulong erase_data );
420-
421-
ulong
422-
fd_funk_rec_get_erase_data( fd_funk_rec_t const * rec );
423-
424-
/* Remove a list of tombstones from funk, thereby freeing up space in
425-
the main index. All the records must be removed and published
426-
beforehand. Reasons for failure include:
427-
428-
FD_FUNK_ERR_INVAL - bad inputs (NULL funk, NULL rec, rec is
429-
obviously not from funk, etc)
430-
431-
FD_FUNK_ERR_KEY - the record did not appear to be a removed record.
432-
Specifically, a record query of funk for rec's (xid,key) pair did
433-
not return rec. Also, the record was never published.
434-
*/
435-
int
436-
fd_funk_rec_forget( fd_funk_t * funk,
437-
fd_funk_rec_t ** recs,
438-
ulong recs_cnt );
392+
fd_funk_rec_t ** rec_out );
439393

440394
/* fd_funk_all_iter_t iterators over all funk record objects in all funk
441395
transactions.

src/funk/test_funk_common.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ struct fake_funk {
201201

202202
fd_funk_txn_t * txn2 = get_real_txn(txn);
203203
auto key = rec->real_id();
204-
assert(fd_funk_rec_remove(_real, txn2, &key, NULL, 0UL) == FD_FUNK_SUCCESS);
204+
assert(fd_funk_rec_remove(_real, txn2, &key, NULL) == FD_FUNK_SUCCESS);
205205

206206
rec->_erased = true;
207207
rec->_data.clear();

src/funk/test_funk_rec.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,14 @@ main( int argc,
115115
FD_TEST( !fd_funk_rec_query_test( rec_query ) );
116116

117117
#ifdef FD_FUNK_HANDHOLDING
118-
FD_TEST( fd_funk_rec_remove( NULL, NULL, NULL, NULL, 0UL )==FD_FUNK_ERR_INVAL );
119-
FD_TEST( fd_funk_rec_remove( NULL, NULL, tkey, NULL, 0UL )==FD_FUNK_ERR_INVAL );
120-
FD_TEST( fd_funk_rec_remove( tst, NULL, NULL, NULL, 0UL )==FD_FUNK_ERR_INVAL );
118+
FD_TEST( fd_funk_rec_remove( NULL, NULL, NULL, NULL )==FD_FUNK_ERR_INVAL );
119+
FD_TEST( fd_funk_rec_remove( NULL, NULL, tkey, NULL )==FD_FUNK_ERR_INVAL );
120+
FD_TEST( fd_funk_rec_remove( tst, NULL, NULL, NULL )==FD_FUNK_ERR_INVAL );
121121
#endif
122122

123123
if( trec ) {
124124
if( is_frozen ) {
125-
FD_TEST( fd_funk_rec_remove( tst, NULL, tkey, NULL, 0UL )==FD_FUNK_ERR_FROZEN );
125+
FD_TEST( fd_funk_rec_remove( tst, NULL, tkey, NULL )==FD_FUNK_ERR_FROZEN );
126126
}
127127
}
128128

@@ -204,13 +204,13 @@ main( int argc,
204204
FD_TEST( !fd_funk_rec_query_test( rec_query ) );
205205

206206
#ifdef FD_FUNK_HANDHOLDING
207-
FD_TEST( fd_funk_rec_remove( NULL, ttxn, NULL, NULL, 0UL )==FD_FUNK_ERR_INVAL );
208-
FD_TEST( fd_funk_rec_remove( NULL, ttxn, tkey, NULL, 0UL )==FD_FUNK_ERR_INVAL );
209-
FD_TEST( fd_funk_rec_remove( tst, ttxn, NULL, NULL, 0UL )==FD_FUNK_ERR_INVAL );
207+
FD_TEST( fd_funk_rec_remove( NULL, ttxn, NULL, NULL )==FD_FUNK_ERR_INVAL );
208+
FD_TEST( fd_funk_rec_remove( NULL, ttxn, tkey, NULL )==FD_FUNK_ERR_INVAL );
209+
FD_TEST( fd_funk_rec_remove( tst, ttxn, NULL, NULL )==FD_FUNK_ERR_INVAL );
210210
#endif
211211

212212
if( trec && ttxn_is_frozen ) {
213-
FD_TEST( fd_funk_rec_remove( tst, ttxn, tkey, NULL, 0UL )==FD_FUNK_ERR_FROZEN );
213+
FD_TEST( fd_funk_rec_remove( tst, ttxn, tkey, NULL )==FD_FUNK_ERR_FROZEN );
214214
}
215215

216216
fd_funk_rec_prepare_t rec_prepare[1];
@@ -346,7 +346,7 @@ main( int argc,
346346
FD_TEST( !fd_funk_rec_query_test( query ) );
347347

348348
fd_funk_rec_t * trec2;
349-
FD_TEST( !fd_funk_rec_remove( tst, ttxn, key_set( tkey, rkey ), &trec2, 0UL ) );
349+
FD_TEST( !fd_funk_rec_remove( tst, ttxn, key_set( tkey, rkey ), &trec2 ) );
350350
FD_TEST( trec == trec2 );
351351

352352
} else if( op>=2 ) { /* Prepare 8x as publish and cancel combined */

src/funk/test_funk_val.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ main( int argc,
173173
rec_remove( ref, rrec );
174174

175175
fd_funk_txn_t * ttxn = rxid ? fd_funk_txn_query( xid_set( txid, rxid ), txn_map ) : NULL;
176-
FD_TEST( !fd_funk_rec_remove( tst, ttxn, key_set( tkey, rkey ), NULL, 0UL ) );
176+
FD_TEST( !fd_funk_rec_remove( tst, ttxn, key_set( tkey, rkey ), NULL ) );
177177

178178
} else if( op>=2 ) { /* Prepare 8x as publish and cancel combined */
179179

0 commit comments

Comments
 (0)