ethersphere / swarm

Swarm: Censorship resistant storage and communication infrastructure for a truly sovereign digital society
https://swarm.ethereum.org/
GNU Lesser General Public License v3.0
489 stars 110 forks source link

storage/localstore: Local Pinning fix for pinned chunks #2200

Closed santicomp2014 closed 4 years ago

santicomp2014 commented 4 years ago

This PR closes issue #2195, to summarize GC was removing pinned chunks when it was not supposed to.

This is related to PR #2190 which was the incorrect fix for this bug, thanks to @jmozah for providing the correct fix for this situation.

The solution is to check if the chunk is in the pinIndex before inserting it into gcIndex, this avoids the GC removing the chunk in the first place.

Replaced in these files

ok, err := db.pinIndex.Has(item)
    if err != nil {
        return 0, err
    }
    if !ok {
        err = db.gcIndex.PutInBatch(batch, item)
        if err != nil {
            return 0, err
        }
        gcSizeChange++
    }

Also, the test TestDBDebugIndexes was corrected due to the pinned chunks now being avoided correctly.

Test criteria were:

The bug is also in Bee and it is fixed in a similar fashion