Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug about set idxNew in Set function #51

Closed
luozhiyun993 opened this issue May 7, 2021 · 1 comment
Closed

bug about set idxNew in Set function #51

luozhiyun993 opened this issue May 7, 2021 · 1 comment

Comments

@luozhiyun993
Copy link

func (b *bucket) Set(k, v []byte, h uint64) {
	...
    b.mu.Lock()
	idx := b.idx
	idxNew := idx + kvLen
	chunkIdx := idx / chunkSize
	chunkIdxNew := idxNew / chunkSize
	if chunkIdxNew > chunkIdx { 
		if chunkIdxNew >= uint64(len(b.chunks)) { 
			idx = 0
			idxNew = kvLen
			chunkIdx = 0
			b.gen++ 
			if b.gen&((1<<genSizeBits)-1) == 0 {
				b.gen++
			}
		} else {
            //actually idx = idxNew
			idx = chunkIdxNew * chunkSize
            //bug here: repeat set idxNew = chunkIdxNew * chunkSize + kvlen
			idxNew = idx + kvLen
			chunkIdx = chunkIdxNew
		} 
		b.chunks[chunkIdx] = b.chunks[chunkIdx][:0]
	}
    ...
    // set idxNew
    b.idx = idxNew
}

i mark the bug in the comment. In the else block repeat set idxNew cause need to waste kvLen bytes memory.

@luozhiyun993
Copy link
Author

forget it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant