Use Protobuf for encoding Raft Log commands
This PR changes Raft Log Entry encoding from JSON to Protobuf. Furthermore, larger Raft commands (which can result from batching SQL statements, or individually long SQL statements) are compressed before encoding. This primary reason for this change is to reduce IO load since that is one of the largest performance bottlenecks. It will also reduce internode traffic. Legacy JSON-encoded commands are still handled by this code, so this change is backwards-compatible with previous releases in the v5 series.master
parent
7d4445d92d
commit
6575de779d
@ -0,0 +1,905 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.25.0
|
||||
// protoc v3.13.0
|
||||
// source: command.proto
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
// This is a compile-time assertion that a sufficiently up-to-date version
|
||||
// of the legacy proto package is being used.
|
||||
const _ = proto.ProtoPackageIsVersion4
|
||||
|
||||
type QueryRequest_Level int32
|
||||
|
||||
const (
|
||||
QueryRequest_QUERY_REQUEST_LEVEL_NONE QueryRequest_Level = 0
|
||||
QueryRequest_QUERY_REQUEST_LEVEL_WEAK QueryRequest_Level = 1
|
||||
QueryRequest_QUERY_REQUEST_LEVEL_STRONG QueryRequest_Level = 2
|
||||
)
|
||||
|
||||
// Enum value maps for QueryRequest_Level.
|
||||
var (
|
||||
QueryRequest_Level_name = map[int32]string{
|
||||
0: "QUERY_REQUEST_LEVEL_NONE",
|
||||
1: "QUERY_REQUEST_LEVEL_WEAK",
|
||||
2: "QUERY_REQUEST_LEVEL_STRONG",
|
||||
}
|
||||
QueryRequest_Level_value = map[string]int32{
|
||||
"QUERY_REQUEST_LEVEL_NONE": 0,
|
||||
"QUERY_REQUEST_LEVEL_WEAK": 1,
|
||||
"QUERY_REQUEST_LEVEL_STRONG": 2,
|
||||
}
|
||||
)
|
||||
|
||||
func (x QueryRequest_Level) Enum() *QueryRequest_Level {
|
||||
p := new(QueryRequest_Level)
|
||||
*p = x
|
||||
return p
|
||||
}
|
||||
|
||||
func (x QueryRequest_Level) String() string {
|
||||
return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
|
||||
}
|
||||
|
||||
func (QueryRequest_Level) Descriptor() protoreflect.EnumDescriptor {
|
||||
return file_command_proto_enumTypes[0].Descriptor()
|
||||
}
|
||||
|
||||
func (QueryRequest_Level) Type() protoreflect.EnumType {
|
||||
return &file_command_proto_enumTypes[0]
|
||||
}
|
||||
|
||||
func (x QueryRequest_Level) Number() protoreflect.EnumNumber {
|
||||
return protoreflect.EnumNumber(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use QueryRequest_Level.Descriptor instead.
|
||||
func (QueryRequest_Level) EnumDescriptor() ([]byte, []int) {
|
||||
return file_command_proto_rawDescGZIP(), []int{3, 0}
|
||||
}
|
||||
|
||||
type Command_Type int32
|
||||
|
||||
const (
|
||||
Command_COMMAND_TYPE_UNKNOWN Command_Type = 0
|
||||
Command_COMMAND_TYPE_QUERY Command_Type = 1
|
||||
Command_COMMAND_TYPE_EXECUTE Command_Type = 2
|
||||
Command_COMMAND_TYPE_METADATA_SET Command_Type = 3
|
||||
Command_COMMAND_TYPE_METADATA_DELETE Command_Type = 4
|
||||
)
|
||||
|
||||
// Enum value maps for Command_Type.
|
||||
var (
|
||||
Command_Type_name = map[int32]string{
|
||||
0: "COMMAND_TYPE_UNKNOWN",
|
||||
1: "COMMAND_TYPE_QUERY",
|
||||
2: "COMMAND_TYPE_EXECUTE",
|
||||
3: "COMMAND_TYPE_METADATA_SET",
|
||||
4: "COMMAND_TYPE_METADATA_DELETE",
|
||||
}
|
||||
Command_Type_value = map[string]int32{
|
||||
"COMMAND_TYPE_UNKNOWN": 0,
|
||||
"COMMAND_TYPE_QUERY": 1,
|
||||
"COMMAND_TYPE_EXECUTE": 2,
|
||||
"COMMAND_TYPE_METADATA_SET": 3,
|
||||
"COMMAND_TYPE_METADATA_DELETE": 4,
|
||||
}
|
||||
)
|
||||
|
||||
func (x Command_Type) Enum() *Command_Type {
|
||||
p := new(Command_Type)
|
||||
*p = x
|
||||
return p
|
||||
}
|
||||
|
||||
func (x Command_Type) String() string {
|
||||
return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
|
||||
}
|
||||
|
||||
func (Command_Type) Descriptor() protoreflect.EnumDescriptor {
|
||||
return file_command_proto_enumTypes[1].Descriptor()
|
||||
}
|
||||
|
||||
func (Command_Type) Type() protoreflect.EnumType {
|
||||
return &file_command_proto_enumTypes[1]
|
||||
}
|
||||
|
||||
func (x Command_Type) Number() protoreflect.EnumNumber {
|
||||
return protoreflect.EnumNumber(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use Command_Type.Descriptor instead.
|
||||
func (Command_Type) EnumDescriptor() ([]byte, []int) {
|
||||
return file_command_proto_rawDescGZIP(), []int{7, 0}
|
||||
}
|
||||
|
||||
type Parameter struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
// Types that are assignable to Value:
|
||||
// *Parameter_I
|
||||
// *Parameter_D
|
||||
// *Parameter_B
|
||||
// *Parameter_Y
|
||||
// *Parameter_S
|
||||
Value isParameter_Value `protobuf_oneof:"value"`
|
||||
}
|
||||
|
||||
func (x *Parameter) Reset() {
|
||||
*x = Parameter{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_command_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Parameter) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Parameter) ProtoMessage() {}
|
||||
|
||||
func (x *Parameter) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_command_proto_msgTypes[0]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use Parameter.ProtoReflect.Descriptor instead.
|
||||
func (*Parameter) Descriptor() ([]byte, []int) {
|
||||
return file_command_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (m *Parameter) GetValue() isParameter_Value {
|
||||
if m != nil {
|
||||
return m.Value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *Parameter) GetI() int64 {
|
||||
if x, ok := x.GetValue().(*Parameter_I); ok {
|
||||
return x.I
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *Parameter) GetD() float64 {
|
||||
if x, ok := x.GetValue().(*Parameter_D); ok {
|
||||
return x.D
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *Parameter) GetB() bool {
|
||||
if x, ok := x.GetValue().(*Parameter_B); ok {
|
||||
return x.B
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *Parameter) GetY() []byte {
|
||||
if x, ok := x.GetValue().(*Parameter_Y); ok {
|
||||
return x.Y
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *Parameter) GetS() string {
|
||||
if x, ok := x.GetValue().(*Parameter_S); ok {
|
||||
return x.S
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type isParameter_Value interface {
|
||||
isParameter_Value()
|
||||
}
|
||||
|
||||
type Parameter_I struct {
|
||||
I int64 `protobuf:"zigzag64,1,opt,name=i,proto3,oneof"`
|
||||
}
|
||||
|
||||
type Parameter_D struct {
|
||||
D float64 `protobuf:"fixed64,2,opt,name=d,proto3,oneof"`
|
||||
}
|
||||
|
||||
type Parameter_B struct {
|
||||
B bool `protobuf:"varint,3,opt,name=b,proto3,oneof"`
|
||||
}
|
||||
|
||||
type Parameter_Y struct {
|
||||
Y []byte `protobuf:"bytes,4,opt,name=y,proto3,oneof"`
|
||||
}
|
||||
|
||||
type Parameter_S struct {
|
||||
S string `protobuf:"bytes,5,opt,name=s,proto3,oneof"`
|
||||
}
|
||||
|
||||
func (*Parameter_I) isParameter_Value() {}
|
||||
|
||||
func (*Parameter_D) isParameter_Value() {}
|
||||
|
||||
func (*Parameter_B) isParameter_Value() {}
|
||||
|
||||
func (*Parameter_Y) isParameter_Value() {}
|
||||
|
||||
func (*Parameter_S) isParameter_Value() {}
|
||||
|
||||
type Statement struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Sql string `protobuf:"bytes,1,opt,name=sql,proto3" json:"sql,omitempty"`
|
||||
Parameters []*Parameter `protobuf:"bytes,2,rep,name=parameters,proto3" json:"parameters,omitempty"`
|
||||
}
|
||||
|
||||
func (x *Statement) Reset() {
|
||||
*x = Statement{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_command_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Statement) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Statement) ProtoMessage() {}
|
||||
|
||||
func (x *Statement) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_command_proto_msgTypes[1]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use Statement.ProtoReflect.Descriptor instead.
|
||||
func (*Statement) Descriptor() ([]byte, []int) {
|
||||
return file_command_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *Statement) GetSql() string {
|
||||
if x != nil {
|
||||
return x.Sql
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Statement) GetParameters() []*Parameter {
|
||||
if x != nil {
|
||||
return x.Parameters
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Transaction bool `protobuf:"varint,1,opt,name=transaction,proto3" json:"transaction,omitempty"`
|
||||
Statements []*Statement `protobuf:"bytes,2,rep,name=statements,proto3" json:"statements,omitempty"`
|
||||
}
|
||||
|
||||
func (x *Request) Reset() {
|
||||
*x = Request{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_command_proto_msgTypes[2]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Request) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Request) ProtoMessage() {}
|
||||
|
||||
func (x *Request) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_command_proto_msgTypes[2]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use Request.ProtoReflect.Descriptor instead.
|
||||
func (*Request) Descriptor() ([]byte, []int) {
|
||||
return file_command_proto_rawDescGZIP(), []int{2}
|
||||
}
|
||||
|
||||
func (x *Request) GetTransaction() bool {
|
||||
if x != nil {
|
||||
return x.Transaction
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *Request) GetStatements() []*Statement {
|
||||
if x != nil {
|
||||
return x.Statements
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type QueryRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Request *Request `protobuf:"bytes,1,opt,name=request,proto3" json:"request,omitempty"`
|
||||
Timings bool `protobuf:"varint,2,opt,name=timings,proto3" json:"timings,omitempty"`
|
||||
Level QueryRequest_Level `protobuf:"varint,3,opt,name=level,proto3,enum=command.QueryRequest_Level" json:"level,omitempty"`
|
||||
Freshness int64 `protobuf:"varint,4,opt,name=freshness,proto3" json:"freshness,omitempty"`
|
||||
}
|
||||
|
||||
func (x *QueryRequest) Reset() {
|
||||
*x = QueryRequest{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_command_proto_msgTypes[3]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *QueryRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*QueryRequest) ProtoMessage() {}
|
||||
|
||||
func (x *QueryRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_command_proto_msgTypes[3]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use QueryRequest.ProtoReflect.Descriptor instead.
|
||||
func (*QueryRequest) Descriptor() ([]byte, []int) {
|
||||
return file_command_proto_rawDescGZIP(), []int{3}
|
||||
}
|
||||
|
||||
func (x *QueryRequest) GetRequest() *Request {
|
||||
if x != nil {
|
||||
return x.Request
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *QueryRequest) GetTimings() bool {
|
||||
if x != nil {
|
||||
return x.Timings
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *QueryRequest) GetLevel() QueryRequest_Level {
|
||||
if x != nil {
|
||||
return x.Level
|
||||
}
|
||||
return QueryRequest_QUERY_REQUEST_LEVEL_NONE
|
||||
}
|
||||
|
||||
func (x *QueryRequest) GetFreshness() int64 {
|
||||
if x != nil {
|
||||
return x.Freshness
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type ExecuteRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Request *Request `protobuf:"bytes,1,opt,name=request,proto3" json:"request,omitempty"`
|
||||
Timings bool `protobuf:"varint,2,opt,name=timings,proto3" json:"timings,omitempty"`
|
||||
}
|
||||
|
||||
func (x *ExecuteRequest) Reset() {
|
||||
*x = ExecuteRequest{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_command_proto_msgTypes[4]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *ExecuteRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*ExecuteRequest) ProtoMessage() {}
|
||||
|
||||
func (x *ExecuteRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_command_proto_msgTypes[4]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use ExecuteRequest.ProtoReflect.Descriptor instead.
|
||||
func (*ExecuteRequest) Descriptor() ([]byte, []int) {
|
||||
return file_command_proto_rawDescGZIP(), []int{4}
|
||||
}
|
||||
|
||||
func (x *ExecuteRequest) GetRequest() *Request {
|
||||
if x != nil {
|
||||
return x.Request
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *ExecuteRequest) GetTimings() bool {
|
||||
if x != nil {
|
||||
return x.Timings
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type MetadataSet struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
RaftId string `protobuf:"bytes,1,opt,name=raft_id,json=raftId,proto3" json:"raft_id,omitempty"`
|
||||
Data map[string]string `protobuf:"bytes,2,rep,name=data,proto3" json:"data,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
|
||||
}
|
||||
|
||||
func (x *MetadataSet) Reset() {
|
||||
*x = MetadataSet{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_command_proto_msgTypes[5]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *MetadataSet) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*MetadataSet) ProtoMessage() {}
|
||||
|
||||
func (x *MetadataSet) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_command_proto_msgTypes[5]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use MetadataSet.ProtoReflect.Descriptor instead.
|
||||
func (*MetadataSet) Descriptor() ([]byte, []int) {
|
||||
return file_command_proto_rawDescGZIP(), []int{5}
|
||||
}
|
||||
|
||||
func (x *MetadataSet) GetRaftId() string {
|
||||
if x != nil {
|
||||
return x.RaftId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *MetadataSet) GetData() map[string]string {
|
||||
if x != nil {
|
||||
return x.Data
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type MetadataDelete struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
RaftId string `protobuf:"bytes,1,opt,name=raft_id,json=raftId,proto3" json:"raft_id,omitempty"`
|
||||
}
|
||||
|
||||
func (x *MetadataDelete) Reset() {
|
||||
*x = MetadataDelete{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_command_proto_msgTypes[6]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *MetadataDelete) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*MetadataDelete) ProtoMessage() {}
|
||||
|
||||
func (x *MetadataDelete) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_command_proto_msgTypes[6]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use MetadataDelete.ProtoReflect.Descriptor instead.
|
||||
func (*MetadataDelete) Descriptor() ([]byte, []int) {
|
||||
return file_command_proto_rawDescGZIP(), []int{6}
|
||||
}
|
||||
|
||||
func (x *MetadataDelete) GetRaftId() string {
|
||||
if x != nil {
|
||||
return x.RaftId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type Command struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Type Command_Type `protobuf:"varint,1,opt,name=type,proto3,enum=command.Command_Type" json:"type,omitempty"`
|
||||
SubCommand []byte `protobuf:"bytes,2,opt,name=sub_command,json=subCommand,proto3" json:"sub_command,omitempty"`
|
||||
Compressed bool `protobuf:"varint,3,opt,name=compressed,proto3" json:"compressed,omitempty"`
|
||||
}
|
||||
|
||||
func (x *Command) Reset() {
|
||||
*x = Command{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_command_proto_msgTypes[7]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Command) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Command) ProtoMessage() {}
|
||||
|
||||
func (x *Command) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_command_proto_msgTypes[7]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use Command.ProtoReflect.Descriptor instead.
|
||||
func (*Command) Descriptor() ([]byte, []int) {
|
||||
return file_command_proto_rawDescGZIP(), []int{7}
|
||||
}
|
||||
|
||||
func (x *Command) GetType() Command_Type {
|
||||
if x != nil {
|
||||
return x.Type
|
||||
}
|
||||
return Command_COMMAND_TYPE_UNKNOWN
|
||||
}
|
||||
|
||||
func (x *Command) GetSubCommand() []byte {
|
||||
if x != nil {
|
||||
return x.SubCommand
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *Command) GetCompressed() bool {
|
||||
if x != nil {
|
||||
return x.Compressed
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var File_command_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_command_proto_rawDesc = []byte{
|
||||
0x0a, 0x0d, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12,
|
||||
0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x22, 0x64, 0x0a, 0x09, 0x50, 0x61, 0x72, 0x61,
|
||||
0x6d, 0x65, 0x74, 0x65, 0x72, 0x12, 0x0e, 0x0a, 0x01, 0x69, 0x18, 0x01, 0x20, 0x01, 0x28, 0x12,
|
||||
0x48, 0x00, 0x52, 0x01, 0x69, 0x12, 0x0e, 0x0a, 0x01, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x01,
|
||||
0x48, 0x00, 0x52, 0x01, 0x64, 0x12, 0x0e, 0x0a, 0x01, 0x62, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08,
|
||||
0x48, 0x00, 0x52, 0x01, 0x62, 0x12, 0x0e, 0x0a, 0x01, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c,
|
||||
0x48, 0x00, 0x52, 0x01, 0x79, 0x12, 0x0e, 0x0a, 0x01, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09,
|
||||
0x48, 0x00, 0x52, 0x01, 0x73, 0x42, 0x07, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x51,
|
||||
0x0a, 0x09, 0x53, 0x74, 0x61, 0x74, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x73,
|
||||
0x71, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x73, 0x71, 0x6c, 0x12, 0x32, 0x0a,
|
||||
0x0a, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28,
|
||||
0x0b, 0x32, 0x12, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x2e, 0x50, 0x61, 0x72, 0x61,
|
||||
0x6d, 0x65, 0x74, 0x65, 0x72, 0x52, 0x0a, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72,
|
||||
0x73, 0x22, 0x5f, 0x0a, 0x07, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x0b,
|
||||
0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||
0x08, 0x52, 0x0b, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x32,
|
||||
0x0a, 0x0a, 0x73, 0x74, 0x61, 0x74, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x02, 0x20, 0x03,
|
||||
0x28, 0x0b, 0x32, 0x12, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x2e, 0x53, 0x74, 0x61,
|
||||
0x74, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x0a, 0x73, 0x74, 0x61, 0x74, 0x65, 0x6d, 0x65, 0x6e,
|
||||
0x74, 0x73, 0x22, 0x8a, 0x02, 0x0a, 0x0c, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75,
|
||||
0x65, 0x73, 0x74, 0x12, 0x2a, 0x0a, 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x18, 0x01,
|
||||
0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x2e, 0x52,
|
||||
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12,
|
||||
0x18, 0x0a, 0x07, 0x74, 0x69, 0x6d, 0x69, 0x6e, 0x67, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08,
|
||||
0x52, 0x07, 0x74, 0x69, 0x6d, 0x69, 0x6e, 0x67, 0x73, 0x12, 0x31, 0x0a, 0x05, 0x6c, 0x65, 0x76,
|
||||
0x65, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1b, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61,
|
||||
0x6e, 0x64, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e,
|
||||
0x4c, 0x65, 0x76, 0x65, 0x6c, 0x52, 0x05, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x12, 0x1c, 0x0a, 0x09,
|
||||
0x66, 0x72, 0x65, 0x73, 0x68, 0x6e, 0x65, 0x73, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52,
|
||||
0x09, 0x66, 0x72, 0x65, 0x73, 0x68, 0x6e, 0x65, 0x73, 0x73, 0x22, 0x63, 0x0a, 0x05, 0x4c, 0x65,
|
||||
0x76, 0x65, 0x6c, 0x12, 0x1c, 0x0a, 0x18, 0x51, 0x55, 0x45, 0x52, 0x59, 0x5f, 0x52, 0x45, 0x51,
|
||||
0x55, 0x45, 0x53, 0x54, 0x5f, 0x4c, 0x45, 0x56, 0x45, 0x4c, 0x5f, 0x4e, 0x4f, 0x4e, 0x45, 0x10,
|
||||
0x00, 0x12, 0x1c, 0x0a, 0x18, 0x51, 0x55, 0x45, 0x52, 0x59, 0x5f, 0x52, 0x45, 0x51, 0x55, 0x45,
|
||||
0x53, 0x54, 0x5f, 0x4c, 0x45, 0x56, 0x45, 0x4c, 0x5f, 0x57, 0x45, 0x41, 0x4b, 0x10, 0x01, 0x12,
|
||||
0x1e, 0x0a, 0x1a, 0x51, 0x55, 0x45, 0x52, 0x59, 0x5f, 0x52, 0x45, 0x51, 0x55, 0x45, 0x53, 0x54,
|
||||
0x5f, 0x4c, 0x45, 0x56, 0x45, 0x4c, 0x5f, 0x53, 0x54, 0x52, 0x4f, 0x4e, 0x47, 0x10, 0x02, 0x22,
|
||||
0x56, 0x0a, 0x0e, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
|
||||
0x74, 0x12, 0x2a, 0x0a, 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01,
|
||||
0x28, 0x0b, 0x32, 0x10, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x2e, 0x52, 0x65, 0x71,
|
||||
0x75, 0x65, 0x73, 0x74, 0x52, 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a,
|
||||
0x07, 0x74, 0x69, 0x6d, 0x69, 0x6e, 0x67, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07,
|
||||
0x74, 0x69, 0x6d, 0x69, 0x6e, 0x67, 0x73, 0x22, 0x93, 0x01, 0x0a, 0x0b, 0x4d, 0x65, 0x74, 0x61,
|
||||
0x64, 0x61, 0x74, 0x61, 0x53, 0x65, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x72, 0x61, 0x66, 0x74, 0x5f,
|
||||
0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x61, 0x66, 0x74, 0x49, 0x64,
|
||||
0x12, 0x32, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e,
|
||||
0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x2e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74,
|
||||
0x61, 0x53, 0x65, 0x74, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x04,
|
||||
0x64, 0x61, 0x74, 0x61, 0x1a, 0x37, 0x0a, 0x09, 0x44, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72,
|
||||
0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03,
|
||||
0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01,
|
||||
0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x29, 0x0a,
|
||||
0x0e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12,
|
||||
0x17, 0x0a, 0x07, 0x72, 0x61, 0x66, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
|
||||
0x52, 0x06, 0x72, 0x61, 0x66, 0x74, 0x49, 0x64, 0x22, 0x8b, 0x02, 0x0a, 0x07, 0x43, 0x6f, 0x6d,
|
||||
0x6d, 0x61, 0x6e, 0x64, 0x12, 0x29, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01,
|
||||
0x28, 0x0e, 0x32, 0x15, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x2e, 0x43, 0x6f, 0x6d,
|
||||
0x6d, 0x61, 0x6e, 0x64, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12,
|
||||
0x1f, 0x0a, 0x0b, 0x73, 0x75, 0x62, 0x5f, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x18, 0x02,
|
||||
0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x73, 0x75, 0x62, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64,
|
||||
0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x70, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, 0x18, 0x03,
|
||||
0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x63, 0x6f, 0x6d, 0x70, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64,
|
||||
0x22, 0x93, 0x01, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x14, 0x43, 0x4f, 0x4d,
|
||||
0x4d, 0x41, 0x4e, 0x44, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57,
|
||||
0x4e, 0x10, 0x00, 0x12, 0x16, 0x0a, 0x12, 0x43, 0x4f, 0x4d, 0x4d, 0x41, 0x4e, 0x44, 0x5f, 0x54,
|
||||
0x59, 0x50, 0x45, 0x5f, 0x51, 0x55, 0x45, 0x52, 0x59, 0x10, 0x01, 0x12, 0x18, 0x0a, 0x14, 0x43,
|
||||
0x4f, 0x4d, 0x4d, 0x41, 0x4e, 0x44, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x45, 0x58, 0x45, 0x43,
|
||||
0x55, 0x54, 0x45, 0x10, 0x02, 0x12, 0x1d, 0x0a, 0x19, 0x43, 0x4f, 0x4d, 0x4d, 0x41, 0x4e, 0x44,
|
||||
0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x4d, 0x45, 0x54, 0x41, 0x44, 0x41, 0x54, 0x41, 0x5f, 0x53,
|
||||
0x45, 0x54, 0x10, 0x03, 0x12, 0x20, 0x0a, 0x1c, 0x43, 0x4f, 0x4d, 0x4d, 0x41, 0x4e, 0x44, 0x5f,
|
||||
0x54, 0x59, 0x50, 0x45, 0x5f, 0x4d, 0x45, 0x54, 0x41, 0x44, 0x41, 0x54, 0x41, 0x5f, 0x44, 0x45,
|
||||
0x4c, 0x45, 0x54, 0x45, 0x10, 0x04, 0x42, 0x22, 0x5a, 0x20, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62,
|
||||
0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x72, 0x71, 0x6c, 0x69, 0x74, 0x65, 0x2f, 0x72, 0x71, 0x6c, 0x69,
|
||||
0x74, 0x65, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
|
||||
0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
file_command_proto_rawDescOnce sync.Once
|
||||
file_command_proto_rawDescData = file_command_proto_rawDesc
|
||||
)
|
||||
|
||||
func file_command_proto_rawDescGZIP() []byte {
|
||||
file_command_proto_rawDescOnce.Do(func() {
|
||||
file_command_proto_rawDescData = protoimpl.X.CompressGZIP(file_command_proto_rawDescData)
|
||||
})
|
||||
return file_command_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_command_proto_enumTypes = make([]protoimpl.EnumInfo, 2)
|
||||
var file_command_proto_msgTypes = make([]protoimpl.MessageInfo, 9)
|
||||
var file_command_proto_goTypes = []interface{}{
|
||||
(QueryRequest_Level)(0), // 0: command.QueryRequest.Level
|
||||
(Command_Type)(0), // 1: command.Command.Type
|
||||
(*Parameter)(nil), // 2: command.Parameter
|
||||
(*Statement)(nil), // 3: command.Statement
|
||||
(*Request)(nil), // 4: command.Request
|
||||
(*QueryRequest)(nil), // 5: command.QueryRequest
|
||||
(*ExecuteRequest)(nil), // 6: command.ExecuteRequest
|
||||
(*MetadataSet)(nil), // 7: command.MetadataSet
|
||||
(*MetadataDelete)(nil), // 8: command.MetadataDelete
|
||||
(*Command)(nil), // 9: command.Command
|
||||
nil, // 10: command.MetadataSet.DataEntry
|
||||
}
|
||||
var file_command_proto_depIdxs = []int32{
|
||||
2, // 0: command.Statement.parameters:type_name -> command.Parameter
|
||||
3, // 1: command.Request.statements:type_name -> command.Statement
|
||||
4, // 2: command.QueryRequest.request:type_name -> command.Request
|
||||
0, // 3: command.QueryRequest.level:type_name -> command.QueryRequest.Level
|
||||
4, // 4: command.ExecuteRequest.request:type_name -> command.Request
|
||||
10, // 5: command.MetadataSet.data:type_name -> command.MetadataSet.DataEntry
|
||||
1, // 6: command.Command.type:type_name -> command.Command.Type
|
||||
7, // [7:7] is the sub-list for method output_type
|
||||
7, // [7:7] is the sub-list for method input_type
|
||||
7, // [7:7] is the sub-list for extension type_name
|
||||
7, // [7:7] is the sub-list for extension extendee
|
||||
0, // [0:7] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_command_proto_init() }
|
||||
func file_command_proto_init() {
|
||||
if File_command_proto != nil {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_command_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Parameter); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_command_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Statement); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_command_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Request); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_command_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*QueryRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_command_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*ExecuteRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_command_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*MetadataSet); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_command_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*MetadataDelete); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_command_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Command); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
file_command_proto_msgTypes[0].OneofWrappers = []interface{}{
|
||||
(*Parameter_I)(nil),
|
||||
(*Parameter_D)(nil),
|
||||
(*Parameter_B)(nil),
|
||||
(*Parameter_Y)(nil),
|
||||
(*Parameter_S)(nil),
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_command_proto_rawDesc,
|
||||
NumEnums: 2,
|
||||
NumMessages: 9,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
GoTypes: file_command_proto_goTypes,
|
||||
DependencyIndexes: file_command_proto_depIdxs,
|
||||
EnumInfos: file_command_proto_enumTypes,
|
||||
MessageInfos: file_command_proto_msgTypes,
|
||||
}.Build()
|
||||
File_command_proto = out.File
|
||||
file_command_proto_rawDesc = nil
|
||||
file_command_proto_goTypes = nil
|
||||
file_command_proto_depIdxs = nil
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
syntax = "proto3";
|
||||
package command;
|
||||
|
||||
option go_package = "github.com/rqlite/rqlite/command";
|
||||
|
||||
message Parameter {
|
||||
oneof value {
|
||||
sint64 i = 1;
|
||||
double d = 2;
|
||||
bool b = 3;
|
||||
bytes y = 4;
|
||||
string s = 5;
|
||||
}
|
||||
}
|
||||
|
||||
message Statement {
|
||||
string sql = 1;
|
||||
repeated Parameter parameters = 2;
|
||||
}
|
||||
|
||||
message Request {
|
||||
bool transaction = 1;
|
||||
repeated Statement statements = 2;
|
||||
}
|
||||
|
||||
message QueryRequest {
|
||||
Request request = 1;
|
||||
bool timings = 2;
|
||||
enum Level {
|
||||
QUERY_REQUEST_LEVEL_NONE = 0;
|
||||
QUERY_REQUEST_LEVEL_WEAK = 1;
|
||||
QUERY_REQUEST_LEVEL_STRONG = 2;
|
||||
}
|
||||
Level level = 3;
|
||||
int64 freshness = 4;
|
||||
}
|
||||
|
||||
message ExecuteRequest {
|
||||
Request request = 1;
|
||||
bool timings = 2;
|
||||
}
|
||||
|
||||
message MetadataSet {
|
||||
string raft_id = 1;
|
||||
map<string, string> data = 2;
|
||||
}
|
||||
|
||||
message MetadataDelete {
|
||||
string raft_id = 1;
|
||||
}
|
||||
|
||||
message Command {
|
||||
enum Type {
|
||||
COMMAND_TYPE_UNKNOWN = 0;
|
||||
COMMAND_TYPE_QUERY = 1;
|
||||
COMMAND_TYPE_EXECUTE = 2;
|
||||
COMMAND_TYPE_METADATA_SET = 3;
|
||||
COMMAND_TYPE_METADATA_DELETE = 4;
|
||||
}
|
||||
Type type = 1;
|
||||
bytes sub_command = 2;
|
||||
bool compressed = 3;
|
||||
}
|
@ -0,0 +1,189 @@
|
||||
package legacy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/rqlite/rqlite/command"
|
||||
)
|
||||
|
||||
const (
|
||||
execute commandType = iota // Commands which modify the database.
|
||||
query // Commands which query the database.
|
||||
metadataSet // Commands which sets Store metadata
|
||||
metadataDelete // Commands which deletes Store metadata
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrNotLegacyCommand is returned when a command is not legacy encoded.
|
||||
ErrNotLegacyCommand = errors.New("not legacy command")
|
||||
|
||||
// ErrUnknownType is returned when an unknown command type is encountered.
|
||||
ErrUnknownCommandType = errors.New("unknown command type")
|
||||
|
||||
// ErrUnsupportedType is returned when a request contains an unsupported type.
|
||||
ErrUnsupportedType = errors.New("unsupported type")
|
||||
)
|
||||
|
||||
// commandType are commands that affect the state of the cluster, and must go through Raft.
|
||||
type commandType int
|
||||
|
||||
// Value is the type for parameters passed to a parameterized SQL statement.
|
||||
type Value interface{}
|
||||
|
||||
type Command struct {
|
||||
Typ commandType `json:"typ,omitempty"`
|
||||
Sub json.RawMessage `json:"sub,omitempty"`
|
||||
}
|
||||
|
||||
// databaseSub is a command sub which involves interaction with the database.
|
||||
// Queries and Parameters are separate fields, for backwards-compatibility
|
||||
// reasons. Unless Parameters is nil, it should be the same length as Queries.
|
||||
type databaseSub struct {
|
||||
Tx bool `json:"tx,omitempty"`
|
||||
SQLs []string `json:"queries,omitempty"`
|
||||
Parameters [][]Value `json:"Parameters,omitempty`
|
||||
Timings bool `json:"timings,omitempty"`
|
||||
}
|
||||
|
||||
type metadataSetSub struct {
|
||||
RaftID string `json:"raft_id,omitempty"`
|
||||
Data map[string]string `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
func Unmarshal(b []byte, c *command.Command) error {
|
||||
if b == nil || len(b) == 0 || b[0] != '{' {
|
||||
return ErrNotLegacyCommand
|
||||
}
|
||||
|
||||
var lc Command
|
||||
if err := json.Unmarshal(b, &lc); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var m proto.Message
|
||||
switch lc.Typ {
|
||||
case execute, query:
|
||||
var d databaseSub
|
||||
if err := json.Unmarshal(lc.Sub, &d); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
stmts, err := subCommandToStatements(&d)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if lc.Typ == execute {
|
||||
c.Type = command.Command_COMMAND_TYPE_EXECUTE
|
||||
m = &command.ExecuteRequest{
|
||||
Request: &command.Request{
|
||||
Transaction: d.Tx,
|
||||
Statements: stmts,
|
||||
},
|
||||
Timings: d.Timings,
|
||||
}
|
||||
} else {
|
||||
c.Type = command.Command_COMMAND_TYPE_QUERY
|
||||
m = &command.QueryRequest{
|
||||
Request: &command.Request{
|
||||
Transaction: d.Tx,
|
||||
Statements: stmts,
|
||||
},
|
||||
Timings: d.Timings,
|
||||
}
|
||||
}
|
||||
|
||||
case metadataSet:
|
||||
var d metadataSetSub
|
||||
if err := json.Unmarshal(lc.Sub, &d); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c.Type = command.Command_COMMAND_TYPE_METADATA_SET
|
||||
m = &command.MetadataSet{
|
||||
RaftId: d.RaftID,
|
||||
Data: d.Data,
|
||||
}
|
||||
case metadataDelete:
|
||||
var d string
|
||||
if err := json.Unmarshal(lc.Sub, &d); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c.Type = command.Command_COMMAND_TYPE_METADATA_DELETE
|
||||
m = &command.MetadataDelete{
|
||||
RaftId: d,
|
||||
}
|
||||
default:
|
||||
return ErrUnknownCommandType
|
||||
}
|
||||
|
||||
// Just marshal it, forget about compression, this will
|
||||
// never go to disk after all.
|
||||
b, err := proto.Marshal(m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.SubCommand = b
|
||||
c.Compressed = false
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func subCommandToStatements(d *databaseSub) ([]*command.Statement, error) {
|
||||
stmts := make([]*command.Statement, len(d.SQLs))
|
||||
|
||||
for i := range d.SQLs {
|
||||
stmts[i] = &command.Statement{
|
||||
Sql: d.SQLs[i],
|
||||
Parameters: nil,
|
||||
}
|
||||
|
||||
// Support backwards-compatibility, since old versions didn't
|
||||
// have any Parameters in legacy Raft commands
|
||||
if len(d.Parameters) == 0 {
|
||||
continue
|
||||
}
|
||||
stmts[i].Parameters = make([]*command.Parameter, len(d.Parameters[i]))
|
||||
for j := range d.Parameters[i] {
|
||||
switch v := d.Parameters[i][j].(type) {
|
||||
case int:
|
||||
case int64:
|
||||
stmts[i].Parameters[j] = &command.Parameter{
|
||||
Value: &command.Parameter_I{
|
||||
I: v,
|
||||
},
|
||||
}
|
||||
case float64:
|
||||
stmts[i].Parameters[j] = &command.Parameter{
|
||||
Value: &command.Parameter_D{
|
||||
D: v,
|
||||
},
|
||||
}
|
||||
case bool:
|
||||
stmts[i].Parameters[j] = &command.Parameter{
|
||||
Value: &command.Parameter_B{
|
||||
B: v,
|
||||
},
|
||||
}
|
||||
case []byte:
|
||||
stmts[i].Parameters[j] = &command.Parameter{
|
||||
Value: &command.Parameter_Y{
|
||||
Y: v,
|
||||
},
|
||||
}
|
||||
case string:
|
||||
stmts[i].Parameters[j] = &command.Parameter{
|
||||
Value: &command.Parameter_S{
|
||||
S: v,
|
||||
},
|
||||
}
|
||||
default:
|
||||
return nil, ErrUnsupportedType
|
||||
}
|
||||
}
|
||||
}
|
||||
return stmts, nil
|
||||
}
|
@ -0,0 +1,208 @@
|
||||
package legacy
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/rqlite/rqlite/command"
|
||||
)
|
||||
|
||||
func Test_SimpleExecute(t *testing.T) {
|
||||
// "CREATE TABLE foo (id INTEGER NOT NULL PRIMARY KEY, name TEXT, age INTEGER)" timings=true
|
||||
b := []byte{123, 34, 115, 117, 98, 34, 58, 123, 34, 113, 117, 101, 114, 105, 101, 115, 34, 58, 91, 34, 67, 82, 69, 65, 84, 69, 32, 84, 65, 66, 76, 69, 32, 102, 111, 111, 32, 40, 105, 100, 32, 73, 78, 84, 69, 71, 69, 82, 32, 78, 79, 84, 32, 78, 85, 76, 76, 32, 80, 82, 73, 77, 65, 82, 89, 32, 75, 69, 89, 44, 32, 110, 97, 109, 101, 32, 84, 69, 88, 84, 44, 32, 97, 103, 101, 32, 73, 78, 84, 69, 71, 69, 82, 41, 34, 93, 44, 34, 80, 97, 114, 97, 109, 101, 116, 101, 114, 115, 34, 58, 91, 110, 117, 108, 108, 93, 44, 34, 116, 105, 109, 105, 110, 103, 115, 34, 58, 116, 114, 117, 101, 125, 125}
|
||||
|
||||
var c command.Command
|
||||
var er command.ExecuteRequest
|
||||
if err := Unmarshal(b, &c); err != nil {
|
||||
t.Fatalf("failed to Unmarshal: %s", err)
|
||||
}
|
||||
|
||||
if c.Type != command.Command_COMMAND_TYPE_EXECUTE {
|
||||
t.Fatalf("incorrect command type: %s", c.Type)
|
||||
}
|
||||
if err := command.UnmarshalSubCommand(&c, &er); err != nil {
|
||||
t.Fatalf("failed to Unmarshal subcommand: %s", err)
|
||||
}
|
||||
if !er.Timings {
|
||||
t.Fatalf("timings not set")
|
||||
}
|
||||
if er.Request.Transaction {
|
||||
t.Fatalf("transaction set")
|
||||
}
|
||||
if n := len(er.Request.Statements); n != 1 {
|
||||
t.Fatalf("incorrect number of statments: %d", n)
|
||||
}
|
||||
if s := er.Request.Statements[0].Sql; s != "CREATE TABLE foo (id INTEGER NOT NULL PRIMARY KEY, name TEXT, age INTEGER)" {
|
||||
t.Fatalf("incorrect SQL: %s", s)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_SimpleQuery(t *testing.T) {
|
||||
// "SELECT * FROM foo", timings=true
|
||||
b := []byte{123, 34, 116, 121, 112, 34, 58, 49, 44, 34, 115, 117, 98, 34, 58, 123, 34, 113, 117, 101, 114, 105, 101, 115, 34, 58, 91, 34, 83, 69, 76, 69, 67, 84, 32, 42, 32, 70, 82, 79, 77, 32, 102, 111, 111, 34, 93, 44, 34, 80, 97, 114, 97, 109, 101, 116, 101, 114, 115, 34, 58, 91, 110, 117, 108, 108, 93, 44, 34, 116, 105, 109, 105, 110, 103, 115, 34, 58, 116, 114, 117, 101, 125, 125}
|
||||
|
||||
var c command.Command
|
||||
var qr command.QueryRequest
|
||||
if err := Unmarshal(b, &c); err != nil {
|
||||
t.Fatalf("failed to Unmarshal: %s", err)
|
||||
}
|
||||
|
||||
if c.Type != command.Command_COMMAND_TYPE_QUERY {
|
||||
t.Fatalf("incorrect command type: %s", c.Type)
|
||||
}
|
||||
if err := command.UnmarshalSubCommand(&c, &qr); err != nil {
|
||||
t.Fatalf("failed to Unmarshal subcommand: %s", err)
|
||||
}
|
||||
if !qr.Timings {
|
||||
t.Fatalf("timings not set")
|
||||
}
|
||||
if qr.Request.Transaction {
|
||||
t.Fatalf("transaction set")
|
||||
}
|
||||
if n := len(qr.Request.Statements); n != 1 {
|
||||
t.Fatalf("incorrect number of statments: %d", n)
|
||||
}
|
||||
if s := qr.Request.Statements[0].Sql; s != "SELECT * FROM foo" {
|
||||
t.Fatalf("incorrect SQL: %s", s)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_SingleParameterized(t *testing.T) {
|
||||
// ["INSERT INTO foo(name, age) VALUES(?, ?)", "fiona", 20], timings=true
|
||||
b := []byte{123, 34, 115, 117, 98, 34, 58, 123, 34, 113, 117, 101, 114, 105, 101, 115, 34, 58, 91, 34, 73, 78, 83, 69, 82, 84, 32, 73, 78, 84, 79, 32, 102, 111, 111, 40, 110, 97, 109, 101, 44, 32, 97, 103, 101, 41, 32, 86, 65, 76, 85, 69, 83, 40, 63, 44, 32, 63, 41, 34, 93, 44, 34, 80, 97, 114, 97, 109, 101, 116, 101, 114, 115, 34, 58, 91, 91, 34, 102, 105, 111, 110, 97, 34, 44, 50, 48, 93, 93, 44, 34, 116, 105, 109, 105, 110, 103, 115, 34, 58, 116, 114, 117, 101, 125, 125}
|
||||
|
||||
var c command.Command
|
||||
var er command.ExecuteRequest
|
||||
if err := Unmarshal(b, &c); err != nil {
|
||||
t.Fatalf("failed to Unmarshal: %s", err)
|
||||
}
|
||||
|
||||
if c.Type != command.Command_COMMAND_TYPE_EXECUTE {
|
||||
t.Fatalf("incorrect command type: %s", c.Type)
|
||||
}
|
||||
if err := command.UnmarshalSubCommand(&c, &er); err != nil {
|
||||
t.Fatalf("failed to Unmarshal subcommand: %s", err)
|
||||
}
|
||||
if !er.Timings {
|
||||
t.Fatalf("timings not set")
|
||||
}
|
||||
if er.Request.Transaction {
|
||||
t.Fatalf("transaction set")
|
||||
}
|
||||
if n := len(er.Request.Statements); n != 1 {
|
||||
t.Fatalf("incorrect number of statments: %d", n)
|
||||
}
|
||||
if s := er.Request.Statements[0].Sql; s != "INSERT INTO foo(name, age) VALUES(?, ?)" {
|
||||
t.Fatalf("incorrect SQL: %s", s)
|
||||
}
|
||||
if l := len(er.Request.Statements[0].Parameters); l != 2 {
|
||||
t.Fatalf("incorrect number of parameters: %d", l)
|
||||
}
|
||||
if v := er.Request.Statements[0].Parameters[0].GetS(); v != "fiona" {
|
||||
t.Fatalf("incorrect value for 1st parameter: %s", v)
|
||||
}
|
||||
if v := er.Request.Statements[0].Parameters[1].GetD(); v != 20 {
|
||||
t.Fatalf("incorrect value for 2nd parameter: %f", v)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_MultipleParameterized(t *testing.T) {
|
||||
// ["INSERT INTO foo(name, age) VALUES(?, ?)", "fiona", 20], ["INSERT INTO bar(name, age, address) VALUES(?, ?, ?)", "declan", 5, "galway"], timings=true
|
||||
b := []byte{123, 34, 115, 117, 98, 34, 58, 123, 34, 113, 117, 101, 114, 105, 101, 115, 34, 58, 91, 34, 73, 78, 83, 69, 82, 84, 32, 73, 78, 84, 79, 32, 102, 111, 111, 40, 110, 97, 109, 101, 44, 32, 97, 103, 101, 41, 32, 86, 65, 76, 85, 69, 83, 40, 63, 44, 32, 63, 41, 34, 44, 34, 73, 78, 83, 69, 82, 84, 32, 73, 78, 84, 79, 32, 98, 97, 114, 40, 110, 97, 109, 101, 44, 32, 97, 103, 101, 44, 32, 97, 100, 100, 114, 101, 115, 115, 41, 32, 86, 65, 76, 85, 69, 83, 40, 63, 44, 32, 63, 44, 32, 63, 41, 34, 93, 44, 34, 80, 97, 114, 97, 109, 101, 116, 101, 114, 115, 34, 58, 91, 91, 34, 102, 105, 111, 110, 97, 34, 44, 50, 48, 93, 44, 91, 34, 100, 101, 99, 108, 97, 110, 34, 44, 53, 44, 34, 103, 97, 108, 119, 97, 121, 34, 93, 93, 44, 34, 116, 105, 109, 105, 110, 103, 115, 34, 58, 116, 114, 117, 101, 125, 125}
|
||||
|
||||
var c command.Command
|
||||
var er command.ExecuteRequest
|
||||
if err := Unmarshal(b, &c); err != nil {
|
||||
t.Fatalf("failed to Unmarshal: %s", err)
|
||||
}
|
||||
|
||||
if c.Type != command.Command_COMMAND_TYPE_EXECUTE {
|
||||
t.Fatalf("incorrect command type: %s", c.Type)
|
||||
}
|
||||
if err := command.UnmarshalSubCommand(&c, &er); err != nil {
|
||||
t.Fatalf("failed to Unmarshal subcommand: %s", err)
|
||||
}
|
||||
if !er.Timings {
|
||||
t.Fatalf("timings not set")
|
||||
}
|
||||
if er.Request.Transaction {
|
||||
t.Fatalf("transaction set")
|
||||
}
|
||||
if n := len(er.Request.Statements); n != 2 {
|
||||
t.Fatalf("incorrect number of statments: %d", n)
|
||||
}
|
||||
|
||||
if s := er.Request.Statements[0].Sql; s != "INSERT INTO foo(name, age) VALUES(?, ?)" {
|
||||
t.Fatalf("incorrect SQL: %s", s)
|
||||
}
|
||||
if l := len(er.Request.Statements[0].Parameters); l != 2 {
|
||||
t.Fatalf("incorrect number of parameters: %d", l)
|
||||
}
|
||||
if v := er.Request.Statements[0].Parameters[0].GetS(); v != "fiona" {
|
||||
t.Fatalf("incorrect value for 1st parameter: %s", v)
|
||||
}
|
||||
if v := er.Request.Statements[0].Parameters[1].GetD(); v != 20 {
|
||||
t.Fatalf("incorrect value for 2nd parameter: %f", v)
|
||||
}
|
||||
|
||||
if s := er.Request.Statements[1].Sql; s != "INSERT INTO bar(name, age, address) VALUES(?, ?, ?)" {
|
||||
t.Fatalf("incorrect SQL: %s", s)
|
||||
}
|
||||
if l := len(er.Request.Statements[1].Parameters); l != 3 {
|
||||
t.Fatalf("incorrect number of parameters: %d", l)
|
||||
}
|
||||
if v := er.Request.Statements[1].Parameters[0].GetS(); v != "declan" {
|
||||
t.Fatalf("incorrect value for 1st parameter: %s", v)
|
||||
}
|
||||
if v := er.Request.Statements[1].Parameters[1].GetD(); v != 5 {
|
||||
t.Fatalf("incorrect value for 2nd parameter: %f", v)
|
||||
}
|
||||
if v := er.Request.Statements[1].Parameters[2].GetS(); v != "galway" {
|
||||
t.Fatalf("incorrect value for 1st parameter: %s", v)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_MetadataSet(t *testing.T) {
|
||||
b := []byte{123, 34, 116, 121, 112, 34, 58, 50, 44, 34, 115, 117, 98, 34, 58, 123, 34, 114, 97, 102, 116, 95, 105, 100, 34, 58, 34, 108, 111, 99, 97, 108, 104, 111, 115, 116, 58, 52, 48, 48, 50, 34, 44, 34, 100, 97, 116, 97, 34, 58, 123, 34, 97, 112, 105, 95, 97, 100, 100, 114, 34, 58, 34, 108, 111, 99, 97, 108, 104, 111, 115, 116, 58, 52, 48, 48, 49, 34, 44, 34, 97, 112, 105, 95, 112, 114, 111, 116, 111, 34, 58, 34, 104, 116, 116, 112, 34, 125, 125, 125}
|
||||
|
||||
var c command.Command
|
||||
var ms command.MetadataSet
|
||||
|
||||
if err := Unmarshal(b, &c); err != nil {
|
||||
t.Fatalf("failed to Unmarshal: %s", err)
|
||||
}
|
||||
|
||||
if c.Type != command.Command_COMMAND_TYPE_METADATA_SET {
|
||||
t.Fatalf("incorrect command type: %s", c.Type)
|
||||
}
|
||||
if err := command.UnmarshalSubCommand(&c, &ms); err != nil {
|
||||
t.Fatalf("failed to Unmarshal subcommand: %s", err)
|
||||
}
|
||||
if id := ms.RaftId; id != "localhost:4002" {
|
||||
t.Fatalf("incorrect Raft ID: %s", id)
|
||||
}
|
||||
if !reflect.DeepEqual(ms.Data, map[string]string{"api_addr": "localhost:4001", "api_proto": "http"}) {
|
||||
t.Fatalf("map is incorrect: %s", ms.Data)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_MetadataDelete(t *testing.T) {
|
||||
b := []byte{123, 34, 116, 121, 112, 34, 58, 51, 44, 34, 115, 117, 98, 34, 58, 34, 108, 111, 99, 97, 108, 104, 111, 115, 116, 58, 52, 48, 48, 52, 34, 125}
|
||||
|
||||
var c command.Command
|
||||
var md command.MetadataDelete
|
||||
|
||||
if err := Unmarshal(b, &c); err != nil {
|
||||
t.Fatalf("failed to Unmarshal: %s", err)
|
||||
}
|
||||
|
||||
if c.Type != command.Command_COMMAND_TYPE_METADATA_DELETE {
|
||||
t.Fatalf("incorrect command type: %s", c.Type)
|
||||
}
|
||||
if err := command.UnmarshalSubCommand(&c, &md); err != nil {
|
||||
t.Fatalf("failed to Unmarshal subcommand: %s", err)
|
||||
}
|
||||
if id := md.RaftId; id != "localhost:4004" {
|
||||
t.Fatalf("incorrect Raft ID: %s", id)
|
||||
}
|
||||
}
|
@ -0,0 +1,174 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"expvar"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultBatchThreshold = 5
|
||||
DefaultSizeThreshold = 150
|
||||
)
|
||||
|
||||
type Requester interface {
|
||||
proto.Message
|
||||
GetRequest() *Request
|
||||
}
|
||||
|
||||
type RequestMarshaler struct {
|
||||
BatchThreshold int
|
||||
SizeThreshold int
|
||||
ForceCompression bool
|
||||
|
||||
gz *gzip.Writer
|
||||
}
|
||||
|
||||
const (
|
||||
numRequests = "num_requests"
|
||||
numCompressedRequests = "num_compressed_requests"
|
||||
numUncompressedRequests = "num_uncompressed_requests"
|
||||
numCompressedBytes = "num_compressed_bytes"
|
||||
numPrecompressedBytes = "num_precompressed_bytes"
|
||||
numUncompressedBytes = "num_uncompressed_bytes"
|
||||
numCompressionMisses = "num_compression_misses"
|
||||
)
|
||||
|
||||
// stats captures stats for the Proto marshaler.
|
||||
var stats *expvar.Map
|
||||
|
||||
func init() {
|
||||
stats = expvar.NewMap("proto")
|
||||
stats.Add(numRequests, 0)
|
||||
stats.Add(numCompressedRequests, 0)
|
||||
stats.Add(numUncompressedRequests, 0)
|
||||
stats.Add(numCompressedBytes, 0)
|
||||
stats.Add(numUncompressedBytes, 0)
|
||||
stats.Add(numCompressionMisses, 0)
|
||||
stats.Add(numPrecompressedBytes, 0)
|
||||
}
|
||||
|
||||
func NewRequestMarshaler() *RequestMarshaler {
|
||||
w, err := gzip.NewWriterLevel(nil, gzip.BestCompression)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to create GZIP writer: %s", err.Error()))
|
||||
}
|
||||
|
||||
return &RequestMarshaler{
|
||||
BatchThreshold: DefaultBatchThreshold,
|
||||
SizeThreshold: DefaultSizeThreshold,
|
||||
gz: w,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *RequestMarshaler) Marshal(r Requester) ([]byte, bool, error) {
|
||||
stats.Add(numRequests, 0)
|
||||
compress := false
|
||||
|
||||
stmts := r.GetRequest().GetStatements()
|
||||
if len(stmts) >= m.BatchThreshold {
|
||||
compress = true
|
||||
} else {
|
||||
for i := range stmts {
|
||||
if len(stmts[i].Sql) >= m.SizeThreshold {
|
||||
compress = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
b, err := proto.Marshal(r)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
ubz := len(b)
|
||||
stats.Add(numPrecompressedBytes, int64(ubz))
|
||||
|
||||
if compress {
|
||||
// Let's try compression.
|
||||
var buf bytes.Buffer
|
||||
m.gz.Reset(&buf)
|
||||
if _, err := m.gz.Write(b); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
if err := m.gz.Close(); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
// Is compression better?
|
||||
if ubz > len(buf.Bytes()) || m.ForceCompression {
|
||||
// Yes! Let's keep it.
|
||||
b = buf.Bytes()
|
||||
stats.Add(numCompressedRequests, 1)
|
||||
stats.Add(numCompressedBytes, int64(len(b)))
|
||||
} else {
|
||||
// No. :-( Dump it.
|
||||
compress = false
|
||||
stats.Add(numCompressionMisses, 1)
|
||||
}
|
||||
} else {
|
||||
stats.Add(numUncompressedRequests, 1)
|
||||
stats.Add(numUncompressedBytes, int64(len(b)))
|
||||
}
|
||||
|
||||
return b, compress, nil
|
||||
}
|
||||
|
||||
func (m *RequestMarshaler) Stats() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"compression_size": m.SizeThreshold,
|
||||
"compression_batch": m.BatchThreshold,
|
||||
"force_compression": m.ForceCompression,
|
||||
}
|
||||
}
|
||||
|
||||
func Marshal(c *Command) ([]byte, error) {
|
||||
return proto.Marshal(c)
|
||||
}
|
||||
|
||||
func Unmarshal(b []byte, c *Command) error {
|
||||
return proto.Unmarshal(b, c)
|
||||
}
|
||||
|
||||
func MarshalMetadataSet(c *MetadataSet) ([]byte, error) {
|
||||
return proto.Marshal(c)
|
||||
}
|
||||
|
||||
func UnMarshalMetadataSet(b []byte, c *MetadataSet) error {
|
||||
return proto.Unmarshal(b, c)
|
||||
}
|
||||
|
||||
func MarshalMetadataDelete(c *MetadataDelete) ([]byte, error) {
|
||||
return proto.Marshal(c)
|
||||
}
|
||||
|
||||
func UnMarshalMetadataDelete(b []byte, c *MetadataDelete) error {
|
||||
return proto.Unmarshal(b, c)
|
||||
}
|
||||
|
||||
// Assumes m is the is the right type....caller must use c.Type
|
||||
func UnmarshalSubCommand(c *Command, m proto.Message) error {
|
||||
b := c.SubCommand
|
||||
if c.Compressed {
|
||||
gz, err := gzip.NewReader(bytes.NewReader(b))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ub, err := ioutil.ReadAll(gz)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := gz.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
b = ub
|
||||
}
|
||||
|
||||
return proto.Unmarshal(b, m)
|
||||
}
|
@ -0,0 +1,238 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
func Test_NewRequestMarshaler(t *testing.T) {
|
||||
r := NewRequestMarshaler()
|
||||
if r == nil {
|
||||
t.Fatal("failed to create Request marshaler")
|
||||
}
|
||||
}
|
||||
|
||||
func Test_MarshalUncompressed(t *testing.T) {
|
||||
rm := NewRequestMarshaler()
|
||||
r := &QueryRequest{
|
||||
Request: &Request{
|
||||
Statements: []*Statement{
|
||||
{
|
||||
Sql: `INSERT INTO "names" VALUES(1,'bob','123-45-678')`,
|
||||
},
|
||||
},
|
||||
},
|
||||
Timings: true,
|
||||
Freshness: 100,
|
||||
}
|
||||
|
||||
b, comp, err := rm.Marshal(r)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to marshal QueryRequest: %s", err)
|
||||
}
|
||||
if comp {
|
||||
t.Fatal("Marshaled QueryRequest incorrectly compressed")
|
||||
}
|
||||
|
||||
c := &Command{
|
||||
Type: Command_COMMAND_TYPE_QUERY,
|
||||
SubCommand: b,
|
||||
Compressed: comp,
|
||||
}
|
||||
|
||||
b, err = Marshal(c)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to marshal Command: %s", err)
|
||||
}
|
||||
|
||||
var nc Command
|
||||
if err := Unmarshal(b, &nc); err != nil {
|
||||
t.Fatalf("failed to unmarshal Command: %s", err)
|
||||
}
|
||||
if nc.Type != Command_COMMAND_TYPE_QUERY {
|
||||
t.Fatalf("unmarshaled command has wrong type: %s", nc.Type)
|
||||
}
|
||||
if nc.Compressed {
|
||||
t.Fatal("Unmarshaled QueryRequest incorrectly marked as compressed")
|
||||
}
|
||||
|
||||
var nr QueryRequest
|
||||
if err := UnmarshalSubCommand(&nc, &nr); err != nil {
|
||||
t.Fatalf("failed to unmarshal sub command: %s", err)
|
||||
}
|
||||
if nr.Timings != r.Timings {
|
||||
t.Fatalf("unmarshaled timings incorrect")
|
||||
}
|
||||
if nr.Freshness != r.Freshness {
|
||||
t.Fatalf("unmarshaled Freshness incorrect")
|
||||
}
|
||||
if len(nr.Request.Statements) != 1 {
|
||||
t.Fatalf("unmarshaled number of statements incorrect")
|
||||
}
|
||||
if nr.Request.Statements[0].Sql != `INSERT INTO "names" VALUES(1,'bob','123-45-678')` {
|
||||
t.Fatalf("unmarshaled SQL incorrect")
|
||||
}
|
||||
}
|
||||
|
||||
func Test_MarshalCompressedBatch(t *testing.T) {
|
||||
rm := NewRequestMarshaler()
|
||||
rm.BatchThreshold = 1
|
||||
rm.ForceCompression = true
|
||||
|
||||
r := &QueryRequest{
|
||||
Request: &Request{
|
||||
Statements: []*Statement{
|
||||
{
|
||||
Sql: `INSERT INTO "names" VALUES(1,'bob','123-45-678')`,
|
||||
},
|
||||
},
|
||||
},
|
||||
Timings: true,
|
||||
Freshness: 100,
|
||||
}
|
||||
|
||||
b, comp, err := rm.Marshal(r)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to marshal QueryRequest: %s", err)
|
||||
}
|
||||
if !comp {
|
||||
t.Fatal("Marshaled QueryRequest wasn't compressed")
|
||||
}
|
||||
|
||||
c := &Command{
|
||||
Type: Command_COMMAND_TYPE_QUERY,
|
||||
SubCommand: b,
|
||||
Compressed: comp,
|
||||
}
|
||||
|
||||
b, err = Marshal(c)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to marshal Command: %s", err)
|
||||
}
|
||||
|
||||
var nc Command
|
||||
if err := Unmarshal(b, &nc); err != nil {
|
||||
t.Fatalf("failed to unmarshal Command: %s", err)
|
||||
}
|
||||
if nc.Type != Command_COMMAND_TYPE_QUERY {
|
||||
t.Fatalf("unmarshaled command has wrong type: %s", nc.Type)
|
||||
}
|
||||
if !nc.Compressed {
|
||||
t.Fatal("Unmarshaled QueryRequest incorrectly marked as uncompressed")
|
||||
}
|
||||
|
||||
var nr QueryRequest
|
||||
if err := UnmarshalSubCommand(&nc, &nr); err != nil {
|
||||
t.Fatalf("failed to unmarshal sub command: %s", err)
|
||||
}
|
||||
if !proto.Equal(&nr, r) {
|
||||
t.Fatal("Original and unmarshaled Query Request are not equal")
|
||||
}
|
||||
}
|
||||
|
||||
func Test_MarshalCompressedSize(t *testing.T) {
|
||||
rm := NewRequestMarshaler()
|
||||
rm.SizeThreshold = 1
|
||||
rm.ForceCompression = true
|
||||
|
||||
r := &QueryRequest{
|
||||
Request: &Request{
|
||||
Statements: []*Statement{
|
||||
{
|
||||
Sql: `INSERT INTO "names" VALUES(1,'bob','123-45-678')`,
|
||||
},
|
||||
},
|
||||
},
|
||||
Timings: true,
|
||||
Freshness: 100,
|
||||
}
|
||||
|
||||
b, comp, err := rm.Marshal(r)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to marshal QueryRequest: %s", err)
|
||||
}
|
||||
if !comp {
|
||||
t.Fatal("Marshaled QueryRequest wasn't compressed")
|
||||
}
|
||||
|
||||
c := &Command{
|
||||
Type: Command_COMMAND_TYPE_QUERY,
|
||||
SubCommand: b,
|
||||
Compressed: comp,
|
||||
}
|
||||
|
||||
b, err = Marshal(c)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to marshal Command: %s", err)
|
||||
}
|
||||
|
||||
var nc Command
|
||||
if err := Unmarshal(b, &nc); err != nil {
|
||||
t.Fatalf("failed to unmarshal Command: %s", err)
|
||||
}
|
||||
if nc.Type != Command_COMMAND_TYPE_QUERY {
|
||||
t.Fatalf("unmarshaled command has wrong type: %s", nc.Type)
|
||||
}
|
||||
if !nc.Compressed {
|
||||
t.Fatal("Unmarshaled QueryRequest incorrectly marked as uncompressed")
|
||||
}
|
||||
|
||||
var nr QueryRequest
|
||||
if err := UnmarshalSubCommand(&nc, &nr); err != nil {
|
||||
t.Fatalf("failed to unmarshal sub command: %s", err)
|
||||
}
|
||||
if !proto.Equal(&nr, r) {
|
||||
t.Fatal("Original and unmarshaled Query Request are not equal")
|
||||
}
|
||||
}
|
||||
|
||||
func Test_MarshalWontCompressBatch(t *testing.T) {
|
||||
rm := NewRequestMarshaler()
|
||||
rm.BatchThreshold = 1
|
||||
|
||||
r := &QueryRequest{
|
||||
Request: &Request{
|
||||
Statements: []*Statement{
|
||||
{
|
||||
Sql: `INSERT INTO "names" VALUES(1,'bob','123-45-678')`,
|
||||
},
|
||||
},
|
||||
},
|
||||
Timings: true,
|
||||
Freshness: 100,
|
||||
}
|
||||
|
||||
_, comp, err := rm.Marshal(r)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to marshal QueryRequest: %s", err)
|
||||
}
|
||||
if comp {
|
||||
t.Fatal("Marshaled QueryRequest was compressed")
|
||||
}
|
||||
}
|
||||
|
||||
func Test_MarshalWontCompressSize(t *testing.T) {
|
||||
rm := NewRequestMarshaler()
|
||||
rm.SizeThreshold = 1
|
||||
|
||||
r := &QueryRequest{
|
||||
Request: &Request{
|
||||
Statements: []*Statement{
|
||||
{
|
||||
Sql: `INSERT INTO "names" VALUES(1,'bob','123-45-678')`,
|
||||
},
|
||||
},
|
||||
},
|
||||
Timings: true,
|
||||
Freshness: 100,
|
||||
}
|
||||
|
||||
_, comp, err := rm.Marshal(r)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to marshal QueryRequest: %s", err)
|
||||
}
|
||||
if comp {
|
||||
t.Fatal("Marshaled QueryRequest was compressed")
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// commandType are commands that affect the state of the cluster, and must go through Raft.
|
||||
type commandType int
|
||||
|
||||
const (
|
||||
execute commandType = iota // Commands which modify the database.
|
||||
query // Commands which query the database.
|
||||
metadataSet // Commands which sets Store metadata
|
||||
metadataDelete // Commands which deletes Store metadata
|
||||
)
|
||||
|
||||
type command struct {
|
||||
Typ commandType `json:"typ,omitempty"`
|
||||
Sub json.RawMessage `json:"sub,omitempty"`
|
||||
}
|
||||
|
||||
func newCommand(t commandType, d interface{}) (*command, error) {
|
||||
b, err := json.Marshal(d)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &command{
|
||||
Typ: t,
|
||||
Sub: b,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func newMetadataSetCommand(id string, md map[string]string) (*command, error) {
|
||||
m := metadataSetSub{
|
||||
RaftID: id,
|
||||
Data: md,
|
||||
}
|
||||
return newCommand(metadataSet, m)
|
||||
}
|
||||
|
||||
// databaseSub is a command sub which involves interaction with the database.
|
||||
// Queries and Parameters are separate fields, for backwards-compatibility
|
||||
// reasons. Unless Parameters is nil, it should be the same length as Queries.
|
||||
type databaseSub struct {
|
||||
Tx bool `json:"tx,omitempty"`
|
||||
SQLs []string `json:"queries,omitempty"`
|
||||
Parameters [][]Value `json:"Parameters,omitempty`
|
||||
Timings bool `json:"timings,omitempty"`
|
||||
}
|
||||
|
||||
type metadataSetSub struct {
|
||||
RaftID string `json:"raft_id,omitempty"`
|
||||
Data map[string]string `json:"data,omitempty"`
|
||||
}
|
Loading…
Reference in New Issue