Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Vault
Commits
859cf45d
Unverified
Commit
859cf45d
authored
3 years ago
by
Nick Cabatoff
Committed by
GitHub
3 years ago
Browse files
Options
Download
Email Patches
Plain Diff
Return an error when trying to store a too-large key with Raft (#13282)
parent
29561c71
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
changelog/13282.txt
+3
-0
changelog/13282.txt
physical/raft/raft.go
+3
-0
physical/raft/raft.go
physical/raft/raft_test.go
+30
-0
physical/raft/raft_test.go
sdk/physical/physical.go
+1
-0
sdk/physical/physical.go
with
37 additions
and
0 deletions
+37
-0
changelog/13282.txt
0 → 100644
+
3
-
0
View file @
859cf45d
```release-note:bug
storage/raft: Fix a panic when trying to write a key > 32KB
```
This diff is collapsed.
Click to expand it.
physical/raft/raft.go
+
3
-
0
View file @
859cf45d
...
...
@@ -1288,6 +1288,9 @@ func (b *RaftBackend) Get(ctx context.Context, path string) (*physical.Entry, er
// or if the call to applyLog fails.
func
(
b
*
RaftBackend
)
Put
(
ctx
context
.
Context
,
entry
*
physical
.
Entry
)
error
{
defer
metrics
.
MeasureSince
([]
string
{
"raft-storage"
,
"put"
},
time
.
Now
())
if
len
(
entry
.
Key
)
>
bolt
.
MaxKeySize
{
return
fmt
.
Errorf
(
"%s, max key size for integrated storage is %d"
,
physical
.
ErrKeyTooLarge
,
bolt
.
MaxKeySize
)
}
if
err
:=
ctx
.
Err
();
err
!=
nil
{
return
err
...
...
This diff is collapsed.
Click to expand it.
physical/raft/raft_test.go
+
30
-
0
View file @
859cf45d
...
...
@@ -15,6 +15,8 @@ import (
"testing"
"time"
"github.com/hashicorp/go-secure-stdlib/base62"
"github.com/go-test/deep"
"github.com/golang/protobuf/proto"
hclog
"github.com/hashicorp/go-hclog"
...
...
@@ -224,6 +226,34 @@ func TestRaft_Backend(t *testing.T) {
physical
.
ExerciseBackend
(
t
,
b
)
}
func
TestRaft_Backend_LargeKey
(
t
*
testing
.
T
)
{
b
,
dir
:=
getRaft
(
t
,
true
,
true
)
defer
os
.
RemoveAll
(
dir
)
key
,
err
:=
base62
.
Random
(
bolt
.
MaxKeySize
+
1
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
entry
:=
&
physical
.
Entry
{
Key
:
key
,
Value
:
[]
byte
(
key
)}
err
=
b
.
Put
(
context
.
Background
(),
entry
)
if
err
==
nil
{
t
.
Fatal
(
"expected error for put entry"
)
}
if
!
strings
.
Contains
(
err
.
Error
(),
physical
.
ErrKeyTooLarge
)
{
t
.
Fatalf
(
"expected %q, got %v"
,
physical
.
ErrKeyTooLarge
,
err
)
}
out
,
err
:=
b
.
Get
(
context
.
Background
(),
entry
.
Key
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error after failed put: %v"
,
err
)
}
if
out
!=
nil
{
t
.
Fatal
(
"expected response entry to be nil after a failed put"
)
}
}
func
TestRaft_Backend_LargeValue
(
t
*
testing
.
T
)
{
b
,
dir
:=
getRaft
(
t
,
true
,
true
)
defer
os
.
RemoveAll
(
dir
)
...
...
This diff is collapsed.
Click to expand it.
sdk/physical/physical.go
+
1
-
0
View file @
859cf45d
...
...
@@ -21,6 +21,7 @@ const (
const
(
ErrValueTooLarge
=
"put failed due to value being too large"
ErrKeyTooLarge
=
"put failed due to key being too large"
)
// Backend is the interface required for a physical
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment