Skip to content

Commit 4b4c051

Browse files
committed
feat(storagenode): add empty payload validation
Add validation for empty payloads in the Append RPC. If there is no payload in the append request, the RPC returns a gRPC status code of InvalidArgument.
1 parent 4df0785 commit 4b4c051

File tree

4 files changed

+49
-36
lines changed

4 files changed

+49
-36
lines changed

internal/storagenode/log_server.go

+5
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ func (ls *logServer) appendStreamRecvLoop(stream snpb.LogIO_AppendServer, cq cha
103103
goto Out
104104
}
105105

106+
if len(req.Payload) == 0 {
107+
err = status.Error(codes.InvalidArgument, "no payload")
108+
goto Out
109+
}
110+
106111
if tpid.Invalid() && lsid.Invalid() {
107112
err = snpb.ValidateTopicLogStream(req)
108113
if err != nil {

internal/storagenode/storagenode_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,14 @@ func TestStorageNode_Append(t *testing.T) {
458458
name string
459459
testf func(t *testing.T, addr string, lc *client.LogClient)
460460
}{
461+
{
462+
name: "NoPayload",
463+
testf: func(t *testing.T, addr string, lc *client.LogClient) {
464+
_, err := lc.Append(context.Background(), tpid, lsid, nil)
465+
require.Error(t, err)
466+
require.Equal(t, codes.InvalidArgument, status.Code(err))
467+
},
468+
},
461469
{
462470
name: "InvalidTopicID",
463471
testf: func(t *testing.T, _ string, lc *client.LogClient) {

proto/snpb/log_io.pb.go

+24-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/snpb/log_io.proto

+12-12
Original file line numberDiff line numberDiff line change
@@ -184,18 +184,18 @@ service LogIO {
184184
// is, some of the log entries could not be stored due to failures.
185185
//
186186
// It returns the following gRPC errors:
187-
// - InvalidArgument: AppendRequest has invalid fields; for instance, TopicID
188-
// is invalid.
189-
// - NotFound: The log stream replica specified by the AppendRequest does not
190-
// exist in the storage node. Note that it does not mean that the log stream
191-
// does not exist in the cluster.
192-
// - FailedPrecondition: The log stream may be sealed; thus, clients cannot
193-
// write the log entry. Clients should unseal the log stream to append a log
194-
// entry to the log stream.
195-
// - Unavailable: The storage node is shutting down, or the log stream replica
196-
// is not primary.
197-
// - Canceled: The client canceled the request.
198-
// - DeadlineExceeded: The client's timeout has expired.
187+
// - InvalidArgument: AppendRequest has invalid fields; for instance,
188+
// TopicID or LogStreamID is invalid, or there is no payload.
189+
// - NotFound: The log stream replica specified by the AppendRequest does
190+
// not exist in the storage node. Note that it does not mean that the log
191+
// stream does not exist in the cluster.
192+
// - FailedPrecondition: The log stream may be sealed; thus, clients cannot
193+
// write the log entry. Clients should unseal the log stream to append a log
194+
// entry to the log stream.
195+
// - Unavailable: The storage node is shutting down, or the log stream
196+
// replica is not primary.
197+
// - Canceled: The client canceled the request.
198+
// - DeadlineExceeded: The client's timeout has expired.
199199
//
200200
// FIXME: Partial failures are not specified by the gRPC error codes.
201201
rpc Append(stream AppendRequest) returns (stream AppendResponse) {}

0 commit comments

Comments
 (0)