func (db *DB) setSync(batch *leveldb.Batch, addr swarm.Address) (gcSizeChange int64, err error) {
	item := addressToItem(addr)
	i, err := db.retrievalDataIndex.Get(item)
	if err != nil {
		if errors.Is(err, leveldb.ErrNotFound) {
			err = db.pushIndex.DeleteInBatch(batch, item)
			if err != nil {
				return 0, err
			}
			return 0, nil
		}
		return 0, err
	}
	item.StoreTimestamp = i.StoreTimestamp
	item.BinID = i.BinID
	item.BatchID = i.BatchID
	item.Index = i.Index
	item.Timestamp = i.Timestamp
	i, err = db.pushIndex.Get(item)
	if err != nil {
		if errors.Is(err, leveldb.ErrNotFound) {
			db.logger.Debugf("localstore: chunk with address %s not found in push index", addr)
		} else {
			return 0, err
		}
	}
	if err == nil && db.tags != nil && i.Tag != 0 {
		t, err := db.tags.Get(i.Tag)
		if err != nil {
			db.logger.Errorf("localstore: get tags on push sync set uid %d: %v", i.Tag, err)
		} else {
			err = t.Inc(tags.StateSynced)
			if err != nil {
				return 0, err
			}
		}
	}
	err = db.pushIndex.DeleteInBatch(batch, item)
	if err != nil {
		return 0, err
	}
	i1, err := db.retrievalAccessIndex.Get(item)
	if err != nil {
		if !errors.Is(err, leveldb.ErrNotFound) {
			return 0, err
		}
		item.AccessTimestamp = now()
		err := db.retrievalAccessIndex.PutInBatch(batch, item)
		if err != nil {
			return 0, err
		}
	} else {
		item.AccessTimestamp = i1.AccessTimestamp
	}
	return db.preserveOrCache(batch, item, false, false)
}
setSync adds the chunk to the garbage collection after syncing by updating indexes
- ModeSetSync - the corresponding tag is incremented, then item is removed
from push sync index
- update to gc index happens given item does not exist in pin index
Provided batch is updated.
package localstore
import (
	"context"
	"errors"
	"time"
	"github.com/ethsana/sana/pkg/shed"
	"github.com/ethsana/sana/pkg/storage"
	"github.com/ethsana/sana/pkg/swarm"
	"github.com/ethsana/sana/pkg/tags"
	"github.com/syndtr/goleveldb/leveldb"
)
func (db *DB) Set(ctx context.Context, mode storage.ModeSet, addrs ...swarm.Address) (err error) {
	db.metrics.ModeSet.Inc()
	defer totalTimeMetric(db.metrics.TotalTimeSet, time.Now())
	err = db.set(mode, addrs...)
	if err != nil {
		db.metrics.ModeSetFailure.Inc()
	}
	return err
}
func (db *DB) set(mode storage.ModeSet, addrs ...swarm.Address) (err error) {
	db.batchMu.Lock()
	defer db.batchMu.Unlock()
	if db.gcRunning {
		db.dirtyAddresses = append(db.dirtyAddresses, addrs...)
	}
	batch := new(leveldb.Batch)
	var gcSizeChange int64                       
	triggerPullFeed := make(map[uint8]struct{})  
	switch mode {
	case storage.ModeSetSync:
		for _, addr := range addrs {
			c, err := db.setSync(batch, addr)
			if err != nil {
				return err
			}
			gcSizeChange += c
		}
	case storage.ModeSetRemove:
		for _, addr := range addrs {
			item := addressToItem(addr)
			c, err := db.setRemove(batch, item, true)
			if err != nil {
				return err
			}
			gcSizeChange += c
		}
	case storage.ModeSetPin:
		for _, addr := range addrs {
			item := addressToItem(addr)
			c, err := db.setPin(batch, item)
			if err != nil {
				return err
			}
			gcSizeChange += c
		}
	case storage.ModeSetUnpin:
		for _, addr := range addrs {
			c, err := db.setUnpin(batch, addr)
			if err != nil {
				return err
			}
			gcSizeChange += c
		}
	default:
		return ErrInvalidMode
	}
	err = db.incGCSizeInBatch(batch, gcSizeChange)
	if err != nil {
		return err
	}
	err = db.shed.WriteBatch(batch)
	if err != nil {
		return err
	}
	for po := range triggerPullFeed {
		db.triggerPullSubscriptions(po)
	}
	return nil
}