fix(container/gmap): added WithError methods for KVMap and ListKVMap#4714
Open
LanceAdd wants to merge 5 commits into
Open
fix(container/gmap): added WithError methods for KVMap and ListKVMap#4714LanceAdd wants to merge 5 commits into
LanceAdd wants to merge 5 commits into
Conversation
- 在 KVMap 中新增 GetOrSetFuncWithError 和 GetOrSetFuncLockWithError 方法 - 在 KVMap 中新增 SetIfNotExistFuncWithError 和 SetIfNotExistFuncLockWithError 方法 - 在 ListKVMap 中新增 GetOrSetFuncWithError 和 GetOrSetFuncLockWithError 方法 - 在 ListKVMap 中新增 SetIfNotExistFuncWithError 和 SetIfNotExistFuncLockWithError 方法 - 修改 Instance 函数返回值处理逻辑,使用 GetOrSetFuncLockWithError 替代原有实现 - 所有新方法支持回调函数返回错误并进行相应处理
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds error-returning variants of callback-based methods to KVMap and ListKVMap, refactors the database Instance function to use the new API, and fixes a concurrency bug in ListKVMap.SetIfNotExistFunc.
Changes:
- Added
GetOrSetFuncWithError,GetOrSetFuncLockWithError,SetIfNotExistFuncWithError, andSetIfNotExistFuncLockWithErrormethods to bothKVMapandListKVMapto support callbacks that can return errors - Fixed
ListKVMap.SetIfNotExistFuncto call the callback outside the lock (was incorrectly calling it inside the lock, making it identical toSetIfNotExistFuncLock) - Added the previously missing
ListKVMap.SetIfNotExistFuncLockmethod - Refactored
database/gdb/gdb.goInstance function to useGetOrSetFuncLockWithError, simplifying error handling
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| container/gmap/gmap_hash_k_v_map.go | Added four new WithError method variants for KVMap to support error-returning callbacks |
| container/gmap/gmap_list_k_v_map.go | Added four new WithError method variants, fixed SetIfNotExistFunc to call callback outside lock, added missing SetIfNotExistFuncLock |
| database/gdb/gdb.go | Simplified Instance function to use GetOrSetFuncLockWithError for cleaner error handling |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
新增内容
为
KVMap和ListKVMap新增支持错误返回的回调方法变体:GetOrSetFuncWithErrorf(),若f返回 error 则不写入GetOrSetFuncLockWithErrorf(),若f返回 error 则不写入SetIfNotExistFuncWithErrorf(),若f返回 error 则不写入SetIfNotExistFuncLockWithErrorf(),若f返回 error 则不写入以上方法在以下情况均不会向 map 写入值:
f()返回 non-nil errorf()返回 nil 值同步修复
在实现过程中发现并修复了以下问题:
ListKVMap.SetIfNotExistFunc原实现在持锁状态下调用f(),与
SetIfNotExistFuncLock行为完全相同,违反了命名约定(
Func= 锁外,FuncLock= 锁内)。已重构为在锁外调用f(),同时补充了缺失的
SetIfNotExistFuncLock实现。涉及文件
container/gmap/gmap_hash_k_v_map.gocontainer/gmap/gmap_list_k_v_map.go