# deleteRecordAsync does not delete secondary index

**URL:** <https://forums.foundationdb.org/t/deleterecordasync-does-not-delete-secondary-index/2797>\
**Category:** Record Layer\
**Created:** [July 16, 2021, 4:33am UTC](https://forums.foundationdb.org/t/deleterecordasync-does-not-delete-secondary-index/2797 "2021-07-16T04:33:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sergey](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/sergey/32/1136_2.png) [@sergey](https://forums.foundationdb.org/u/sergey)\
**Post date:** [July 16, 2021, 4:33am UTC](https://forums.foundationdb.org/t/deleterecordasync-does-not-delete-secondary-index/2797/1 "2021-07-16T04:33:49Z")

</div>

Hi everyone! I see an issue using Record Layer and do not know how could I fix it properly.

I scan in a given recordStore by secondary index (let’s call it expiration\_timestamp) and getting primary keys that using later in deleteRecordAsync. deleteRecordAsync returns false for some pKeys. I check and looks like there is a number of indexes that referring to nonexistent records.  
First of all, I’m not sure how could it happen, as I understand that deleteRecord should delete both the record itself and related index(indexes), but some records have been deleted and related indexes are still there.

So the question is how to delete invalid indexes using record layer? And how to prevent such cases in a first place? I do appreciate if someone could help with this case.

Thanks in advance,  
Sergey

---

<div class="post-metadata">

**Author:** ![scgray](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/scgray/32/30_2.png) [@scgray](https://forums.foundationdb.org/u/scgray)\
**Post date:** [August 5, 2021, 12:16pm UTC](https://forums.foundationdb.org/t/deleterecordasync-does-not-delete-secondary-index/2797/2 "2021-08-05T12:16:12Z")

</div>

Hi Sergey, I apologize for the long delay in replying to your question. To clarify to wording:

> as I understand that deleteRecord should delete both the record itself and related index(indexes), but some records have been deleted and related indexes are still there.

I assume you mean “related index _entries_ are still there”? Deleting a record should never delete and index, only the index entries associated with that index.

Do you have an example program that can reproduce this? Certainly, deleting a record should clean up all associated entries, so we would be very interested in a case that can reproduce this problem.

We do have tools to repair invalid value indexes (see [https://github.com/FoundationDB/fdb-record-layer/blob/dbd90f9c6bc57518777c756340d02ede2e1e83c5/fdb-record-layer-core/src/test/java/com/apple/foundationdb/record/provider/foundationdb/OnlineIndexScrubberTest.java#L50](https://github.com/FoundationDB/fdb-record-layer/blob/dbd90f9c6bc57518777c756340d02ede2e1e83c5/fdb-record-layer-core/src/test/java/com/apple/foundationdb/record/provider/foundationdb/OnlineIndexScrubberTest.java#L50), note that we don’t have tools to repair other index types at the moment). However, if this indeed is a repeatable bug, we would be very interested in having an example of a test that can result in a corrupt index.
