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

fix panic #39

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func openSegmentFile(dirPath, extName string, id uint32) (*segment, error) {
// set the current block number and block size.
offset, err := fd.Seek(0, io.SeekEnd)
if err != nil {
panic(fmt.Errorf("seek to the end of segment file %d%s failed: %v", id, extName, err))
return nil, fmt.Errorf("seek to the end of segment file %d%s failed: %v", id, extName, err)
}

// init cached block
Expand Down Expand Up @@ -244,8 +244,8 @@ func (seg *segment) writeToBuffer(data []byte, chunkBuffer *bytebufferpool.ByteB
// the buffer length must be equal to chunkSize+padding length
endBufferLen := chunkBuffer.Len()
if position.ChunkSize+padding != uint32(endBufferLen-startBufferLen) {
panic(fmt.Sprintf("wrong!!! the chunk size %d is not equal to the buffer len %d",
position.ChunkSize+padding, endBufferLen-startBufferLen))
return nil, fmt.Errorf("wrong!!! the chunk size %d is not equal to the buffer len %d",
position.ChunkSize+padding, endBufferLen-startBufferLen)
}

// update segment status
Expand Down Expand Up @@ -347,7 +347,7 @@ func (seg *segment) appendChunkBuffer(buf *bytebufferpool.ByteBuffer, data []byt
// write the pending chunk buffer to the segment file
func (seg *segment) writeChunkBuffer(buf *bytebufferpool.ByteBuffer) error {
if seg.currentBlockSize > blockSize {
panic("wrong! can not exceed the block size")
return errors.New("the current block size exceeds the maximum block size")
}

// write the data into underlying file
Expand Down
Loading