-
Notifications
You must be signed in to change notification settings - Fork 2
fix(proxy): retry secondary writes on "read timestamp has been compacted" #528
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
04874ad
fix(proxy): retry secondary writes on "read timestamp has been compac…
claude 1d57c01
feat(proxy): route ElasticKV traffic to the current Raft leader via INFO
claude 0aecc59
refactor(proxy): address review feedback on retry and leader discovery
claude 80157cb
fix(proxy): move nolint:wrapcheck to the return sites in executeSecon…
claude 7becc72
fix(proxy): wrap secondary errors and name retry magic numbers
claude 9eb8c95
refactor(proxy): drop nolint escapes, keep raw redis errors
claude cc5e299
fix(proxy): close LeaderAwareRedisBackend without racing Do()
claude 736b2af
refactor(proxy): bound leader-aware client cache and drop unused test…
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| package adapter | ||
|
|
||
| import ( | ||
| "context" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/bootjp/elastickv/kv" | ||
| "github.com/hashicorp/raft" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| "github.com/tidwall/redcon" | ||
| ) | ||
|
|
||
| type infoTestCoordinator struct { | ||
| isLeader bool | ||
| raftLeader raft.ServerAddress | ||
| clock *kv.HLC | ||
| } | ||
|
|
||
| func (c *infoTestCoordinator) Dispatch(context.Context, *kv.OperationGroup[kv.OP]) (*kv.CoordinateResponse, error) { | ||
| return &kv.CoordinateResponse{}, nil | ||
| } | ||
| func (c *infoTestCoordinator) IsLeader() bool { return c.isLeader } | ||
| func (c *infoTestCoordinator) VerifyLeader() error { return nil } | ||
| func (c *infoTestCoordinator) RaftLeader() raft.ServerAddress { return c.raftLeader } | ||
| func (c *infoTestCoordinator) IsLeaderForKey([]byte) bool { return c.isLeader } | ||
| func (c *infoTestCoordinator) VerifyLeaderForKey([]byte) error { return nil } | ||
| func (c *infoTestCoordinator) RaftLeaderForKey([]byte) raft.ServerAddress { return c.raftLeader } | ||
| func (c *infoTestCoordinator) Clock() *kv.HLC { | ||
| if c.clock == nil { | ||
| c.clock = kv.NewHLC() | ||
| } | ||
| return c.clock | ||
| } | ||
|
|
||
| func TestRedisServer_Info_LeaderRole(t *testing.T) { | ||
| r := &RedisServer{ | ||
| redisAddr: "10.0.0.1:6379", | ||
| leaderRedis: map[raft.ServerAddress]string{"raft-1": "10.0.0.1:6379"}, | ||
| coordinator: &infoTestCoordinator{isLeader: true, raftLeader: "raft-1"}, | ||
| } | ||
|
|
||
| conn := &recordingConn{} | ||
| r.info(conn, redcon.Command{}) | ||
|
|
||
| out := string(conn.bulk) | ||
| assert.Contains(t, out, "# Server", "INFO reply must keep the Server section") | ||
| assert.Contains(t, out, "# Replication", "INFO reply must expose a Replication section") | ||
| assert.Contains(t, out, "role:master", "leader must advertise role:master") | ||
| assert.Contains(t, out, "raft_leader_redis:10.0.0.1:6379", | ||
| "leader must point raft_leader_redis at itself") | ||
| } | ||
|
|
||
| func TestRedisServer_Info_FollowerRole(t *testing.T) { | ||
| r := &RedisServer{ | ||
| redisAddr: "10.0.0.2:6379", | ||
| leaderRedis: map[raft.ServerAddress]string{ | ||
| "raft-1": "10.0.0.1:6379", | ||
| "raft-2": "10.0.0.2:6379", | ||
| }, | ||
| coordinator: &infoTestCoordinator{isLeader: false, raftLeader: "raft-1"}, | ||
| } | ||
|
|
||
| conn := &recordingConn{} | ||
| r.info(conn, redcon.Command{}) | ||
|
|
||
| out := string(conn.bulk) | ||
| assert.Contains(t, out, "role:slave", "follower must advertise role:slave") | ||
| assert.Contains(t, out, "raft_leader_redis:10.0.0.1:6379", | ||
| "follower must point raft_leader_redis at the actual leader") | ||
| // The role must appear in the Replication section so clients that only | ||
| // scan that section still see the right value. | ||
| idx := strings.Index(out, "# Replication") | ||
| require.GreaterOrEqual(t, idx, 0) | ||
| assert.Contains(t, out[idx:], "role:slave") | ||
| assert.Contains(t, out[idx:], "raft_leader_redis:10.0.0.1:6379") | ||
| } | ||
|
|
||
| func TestRedisServer_Info_UnknownLeader(t *testing.T) { | ||
| r := &RedisServer{ | ||
| redisAddr: "10.0.0.3:6379", | ||
| leaderRedis: map[raft.ServerAddress]string{}, | ||
| coordinator: &infoTestCoordinator{isLeader: false, raftLeader: ""}, | ||
| } | ||
|
|
||
| conn := &recordingConn{} | ||
| r.info(conn, redcon.Command{}) | ||
|
|
||
| out := string(conn.bulk) | ||
| assert.Contains(t, out, "role:slave") | ||
| assert.Contains(t, out, "raft_leader_redis:\r\n", | ||
| "when the leader is unknown the field must be empty so clients know to keep probing") | ||
| } |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.