rosedblabs / rosedb

Lightweight, fast and reliable key/value storage engine based on Bitcask.

Home Page:https://rosedblabs.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

lpop or rpop命令每删除一个数据,发送两次discard数据到discard文件

YukinoMashiro opened this issue · comments

Describe the bug
https://github.com/flower-corp/rosedb/blob/main/list.go#L381

	if err = db.saveListMeta(idxTree, key, headSeq, tailSeq); err != nil {
		return nil, err
	}
	// send discard
	db.sendDiscard(oldVal, updated, List)                                                 // 第一次发送到discard
	_, entrySize := logfile.EncodeEntry(ent)
	node := &indexNode{fid: pos.fid, entrySize: entrySize}
	select {
	case db.discards[List].valChan <- node:                                           // 第二次发送到discard
	default:
		logger.Warn("send to discard chan fail")
	}

我认为删除一条entry数据,仅需要发送一次discard文件,因此我想仅保存db.sendDiscard(oldVal, updated, List) ,此处是否为一个bug?
To Reproduce
Steps to reproduce the behavior:
NA

Expected behavior
NA

Additional context
NA

很久之前看的,现在大致看了一下所以也不是很确定,没弄错的话saveListMeta里也有一次。

  1. list元数据信息更新,旧的元数据信息需要被回收
  2. 旧数据删除,需要被回收
  3. “删除”这条log本身在垃圾回收中要被回收,被搬运到新的块中没有意义

@Roderland

  1. list元数据本来也是单独存的一个entry,所以旧的元数据被回收无可厚非
  2. discard文件的作用好像只是记录了各个文件无效数据的比率,不影响回收。
  3. 如果说我只发送一次数据discard文件,感觉也不会影响这条数据的回收

主要就是 @Roderland 说的第三点,“删除”这条log本身在垃圾回收中要被回收
所以也需要在 discard 文件中记录

其他的地方也类似,比如 Delete

@roseduan @Roderland 谢谢两位解答