1
0
Fork 0
master
Philip O'Toole 9 months ago
parent 9c9e911caa
commit 5c5b226303

@ -8,7 +8,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/rqlite/rqlite/v8/command" command "github.com/rqlite/rqlite/v8/command/proto"
"github.com/rqlite/rqlite/v8/random" "github.com/rqlite/rqlite/v8/random"
) )

@ -13,7 +13,7 @@ import (
"time" "time"
"github.com/rqlite/rqlite/v8/auth" "github.com/rqlite/rqlite/v8/auth"
"github.com/rqlite/rqlite/v8/command" command "github.com/rqlite/rqlite/v8/command/proto"
"github.com/rqlite/rqlite/v8/rtls" "github.com/rqlite/rqlite/v8/rtls"
"github.com/rqlite/rqlite/v8/tcp" "github.com/rqlite/rqlite/v8/tcp"
"github.com/rqlite/rqlite/v8/tcp/pool" "github.com/rqlite/rqlite/v8/tcp/pool"

@ -9,7 +9,7 @@ import (
"time" "time"
"github.com/rqlite/rqlite/v8/cluster/servicetest" "github.com/rqlite/rqlite/v8/cluster/servicetest"
"github.com/rqlite/rqlite/v8/command" command "github.com/rqlite/rqlite/v8/command/proto"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )

@ -6,7 +6,7 @@ import (
"os" "os"
"time" "time"
"github.com/rqlite/rqlite/v8/command" command "github.com/rqlite/rqlite/v8/command/proto"
) )
var ( var (

@ -1,7 +1,7 @@
syntax = "proto3"; syntax = "proto3";
package cluster; package cluster;
import "command/command.proto"; import "command/proto/command.proto";
option go_package = "github.com/rqlite/rqlite/v8/cluster"; option go_package = "github.com/rqlite/rqlite/v8/cluster";

@ -5,7 +5,7 @@ import (
"os" "os"
"time" "time"
"github.com/rqlite/rqlite/v8/command" command "github.com/rqlite/rqlite/v8/command/proto"
) )
const ( const (

@ -15,7 +15,7 @@ import (
"time" "time"
"github.com/rqlite/rqlite/v8/auth" "github.com/rqlite/rqlite/v8/auth"
"github.com/rqlite/rqlite/v8/command" command "github.com/rqlite/rqlite/v8/command/proto"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )

@ -10,8 +10,8 @@ import (
"testing" "testing"
"time" "time"
"github.com/rqlite/rqlite/v8/command"
"github.com/rqlite/rqlite/v8/command/encoding" "github.com/rqlite/rqlite/v8/command/encoding"
command "github.com/rqlite/rqlite/v8/command/proto"
) )
const shortWait = 1 * time.Second const shortWait = 1 * time.Second

@ -10,7 +10,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/rqlite/rqlite/v8/command" command "github.com/rqlite/rqlite/v8/command/proto"
"github.com/rqlite/rqlite/v8/testdata/x509" "github.com/rqlite/rqlite/v8/testdata/x509"
) )

@ -9,7 +9,7 @@ import (
"io" "io"
"sync" "sync"
"github.com/rqlite/rqlite/v8/command" "github.com/rqlite/rqlite/v8/command/proto"
) )
const ( const (
@ -70,7 +70,7 @@ func generateStreamID() string {
} }
// Next returns the next LoadChunkRequest, or io.EOF if finished. // Next returns the next LoadChunkRequest, or io.EOF if finished.
func (c *Chunker) Next() (*command.LoadChunkRequest, error) { func (c *Chunker) Next() (*proto.LoadChunkRequest, error) {
c.statsMu.Lock() c.statsMu.Lock()
defer c.statsMu.Unlock() defer c.statsMu.Unlock()
@ -126,7 +126,7 @@ func (c *Chunker) Next() (*command.LoadChunkRequest, error) {
return nil, io.EOF return nil, io.EOF
} }
// If previous chunks were sent, return a final empty chunk with IsLast = true // If previous chunks were sent, return a final empty chunk with IsLast = true
return &command.LoadChunkRequest{ return &proto.LoadChunkRequest{
StreamId: c.streamID, StreamId: c.streamID,
SequenceNum: c.sequenceNum + 1, SequenceNum: c.sequenceNum + 1,
IsLast: true, IsLast: true,
@ -135,7 +135,7 @@ func (c *Chunker) Next() (*command.LoadChunkRequest, error) {
} }
c.sequenceNum++ c.sequenceNum++
return &command.LoadChunkRequest{ return &proto.LoadChunkRequest{
StreamId: c.streamID, StreamId: c.streamID,
SequenceNum: c.sequenceNum, SequenceNum: c.sequenceNum,
IsLast: totalRead < c.chunkSize, IsLast: totalRead < c.chunkSize,
@ -145,8 +145,8 @@ func (c *Chunker) Next() (*command.LoadChunkRequest, error) {
// Abort returns a LoadChunkRequest that signals the receiver to abort the // Abort returns a LoadChunkRequest that signals the receiver to abort the
// given stream. // given stream.
func (c *Chunker) Abort() *command.LoadChunkRequest { func (c *Chunker) Abort() *proto.LoadChunkRequest {
return &command.LoadChunkRequest{ return &proto.LoadChunkRequest{
StreamId: c.streamID, StreamId: c.streamID,
Abort: true, Abort: true,
} }

@ -8,7 +8,7 @@ import (
"os" "os"
"sync" "sync"
"github.com/rqlite/rqlite/v8/command" "github.com/rqlite/rqlite/v8/command/proto"
) )
// Dechunker is a writer that writes chunks to a file and returns the file path when // Dechunker is a writer that writes chunks to a file and returns the file path when
@ -34,7 +34,7 @@ func NewDechunker(dir string) (*Dechunker, error) {
// WriteChunk writes the chunk to the file. If the chunk is the last chunk, the // WriteChunk writes the chunk to the file. If the chunk is the last chunk, the
// the bool return value is true. // the bool return value is true.
func (d *Dechunker) WriteChunk(chunk *command.LoadChunkRequest) (bool, error) { func (d *Dechunker) WriteChunk(chunk *proto.LoadChunkRequest) (bool, error) {
if d.streamID == "" { if d.streamID == "" {
d.streamID = chunk.StreamId d.streamID = chunk.StreamId
} else if d.streamID != chunk.StreamId { } else if d.streamID != chunk.StreamId {

@ -10,12 +10,12 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/rqlite/rqlite/v8/command" "github.com/rqlite/rqlite/v8/command/proto"
) )
func Test_SingleChunk(t *testing.T) { func Test_SingleChunk(t *testing.T) {
data := []byte("Hello, World!") data := []byte("Hello, World!")
chunk := &command.LoadChunkRequest{ chunk := &proto.LoadChunkRequest{
StreamId: "123", StreamId: "123",
SequenceNum: 1, SequenceNum: 1,
IsLast: true, IsLast: true,
@ -58,14 +58,14 @@ func Test_SingleChunk(t *testing.T) {
func Test_MultiChunk(t *testing.T) { func Test_MultiChunk(t *testing.T) {
data1 := []byte("Hello, World!") data1 := []byte("Hello, World!")
chunk1 := &command.LoadChunkRequest{ chunk1 := &proto.LoadChunkRequest{
StreamId: "123", StreamId: "123",
SequenceNum: 1, SequenceNum: 1,
IsLast: false, IsLast: false,
Data: mustCompressData(data1), Data: mustCompressData(data1),
} }
data2 := []byte("I'm OK") data2 := []byte("I'm OK")
chunk2 := &command.LoadChunkRequest{ chunk2 := &proto.LoadChunkRequest{
StreamId: "123", StreamId: "123",
SequenceNum: 2, SequenceNum: 2,
IsLast: true, IsLast: true,
@ -83,7 +83,7 @@ func Test_MultiChunk(t *testing.T) {
t.Fatalf("failed to create Dechunker: %v", err) t.Fatalf("failed to create Dechunker: %v", err)
} }
for _, chunk := range []*command.LoadChunkRequest{chunk1, chunk2} { for _, chunk := range []*proto.LoadChunkRequest{chunk1, chunk2} {
isLast, err := dechunker.WriteChunk(chunk) isLast, err := dechunker.WriteChunk(chunk)
if err != nil { if err != nil {
t.Fatalf("failed to write chunk: %v", err) t.Fatalf("failed to write chunk: %v", err)
@ -110,20 +110,20 @@ func Test_MultiChunk(t *testing.T) {
func Test_MultiChunkNilData(t *testing.T) { func Test_MultiChunkNilData(t *testing.T) {
data1 := []byte("Hello, World!") data1 := []byte("Hello, World!")
chunk1 := &command.LoadChunkRequest{ chunk1 := &proto.LoadChunkRequest{
StreamId: "123", StreamId: "123",
SequenceNum: 1, SequenceNum: 1,
IsLast: false, IsLast: false,
Data: mustCompressData(data1), Data: mustCompressData(data1),
} }
data2 := []byte("I'm OK") data2 := []byte("I'm OK")
chunk2 := &command.LoadChunkRequest{ chunk2 := &proto.LoadChunkRequest{
StreamId: "123", StreamId: "123",
SequenceNum: 2, SequenceNum: 2,
IsLast: false, IsLast: false,
Data: mustCompressData(data2), Data: mustCompressData(data2),
} }
chunk3 := &command.LoadChunkRequest{ chunk3 := &proto.LoadChunkRequest{
StreamId: "123", StreamId: "123",
SequenceNum: 3, SequenceNum: 3,
IsLast: true, IsLast: true,
@ -141,7 +141,7 @@ func Test_MultiChunkNilData(t *testing.T) {
t.Fatalf("failed to create Dechunker: %v", err) t.Fatalf("failed to create Dechunker: %v", err)
} }
for _, chunk := range []*command.LoadChunkRequest{chunk1, chunk2, chunk3} { for _, chunk := range []*proto.LoadChunkRequest{chunk1, chunk2, chunk3} {
isLast, err := dechunker.WriteChunk(chunk) isLast, err := dechunker.WriteChunk(chunk)
if err != nil { if err != nil {
t.Fatalf("failed to write chunk: %v", err) t.Fatalf("failed to write chunk: %v", err)
@ -170,14 +170,14 @@ func Test_UnexpectedStreamID(t *testing.T) {
originalData := []byte("Hello, World!") originalData := []byte("Hello, World!")
compressedData := mustCompressData(originalData) compressedData := mustCompressData(originalData)
chunk1 := &command.LoadChunkRequest{ chunk1 := &proto.LoadChunkRequest{
StreamId: "123", StreamId: "123",
SequenceNum: 1, SequenceNum: 1,
IsLast: false, IsLast: false,
Data: compressedData, Data: compressedData,
} }
chunk2 := &command.LoadChunkRequest{ chunk2 := &proto.LoadChunkRequest{
StreamId: "456", StreamId: "456",
SequenceNum: 2, SequenceNum: 2,
IsLast: true, IsLast: true,
@ -214,14 +214,14 @@ func Test_ChunksOutOfOrder(t *testing.T) {
originalData := []byte("Hello, World!") originalData := []byte("Hello, World!")
compressedData := mustCompressData(originalData) compressedData := mustCompressData(originalData)
chunk1 := &command.LoadChunkRequest{ chunk1 := &proto.LoadChunkRequest{
StreamId: "123", StreamId: "123",
SequenceNum: 1, SequenceNum: 1,
IsLast: false, IsLast: false,
Data: compressedData, Data: compressedData,
} }
chunk3 := &command.LoadChunkRequest{ chunk3 := &proto.LoadChunkRequest{
StreamId: "123", StreamId: "123",
SequenceNum: 3, SequenceNum: 3,
IsLast: true, IsLast: true,
@ -283,7 +283,7 @@ func Test_ReassemblyOfLargeData(t *testing.T) {
end := start + chunkSize end := start + chunkSize
isLast := i == numChunks-1 isLast := i == numChunks-1
if _, err := d.WriteChunk(&command.LoadChunkRequest{ if _, err := d.WriteChunk(&proto.LoadChunkRequest{
StreamId: "1", StreamId: "1",
SequenceNum: int64(i + 1), SequenceNum: int64(i + 1),
IsLast: isLast, IsLast: isLast,

File diff suppressed because it is too large Load Diff

@ -6,7 +6,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/rqlite/rqlite/v8/command" "github.com/rqlite/rqlite/v8/command/proto"
) )
var ( var (
@ -50,7 +50,7 @@ type ResultWithRows struct {
// NewResultRowsFromExecuteQueryResponse returns an API object from an // NewResultRowsFromExecuteQueryResponse returns an API object from an
// ExecuteQueryResponse. // ExecuteQueryResponse.
func NewResultRowsFromExecuteQueryResponse(e *command.ExecuteQueryResponse) (interface{}, error) { func NewResultRowsFromExecuteQueryResponse(e *proto.ExecuteQueryResponse) (interface{}, error) {
if er := e.GetE(); er != nil { if er := e.GetE(); er != nil {
return NewResultFromExecuteResult(er) return NewResultFromExecuteResult(er)
} else if qr := e.GetQ(); qr != nil { } else if qr := e.GetQ(); qr != nil {
@ -63,7 +63,7 @@ func NewResultRowsFromExecuteQueryResponse(e *command.ExecuteQueryResponse) (int
return nil, errors.New("no ExecuteResult, QueryRows, or Error") return nil, errors.New("no ExecuteResult, QueryRows, or Error")
} }
func NewAssociativeResultRowsFromExecuteQueryResponse(e *command.ExecuteQueryResponse) (interface{}, error) { func NewAssociativeResultRowsFromExecuteQueryResponse(e *proto.ExecuteQueryResponse) (interface{}, error) {
if er := e.GetE(); er != nil { if er := e.GetE(); er != nil {
r, err := NewResultFromExecuteResult(er) r, err := NewResultFromExecuteResult(er)
if err != nil { if err != nil {
@ -83,7 +83,7 @@ func NewAssociativeResultRowsFromExecuteQueryResponse(e *command.ExecuteQueryRes
} }
// NewResultFromExecuteResult returns an API Result object from an ExecuteResult. // NewResultFromExecuteResult returns an API Result object from an ExecuteResult.
func NewResultFromExecuteResult(e *command.ExecuteResult) (*Result, error) { func NewResultFromExecuteResult(e *proto.ExecuteResult) (*Result, error) {
return &Result{ return &Result{
LastInsertID: e.LastInsertId, LastInsertID: e.LastInsertId,
RowsAffected: e.RowsAffected, RowsAffected: e.RowsAffected,
@ -93,7 +93,7 @@ func NewResultFromExecuteResult(e *command.ExecuteResult) (*Result, error) {
} }
// NewRowsFromQueryRows returns an API Rows object from a QueryRows // NewRowsFromQueryRows returns an API Rows object from a QueryRows
func NewRowsFromQueryRows(q *command.QueryRows) (*Rows, error) { func NewRowsFromQueryRows(q *proto.QueryRows) (*Rows, error) {
if len(q.Columns) != len(q.Types) { if len(q.Columns) != len(q.Types) {
return nil, ErrTypesColumnsLengthViolation return nil, ErrTypesColumnsLengthViolation
} }
@ -112,7 +112,7 @@ func NewRowsFromQueryRows(q *command.QueryRows) (*Rows, error) {
} }
// NewAssociativeRowsFromQueryRows returns an associative API object from a QueryRows // NewAssociativeRowsFromQueryRows returns an associative API object from a QueryRows
func NewAssociativeRowsFromQueryRows(q *command.QueryRows) (*AssociativeRows, error) { func NewAssociativeRowsFromQueryRows(q *proto.QueryRows) (*AssociativeRows, error) {
if len(q.Columns) != len(q.Types) { if len(q.Columns) != len(q.Types) {
return nil, ErrTypesColumnsLengthViolation return nil, ErrTypesColumnsLengthViolation
} }
@ -145,7 +145,7 @@ func NewAssociativeRowsFromQueryRows(q *command.QueryRows) (*AssociativeRows, er
} }
// NewValuesFromQueryValues sets Values from a QueryValue object. // NewValuesFromQueryValues sets Values from a QueryValue object.
func NewValuesFromQueryValues(dest [][]interface{}, v []*command.Values) error { func NewValuesFromQueryValues(dest [][]interface{}, v []*proto.Values) error {
for n := range v { for n := range v {
vals := v[n] vals := v[n]
if vals == nil { if vals == nil {
@ -162,15 +162,15 @@ func NewValuesFromQueryValues(dest [][]interface{}, v []*command.Values) error {
rowValues := make([]interface{}, len(params)) rowValues := make([]interface{}, len(params))
for p := range params { for p := range params {
switch w := params[p].GetValue().(type) { switch w := params[p].GetValue().(type) {
case *command.Parameter_I: case *proto.Parameter_I:
rowValues[p] = w.I rowValues[p] = w.I
case *command.Parameter_D: case *proto.Parameter_D:
rowValues[p] = w.D rowValues[p] = w.D
case *command.Parameter_B: case *proto.Parameter_B:
rowValues[p] = w.B rowValues[p] = w.B
case *command.Parameter_Y: case *proto.Parameter_Y:
rowValues[p] = w.Y rowValues[p] = w.Y
case *command.Parameter_S: case *proto.Parameter_S:
rowValues[p] = w.S rowValues[p] = w.S
case nil: case nil:
rowValues[p] = nil rowValues[p] = nil
@ -223,13 +223,13 @@ type marshalFunc func(i interface{}) ([]byte, error)
func jsonMarshal(i interface{}, f marshalFunc, assoc bool) ([]byte, error) { func jsonMarshal(i interface{}, f marshalFunc, assoc bool) ([]byte, error) {
switch v := i.(type) { switch v := i.(type) {
case *command.ExecuteResult: case *proto.ExecuteResult:
r, err := NewResultFromExecuteResult(v) r, err := NewResultFromExecuteResult(v)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return f(r) return f(r)
case []*command.ExecuteResult: case []*proto.ExecuteResult:
var err error var err error
results := make([]*Result, len(v)) results := make([]*Result, len(v))
for j := range v { for j := range v {
@ -239,7 +239,7 @@ func jsonMarshal(i interface{}, f marshalFunc, assoc bool) ([]byte, error) {
} }
} }
return f(results) return f(results)
case *command.QueryRows: case *proto.QueryRows:
if assoc { if assoc {
r, err := NewAssociativeRowsFromQueryRows(v) r, err := NewAssociativeRowsFromQueryRows(v)
if err != nil { if err != nil {
@ -253,13 +253,13 @@ func jsonMarshal(i interface{}, f marshalFunc, assoc bool) ([]byte, error) {
} }
return f(r) return f(r)
} }
case *command.ExecuteQueryResponse: case *proto.ExecuteQueryResponse:
r, err := NewResultRowsFromExecuteQueryResponse(v) r, err := NewResultRowsFromExecuteQueryResponse(v)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return f(r) return f(r)
case []*command.QueryRows: case []*proto.QueryRows:
var err error var err error
if assoc { if assoc {
@ -281,7 +281,7 @@ func jsonMarshal(i interface{}, f marshalFunc, assoc bool) ([]byte, error) {
} }
return f(rows) return f(rows)
} }
case []*command.ExecuteQueryResponse: case []*proto.ExecuteQueryResponse:
if assoc { if assoc {
res := make([]interface{}, len(v)) res := make([]interface{}, len(v))
for j := range v { for j := range v {
@ -303,7 +303,7 @@ func jsonMarshal(i interface{}, f marshalFunc, assoc bool) ([]byte, error) {
} }
return f(res) return f(res)
} }
case []*command.Values: case []*proto.Values:
values := make([][]interface{}, len(v)) values := make([][]interface{}, len(v))
if err := NewValuesFromQueryValues(values, v); err != nil { if err := NewValuesFromQueryValues(values, v); err != nil {
return nil, err return nil, err

@ -3,7 +3,7 @@ package encoding
import ( import (
"testing" "testing"
"github.com/rqlite/rqlite/v8/command" "github.com/rqlite/rqlite/v8/command/proto"
) )
func Test_JSONNoEscaping(t *testing.T) { func Test_JSONNoEscaping(t *testing.T) {
@ -25,10 +25,10 @@ func Test_JSONNoEscaping(t *testing.T) {
func Test_MarshalExecuteResult(t *testing.T) { func Test_MarshalExecuteResult(t *testing.T) {
var b []byte var b []byte
var err error var err error
var r *command.ExecuteResult var r *proto.ExecuteResult
enc := Encoder{} enc := Encoder{}
r = &command.ExecuteResult{ r = &proto.ExecuteResult{
LastInsertId: 1, LastInsertId: 1,
RowsAffected: 2, RowsAffected: 2,
Time: 1234, Time: 1234,
@ -41,7 +41,7 @@ func Test_MarshalExecuteResult(t *testing.T) {
t.Fatalf("failed to marshal ExecuteResult: exp %s, got %s", exp, got) t.Fatalf("failed to marshal ExecuteResult: exp %s, got %s", exp, got)
} }
r = &command.ExecuteResult{ r = &proto.ExecuteResult{
LastInsertId: 4, LastInsertId: 4,
RowsAffected: 5, RowsAffected: 5,
Error: "something went wrong", Error: "something went wrong",
@ -78,17 +78,17 @@ func Test_MarshalExecuteResults(t *testing.T) {
var err error var err error
enc := Encoder{} enc := Encoder{}
r1 := &command.ExecuteResult{ r1 := &proto.ExecuteResult{
LastInsertId: 1, LastInsertId: 1,
RowsAffected: 2, RowsAffected: 2,
Time: 1234, Time: 1234,
} }
r2 := &command.ExecuteResult{ r2 := &proto.ExecuteResult{
LastInsertId: 3, LastInsertId: 3,
RowsAffected: 4, RowsAffected: 4,
Time: 5678, Time: 5678,
} }
b, err = enc.JSONMarshal([]*command.ExecuteResult{r1, r2}) b, err = enc.JSONMarshal([]*proto.ExecuteResult{r1, r2})
if err != nil { if err != nil {
t.Fatalf("failed to marshal ExecuteResults: %s", err.Error()) t.Fatalf("failed to marshal ExecuteResults: %s", err.Error())
} }
@ -100,10 +100,10 @@ func Test_MarshalExecuteResults(t *testing.T) {
// Test_MarshalQueryRowsError tests error cases // Test_MarshalQueryRowsError tests error cases
func Test_MarshalQueryRowsError(t *testing.T) { func Test_MarshalQueryRowsError(t *testing.T) {
var err error var err error
var r *command.QueryRows var r *proto.QueryRows
enc := Encoder{} enc := Encoder{}
r = &command.QueryRows{ r = &proto.QueryRows{
Columns: []string{"c1", "c2"}, Columns: []string{"c1", "c2"},
Types: []string{"int", "float", "string"}, Types: []string{"int", "float", "string"},
Time: 6789, Time: 6789,
@ -125,32 +125,32 @@ func Test_MarshalQueryRowsError(t *testing.T) {
func Test_MarshalQueryRows(t *testing.T) { func Test_MarshalQueryRows(t *testing.T) {
var b []byte var b []byte
var err error var err error
var r *command.QueryRows var r *proto.QueryRows
enc := Encoder{} enc := Encoder{}
r = &command.QueryRows{ r = &proto.QueryRows{
Columns: []string{"c1", "c2", "c3"}, Columns: []string{"c1", "c2", "c3"},
Types: []string{"int", "float", "string"}, Types: []string{"int", "float", "string"},
Time: 6789, Time: 6789,
} }
values := make([]*command.Parameter, len(r.Columns)) values := make([]*proto.Parameter, len(r.Columns))
values[0] = &command.Parameter{ values[0] = &proto.Parameter{
Value: &command.Parameter_I{ Value: &proto.Parameter_I{
I: 123, I: 123,
}, },
} }
values[1] = &command.Parameter{ values[1] = &proto.Parameter{
Value: &command.Parameter_D{ Value: &proto.Parameter_D{
D: 678.0, D: 678.0,
}, },
} }
values[2] = &command.Parameter{ values[2] = &proto.Parameter{
Value: &command.Parameter_S{ Value: &proto.Parameter_S{
S: "fiona", S: "fiona",
}, },
} }
r.Values = []*command.Values{ r.Values = []*proto.Values{
{Parameters: values}, {Parameters: values},
} }
@ -196,34 +196,34 @@ func Test_MarshalQueryRows(t *testing.T) {
func Test_MarshalQueryAssociativeRows(t *testing.T) { func Test_MarshalQueryAssociativeRows(t *testing.T) {
var b []byte var b []byte
var err error var err error
var r *command.QueryRows var r *proto.QueryRows
enc := Encoder{ enc := Encoder{
Associative: true, Associative: true,
} }
r = &command.QueryRows{ r = &proto.QueryRows{
Columns: []string{"c1", "c2", "c3"}, Columns: []string{"c1", "c2", "c3"},
Types: []string{"int", "float", "string"}, Types: []string{"int", "float", "string"},
Time: 6789, Time: 6789,
} }
values := make([]*command.Parameter, len(r.Columns)) values := make([]*proto.Parameter, len(r.Columns))
values[0] = &command.Parameter{ values[0] = &proto.Parameter{
Value: &command.Parameter_I{ Value: &proto.Parameter_I{
I: 123, I: 123,
}, },
} }
values[1] = &command.Parameter{ values[1] = &proto.Parameter{
Value: &command.Parameter_D{ Value: &proto.Parameter_D{
D: 678.0, D: 678.0,
}, },
} }
values[2] = &command.Parameter{ values[2] = &proto.Parameter{
Value: &command.Parameter_S{ Value: &proto.Parameter_S{
S: "fiona", S: "fiona",
}, },
} }
r.Values = []*command.Values{ r.Values = []*proto.Values{
{Parameters: values}, {Parameters: values},
} }
@ -264,36 +264,36 @@ func Test_MarshalQueryAssociativeRows(t *testing.T) {
func Test_MarshalQueryRowses(t *testing.T) { func Test_MarshalQueryRowses(t *testing.T) {
var b []byte var b []byte
var err error var err error
var r *command.QueryRows var r *proto.QueryRows
enc := Encoder{} enc := Encoder{}
r = &command.QueryRows{ r = &proto.QueryRows{
Columns: []string{"c1", "c2", "c3"}, Columns: []string{"c1", "c2", "c3"},
Types: []string{"int", "float", "string"}, Types: []string{"int", "float", "string"},
Time: 6789, Time: 6789,
} }
values := make([]*command.Parameter, len(r.Columns)) values := make([]*proto.Parameter, len(r.Columns))
values[0] = &command.Parameter{ values[0] = &proto.Parameter{
Value: &command.Parameter_I{ Value: &proto.Parameter_I{
I: 123, I: 123,
}, },
} }
values[1] = &command.Parameter{ values[1] = &proto.Parameter{
Value: &command.Parameter_D{ Value: &proto.Parameter_D{
D: 678.0, D: 678.0,
}, },
} }
values[2] = &command.Parameter{ values[2] = &proto.Parameter{
Value: &command.Parameter_S{ Value: &proto.Parameter_S{
S: "fiona", S: "fiona",
}, },
} }
r.Values = []*command.Values{ r.Values = []*proto.Values{
{Parameters: values}, {Parameters: values},
} }
b, err = enc.JSONMarshal([]*command.QueryRows{r, r}) b, err = enc.JSONMarshal([]*proto.QueryRows{r, r})
if err != nil { if err != nil {
t.Fatalf("failed to marshal QueryRows: %s", err.Error()) t.Fatalf("failed to marshal QueryRows: %s", err.Error())
} }
@ -306,38 +306,38 @@ func Test_MarshalQueryRowses(t *testing.T) {
func Test_MarshalQueryAssociativeRowses(t *testing.T) { func Test_MarshalQueryAssociativeRowses(t *testing.T) {
var b []byte var b []byte
var err error var err error
var r *command.QueryRows var r *proto.QueryRows
enc := Encoder{ enc := Encoder{
Associative: true, Associative: true,
} }
r = &command.QueryRows{ r = &proto.QueryRows{
Columns: []string{"c1", "c2", "c3"}, Columns: []string{"c1", "c2", "c3"},
Types: []string{"int", "float", "string"}, Types: []string{"int", "float", "string"},
Time: 6789, Time: 6789,
} }
values := make([]*command.Parameter, len(r.Columns)) values := make([]*proto.Parameter, len(r.Columns))
values[0] = &command.Parameter{ values[0] = &proto.Parameter{
Value: &command.Parameter_I{ Value: &proto.Parameter_I{
I: 123, I: 123,
}, },
} }
values[1] = &command.Parameter{ values[1] = &proto.Parameter{
Value: &command.Parameter_D{ Value: &proto.Parameter_D{
D: 678.0, D: 678.0,
}, },
} }
values[2] = &command.Parameter{ values[2] = &proto.Parameter{
Value: &command.Parameter_S{ Value: &proto.Parameter_S{
S: "fiona", S: "fiona",
}, },
} }
r.Values = []*command.Values{ r.Values = []*proto.Values{
{Parameters: values}, {Parameters: values},
} }
b, err = enc.JSONMarshal([]*command.QueryRows{r, r}) b, err = enc.JSONMarshal([]*proto.QueryRows{r, r})
if err != nil { if err != nil {
t.Fatalf("failed to marshal QueryRows: %s", err.Error()) t.Fatalf("failed to marshal QueryRows: %s", err.Error())
} }
@ -351,15 +351,15 @@ func Test_MarshalExecuteQueryResponse(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
responses []*command.ExecuteQueryResponse responses []*proto.ExecuteQueryResponse
expected string expected string
}{ }{
{ {
name: "Test with ExecuteResult", name: "Test with ExecuteResult",
responses: []*command.ExecuteQueryResponse{ responses: []*proto.ExecuteQueryResponse{
{ {
Result: &command.ExecuteQueryResponse_E{ Result: &proto.ExecuteQueryResponse_E{
E: &command.ExecuteResult{ E: &proto.ExecuteResult{
LastInsertId: 123, LastInsertId: 123,
RowsAffected: 456, RowsAffected: 456,
}, },
@ -370,22 +370,22 @@ func Test_MarshalExecuteQueryResponse(t *testing.T) {
}, },
{ {
name: "Test with QueryRows", name: "Test with QueryRows",
responses: []*command.ExecuteQueryResponse{ responses: []*proto.ExecuteQueryResponse{
{ {
Result: &command.ExecuteQueryResponse_Q{ Result: &proto.ExecuteQueryResponse_Q{
Q: &command.QueryRows{ Q: &proto.QueryRows{
Columns: []string{"column1", "column2"}, Columns: []string{"column1", "column2"},
Types: []string{"type1", "type2"}, Types: []string{"type1", "type2"},
Values: []*command.Values{ Values: []*proto.Values{
{ {
Parameters: []*command.Parameter{ Parameters: []*proto.Parameter{
{ {
Value: &command.Parameter_I{ Value: &proto.Parameter_I{
I: 123, I: 123,
}, },
}, },
{ {
Value: &command.Parameter_S{ Value: &proto.Parameter_S{
S: "fiona", S: "fiona",
}, },
}, },
@ -400,35 +400,35 @@ func Test_MarshalExecuteQueryResponse(t *testing.T) {
}, },
{ {
name: "Test with ExecuteResult and QueryRows", name: "Test with ExecuteResult and QueryRows",
responses: []*command.ExecuteQueryResponse{ responses: []*proto.ExecuteQueryResponse{
{ {
Result: &command.ExecuteQueryResponse_E{ Result: &proto.ExecuteQueryResponse_E{
E: &command.ExecuteResult{ E: &proto.ExecuteResult{
LastInsertId: 123, LastInsertId: 123,
RowsAffected: 456, RowsAffected: 456,
}, },
}, },
}, },
{ {
Result: &command.ExecuteQueryResponse_Error{ Result: &proto.ExecuteQueryResponse_Error{
Error: "unique constraint failed", Error: "unique constraint failed",
}, },
}, },
{ {
Result: &command.ExecuteQueryResponse_Q{ Result: &proto.ExecuteQueryResponse_Q{
Q: &command.QueryRows{ Q: &proto.QueryRows{
Columns: []string{"column1", "column2"}, Columns: []string{"column1", "column2"},
Types: []string{"int", "text"}, Types: []string{"int", "text"},
Values: []*command.Values{ Values: []*proto.Values{
{ {
Parameters: []*command.Parameter{ Parameters: []*proto.Parameter{
{ {
Value: &command.Parameter_I{ Value: &proto.Parameter_I{
I: 456, I: 456,
}, },
}, },
{ {
Value: &command.Parameter_S{ Value: &proto.Parameter_S{
S: "declan", S: "declan",
}, },
}, },
@ -439,11 +439,11 @@ func Test_MarshalExecuteQueryResponse(t *testing.T) {
}, },
}, },
{ {
Result: &command.ExecuteQueryResponse_Q{ Result: &proto.ExecuteQueryResponse_Q{
Q: &command.QueryRows{ Q: &proto.QueryRows{
Columns: []string{"column1", "column2"}, Columns: []string{"column1", "column2"},
Types: []string{"int", "text"}, Types: []string{"int", "text"},
Values: []*command.Values{}, Values: []*proto.Values{},
}, },
}, },
}, },
@ -473,15 +473,15 @@ func Test_MarshalExecuteQueryAssociativeResponse(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
responses []*command.ExecuteQueryResponse responses []*proto.ExecuteQueryResponse
expected string expected string
}{ }{
{ {
name: "Test with ExecuteResult", name: "Test with ExecuteResult",
responses: []*command.ExecuteQueryResponse{ responses: []*proto.ExecuteQueryResponse{
{ {
Result: &command.ExecuteQueryResponse_E{ Result: &proto.ExecuteQueryResponse_E{
E: &command.ExecuteResult{ E: &proto.ExecuteResult{
LastInsertId: 123, LastInsertId: 123,
RowsAffected: 456, RowsAffected: 456,
}, },
@ -492,22 +492,22 @@ func Test_MarshalExecuteQueryAssociativeResponse(t *testing.T) {
}, },
{ {
name: "Test with QueryRows", name: "Test with QueryRows",
responses: []*command.ExecuteQueryResponse{ responses: []*proto.ExecuteQueryResponse{
{ {
Result: &command.ExecuteQueryResponse_Q{ Result: &proto.ExecuteQueryResponse_Q{
Q: &command.QueryRows{ Q: &proto.QueryRows{
Columns: []string{"column1", "column2"}, Columns: []string{"column1", "column2"},
Types: []string{"type1", "type2"}, Types: []string{"type1", "type2"},
Values: []*command.Values{ Values: []*proto.Values{
{ {
Parameters: []*command.Parameter{ Parameters: []*proto.Parameter{
{ {
Value: &command.Parameter_I{ Value: &proto.Parameter_I{
I: 123, I: 123,
}, },
}, },
{ {
Value: &command.Parameter_S{ Value: &proto.Parameter_S{
S: "fiona", S: "fiona",
}, },
}, },
@ -522,35 +522,35 @@ func Test_MarshalExecuteQueryAssociativeResponse(t *testing.T) {
}, },
{ {
name: "Test with ExecuteResult and QueryRows", name: "Test with ExecuteResult and QueryRows",
responses: []*command.ExecuteQueryResponse{ responses: []*proto.ExecuteQueryResponse{
{ {
Result: &command.ExecuteQueryResponse_E{ Result: &proto.ExecuteQueryResponse_E{
E: &command.ExecuteResult{ E: &proto.ExecuteResult{
LastInsertId: 123, LastInsertId: 123,
RowsAffected: 456, RowsAffected: 456,
}, },
}, },
}, },
{ {
Result: &command.ExecuteQueryResponse_Error{ Result: &proto.ExecuteQueryResponse_Error{
Error: "unique constraint failed", Error: "unique constraint failed",
}, },
}, },
{ {
Result: &command.ExecuteQueryResponse_Q{ Result: &proto.ExecuteQueryResponse_Q{
Q: &command.QueryRows{ Q: &proto.QueryRows{
Columns: []string{"column1", "column2"}, Columns: []string{"column1", "column2"},
Types: []string{"int", "text"}, Types: []string{"int", "text"},
Values: []*command.Values{ Values: []*proto.Values{
{ {
Parameters: []*command.Parameter{ Parameters: []*proto.Parameter{
{ {
Value: &command.Parameter_I{ Value: &proto.Parameter_I{
I: 456, I: 456,
}, },
}, },
{ {
Value: &command.Parameter_S{ Value: &proto.Parameter_S{
S: "declan", S: "declan",
}, },
}, },
@ -561,17 +561,17 @@ func Test_MarshalExecuteQueryAssociativeResponse(t *testing.T) {
}, },
}, },
{ {
Result: &command.ExecuteQueryResponse_Q{ Result: &proto.ExecuteQueryResponse_Q{
Q: &command.QueryRows{ Q: &proto.QueryRows{
Columns: []string{"aaa", "bbb"}, Columns: []string{"aaa", "bbb"},
Types: []string{"int", "text"}, Types: []string{"int", "text"},
Values: []*command.Values{}, Values: []*proto.Values{},
}, },
}, },
}, },
{ {
Result: &command.ExecuteQueryResponse_Q{ Result: &proto.ExecuteQueryResponse_Q{
Q: &command.QueryRows{ Q: &proto.QueryRows{
Columns: []string{"ccc", "ddd"}, Columns: []string{"ccc", "ddd"},
Types: []string{"int", "text"}, Types: []string{"int", "text"},
Values: nil, Values: nil,

@ -7,7 +7,8 @@ import (
"fmt" "fmt"
"io" "io"
"google.golang.org/protobuf/proto" "github.com/rqlite/rqlite/v8/command/proto"
pb "google.golang.org/protobuf/proto"
) )
const ( const (
@ -18,8 +19,8 @@ const (
// Requester is the interface objects must support to be marshaled // Requester is the interface objects must support to be marshaled
// successfully. // successfully.
type Requester interface { type Requester interface {
proto.Message pb.Message
GetRequest() *Request GetRequest() *proto.Request
} }
// RequestMarshaler marshals Request objects, potentially performing // RequestMarshaler marshals Request objects, potentially performing
@ -80,7 +81,7 @@ func (m *RequestMarshaler) Marshal(r Requester) ([]byte, bool, error) {
} }
} }
b, err := proto.Marshal(r) b, err := pb.Marshal(r)
if err != nil { if err != nil {
return nil, false, err return nil, false, err
} }
@ -124,28 +125,28 @@ func (m *RequestMarshaler) Stats() map[string]interface{} {
} }
// Marshal marshals a Command. // Marshal marshals a Command.
func Marshal(c *Command) ([]byte, error) { func Marshal(c *proto.Command) ([]byte, error) {
return proto.Marshal(c) return pb.Marshal(c)
} }
// Unmarshal unmarshals a Command // Unmarshal unmarshals a Command
func Unmarshal(b []byte, c *Command) error { func Unmarshal(b []byte, c *proto.Command) error {
return proto.Unmarshal(b, c) return pb.Unmarshal(b, c)
} }
// MarshalNoop marshals a Noop command // MarshalNoop marshals a Noop command
func MarshalNoop(c *Noop) ([]byte, error) { func MarshalNoop(c *proto.Noop) ([]byte, error) {
return proto.Marshal(c) return pb.Marshal(c)
} }
// UnmarshalNoop unmarshals a Noop command // UnmarshalNoop unmarshals a Noop command
func UnmarshalNoop(b []byte, c *Noop) error { func UnmarshalNoop(b []byte, c *proto.Noop) error {
return proto.Unmarshal(b, c) return pb.Unmarshal(b, c)
} }
// MarshalLoadRequest marshals a LoadRequest command // MarshalLoadRequest marshals a LoadRequest command
func MarshalLoadRequest(lr *LoadRequest) ([]byte, error) { func MarshalLoadRequest(lr *proto.LoadRequest) ([]byte, error) {
b, err := proto.Marshal(lr) b, err := pb.Marshal(lr)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -153,27 +154,27 @@ func MarshalLoadRequest(lr *LoadRequest) ([]byte, error) {
} }
// UnmarshalLoadRequest unmarshals a LoadRequest command // UnmarshalLoadRequest unmarshals a LoadRequest command
func UnmarshalLoadRequest(b []byte, lr *LoadRequest) error { func UnmarshalLoadRequest(b []byte, lr *proto.LoadRequest) error {
u, err := gzUncompress(b) u, err := gzUncompress(b)
if err != nil { if err != nil {
return err return err
} }
return proto.Unmarshal(u, lr) return pb.Unmarshal(u, lr)
} }
// MarshalLoadChunkRequest marshals a LoadChunkRequest command // MarshalLoadChunkRequest marshals a LoadChunkRequest command
func MarshalLoadChunkRequest(lr *LoadChunkRequest) ([]byte, error) { func MarshalLoadChunkRequest(lr *proto.LoadChunkRequest) ([]byte, error) {
return proto.Marshal(lr) return pb.Marshal(lr)
} }
// UnmarshalLoadChunkRequest unmarshals a LoadChunkRequest command // UnmarshalLoadChunkRequest unmarshals a LoadChunkRequest command
func UnmarshalLoadChunkRequest(b []byte, lr *LoadChunkRequest) error { func UnmarshalLoadChunkRequest(b []byte, lr *proto.LoadChunkRequest) error {
return proto.Unmarshal(b, lr) return pb.Unmarshal(b, lr)
} }
// UnmarshalSubCommand unmarshalls a sub command m. It assumes that // UnmarshalSubCommand unmarshalls a sub command m. It assumes that
// m is the correct type. // m is the correct type.
func UnmarshalSubCommand(c *Command, m proto.Message) error { func UnmarshalSubCommand(c *proto.Command, m pb.Message) error {
b := c.SubCommand b := c.SubCommand
if c.Compressed { if c.Compressed {
var err error var err error
@ -183,7 +184,7 @@ func UnmarshalSubCommand(c *Command, m proto.Message) error {
} }
} }
if err := proto.Unmarshal(b, m); err != nil { if err := pb.Unmarshal(b, m); err != nil {
return fmt.Errorf("proto unmarshal: %s", err) return fmt.Errorf("proto unmarshal: %s", err)
} }
return nil return nil

@ -4,7 +4,8 @@ import (
"sync" "sync"
"testing" "testing"
"google.golang.org/protobuf/proto" "github.com/rqlite/rqlite/v8/command/proto"
pb "google.golang.org/protobuf/proto"
) )
func Test_NewRequestMarshaler(t *testing.T) { func Test_NewRequestMarshaler(t *testing.T) {
@ -16,9 +17,9 @@ func Test_NewRequestMarshaler(t *testing.T) {
func Test_MarshalUncompressed(t *testing.T) { func Test_MarshalUncompressed(t *testing.T) {
rm := NewRequestMarshaler() rm := NewRequestMarshaler()
r := &QueryRequest{ r := &proto.QueryRequest{
Request: &Request{ Request: &proto.Request{
Statements: []*Statement{ Statements: []*proto.Statement{
{ {
Sql: `INSERT INTO "names" VALUES(1,'bob','123-45-678')`, Sql: `INSERT INTO "names" VALUES(1,'bob','123-45-678')`,
}, },
@ -36,8 +37,8 @@ func Test_MarshalUncompressed(t *testing.T) {
t.Fatal("Marshaled QueryRequest incorrectly compressed") t.Fatal("Marshaled QueryRequest incorrectly compressed")
} }
c := &Command{ c := &proto.Command{
Type: Command_COMMAND_TYPE_QUERY, Type: proto.Command_COMMAND_TYPE_QUERY,
SubCommand: b, SubCommand: b,
Compressed: comp, Compressed: comp,
} }
@ -47,18 +48,18 @@ func Test_MarshalUncompressed(t *testing.T) {
t.Fatalf("failed to marshal Command: %s", err) t.Fatalf("failed to marshal Command: %s", err)
} }
var nc Command var nc proto.Command
if err := Unmarshal(b, &nc); err != nil { if err := Unmarshal(b, &nc); err != nil {
t.Fatalf("failed to unmarshal Command: %s", err) t.Fatalf("failed to unmarshal Command: %s", err)
} }
if nc.Type != Command_COMMAND_TYPE_QUERY { if nc.Type != proto.Command_COMMAND_TYPE_QUERY {
t.Fatalf("unmarshaled command has wrong type: %s", nc.Type) t.Fatalf("unmarshaled command has wrong type: %s", nc.Type)
} }
if nc.Compressed { if nc.Compressed {
t.Fatal("Unmarshaled QueryRequest incorrectly marked as compressed") t.Fatal("Unmarshaled QueryRequest incorrectly marked as compressed")
} }
var nr QueryRequest var nr proto.QueryRequest
if err := UnmarshalSubCommand(&nc, &nr); err != nil { if err := UnmarshalSubCommand(&nc, &nr); err != nil {
t.Fatalf("failed to unmarshal sub command: %s", err) t.Fatalf("failed to unmarshal sub command: %s", err)
} }
@ -81,9 +82,9 @@ func Test_MarshalCompressedBatch(t *testing.T) {
rm.BatchThreshold = 1 rm.BatchThreshold = 1
rm.ForceCompression = true rm.ForceCompression = true
r := &QueryRequest{ r := &proto.QueryRequest{
Request: &Request{ Request: &proto.Request{
Statements: []*Statement{ Statements: []*proto.Statement{
{ {
Sql: `INSERT INTO "names" VALUES(1,'bob','123-45-678')`, Sql: `INSERT INTO "names" VALUES(1,'bob','123-45-678')`,
}, },
@ -101,8 +102,8 @@ func Test_MarshalCompressedBatch(t *testing.T) {
t.Fatal("Marshaled QueryRequest wasn't compressed") t.Fatal("Marshaled QueryRequest wasn't compressed")
} }
c := &Command{ c := &proto.Command{
Type: Command_COMMAND_TYPE_QUERY, Type: proto.Command_COMMAND_TYPE_QUERY,
SubCommand: b, SubCommand: b,
Compressed: comp, Compressed: comp,
} }
@ -112,22 +113,22 @@ func Test_MarshalCompressedBatch(t *testing.T) {
t.Fatalf("failed to marshal Command: %s", err) t.Fatalf("failed to marshal Command: %s", err)
} }
var nc Command var nc proto.Command
if err := Unmarshal(b, &nc); err != nil { if err := Unmarshal(b, &nc); err != nil {
t.Fatalf("failed to unmarshal Command: %s", err) t.Fatalf("failed to unmarshal Command: %s", err)
} }
if nc.Type != Command_COMMAND_TYPE_QUERY { if nc.Type != proto.Command_COMMAND_TYPE_QUERY {
t.Fatalf("unmarshaled command has wrong type: %s", nc.Type) t.Fatalf("unmarshaled command has wrong type: %s", nc.Type)
} }
if !nc.Compressed { if !nc.Compressed {
t.Fatal("Unmarshaled QueryRequest incorrectly marked as uncompressed") t.Fatal("Unmarshaled QueryRequest incorrectly marked as uncompressed")
} }
var nr QueryRequest var nr proto.QueryRequest
if err := UnmarshalSubCommand(&nc, &nr); err != nil { if err := UnmarshalSubCommand(&nc, &nr); err != nil {
t.Fatalf("failed to unmarshal sub command: %s", err) t.Fatalf("failed to unmarshal sub command: %s", err)
} }
if !proto.Equal(&nr, r) { if !pb.Equal(&nr, r) {
t.Fatal("Original and unmarshaled Query Request are not equal") t.Fatal("Original and unmarshaled Query Request are not equal")
} }
} }
@ -137,9 +138,9 @@ func Test_MarshalCompressedSize(t *testing.T) {
rm.SizeThreshold = 1 rm.SizeThreshold = 1
rm.ForceCompression = true rm.ForceCompression = true
r := &QueryRequest{ r := &proto.QueryRequest{
Request: &Request{ Request: &proto.Request{
Statements: []*Statement{ Statements: []*proto.Statement{
{ {
Sql: `INSERT INTO "names" VALUES(1,'bob','123-45-678')`, Sql: `INSERT INTO "names" VALUES(1,'bob','123-45-678')`,
}, },
@ -157,8 +158,8 @@ func Test_MarshalCompressedSize(t *testing.T) {
t.Fatal("Marshaled QueryRequest wasn't compressed") t.Fatal("Marshaled QueryRequest wasn't compressed")
} }
c := &Command{ c := &proto.Command{
Type: Command_COMMAND_TYPE_QUERY, Type: proto.Command_COMMAND_TYPE_QUERY,
SubCommand: b, SubCommand: b,
Compressed: comp, Compressed: comp,
} }
@ -168,22 +169,22 @@ func Test_MarshalCompressedSize(t *testing.T) {
t.Fatalf("failed to marshal Command: %s", err) t.Fatalf("failed to marshal Command: %s", err)
} }
var nc Command var nc proto.Command
if err := Unmarshal(b, &nc); err != nil { if err := Unmarshal(b, &nc); err != nil {
t.Fatalf("failed to unmarshal Command: %s", err) t.Fatalf("failed to unmarshal Command: %s", err)
} }
if nc.Type != Command_COMMAND_TYPE_QUERY { if nc.Type != proto.Command_COMMAND_TYPE_QUERY {
t.Fatalf("unmarshaled command has wrong type: %s", nc.Type) t.Fatalf("unmarshaled command has wrong type: %s", nc.Type)
} }
if !nc.Compressed { if !nc.Compressed {
t.Fatal("Unmarshaled QueryRequest incorrectly marked as uncompressed") t.Fatal("Unmarshaled QueryRequest incorrectly marked as uncompressed")
} }
var nr QueryRequest var nr proto.QueryRequest
if err := UnmarshalSubCommand(&nc, &nr); err != nil { if err := UnmarshalSubCommand(&nc, &nr); err != nil {
t.Fatalf("failed to unmarshal sub command: %s", err) t.Fatalf("failed to unmarshal sub command: %s", err)
} }
if !proto.Equal(&nr, r) { if !pb.Equal(&nr, r) {
t.Fatal("Original and unmarshaled Query Request are not equal") t.Fatal("Original and unmarshaled Query Request are not equal")
} }
} }
@ -192,9 +193,9 @@ func Test_MarshalWontCompressBatch(t *testing.T) {
rm := NewRequestMarshaler() rm := NewRequestMarshaler()
rm.BatchThreshold = 1 rm.BatchThreshold = 1
r := &QueryRequest{ r := &proto.QueryRequest{
Request: &Request{ Request: &proto.Request{
Statements: []*Statement{ Statements: []*proto.Statement{
{ {
Sql: `INSERT INTO "names" VALUES(1,'bob','123-45-678')`, Sql: `INSERT INTO "names" VALUES(1,'bob','123-45-678')`,
}, },
@ -218,9 +219,9 @@ func Test_MarshalCompressedConcurrent(t *testing.T) {
rm.SizeThreshold = 1 rm.SizeThreshold = 1
rm.ForceCompression = true rm.ForceCompression = true
r := &QueryRequest{ r := &proto.QueryRequest{
Request: &Request{ Request: &proto.Request{
Statements: []*Statement{ Statements: []*proto.Statement{
{ {
Sql: `INSERT INTO "names" VALUES(1,'bob','123-45-678')`, Sql: `INSERT INTO "names" VALUES(1,'bob','123-45-678')`,
}, },
@ -251,9 +252,9 @@ func Test_MarshalWontCompressSize(t *testing.T) {
rm := NewRequestMarshaler() rm := NewRequestMarshaler()
rm.SizeThreshold = 1 rm.SizeThreshold = 1
r := &QueryRequest{ r := &proto.QueryRequest{
Request: &Request{ Request: &proto.Request{
Statements: []*Statement{ Statements: []*proto.Statement{
{ {
Sql: `INSERT INTO "names" VALUES(1,'bob','123-45-678')`, Sql: `INSERT INTO "names" VALUES(1,'bob','123-45-678')`,
}, },

@ -1,7 +1,6 @@
syntax = "proto3"; syntax = "proto3";
package command;
option go_package = "github.com/rqlite/rqlite/v8/command"; option go_package = "github.com/rqlite/rqlite/command/proto";
message Parameter { message Parameter {
oneof value { oneof value {

@ -3,12 +3,13 @@ package command
import ( import (
"strings" "strings"
"github.com/rqlite/rqlite/v8/command/proto"
"github.com/rqlite/sql" "github.com/rqlite/sql"
) )
// Rewrite rewrites the statements such that RANDOM is rewritten, // Rewrite rewrites the statements such that RANDOM is rewritten,
// if r is true. // if r is true.
func Rewrite(stmts []*Statement, r bool) error { func Rewrite(stmts []*proto.Statement, r bool) error {
if !r { if !r {
return nil return nil
} }

@ -3,6 +3,8 @@ package command
import ( import (
"regexp" "regexp"
"testing" "testing"
"github.com/rqlite/rqlite/v8/command/proto"
) )
func Test_NoRewrites(t *testing.T) { func Test_NoRewrites(t *testing.T) {
@ -13,7 +15,7 @@ func Test_NoRewrites(t *testing.T) {
`INSERT INTO foo(name, age) VALUES(?, ?)`, `INSERT INTO foo(name, age) VALUES(?, ?)`,
} { } {
stmts := []*Statement{ stmts := []*proto.Statement{
{ {
Sql: str, Sql: str,
}, },
@ -28,7 +30,7 @@ func Test_NoRewrites(t *testing.T) {
} }
func Test_NoRewritesMulti(t *testing.T) { func Test_NoRewritesMulti(t *testing.T) {
stmts := []*Statement{ stmts := []*proto.Statement{
{ {
Sql: `INSERT INTO "names" VALUES (1, 'bob', '123-45-678')`, Sql: `INSERT INTO "names" VALUES (1, 'bob', '123-45-678')`,
}, },
@ -65,7 +67,7 @@ func Test_Rewrites(t *testing.T) {
`CREATE TABLE tbl (col1 TEXT, ts DATETIME DEFAULT CURRENT_TIMESTAMP)`, `CREATE TABLE tbl \(col1 TEXT, ts DATETIME DEFAULT CURRENT_TIMESTAMP\)`, `CREATE TABLE tbl (col1 TEXT, ts DATETIME DEFAULT CURRENT_TIMESTAMP)`, `CREATE TABLE tbl \(col1 TEXT, ts DATETIME DEFAULT CURRENT_TIMESTAMP\)`,
} }
for i := 0; i < len(testSQLs)-1; i += 2 { for i := 0; i < len(testSQLs)-1; i += 2 {
stmts := []*Statement{ stmts := []*proto.Statement{
{ {
Sql: testSQLs[i], Sql: testSQLs[i],
}, },

@ -18,7 +18,7 @@ import (
"time" "time"
"github.com/rqlite/go-sqlite3" "github.com/rqlite/go-sqlite3"
"github.com/rqlite/rqlite/v8/command" command "github.com/rqlite/rqlite/v8/command/proto"
"github.com/rqlite/rqlite/v8/db/humanize" "github.com/rqlite/rqlite/v8/db/humanize"
) )

@ -7,7 +7,7 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/rqlite/rqlite/v8/command" command "github.com/rqlite/rqlite/v8/command/proto"
"github.com/rqlite/rqlite/v8/testdata/chinook" "github.com/rqlite/rqlite/v8/testdata/chinook"
) )

@ -10,8 +10,8 @@ import (
"testing" "testing"
"time" "time"
"github.com/rqlite/rqlite/v8/command"
"github.com/rqlite/rqlite/v8/command/encoding" "github.com/rqlite/rqlite/v8/command/encoding"
command "github.com/rqlite/rqlite/v8/command/proto"
) )
// Test_OpenNonExistentDatabase tests that opening a non-existent database // Test_OpenNonExistentDatabase tests that opening a non-existent database

@ -7,7 +7,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/rqlite/rqlite/v8/command" command "github.com/rqlite/rqlite/v8/command/proto"
) )
// QueryParams represents the query parameters passed in an HTTP request. // QueryParams represents the query parameters passed in an HTTP request.

@ -6,7 +6,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/rqlite/rqlite/v8/command" command "github.com/rqlite/rqlite/v8/command/proto"
) )
var ( var (

@ -24,6 +24,7 @@ import (
"github.com/rqlite/rqlite/v8/cluster" "github.com/rqlite/rqlite/v8/cluster"
"github.com/rqlite/rqlite/v8/command" "github.com/rqlite/rqlite/v8/command"
"github.com/rqlite/rqlite/v8/command/encoding" "github.com/rqlite/rqlite/v8/command/encoding"
"github.com/rqlite/rqlite/v8/command/proto"
"github.com/rqlite/rqlite/v8/db" "github.com/rqlite/rqlite/v8/db"
"github.com/rqlite/rqlite/v8/queue" "github.com/rqlite/rqlite/v8/queue"
"github.com/rqlite/rqlite/v8/rtls" "github.com/rqlite/rqlite/v8/rtls"
@ -46,20 +47,20 @@ type Database interface {
// to return rows. If timings is true, then timing information will // to return rows. If timings is true, then timing information will
// be return. If tx is true, then either all queries will be executed // be return. If tx is true, then either all queries will be executed
// successfully or it will as though none executed. // successfully or it will as though none executed.
Execute(er *command.ExecuteRequest) ([]*command.ExecuteResult, error) Execute(er *proto.ExecuteRequest) ([]*proto.ExecuteResult, error)
// Query executes a slice of queries, each of which returns rows. If // Query executes a slice of queries, each of which returns rows. If
// timings is true, then timing information will be returned. If tx // timings is true, then timing information will be returned. If tx
// is true, then all queries will take place while a read transaction // is true, then all queries will take place while a read transaction
// is held on the database. // is held on the database.
Query(qr *command.QueryRequest) ([]*command.QueryRows, error) Query(qr *proto.QueryRequest) ([]*proto.QueryRows, error)
// Request processes a slice of requests, each of which can be either // Request processes a slice of requests, each of which can be either
// an Execute or Query request. // an Execute or Query request.
Request(eqr *command.ExecuteQueryRequest) ([]*command.ExecuteQueryResponse, error) Request(eqr *proto.ExecuteQueryRequest) ([]*proto.ExecuteQueryResponse, error)
// Load loads a SQLite file into the system via Raft consensus. // Load loads a SQLite file into the system via Raft consensus.
Load(lr *command.LoadRequest) error Load(lr *proto.LoadRequest) error
} }
// Store is the interface the Raft-based database must implement. // Store is the interface the Raft-based database must implement.
@ -67,7 +68,7 @@ type Store interface {
Database Database
// Remove removes the node from the cluster. // Remove removes the node from the cluster.
Remove(rn *command.RemoveNodeRequest) error Remove(rn *proto.RemoveNodeRequest) error
// LeaderAddr returns the Raft address of the leader of the cluster. // LeaderAddr returns the Raft address of the leader of the cluster.
LeaderAddr() (string, error) LeaderAddr() (string, error)
@ -82,7 +83,7 @@ type Store interface {
Nodes() ([]*store.Server, error) Nodes() ([]*store.Server, error)
// Backup writes backup of the node state to dst // Backup writes backup of the node state to dst
Backup(br *command.BackupRequest, dst io.Writer) error Backup(br *proto.BackupRequest, dst io.Writer) error
// ReadFrom reads and loads a SQLite database into the node, initially bypassing // ReadFrom reads and loads a SQLite database into the node, initially bypassing
// the Raft system. It then triggers a Raft snapshot, which will then make // the Raft system. It then triggers a Raft snapshot, which will then make
@ -101,22 +102,22 @@ type Cluster interface {
GetAddresser GetAddresser
// Execute performs an Execute Request on a remote node. // Execute performs an Execute Request on a remote node.
Execute(er *command.ExecuteRequest, nodeAddr string, creds *cluster.Credentials, timeout time.Duration) ([]*command.ExecuteResult, error) Execute(er *proto.ExecuteRequest, nodeAddr string, creds *cluster.Credentials, timeout time.Duration) ([]*proto.ExecuteResult, error)
// Query performs an Query Request on a remote node. // Query performs an Query Request on a remote node.
Query(qr *command.QueryRequest, nodeAddr string, creds *cluster.Credentials, timeout time.Duration) ([]*command.QueryRows, error) Query(qr *proto.QueryRequest, nodeAddr string, creds *cluster.Credentials, timeout time.Duration) ([]*proto.QueryRows, error)
// Request performs an ExecuteQuery Request on a remote node. // Request performs an ExecuteQuery Request on a remote node.
Request(eqr *command.ExecuteQueryRequest, nodeAddr string, creds *cluster.Credentials, timeout time.Duration) ([]*command.ExecuteQueryResponse, error) Request(eqr *proto.ExecuteQueryRequest, nodeAddr string, creds *cluster.Credentials, timeout time.Duration) ([]*proto.ExecuteQueryResponse, error)
// Backup retrieves a backup from a remote node and writes to the io.Writer. // Backup retrieves a backup from a remote node and writes to the io.Writer.
Backup(br *command.BackupRequest, nodeAddr string, creds *cluster.Credentials, timeout time.Duration, w io.Writer) error Backup(br *proto.BackupRequest, nodeAddr string, creds *cluster.Credentials, timeout time.Duration, w io.Writer) error
// Load loads a SQLite database into the node. // Load loads a SQLite database into the node.
Load(lr *command.LoadRequest, nodeAddr string, creds *cluster.Credentials, timeout time.Duration) error Load(lr *proto.LoadRequest, nodeAddr string, creds *cluster.Credentials, timeout time.Duration) error
// RemoveNode removes a node from the cluster. // RemoveNode removes a node from the cluster.
RemoveNode(rn *command.RemoveNodeRequest, nodeAddr string, creds *cluster.Credentials, timeout time.Duration) error RemoveNode(rn *proto.RemoveNodeRequest, nodeAddr string, creds *cluster.Credentials, timeout time.Duration) error
// Stats returns stats on the Cluster. // Stats returns stats on the Cluster.
Stats() (map[string]interface{}, error) Stats() (map[string]interface{}, error)
@ -136,9 +137,9 @@ type StatusReporter interface {
// DBResults stores either an Execute result, a Query result, or // DBResults stores either an Execute result, a Query result, or
// an ExecuteQuery result. // an ExecuteQuery result.
type DBResults struct { type DBResults struct {
ExecuteResult []*command.ExecuteResult ExecuteResult []*proto.ExecuteResult
QueryRows []*command.QueryRows QueryRows []*proto.QueryRows
ExecuteQueryResponse []*command.ExecuteQueryResponse ExecuteQueryResponse []*proto.ExecuteQueryResponse
AssociativeJSON bool // Render in associative form AssociativeJSON bool // Render in associative form
} }
@ -540,7 +541,7 @@ func (s *Service) handleRemove(w http.ResponseWriter, r *http.Request, qp QueryP
return return
} }
rn := &command.RemoveNodeRequest{ rn := &proto.RemoveNodeRequest{
Id: remoteID, Id: remoteID,
} }
@ -598,7 +599,7 @@ func (s *Service) handleBackup(w http.ResponseWriter, r *http.Request, qp QueryP
return return
} }
br := &command.BackupRequest{ br := &proto.BackupRequest{
Format: qp.BackupFormat(), Format: qp.BackupFormat(),
Leader: !qp.NoLeader(), Leader: !qp.NoLeader(),
Vacuum: qp.Vacuum(), Vacuum: qp.Vacuum(),
@ -674,7 +675,7 @@ func (s *Service) handleLoad(w http.ResponseWriter, r *http.Request, qp QueryPar
if db.IsValidSQLiteData(b) { if db.IsValidSQLiteData(b) {
s.logger.Printf("SQLite database file detected as load data") s.logger.Printf("SQLite database file detected as load data")
lr := &command.LoadRequest{ lr := &proto.LoadRequest{
Data: b, Data: b,
} }
@ -1121,8 +1122,8 @@ func (s *Service) execute(w http.ResponseWriter, r *http.Request, qp QueryParams
return return
} }
er := &command.ExecuteRequest{ er := &proto.ExecuteRequest{
Request: &command.Request{ Request: &proto.Request{
Transaction: qp.Tx(), Transaction: qp.Tx(),
Statements: stmts, Statements: stmts,
}, },
@ -1197,7 +1198,7 @@ func (s *Service) handleQuery(w http.ResponseWriter, r *http.Request, qp QueryPa
// No point rewriting queries if they don't go through the Raft log, since they // No point rewriting queries if they don't go through the Raft log, since they
// will never be replayed from the log anyway. // will never be replayed from the log anyway.
if qp.Level() == command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG { if qp.Level() == proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG {
if err := command.Rewrite(queries, qp.NoRewriteRandom()); err != nil { if err := command.Rewrite(queries, qp.NoRewriteRandom()); err != nil {
http.Error(w, fmt.Sprintf("SQL rewrite: %s", err.Error()), http.StatusInternalServerError) http.Error(w, fmt.Sprintf("SQL rewrite: %s", err.Error()), http.StatusInternalServerError)
return return
@ -1207,8 +1208,8 @@ func (s *Service) handleQuery(w http.ResponseWriter, r *http.Request, qp QueryPa
resp := NewResponse() resp := NewResponse()
resp.Results.AssociativeJSON = qp.Associative() resp.Results.AssociativeJSON = qp.Associative()
qr := &command.QueryRequest{ qr := &proto.QueryRequest{
Request: &command.Request{ Request: &proto.Request{
Transaction: qp.Tx(), Transaction: qp.Tx(),
Statements: queries, Statements: queries,
}, },
@ -1294,8 +1295,8 @@ func (s *Service) handleRequest(w http.ResponseWriter, r *http.Request, qp Query
resp := NewResponse() resp := NewResponse()
resp.Results.AssociativeJSON = qp.Associative() resp.Results.AssociativeJSON = qp.Associative()
eqr := &command.ExecuteQueryRequest{ eqr := &proto.ExecuteQueryRequest{
Request: &command.Request{ Request: &proto.Request{
Transaction: qp.Tx(), Transaction: qp.Tx(),
Statements: stmts, Statements: stmts,
}, },
@ -1502,8 +1503,8 @@ func (s *Service) runQueue() {
case <-s.closeCh: case <-s.closeCh:
return return
case req := <-s.stmtQueue.C: case req := <-s.stmtQueue.C:
er := &command.ExecuteRequest{ er := &proto.ExecuteRequest{
Request: &command.Request{ Request: &proto.Request{
Statements: req.Statements, Statements: req.Statements,
Transaction: s.DefaultQueueTx, Transaction: s.DefaultQueueTx,
}, },
@ -1590,7 +1591,7 @@ func (s *Service) addAllowHeaders(w http.ResponseWriter) {
// addBackupFormatHeader adds the Content-Type header for the backup format. // addBackupFormatHeader adds the Content-Type header for the backup format.
func addBackupFormatHeader(w http.ResponseWriter, qp QueryParams) { func addBackupFormatHeader(w http.ResponseWriter, qp QueryParams) {
w.Header().Set("Content-Type", "application/octet-stream") w.Header().Set("Content-Type", "application/octet-stream")
if qp.BackupFormat() == command.BackupRequest_BACKUP_REQUEST_FORMAT_SQL { if qp.BackupFormat() == proto.BackupRequest_BACKUP_REQUEST_FORMAT_SQL {
w.Header().Set("Content-Type", "application/sql") w.Header().Set("Content-Type", "application/sql")
} }
} }
@ -1634,9 +1635,9 @@ func (s *Service) writeResponse(w http.ResponseWriter, r *http.Request, qp Query
} }
} }
func requestQueries(r *http.Request, qp QueryParams) ([]*command.Statement, error) { func requestQueries(r *http.Request, qp QueryParams) ([]*proto.Statement, error) {
if r.Method == "GET" { if r.Method == "GET" {
return []*command.Statement{ return []*proto.Statement{
{ {
Sql: qp.Query(), Sql: qp.Query(),
}, },
@ -1698,16 +1699,16 @@ func prettyEnabled(e bool) string {
} }
// queryRequestFromStrings converts a slice of strings into a command.QueryRequest // queryRequestFromStrings converts a slice of strings into a command.QueryRequest
func executeRequestFromStrings(s []string, timings, tx bool) *command.ExecuteRequest { func executeRequestFromStrings(s []string, timings, tx bool) *proto.ExecuteRequest {
stmts := make([]*command.Statement, len(s)) stmts := make([]*proto.Statement, len(s))
for i := range s { for i := range s {
stmts[i] = &command.Statement{ stmts[i] = &proto.Statement{
Sql: s[i], Sql: s[i],
} }
} }
return &command.ExecuteRequest{ return &proto.ExecuteRequest{
Request: &command.Request{ Request: &proto.Request{
Statements: stmts, Statements: stmts,
Transaction: tx, Transaction: tx,
}, },

@ -14,7 +14,7 @@ import (
"time" "time"
"github.com/rqlite/rqlite/v8/cluster" "github.com/rqlite/rqlite/v8/cluster"
"github.com/rqlite/rqlite/v8/command" command "github.com/rqlite/rqlite/v8/command/proto"
"github.com/rqlite/rqlite/v8/store" "github.com/rqlite/rqlite/v8/store"
) )

@ -6,7 +6,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/rqlite/rqlite/v8/command" command "github.com/rqlite/rqlite/v8/command/proto"
) )
// stats captures stats for the Queue. // stats captures stats for the Queue.

@ -5,7 +5,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/rqlite/rqlite/v8/command" command "github.com/rqlite/rqlite/v8/command/proto"
) )
var ( var (

@ -7,6 +7,7 @@ import (
"github.com/rqlite/rqlite/v8/command" "github.com/rqlite/rqlite/v8/command"
"github.com/rqlite/rqlite/v8/command/chunking" "github.com/rqlite/rqlite/v8/command/chunking"
"github.com/rqlite/rqlite/v8/command/proto"
sql "github.com/rqlite/rqlite/v8/db" sql "github.com/rqlite/rqlite/v8/db"
) )
@ -24,37 +25,37 @@ func NewCommandProcessor(logger *log.Logger, dm *chunking.DechunkerManager) *Com
} }
// Process processes the given command against the given database. // Process processes the given command against the given database.
func (c *CommandProcessor) Process(data []byte, pDB **sql.DB) (*command.Command, interface{}) { func (c *CommandProcessor) Process(data []byte, pDB **sql.DB) (*proto.Command, interface{}) {
db := *pDB db := *pDB
cmd := &command.Command{} cmd := &proto.Command{}
if err := command.Unmarshal(data, cmd); err != nil { if err := command.Unmarshal(data, cmd); err != nil {
panic(fmt.Sprintf("failed to unmarshal cluster command: %s", err.Error())) panic(fmt.Sprintf("failed to unmarshal cluster command: %s", err.Error()))
} }
switch cmd.Type { switch cmd.Type {
case command.Command_COMMAND_TYPE_QUERY: case proto.Command_COMMAND_TYPE_QUERY:
var qr command.QueryRequest var qr proto.QueryRequest
if err := command.UnmarshalSubCommand(cmd, &qr); err != nil { if err := command.UnmarshalSubCommand(cmd, &qr); err != nil {
panic(fmt.Sprintf("failed to unmarshal query subcommand: %s", err.Error())) panic(fmt.Sprintf("failed to unmarshal query subcommand: %s", err.Error()))
} }
r, err := db.Query(qr.Request, qr.Timings) r, err := db.Query(qr.Request, qr.Timings)
return cmd, &fsmQueryResponse{rows: r, error: err} return cmd, &fsmQueryResponse{rows: r, error: err}
case command.Command_COMMAND_TYPE_EXECUTE: case proto.Command_COMMAND_TYPE_EXECUTE:
var er command.ExecuteRequest var er proto.ExecuteRequest
if err := command.UnmarshalSubCommand(cmd, &er); err != nil { if err := command.UnmarshalSubCommand(cmd, &er); err != nil {
panic(fmt.Sprintf("failed to unmarshal execute subcommand: %s", err.Error())) panic(fmt.Sprintf("failed to unmarshal execute subcommand: %s", err.Error()))
} }
r, err := db.Execute(er.Request, er.Timings) r, err := db.Execute(er.Request, er.Timings)
return cmd, &fsmExecuteResponse{results: r, error: err} return cmd, &fsmExecuteResponse{results: r, error: err}
case command.Command_COMMAND_TYPE_EXECUTE_QUERY: case proto.Command_COMMAND_TYPE_EXECUTE_QUERY:
var eqr command.ExecuteQueryRequest var eqr proto.ExecuteQueryRequest
if err := command.UnmarshalSubCommand(cmd, &eqr); err != nil { if err := command.UnmarshalSubCommand(cmd, &eqr); err != nil {
panic(fmt.Sprintf("failed to unmarshal execute-query subcommand: %s", err.Error())) panic(fmt.Sprintf("failed to unmarshal execute-query subcommand: %s", err.Error()))
} }
r, err := db.Request(eqr.Request, eqr.Timings) r, err := db.Request(eqr.Request, eqr.Timings)
return cmd, &fsmExecuteQueryResponse{results: r, error: err} return cmd, &fsmExecuteQueryResponse{results: r, error: err}
case command.Command_COMMAND_TYPE_LOAD: case proto.Command_COMMAND_TYPE_LOAD:
var lr command.LoadRequest var lr proto.LoadRequest
if err := command.UnmarshalLoadRequest(cmd.SubCommand, &lr); err != nil { if err := command.UnmarshalLoadRequest(cmd.SubCommand, &lr); err != nil {
panic(fmt.Sprintf("failed to unmarshal load subcommand: %s", err.Error())) panic(fmt.Sprintf("failed to unmarshal load subcommand: %s", err.Error()))
} }
@ -74,8 +75,8 @@ func (c *CommandProcessor) Process(data []byte, pDB **sql.DB) (*command.Command,
*pDB = newDB *pDB = newDB
return cmd, &fsmGenericResponse{} return cmd, &fsmGenericResponse{}
case command.Command_COMMAND_TYPE_LOAD_CHUNK: case proto.Command_COMMAND_TYPE_LOAD_CHUNK:
var lcr command.LoadChunkRequest var lcr proto.LoadChunkRequest
if err := command.UnmarshalLoadChunkRequest(cmd.SubCommand, &lcr); err != nil { if err := command.UnmarshalLoadChunkRequest(cmd.SubCommand, &lcr); err != nil {
panic(fmt.Sprintf("failed to unmarshal load-chunk subcommand: %s", err.Error())) panic(fmt.Sprintf("failed to unmarshal load-chunk subcommand: %s", err.Error()))
} }
@ -134,7 +135,7 @@ func (c *CommandProcessor) Process(data []byte, pDB **sql.DB) (*command.Command,
} }
} }
return cmd, &fsmGenericResponse{} return cmd, &fsmGenericResponse{}
case command.Command_COMMAND_TYPE_NOOP: case proto.Command_COMMAND_TYPE_NOOP:
return cmd, &fsmGenericResponse{} return cmd, &fsmGenericResponse{}
default: default:
return cmd, &fsmGenericResponse{error: fmt.Errorf("unhandled command: %v", cmd.Type)} return cmd, &fsmGenericResponse{error: fmt.Errorf("unhandled command: %v", cmd.Type)}

@ -5,7 +5,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/rqlite/rqlite/v8/command" command "github.com/rqlite/rqlite/v8/command/proto"
) )
// Test_SingleNodeProvide tests that the Store correctly implements // Test_SingleNodeProvide tests that the Store correctly implements

@ -22,6 +22,7 @@ import (
"github.com/hashicorp/raft" "github.com/hashicorp/raft"
"github.com/rqlite/rqlite/v8/command" "github.com/rqlite/rqlite/v8/command"
"github.com/rqlite/rqlite/v8/command/chunking" "github.com/rqlite/rqlite/v8/command/chunking"
"github.com/rqlite/rqlite/v8/command/proto"
sql "github.com/rqlite/rqlite/v8/db" sql "github.com/rqlite/rqlite/v8/db"
"github.com/rqlite/rqlite/v8/db/humanize" "github.com/rqlite/rqlite/v8/db/humanize"
wal "github.com/rqlite/rqlite/v8/db/wal" wal "github.com/rqlite/rqlite/v8/db/wal"
@ -1002,7 +1003,7 @@ func (s *Store) Stats() (map[string]interface{}, error) {
} }
// Execute executes queries that return no rows, but do modify the database. // Execute executes queries that return no rows, but do modify the database.
func (s *Store) Execute(ex *command.ExecuteRequest) ([]*command.ExecuteResult, error) { func (s *Store) Execute(ex *proto.ExecuteRequest) ([]*proto.ExecuteResult, error) {
if !s.open { if !s.open {
return nil, ErrNotOpen return nil, ErrNotOpen
} }
@ -1017,14 +1018,14 @@ func (s *Store) Execute(ex *command.ExecuteRequest) ([]*command.ExecuteResult, e
return s.execute(ex) return s.execute(ex)
} }
func (s *Store) execute(ex *command.ExecuteRequest) ([]*command.ExecuteResult, error) { func (s *Store) execute(ex *proto.ExecuteRequest) ([]*proto.ExecuteResult, error) {
b, compressed, err := s.tryCompress(ex) b, compressed, err := s.tryCompress(ex)
if err != nil { if err != nil {
return nil, err return nil, err
} }
c := &command.Command{ c := &proto.Command{
Type: command.Command_COMMAND_TYPE_EXECUTE, Type: proto.Command_COMMAND_TYPE_EXECUTE,
SubCommand: b, SubCommand: b,
Compressed: compressed, Compressed: compressed,
} }
@ -1050,12 +1051,12 @@ func (s *Store) execute(ex *command.ExecuteRequest) ([]*command.ExecuteResult, e
} }
// Query executes queries that return rows, and do not modify the database. // Query executes queries that return rows, and do not modify the database.
func (s *Store) Query(qr *command.QueryRequest) ([]*command.QueryRows, error) { func (s *Store) Query(qr *proto.QueryRequest) ([]*proto.QueryRows, error) {
if !s.open { if !s.open {
return nil, ErrNotOpen return nil, ErrNotOpen
} }
if qr.Level == command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG { if qr.Level == proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG {
if s.raft.State() != raft.Leader { if s.raft.State() != raft.Leader {
return nil, ErrNotLeader return nil, ErrNotLeader
} }
@ -1068,8 +1069,8 @@ func (s *Store) Query(qr *command.QueryRequest) ([]*command.QueryRows, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
c := &command.Command{ c := &proto.Command{
Type: command.Command_COMMAND_TYPE_QUERY, Type: proto.Command_COMMAND_TYPE_QUERY,
SubCommand: b, SubCommand: b,
Compressed: compressed, Compressed: compressed,
} }
@ -1094,11 +1095,11 @@ func (s *Store) Query(qr *command.QueryRequest) ([]*command.QueryRows, error) {
return r.rows, r.error return r.rows, r.error
} }
if qr.Level == command.QueryRequest_QUERY_REQUEST_LEVEL_WEAK && s.raft.State() != raft.Leader { if qr.Level == proto.QueryRequest_QUERY_REQUEST_LEVEL_WEAK && s.raft.State() != raft.Leader {
return nil, ErrNotLeader return nil, ErrNotLeader
} }
if s.raft.State() != raft.Leader && qr.Level == command.QueryRequest_QUERY_REQUEST_LEVEL_NONE && if s.raft.State() != raft.Leader && qr.Level == proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE &&
qr.Freshness > 0 && time.Since(s.raft.LastContact()).Nanoseconds() > qr.Freshness { qr.Freshness > 0 && time.Since(s.raft.LastContact()).Nanoseconds() > qr.Freshness {
return nil, ErrStaleRead return nil, ErrStaleRead
} }
@ -1114,13 +1115,13 @@ func (s *Store) Query(qr *command.QueryRequest) ([]*command.QueryRows, error) {
} }
// Request processes a request that may contain both Executes and Queries. // Request processes a request that may contain both Executes and Queries.
func (s *Store) Request(eqr *command.ExecuteQueryRequest) ([]*command.ExecuteQueryResponse, error) { func (s *Store) Request(eqr *proto.ExecuteQueryRequest) ([]*proto.ExecuteQueryResponse, error) {
if !s.open { if !s.open {
return nil, ErrNotOpen return nil, ErrNotOpen
} }
if !s.RequiresLeader(eqr) { if !s.RequiresLeader(eqr) {
if eqr.Level == command.QueryRequest_QUERY_REQUEST_LEVEL_NONE && eqr.Freshness > 0 && if eqr.Level == proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE && eqr.Freshness > 0 &&
time.Since(s.raft.LastContact()).Nanoseconds() > eqr.Freshness { time.Since(s.raft.LastContact()).Nanoseconds() > eqr.Freshness {
return nil, ErrStaleRead return nil, ErrStaleRead
} }
@ -1146,8 +1147,8 @@ func (s *Store) Request(eqr *command.ExecuteQueryRequest) ([]*command.ExecuteQue
return nil, err return nil, err
} }
c := &command.Command{ c := &proto.Command{
Type: command.Command_COMMAND_TYPE_EXECUTE_QUERY, Type: proto.Command_COMMAND_TYPE_EXECUTE_QUERY,
SubCommand: b, SubCommand: b,
Compressed: compressed, Compressed: compressed,
} }
@ -1173,12 +1174,12 @@ func (s *Store) Request(eqr *command.ExecuteQueryRequest) ([]*command.ExecuteQue
} }
// Backup writes a consistent snapshot of the underlying database to dst. // Backup writes a consistent snapshot of the underlying database to dst.
func (s *Store) Backup(br *command.BackupRequest, dst io.Writer) (retErr error) { func (s *Store) Backup(br *proto.BackupRequest, dst io.Writer) (retErr error) {
if !s.open { if !s.open {
return ErrNotOpen return ErrNotOpen
} }
if br.Vacuum && br.Format != command.BackupRequest_BACKUP_REQUEST_FORMAT_BINARY { if br.Vacuum && br.Format != proto.BackupRequest_BACKUP_REQUEST_FORMAT_BINARY {
return ErrInvalidBackupFormat return ErrInvalidBackupFormat
} }
@ -1194,7 +1195,7 @@ func (s *Store) Backup(br *command.BackupRequest, dst io.Writer) (retErr error)
return ErrNotLeader return ErrNotLeader
} }
if br.Format == command.BackupRequest_BACKUP_REQUEST_FORMAT_BINARY { if br.Format == proto.BackupRequest_BACKUP_REQUEST_FORMAT_BINARY {
f, err := os.CreateTemp(s.dbDir, backupScatchPattern) f, err := os.CreateTemp(s.dbDir, backupScatchPattern)
if err != nil { if err != nil {
return err return err
@ -1216,7 +1217,7 @@ func (s *Store) Backup(br *command.BackupRequest, dst io.Writer) (retErr error)
_, err = io.Copy(dst, of) _, err = io.Copy(dst, of)
return err return err
} else if br.Format == command.BackupRequest_BACKUP_REQUEST_FORMAT_SQL { } else if br.Format == proto.BackupRequest_BACKUP_REQUEST_FORMAT_SQL {
return s.db.Dump(dst) return s.db.Dump(dst)
} }
return ErrInvalidBackupFormat return ErrInvalidBackupFormat
@ -1224,7 +1225,7 @@ func (s *Store) Backup(br *command.BackupRequest, dst io.Writer) (retErr error)
// Loads an entire SQLite file into the database, sending the request // Loads an entire SQLite file into the database, sending the request
// through the Raft log. // through the Raft log.
func (s *Store) Load(lr *command.LoadRequest) error { func (s *Store) Load(lr *proto.LoadRequest) error {
if !s.open { if !s.open {
return ErrNotOpen return ErrNotOpen
} }
@ -1242,7 +1243,7 @@ func (s *Store) Load(lr *command.LoadRequest) error {
// load loads an entire SQLite file into the database, and is for internal use // load loads an entire SQLite file into the database, and is for internal use
// only. It does not check for readiness, and does not update statistics. // only. It does not check for readiness, and does not update statistics.
func (s *Store) load(lr *command.LoadRequest) error { func (s *Store) load(lr *proto.LoadRequest) error {
startT := time.Now() startT := time.Now()
b, err := command.MarshalLoadRequest(lr) b, err := command.MarshalLoadRequest(lr)
@ -1251,8 +1252,8 @@ func (s *Store) load(lr *command.LoadRequest) error {
return err return err
} }
c := &command.Command{ c := &proto.Command{
Type: command.Command_COMMAND_TYPE_LOAD, Type: proto.Command_COMMAND_TYPE_LOAD,
SubCommand: b, SubCommand: b,
} }
@ -1364,7 +1365,7 @@ func (s *Store) ReadFrom(r io.Reader) (int64, error) {
// with the *advertised Raft address* which the Store doesn't know about. // with the *advertised Raft address* which the Store doesn't know about.
// //
// Notifying is idempotent. A node may repeatedly notify the Store without issue. // Notifying is idempotent. A node may repeatedly notify the Store without issue.
func (s *Store) Notify(nr *command.NotifyRequest) error { func (s *Store) Notify(nr *proto.NotifyRequest) error {
if !s.open { if !s.open {
return ErrNotOpen return ErrNotOpen
} }
@ -1423,7 +1424,7 @@ func (s *Store) Notify(nr *command.NotifyRequest) error {
// Join joins a node, identified by id and located at addr, to this store. // Join joins a node, identified by id and located at addr, to this store.
// The node must be ready to respond to Raft communications at that address. // The node must be ready to respond to Raft communications at that address.
func (s *Store) Join(jr *command.JoinRequest) error { func (s *Store) Join(jr *proto.JoinRequest) error {
if !s.open { if !s.open {
return ErrNotOpen return ErrNotOpen
} }
@ -1491,7 +1492,7 @@ func (s *Store) Join(jr *command.JoinRequest) error {
} }
// Remove removes a node from the store. // Remove removes a node from the store.
func (s *Store) Remove(rn *command.RemoveNodeRequest) error { func (s *Store) Remove(rn *proto.RemoveNodeRequest) error {
if !s.open { if !s.open {
return ErrNotOpen return ErrNotOpen
} }
@ -1510,7 +1511,7 @@ func (s *Store) Remove(rn *command.RemoveNodeRequest) error {
// consumes a slot in the Raft log, but has no other effect on the // consumes a slot in the Raft log, but has no other effect on the
// system. // system.
func (s *Store) Noop(id string) (raft.ApplyFuture, error) { func (s *Store) Noop(id string) (raft.ApplyFuture, error) {
n := &command.Noop{ n := &proto.Noop{
Id: id, Id: id,
} }
b, err := command.MarshalNoop(n) b, err := command.MarshalNoop(n)
@ -1518,8 +1519,8 @@ func (s *Store) Noop(id string) (raft.ApplyFuture, error) {
return nil, err return nil, err
} }
c := &command.Command{ c := &proto.Command{
Type: command.Command_COMMAND_TYPE_NOOP, Type: proto.Command_COMMAND_TYPE_NOOP,
SubCommand: b, SubCommand: b,
} }
bc, err := command.Marshal(c) bc, err := command.Marshal(c)
@ -1532,8 +1533,8 @@ func (s *Store) Noop(id string) (raft.ApplyFuture, error) {
// RequiresLeader returns whether the given ExecuteQueryRequest must be // RequiresLeader returns whether the given ExecuteQueryRequest must be
// processed on the cluster Leader. // processed on the cluster Leader.
func (s *Store) RequiresLeader(eqr *command.ExecuteQueryRequest) bool { func (s *Store) RequiresLeader(eqr *proto.ExecuteQueryRequest) bool {
if eqr.Level != command.QueryRequest_QUERY_REQUEST_LEVEL_NONE { if eqr.Level != proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE {
return true return true
} }
@ -1631,17 +1632,17 @@ func (s *Store) updateAppliedIndex() chan struct{} {
} }
type fsmExecuteResponse struct { type fsmExecuteResponse struct {
results []*command.ExecuteResult results []*proto.ExecuteResult
error error error error
} }
type fsmQueryResponse struct { type fsmQueryResponse struct {
rows []*command.QueryRows rows []*proto.QueryRows
error error error error
} }
type fsmExecuteQueryResponse struct { type fsmExecuteQueryResponse struct {
results []*command.ExecuteQueryResponse results []*proto.ExecuteQueryResponse
error error error error
} }
@ -1673,7 +1674,7 @@ func (s *Store) fsmApply(l *raft.Log) (e interface{}) {
} }
cmd, r := s.cmdProc.Process(l.Data, &s.db) cmd, r := s.cmdProc.Process(l.Data, &s.db)
if cmd.Type == command.Command_COMMAND_TYPE_NOOP { if cmd.Type == proto.Command_COMMAND_TYPE_NOOP {
s.numNoops++ s.numNoops++
} }
return r return r
@ -2039,7 +2040,7 @@ func (s *Store) installRestore() error {
if err != nil { if err != nil {
return err return err
} }
lr := &command.LoadRequest{ lr := &proto.LoadRequest{
Data: b, Data: b,
} }
return s.load(lr) return s.load(lr)

@ -6,7 +6,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/rqlite/rqlite/v8/command" command "github.com/rqlite/rqlite/v8/command/proto"
) )
func test_OpenStoreCloseStartup(t *testing.T, s *Store) { func test_OpenStoreCloseStartup(t *testing.T, s *Store) {

@ -13,8 +13,8 @@ import (
"testing" "testing"
"time" "time"
"github.com/rqlite/rqlite/v8/command"
"github.com/rqlite/rqlite/v8/command/encoding" "github.com/rqlite/rqlite/v8/command/encoding"
"github.com/rqlite/rqlite/v8/command/proto"
"github.com/rqlite/rqlite/v8/db" "github.com/rqlite/rqlite/v8/db"
"github.com/rqlite/rqlite/v8/random" "github.com/rqlite/rqlite/v8/random"
"github.com/rqlite/rqlite/v8/testdata/chinook" "github.com/rqlite/rqlite/v8/testdata/chinook"
@ -77,7 +77,7 @@ func Test_SingleNodeOnDiskSQLitePath(t *testing.T) {
} }
qr := queryRequestFromString("SELECT * FROM foo", false, false) qr := queryRequestFromString("SELECT * FROM foo", false, false)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err := s.Query(qr) r, err := s.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query single node: %s", err.Error()) t.Fatalf("failed to query single node: %s", err.Error())
@ -367,7 +367,7 @@ func Test_OpenStoreCloseSingleNode(t *testing.T) {
} }
qr := queryRequestFromString("SELECT * FROM foo", false, false) qr := queryRequestFromString("SELECT * FROM foo", false, false)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err := s.Query(qr) r, err := s.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query single node: %s", err.Error()) t.Fatalf("failed to query single node: %s", err.Error())
@ -496,7 +496,7 @@ func Test_SingleNodeExecuteQuery(t *testing.T) {
} }
qr := queryRequestFromString("SELECT * FROM foo", false, false) qr := queryRequestFromString("SELECT * FROM foo", false, false)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err := s.Query(qr) r, err := s.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query single node: %s", err.Error()) t.Fatalf("failed to query single node: %s", err.Error())
@ -564,21 +564,21 @@ func Test_SingleNodeExecuteQueryTx(t *testing.T) {
} }
qr := queryRequestFromString("SELECT * FROM foo", false, true) qr := queryRequestFromString("SELECT * FROM foo", false, true)
var r []*command.QueryRows var r []*proto.QueryRows
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
_, err = s.Query(qr) _, err = s.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query single node: %s", err.Error()) t.Fatalf("failed to query single node: %s", err.Error())
} }
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_WEAK qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_WEAK
_, err = s.Query(qr) _, err = s.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query single node: %s", err.Error()) t.Fatalf("failed to query single node: %s", err.Error())
} }
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err = s.Query(qr) r, err = s.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query single node: %s", err.Error()) t.Fatalf("failed to query single node: %s", err.Error())
@ -660,7 +660,7 @@ func Test_SingleNodeRequest(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
eqr := executeQueryRequestFromStrings(tt.stmts, command.QueryRequest_QUERY_REQUEST_LEVEL_WEAK, false, false) eqr := executeQueryRequestFromStrings(tt.stmts, proto.QueryRequest_QUERY_REQUEST_LEVEL_WEAK, false, false)
r, err := s.Request(eqr) r, err := s.Request(eqr)
if err != nil { if err != nil {
t.Fatalf("failed to execute request on single node: %s", err.Error()) t.Fatalf("failed to execute request on single node: %s", err.Error())
@ -740,7 +740,7 @@ func Test_SingleNodeRequestTx(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
eqr := executeQueryRequestFromStrings(tt.stmts, command.QueryRequest_QUERY_REQUEST_LEVEL_WEAK, false, tt.tx) eqr := executeQueryRequestFromStrings(tt.stmts, proto.QueryRequest_QUERY_REQUEST_LEVEL_WEAK, false, tt.tx)
r, err := s.Request(eqr) r, err := s.Request(eqr)
if err != nil { if err != nil {
t.Fatalf("failed to execute request on single node: %s", err.Error()) t.Fatalf("failed to execute request on single node: %s", err.Error())
@ -780,18 +780,18 @@ func Test_SingleNodeRequestParameters(t *testing.T) {
} }
tests := []struct { tests := []struct {
request *command.ExecuteQueryRequest request *proto.ExecuteQueryRequest
expected string expected string
}{ }{
{ {
request: &command.ExecuteQueryRequest{ request: &proto.ExecuteQueryRequest{
Request: &command.Request{ Request: &proto.Request{
Statements: []*command.Statement{ Statements: []*proto.Statement{
{ {
Sql: "SELECT * FROM foo WHERE id = ?", Sql: "SELECT * FROM foo WHERE id = ?",
Parameters: []*command.Parameter{ Parameters: []*proto.Parameter{
{ {
Value: &command.Parameter_I{ Value: &proto.Parameter_I{
I: 1, I: 1,
}, },
}, },
@ -803,14 +803,14 @@ func Test_SingleNodeRequestParameters(t *testing.T) {
expected: `[{"columns":["id","name"],"types":["integer","text"],"values":[[1,"fiona"]]}]`, expected: `[{"columns":["id","name"],"types":["integer","text"],"values":[[1,"fiona"]]}]`,
}, },
{ {
request: &command.ExecuteQueryRequest{ request: &proto.ExecuteQueryRequest{
Request: &command.Request{ Request: &proto.Request{
Statements: []*command.Statement{ Statements: []*proto.Statement{
{ {
Sql: "SELECT id FROM foo WHERE name = :qux", Sql: "SELECT id FROM foo WHERE name = :qux",
Parameters: []*command.Parameter{ Parameters: []*proto.Parameter{
{ {
Value: &command.Parameter_S{ Value: &proto.Parameter_S{
S: "fiona", S: "fiona",
}, },
Name: "qux", Name: "qux",
@ -894,7 +894,7 @@ func Test_SingleNodeOnDiskFileExecuteQuery(t *testing.T) {
} }
// Every query should return the same results, so use a function for the check. // Every query should return the same results, so use a function for the check.
check := func(r []*command.QueryRows) { check := func(r []*proto.QueryRows) {
if exp, got := `["id","name"]`, asJSON(r[0].Columns); exp != got { if exp, got := `["id","name"]`, asJSON(r[0].Columns); exp != got {
t.Fatalf("unexpected results for query\nexp: %s\ngot: %s", exp, got) t.Fatalf("unexpected results for query\nexp: %s\ngot: %s", exp, got)
} }
@ -904,7 +904,7 @@ func Test_SingleNodeOnDiskFileExecuteQuery(t *testing.T) {
} }
qr := queryRequestFromString("SELECT * FROM foo", false, false) qr := queryRequestFromString("SELECT * FROM foo", false, false)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err := s.Query(qr) r, err := s.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query single node: %s", err.Error()) t.Fatalf("failed to query single node: %s", err.Error())
@ -912,7 +912,7 @@ func Test_SingleNodeOnDiskFileExecuteQuery(t *testing.T) {
check(r) check(r)
qr = queryRequestFromString("SELECT * FROM foo", false, false) qr = queryRequestFromString("SELECT * FROM foo", false, false)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_WEAK qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_WEAK
r, err = s.Query(qr) r, err = s.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query single node: %s", err.Error()) t.Fatalf("failed to query single node: %s", err.Error())
@ -920,7 +920,7 @@ func Test_SingleNodeOnDiskFileExecuteQuery(t *testing.T) {
check(r) check(r)
qr = queryRequestFromString("SELECT * FROM foo", false, false) qr = queryRequestFromString("SELECT * FROM foo", false, false)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err = s.Query(qr) r, err = s.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query single node: %s", err.Error()) t.Fatalf("failed to query single node: %s", err.Error())
@ -929,7 +929,7 @@ func Test_SingleNodeOnDiskFileExecuteQuery(t *testing.T) {
qr = queryRequestFromString("SELECT * FROM foo", false, true) qr = queryRequestFromString("SELECT * FROM foo", false, true)
qr.Timings = true qr.Timings = true
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err = s.Query(qr) r, err = s.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query single node: %s", err.Error()) t.Fatalf("failed to query single node: %s", err.Error())
@ -938,7 +938,7 @@ func Test_SingleNodeOnDiskFileExecuteQuery(t *testing.T) {
qr = queryRequestFromString("SELECT * FROM foo", true, false) qr = queryRequestFromString("SELECT * FROM foo", true, false)
qr.Request.Transaction = true qr.Request.Transaction = true
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err = s.Query(qr) r, err = s.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query single node: %s", err.Error()) t.Fatalf("failed to query single node: %s", err.Error())
@ -1071,7 +1071,7 @@ COMMIT;
// Check that data were loaded correctly. // Check that data were loaded correctly.
qr := queryRequestFromString("SELECT * FROM foo", false, true) qr := queryRequestFromString("SELECT * FROM foo", false, true)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err := s.Query(qr) r, err := s.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query single node: %s", err.Error()) t.Fatalf("failed to query single node: %s", err.Error())
@ -1159,7 +1159,7 @@ func Test_SingleNodeLoadTextChinook(t *testing.T) {
// Check that data were loaded correctly. // Check that data were loaded correctly.
qr := queryRequestFromString("SELECT count(*) FROM track", false, true) qr := queryRequestFromString("SELECT count(*) FROM track", false, true)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err := s.Query(qr) r, err := s.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query single node: %s", err.Error()) t.Fatalf("failed to query single node: %s", err.Error())
@ -1172,7 +1172,7 @@ func Test_SingleNodeLoadTextChinook(t *testing.T) {
} }
qr = queryRequestFromString("SELECT count(*) FROM album", false, true) qr = queryRequestFromString("SELECT count(*) FROM album", false, true)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err = s.Query(qr) r, err = s.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query single node: %s", err.Error()) t.Fatalf("failed to query single node: %s", err.Error())
@ -1185,7 +1185,7 @@ func Test_SingleNodeLoadTextChinook(t *testing.T) {
} }
qr = queryRequestFromString("SELECT count(*) FROM artist", false, true) qr = queryRequestFromString("SELECT count(*) FROM artist", false, true)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err = s.Query(qr) r, err = s.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query single node: %s", err.Error()) t.Fatalf("failed to query single node: %s", err.Error())
@ -1229,7 +1229,7 @@ COMMIT;
// Check that data were loaded correctly. // Check that data were loaded correctly.
qr := queryRequestFromString("SELECT * FROM bar", false, true) qr := queryRequestFromString("SELECT * FROM bar", false, true)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err := s.Query(qr) r, err := s.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query single node: %s", err.Error()) t.Fatalf("failed to query single node: %s", err.Error())
@ -1248,7 +1248,7 @@ COMMIT;
// Check that data were loaded correctly. // Check that data were loaded correctly.
qr = queryRequestFromString("SELECT * FROM foo WHERE id=2", false, true) qr = queryRequestFromString("SELECT * FROM foo WHERE id=2", false, true)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err = s.Query(qr) r, err = s.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query single node: %s", err.Error()) t.Fatalf("failed to query single node: %s", err.Error())
@ -1260,7 +1260,7 @@ COMMIT;
t.Fatalf("unexpected results for query\nexp: %s\ngot: %s", exp, got) t.Fatalf("unexpected results for query\nexp: %s\ngot: %s", exp, got)
} }
qr = queryRequestFromString("SELECT count(*) FROM foo", false, true) qr = queryRequestFromString("SELECT count(*) FROM foo", false, true)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err = s.Query(qr) r, err = s.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query single node: %s", err.Error()) t.Fatalf("failed to query single node: %s", err.Error())
@ -1274,7 +1274,7 @@ COMMIT;
// Check pre-existing data is gone. // Check pre-existing data is gone.
qr = queryRequestFromString("SELECT * FROM bar", false, true) qr = queryRequestFromString("SELECT * FROM bar", false, true)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err = s.Query(qr) r, err = s.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query single node: %s", err.Error()) t.Fatalf("failed to query single node: %s", err.Error())
@ -1379,7 +1379,7 @@ COMMIT;
// Check that data were loaded correctly. // Check that data were loaded correctly.
qr := queryRequestFromString("SELECT * FROM bar", false, true) qr := queryRequestFromString("SELECT * FROM bar", false, true)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err := s.Query(qr) r, err := s.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query single node: %s", err.Error()) t.Fatalf("failed to query single node: %s", err.Error())
@ -1415,7 +1415,7 @@ COMMIT;
// Check that data were loaded correctly. // Check that data were loaded correctly.
qr = queryRequestFromString("SELECT * FROM foo WHERE id=2", false, true) qr = queryRequestFromString("SELECT * FROM foo WHERE id=2", false, true)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err = s.Query(qr) r, err = s.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query single node: %s", err.Error()) t.Fatalf("failed to query single node: %s", err.Error())
@ -1427,7 +1427,7 @@ COMMIT;
t.Fatalf("unexpected results for query\nexp: %s\ngot: %s", exp, got) t.Fatalf("unexpected results for query\nexp: %s\ngot: %s", exp, got)
} }
qr = queryRequestFromString("SELECT count(*) FROM foo", false, true) qr = queryRequestFromString("SELECT count(*) FROM foo", false, true)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err = s.Query(qr) r, err = s.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query single node: %s", err.Error()) t.Fatalf("failed to query single node: %s", err.Error())
@ -1441,7 +1441,7 @@ COMMIT;
// Check pre-existing data is gone. // Check pre-existing data is gone.
qr = queryRequestFromString("SELECT * FROM bar", false, true) qr = queryRequestFromString("SELECT * FROM bar", false, true)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err = s.Query(qr) r, err = s.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query single node: %s", err.Error()) t.Fatalf("failed to query single node: %s", err.Error())
@ -1503,7 +1503,7 @@ func Test_SingleNodeRecoverNoChange(t *testing.T) {
queryTest := func() { queryTest := func() {
t.Helper() t.Helper()
qr := queryRequestFromString("SELECT * FROM foo", false, false) qr := queryRequestFromString("SELECT * FROM foo", false, false)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err := s.Query(qr) r, err := s.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query single node: %s", err.Error()) t.Fatalf("failed to query single node: %s", err.Error())
@ -1571,7 +1571,7 @@ func Test_SingleNodeRecoverNetworkChange(t *testing.T) {
queryTest := func(s *Store) { queryTest := func(s *Store) {
qr := queryRequestFromString("SELECT * FROM foo", false, false) qr := queryRequestFromString("SELECT * FROM foo", false, false)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err := s.Query(qr) r, err := s.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query single node: %s", err.Error()) t.Fatalf("failed to query single node: %s", err.Error())
@ -1652,7 +1652,7 @@ func Test_SingleNodeRecoverNetworkChangeSnapshot(t *testing.T) {
queryTest := func(s *Store, c int) { queryTest := func(s *Store, c int) {
qr := queryRequestFromString("SELECT COUNT(*) FROM foo", false, false) qr := queryRequestFromString("SELECT COUNT(*) FROM foo", false, false)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err := s.Query(qr) r, err := s.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query single node: %s", err.Error()) t.Fatalf("failed to query single node: %s", err.Error())
@ -2238,7 +2238,7 @@ func Test_MultiNodeExecuteQuery(t *testing.T) {
} }
qr := queryRequestFromString("SELECT * FROM foo", false, false) qr := queryRequestFromString("SELECT * FROM foo", false, false)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err := s0.Query(qr) r, err := s0.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query leader node: %s", err.Error()) t.Fatalf("failed to query leader node: %s", err.Error())
@ -2256,17 +2256,17 @@ func Test_MultiNodeExecuteQuery(t *testing.T) {
t.Fatalf("error waiting for follower to apply index: %s:", err.Error()) t.Fatalf("error waiting for follower to apply index: %s:", err.Error())
} }
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_WEAK qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_WEAK
_, err = s1.Query(qr) _, err = s1.Query(qr)
if err == nil { if err == nil {
t.Fatalf("successfully queried non-leader node") t.Fatalf("successfully queried non-leader node")
} }
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
_, err = s1.Query(qr) _, err = s1.Query(qr)
if err == nil { if err == nil {
t.Fatalf("successfully queried non-leader node") t.Fatalf("successfully queried non-leader node")
} }
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err = s1.Query(qr) r, err = s1.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query follower node: %s", err.Error()) t.Fatalf("failed to query follower node: %s", err.Error())
@ -2284,17 +2284,17 @@ func Test_MultiNodeExecuteQuery(t *testing.T) {
t.Fatalf("error waiting for follower to apply index: %s:", err.Error()) t.Fatalf("error waiting for follower to apply index: %s:", err.Error())
} }
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_WEAK qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_WEAK
_, err = s1.Query(qr) _, err = s1.Query(qr)
if err == nil { if err == nil {
t.Fatalf("successfully queried non-voting node with Weak") t.Fatalf("successfully queried non-voting node with Weak")
} }
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
_, err = s1.Query(qr) _, err = s1.Query(qr)
if err == nil { if err == nil {
t.Fatalf("successfully queried non-voting node with Strong") t.Fatalf("successfully queried non-voting node with Strong")
} }
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err = s1.Query(qr) r, err = s1.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query non-voting node: %s", err.Error()) t.Fatalf("failed to query non-voting node: %s", err.Error())
@ -2336,7 +2336,7 @@ func Test_SingleNodeExecuteQueryFreshness(t *testing.T) {
t.Fatalf("failed to wait for fsmIndex: %s", err.Error()) t.Fatalf("failed to wait for fsmIndex: %s", err.Error())
} }
qr := queryRequestFromString("SELECT * FROM foo", false, false) qr := queryRequestFromString("SELECT * FROM foo", false, false)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
qr.Freshness = mustParseDuration("1ns").Nanoseconds() qr.Freshness = mustParseDuration("1ns").Nanoseconds()
r, err := s0.Query(qr) r, err := s0.Query(qr)
if err != nil { if err != nil {
@ -2386,7 +2386,7 @@ func Test_MultiNodeExecuteQueryFreshness(t *testing.T) {
} }
qr := queryRequestFromString("SELECT * FROM foo", false, false) qr := queryRequestFromString("SELECT * FROM foo", false, false)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err := s0.Query(qr) r, err := s0.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query leader node: %s", err.Error()) t.Fatalf("failed to query leader node: %s", err.Error())
@ -2406,13 +2406,13 @@ func Test_MultiNodeExecuteQueryFreshness(t *testing.T) {
// "Weak" consistency queries with 1 nanosecond freshness should pass, because freshness // "Weak" consistency queries with 1 nanosecond freshness should pass, because freshness
// is ignored in this case. // is ignored in this case.
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_WEAK qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_WEAK
qr.Freshness = mustParseDuration("1ns").Nanoseconds() qr.Freshness = mustParseDuration("1ns").Nanoseconds()
_, err = s0.Query(qr) _, err = s0.Query(qr)
if err != nil { if err != nil {
t.Fatalf("Failed to ignore freshness if level is Weak: %s", err.Error()) t.Fatalf("Failed to ignore freshness if level is Weak: %s", err.Error())
} }
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
// "Strong" consistency queries with 1 nanosecond freshness should pass, because freshness // "Strong" consistency queries with 1 nanosecond freshness should pass, because freshness
// is ignored in this case. // is ignored in this case.
_, err = s0.Query(qr) _, err = s0.Query(qr)
@ -2424,7 +2424,7 @@ func Test_MultiNodeExecuteQueryFreshness(t *testing.T) {
s0.Close(true) s0.Close(true)
// "None" consistency queries should still work. // "None" consistency queries should still work.
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
qr.Freshness = 0 qr.Freshness = 0
r, err = s1.Query(qr) r, err = s1.Query(qr)
if err != nil { if err != nil {
@ -2442,7 +2442,7 @@ func Test_MultiNodeExecuteQueryFreshness(t *testing.T) {
// "None" consistency queries with 1 nanosecond freshness should fail, because at least // "None" consistency queries with 1 nanosecond freshness should fail, because at least
// one nanosecond *should* have passed since leader died (surely!). // one nanosecond *should* have passed since leader died (surely!).
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
qr.Freshness = mustParseDuration("1ns").Nanoseconds() qr.Freshness = mustParseDuration("1ns").Nanoseconds()
_, err = s1.Query(qr) _, err = s1.Query(qr)
if err == nil { if err == nil {
@ -2480,7 +2480,7 @@ func Test_MultiNodeExecuteQueryFreshness(t *testing.T) {
} }
// Check Stale-read detection works with Requests too. // Check Stale-read detection works with Requests too.
eqr := executeQueryRequestFromString("SELECT * FROM foo", command.QueryRequest_QUERY_REQUEST_LEVEL_NONE, eqr := executeQueryRequestFromString("SELECT * FROM foo", proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE,
false, false) false, false)
eqr.Freshness = mustParseDuration("1ns").Nanoseconds() eqr.Freshness = mustParseDuration("1ns").Nanoseconds()
_, err = s1.Request(eqr) _, err = s1.Request(eqr)
@ -2570,7 +2570,7 @@ func Test_StoreLogTruncationMultinode(t *testing.T) {
t.Fatalf("error waiting for follower to apply index: %s:", err.Error()) t.Fatalf("error waiting for follower to apply index: %s:", err.Error())
} }
qr := queryRequestFromString("SELECT count(*) FROM foo", false, true) qr := queryRequestFromString("SELECT count(*) FROM foo", false, true)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err := s1.Query(qr) r, err := s1.Query(qr)
if err != nil { if err != nil {
t.Fatalf("failed to query single node: %s", err.Error()) t.Fatalf("failed to query single node: %s", err.Error())
@ -2767,7 +2767,7 @@ func Test_RequiresLeader(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
stmts []string stmts []string
lvl command.QueryRequest_Level lvl proto.QueryRequest_Level
requires bool requires bool
}{ }{
{ {
@ -2808,43 +2808,43 @@ func Test_RequiresLeader(t *testing.T) {
{ {
name: "Single SELECT with NONE", name: "Single SELECT with NONE",
stmts: []string{"SELECT * FROM foo"}, stmts: []string{"SELECT * FROM foo"},
lvl: command.QueryRequest_QUERY_REQUEST_LEVEL_NONE, lvl: proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE,
requires: false, requires: false,
}, },
{ {
name: "Single SELECT from non-existent table with NONE", name: "Single SELECT from non-existent table with NONE",
stmts: []string{"SELECT * FROM qux"}, stmts: []string{"SELECT * FROM qux"},
lvl: command.QueryRequest_QUERY_REQUEST_LEVEL_NONE, lvl: proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE,
requires: true, requires: true,
}, },
{ {
name: "Double SELECT with NONE", name: "Double SELECT with NONE",
stmts: []string{"SELECT * FROM foo", "SELECT * FROM foo WHERE id = 1"}, stmts: []string{"SELECT * FROM foo", "SELECT * FROM foo WHERE id = 1"},
lvl: command.QueryRequest_QUERY_REQUEST_LEVEL_NONE, lvl: proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE,
requires: false, requires: false,
}, },
{ {
name: "Single SELECT with STRONG", name: "Single SELECT with STRONG",
stmts: []string{"SELECT * FROM foo"}, stmts: []string{"SELECT * FROM foo"},
lvl: command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG, lvl: proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG,
requires: true, requires: true,
}, },
{ {
name: "Single SELECT with WEAK", name: "Single SELECT with WEAK",
stmts: []string{"SELECT * FROM foo"}, stmts: []string{"SELECT * FROM foo"},
lvl: command.QueryRequest_QUERY_REQUEST_LEVEL_WEAK, lvl: proto.QueryRequest_QUERY_REQUEST_LEVEL_WEAK,
requires: true, requires: true,
}, },
{ {
name: "Mix queries and executes with NONE", name: "Mix queries and executes with NONE",
stmts: []string{"SELECT * FROM foo", "INSERT INTO foo(id, name) VALUES(1, 'fiona')"}, stmts: []string{"SELECT * FROM foo", "INSERT INTO foo(id, name) VALUES(1, 'fiona')"},
lvl: command.QueryRequest_QUERY_REQUEST_LEVEL_NONE, lvl: proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE,
requires: true, requires: true,
}, },
{ {
name: "Mix queries and executes with WEAK", name: "Mix queries and executes with WEAK",
stmts: []string{"SELECT * FROM foo", "INSERT INTO foo(id, name) VALUES(1, 'fiona')"}, stmts: []string{"SELECT * FROM foo", "INSERT INTO foo(id, name) VALUES(1, 'fiona')"},
lvl: command.QueryRequest_QUERY_REQUEST_LEVEL_WEAK, lvl: proto.QueryRequest_QUERY_REQUEST_LEVEL_WEAK,
requires: true, requires: true,
}, },
} }
@ -3001,20 +3001,20 @@ func mustFileSize(path string) int64 {
return n return n
} }
func executeRequestFromString(s string, timings, tx bool) *command.ExecuteRequest { func executeRequestFromString(s string, timings, tx bool) *proto.ExecuteRequest {
return executeRequestFromStrings([]string{s}, timings, tx) return executeRequestFromStrings([]string{s}, timings, tx)
} }
// executeRequestFromStrings converts a slice of strings into a command.ExecuteRequest // executeRequestFromStrings converts a slice of strings into a proto.ExecuteRequest
func executeRequestFromStrings(s []string, timings, tx bool) *command.ExecuteRequest { func executeRequestFromStrings(s []string, timings, tx bool) *proto.ExecuteRequest {
stmts := make([]*command.Statement, len(s)) stmts := make([]*proto.Statement, len(s))
for i := range s { for i := range s {
stmts[i] = &command.Statement{ stmts[i] = &proto.Statement{
Sql: s[i], Sql: s[i],
} }
} }
return &command.ExecuteRequest{ return &proto.ExecuteRequest{
Request: &command.Request{ Request: &proto.Request{
Statements: stmts, Statements: stmts,
Transaction: tx, Transaction: tx,
}, },
@ -3022,20 +3022,20 @@ func executeRequestFromStrings(s []string, timings, tx bool) *command.ExecuteReq
} }
} }
func queryRequestFromString(s string, timings, tx bool) *command.QueryRequest { func queryRequestFromString(s string, timings, tx bool) *proto.QueryRequest {
return queryRequestFromStrings([]string{s}, timings, tx) return queryRequestFromStrings([]string{s}, timings, tx)
} }
// queryRequestFromStrings converts a slice of strings into a command.QueryRequest // queryRequestFromStrings converts a slice of strings into a proto.QueryRequest
func queryRequestFromStrings(s []string, timings, tx bool) *command.QueryRequest { func queryRequestFromStrings(s []string, timings, tx bool) *proto.QueryRequest {
stmts := make([]*command.Statement, len(s)) stmts := make([]*proto.Statement, len(s))
for i := range s { for i := range s {
stmts[i] = &command.Statement{ stmts[i] = &proto.Statement{
Sql: s[i], Sql: s[i],
} }
} }
return &command.QueryRequest{ return &proto.QueryRequest{
Request: &command.Request{ Request: &proto.Request{
Statements: stmts, Statements: stmts,
Transaction: tx, Transaction: tx,
}, },
@ -3043,19 +3043,19 @@ func queryRequestFromStrings(s []string, timings, tx bool) *command.QueryRequest
} }
} }
func executeQueryRequestFromString(s string, lvl command.QueryRequest_Level, timings, tx bool) *command.ExecuteQueryRequest { func executeQueryRequestFromString(s string, lvl proto.QueryRequest_Level, timings, tx bool) *proto.ExecuteQueryRequest {
return executeQueryRequestFromStrings([]string{s}, lvl, timings, tx) return executeQueryRequestFromStrings([]string{s}, lvl, timings, tx)
} }
func executeQueryRequestFromStrings(s []string, lvl command.QueryRequest_Level, timings, tx bool) *command.ExecuteQueryRequest { func executeQueryRequestFromStrings(s []string, lvl proto.QueryRequest_Level, timings, tx bool) *proto.ExecuteQueryRequest {
stmts := make([]*command.Statement, len(s)) stmts := make([]*proto.Statement, len(s))
for i := range s { for i := range s {
stmts[i] = &command.Statement{ stmts[i] = &proto.Statement{
Sql: s[i], Sql: s[i],
} }
} }
return &command.ExecuteQueryRequest{ return &proto.ExecuteQueryRequest{
Request: &command.Request{ Request: &proto.Request{
Statements: stmts, Statements: stmts,
Transaction: tx, Transaction: tx,
}, },
@ -3064,43 +3064,43 @@ func executeQueryRequestFromStrings(s []string, lvl command.QueryRequest_Level,
} }
} }
func backupRequestSQL(leader bool) *command.BackupRequest { func backupRequestSQL(leader bool) *proto.BackupRequest {
return &command.BackupRequest{ return &proto.BackupRequest{
Format: command.BackupRequest_BACKUP_REQUEST_FORMAT_SQL, Format: proto.BackupRequest_BACKUP_REQUEST_FORMAT_SQL,
Leader: leader, Leader: leader,
} }
} }
func backupRequestBinary(leader bool) *command.BackupRequest { func backupRequestBinary(leader bool) *proto.BackupRequest {
return &command.BackupRequest{ return &proto.BackupRequest{
Format: command.BackupRequest_BACKUP_REQUEST_FORMAT_BINARY, Format: proto.BackupRequest_BACKUP_REQUEST_FORMAT_BINARY,
Leader: leader, Leader: leader,
} }
} }
func loadRequestFromFile(path string) *command.LoadRequest { func loadRequestFromFile(path string) *proto.LoadRequest {
return &command.LoadRequest{ return &proto.LoadRequest{
Data: mustReadFile(path), Data: mustReadFile(path),
} }
} }
func joinRequest(id, addr string, voter bool) *command.JoinRequest { func joinRequest(id, addr string, voter bool) *proto.JoinRequest {
return &command.JoinRequest{ return &proto.JoinRequest{
Id: id, Id: id,
Address: addr, Address: addr,
Voter: voter, Voter: voter,
} }
} }
func notifyRequest(id, addr string) *command.NotifyRequest { func notifyRequest(id, addr string) *proto.NotifyRequest {
return &command.NotifyRequest{ return &proto.NotifyRequest{
Id: id, Id: id,
Address: addr, Address: addr,
} }
} }
func removeNodeRequest(id string) *command.RemoveNodeRequest { func removeNodeRequest(id string) *proto.RemoveNodeRequest {
return &command.RemoveNodeRequest{ return &proto.RemoveNodeRequest{
Id: id, Id: id,
} }
} }

@ -19,8 +19,8 @@ import (
"time" "time"
"github.com/rqlite/rqlite/v8/cluster" "github.com/rqlite/rqlite/v8/cluster"
"github.com/rqlite/rqlite/v8/command"
"github.com/rqlite/rqlite/v8/command/encoding" "github.com/rqlite/rqlite/v8/command/encoding"
"github.com/rqlite/rqlite/v8/command/proto"
httpd "github.com/rqlite/rqlite/v8/http" httpd "github.com/rqlite/rqlite/v8/http"
"github.com/rqlite/rqlite/v8/store" "github.com/rqlite/rqlite/v8/store"
"github.com/rqlite/rqlite/v8/tcp" "github.com/rqlite/rqlite/v8/tcp"
@ -235,7 +235,7 @@ func (n *Node) JoinAsNonVoter(leader *Node) error {
// Notify notifies this node of the existence of another node // Notify notifies this node of the existence of another node
func (n *Node) Notify(id, raftAddr string) error { func (n *Node) Notify(id, raftAddr string) error {
nr := &command.NotifyRequest{ nr := &proto.NotifyRequest{
Id: n.Store.ID(), Id: n.Store.ID(),
Address: n.RaftAddr, Address: n.RaftAddr,
} }

@ -7,7 +7,7 @@ import (
"time" "time"
"github.com/rqlite/rqlite/v8/cluster" "github.com/rqlite/rqlite/v8/cluster"
"github.com/rqlite/rqlite/v8/command" "github.com/rqlite/rqlite/v8/command/proto"
"github.com/rqlite/rqlite/v8/rtls" "github.com/rqlite/rqlite/v8/rtls"
"github.com/rqlite/rqlite/v8/tcp" "github.com/rqlite/rqlite/v8/tcp"
) )
@ -314,20 +314,20 @@ func Test_MultiNodeClusterQueuedRequestForwardOK(t *testing.T) {
} }
} }
func executeRequestFromString(s string) *command.ExecuteRequest { func executeRequestFromString(s string) *proto.ExecuteRequest {
return executeRequestFromStrings([]string{s}) return executeRequestFromStrings([]string{s})
} }
// queryRequestFromStrings converts a slice of strings into a command.ExecuteRequest // queryRequestFromStrings converts a slice of strings into a command.ExecuteRequest
func executeRequestFromStrings(s []string) *command.ExecuteRequest { func executeRequestFromStrings(s []string) *proto.ExecuteRequest {
stmts := make([]*command.Statement, len(s)) stmts := make([]*proto.Statement, len(s))
for i := range s { for i := range s {
stmts[i] = &command.Statement{ stmts[i] = &proto.Statement{
Sql: s[i], Sql: s[i],
} }
} }
return &command.ExecuteRequest{ return &proto.ExecuteRequest{
Request: &command.Request{ Request: &proto.Request{
Statements: stmts, Statements: stmts,
Transaction: false, Transaction: false,
}, },
@ -335,20 +335,20 @@ func executeRequestFromStrings(s []string) *command.ExecuteRequest {
} }
} }
func queryRequestFromString(s string) *command.QueryRequest { func queryRequestFromString(s string) *proto.QueryRequest {
return queryRequestFromStrings([]string{s}) return queryRequestFromStrings([]string{s})
} }
// queryRequestFromStrings converts a slice of strings into a command.QueryRequest // queryRequestFromStrings converts a slice of strings into a command.QueryRequest
func queryRequestFromStrings(s []string) *command.QueryRequest { func queryRequestFromStrings(s []string) *proto.QueryRequest {
stmts := make([]*command.Statement, len(s)) stmts := make([]*proto.Statement, len(s))
for i := range s { for i := range s {
stmts[i] = &command.Statement{ stmts[i] = &proto.Statement{
Sql: s[i], Sql: s[i],
} }
} }
return &command.QueryRequest{ return &proto.QueryRequest{
Request: &command.Request{ Request: &proto.Request{
Statements: stmts, Statements: stmts,
Transaction: false, Transaction: false,
}, },
@ -356,20 +356,20 @@ func queryRequestFromStrings(s []string) *command.QueryRequest {
} }
} }
func executeQueryRequestFromString(s string) *command.ExecuteQueryRequest { func executeQueryRequestFromString(s string) *proto.ExecuteQueryRequest {
return executeQueryRequestFromStrings([]string{s}) return executeQueryRequestFromStrings([]string{s})
} }
// executeQueryRequestFromStrings converts a slice of strings into a command.ExecuteQueryRequest // executeQueryRequestFromStrings converts a slice of strings into a command.ExecuteQueryRequest
func executeQueryRequestFromStrings(s []string) *command.ExecuteQueryRequest { func executeQueryRequestFromStrings(s []string) *proto.ExecuteQueryRequest {
stmts := make([]*command.Statement, len(s)) stmts := make([]*proto.Statement, len(s))
for i := range s { for i := range s {
stmts[i] = &command.Statement{ stmts[i] = &proto.Statement{
Sql: s[i], Sql: s[i],
} }
} }
return &command.ExecuteQueryRequest{ return &proto.ExecuteQueryRequest{
Request: &command.Request{ Request: &proto.Request{
Statements: stmts, Statements: stmts,
Transaction: false, Transaction: false,
}, },

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save