Add tree params and debugging

This commit is contained in:
mcrakhman 2022-12-03 15:06:43 +01:00 committed by Mikhail Iudin
parent e6f4ff2f20
commit 8735700514
No known key found for this signature in database
GPG Key ID: FAAAA8BAABDFF1C0
8 changed files with 600 additions and 29 deletions

View File

@ -144,5 +144,3 @@ func (r *rpcHandler) TreeParams(ctx context.Context, request *apiproto.TreeParam
} }
return return
} }
//TreeParams(spaceId, documentId string) (root string, head []string, err error)

View File

@ -338,6 +338,110 @@ func (m *AllSpacesResponse) GetSpaceIds() []string {
return nil return nil
} }
type TreeParamsRequest struct {
SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"`
DocumentId string `protobuf:"bytes,2,opt,name=documentId,proto3" json:"documentId,omitempty"`
}
func (m *TreeParamsRequest) Reset() { *m = TreeParamsRequest{} }
func (m *TreeParamsRequest) String() string { return proto.CompactTextString(m) }
func (*TreeParamsRequest) ProtoMessage() {}
func (*TreeParamsRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_fc31080c27db9707, []int{7}
}
func (m *TreeParamsRequest) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *TreeParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_TreeParamsRequest.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (m *TreeParamsRequest) XXX_Merge(src proto.Message) {
xxx_messageInfo_TreeParamsRequest.Merge(m, src)
}
func (m *TreeParamsRequest) XXX_Size() int {
return m.Size()
}
func (m *TreeParamsRequest) XXX_DiscardUnknown() {
xxx_messageInfo_TreeParamsRequest.DiscardUnknown(m)
}
var xxx_messageInfo_TreeParamsRequest proto.InternalMessageInfo
func (m *TreeParamsRequest) GetSpaceId() string {
if m != nil {
return m.SpaceId
}
return ""
}
func (m *TreeParamsRequest) GetDocumentId() string {
if m != nil {
return m.DocumentId
}
return ""
}
type TreeParamsResponse struct {
RootId string `protobuf:"bytes,1,opt,name=rootId,proto3" json:"rootId,omitempty"`
HeadIds []string `protobuf:"bytes,2,rep,name=headIds,proto3" json:"headIds,omitempty"`
}
func (m *TreeParamsResponse) Reset() { *m = TreeParamsResponse{} }
func (m *TreeParamsResponse) String() string { return proto.CompactTextString(m) }
func (*TreeParamsResponse) ProtoMessage() {}
func (*TreeParamsResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_fc31080c27db9707, []int{8}
}
func (m *TreeParamsResponse) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *TreeParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_TreeParamsResponse.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (m *TreeParamsResponse) XXX_Merge(src proto.Message) {
xxx_messageInfo_TreeParamsResponse.Merge(m, src)
}
func (m *TreeParamsResponse) XXX_Size() int {
return m.Size()
}
func (m *TreeParamsResponse) XXX_DiscardUnknown() {
xxx_messageInfo_TreeParamsResponse.DiscardUnknown(m)
}
var xxx_messageInfo_TreeParamsResponse proto.InternalMessageInfo
func (m *TreeParamsResponse) GetRootId() string {
if m != nil {
return m.RootId
}
return ""
}
func (m *TreeParamsResponse) GetHeadIds() []string {
if m != nil {
return m.HeadIds
}
return nil
}
func init() { func init() {
proto.RegisterType((*DumpTreeRequest)(nil), "nodeapi.DumpTreeRequest") proto.RegisterType((*DumpTreeRequest)(nil), "nodeapi.DumpTreeRequest")
proto.RegisterType((*DumpTreeResponse)(nil), "nodeapi.DumpTreeResponse") proto.RegisterType((*DumpTreeResponse)(nil), "nodeapi.DumpTreeResponse")
@ -346,34 +450,39 @@ func init() {
proto.RegisterType((*AllTreesResponse)(nil), "nodeapi.AllTreesResponse") proto.RegisterType((*AllTreesResponse)(nil), "nodeapi.AllTreesResponse")
proto.RegisterType((*AllSpacesRequest)(nil), "nodeapi.AllSpacesRequest") proto.RegisterType((*AllSpacesRequest)(nil), "nodeapi.AllSpacesRequest")
proto.RegisterType((*AllSpacesResponse)(nil), "nodeapi.AllSpacesResponse") proto.RegisterType((*AllSpacesResponse)(nil), "nodeapi.AllSpacesResponse")
proto.RegisterType((*TreeParamsRequest)(nil), "nodeapi.TreeParamsRequest")
proto.RegisterType((*TreeParamsResponse)(nil), "nodeapi.TreeParamsResponse")
} }
func init() { proto.RegisterFile("api/apiproto/protos/api.proto", fileDescriptor_fc31080c27db9707) } func init() { proto.RegisterFile("api/apiproto/protos/api.proto", fileDescriptor_fc31080c27db9707) }
var fileDescriptor_fc31080c27db9707 = []byte{ var fileDescriptor_fc31080c27db9707 = []byte{
// 339 bytes of a gzipped FileDescriptorProto // 394 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0xc1, 0x4e, 0xf2, 0x40, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x53, 0xcd, 0x4a, 0xf3, 0x40,
0x10, 0xc7, 0xd9, 0x02, 0x1f, 0x74, 0x3e, 0x15, 0xdc, 0x78, 0x58, 0x9b, 0xb8, 0x21, 0x6b, 0x42, 0x14, 0x6d, 0xd2, 0xdf, 0xdc, 0xef, 0xa7, 0xed, 0x20, 0x12, 0x23, 0x86, 0x32, 0x42, 0x29, 0x28,
0x48, 0x34, 0x90, 0xe0, 0xc1, 0x23, 0x81, 0x78, 0x21, 0x26, 0x1e, 0xaa, 0x27, 0x6f, 0x95, 0xdd, 0x2d, 0xd4, 0x85, 0xcb, 0xd2, 0xa2, 0x42, 0x11, 0x45, 0xa2, 0x2b, 0x77, 0xb1, 0x33, 0x60, 0xa0,
0xc4, 0x4d, 0x80, 0x5d, 0xd9, 0xf6, 0x3d, 0x7c, 0x2c, 0x6f, 0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, 0x08, 0x1a, 0x69, 0x50, 0x39, 0x1f, 0x5b, 0xd7, 0x22, 0xe7, 0xe3, 0x5b, 0xaa, 0x13,
0x02, 0x00, 0x00, 0x30, 0xb2, 0x70, 0x50, 0xa1, 0xae, 0x10, 0xa2, 0x65, 0xed, 0xa2, 0x12, 0x8d, 0x49, 0xf7, 0x7d,
0x65, 0x6b, 0xcb, 0x95, 0xad, 0x7d, 0xae, 0x6c, 0xed, 0x75, 0x6d, 0x97, 0x96, 0x6b, 0xbb, 0xf4,
0xb1, 0xb6, 0x4b, 0x8f, 0x7f, 0xf3, 0xff, 0xcf, 0x53, 0x2d, 0x7e, 0x9d, 0x7d, 0x05, 0x00, 0x00,
0xff, 0xff, 0xb6, 0x98, 0xe5, 0x1d, 0x56, 0x03, 0x00, 0x00,
} }
func (m *DumpTreeRequest) Marshal() (dAtA []byte, err error) { func (m *DumpTreeRequest) Marshal() (dAtA []byte, err error) {
@ -604,6 +713,82 @@ func (m *AllSpacesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) {
return len(dAtA) - i, nil return len(dAtA) - i, nil
} }
func (m *TreeParamsRequest) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *TreeParamsRequest) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *TreeParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if len(m.DocumentId) > 0 {
i -= len(m.DocumentId)
copy(dAtA[i:], m.DocumentId)
i = encodeVarintApi(dAtA, i, uint64(len(m.DocumentId)))
i--
dAtA[i] = 0x12
}
if len(m.SpaceId) > 0 {
i -= len(m.SpaceId)
copy(dAtA[i:], m.SpaceId)
i = encodeVarintApi(dAtA, i, uint64(len(m.SpaceId)))
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
func (m *TreeParamsResponse) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *TreeParamsResponse) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *TreeParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if len(m.HeadIds) > 0 {
for iNdEx := len(m.HeadIds) - 1; iNdEx >= 0; iNdEx-- {
i -= len(m.HeadIds[iNdEx])
copy(dAtA[i:], m.HeadIds[iNdEx])
i = encodeVarintApi(dAtA, i, uint64(len(m.HeadIds[iNdEx])))
i--
dAtA[i] = 0x12
}
}
if len(m.RootId) > 0 {
i -= len(m.RootId)
copy(dAtA[i:], m.RootId)
i = encodeVarintApi(dAtA, i, uint64(len(m.RootId)))
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
func encodeVarintApi(dAtA []byte, offset int, v uint64) int { func encodeVarintApi(dAtA []byte, offset int, v uint64) int {
offset -= sovApi(v) offset -= sovApi(v)
base := offset base := offset
@ -716,6 +901,42 @@ func (m *AllSpacesResponse) Size() (n int) {
return n return n
} }
func (m *TreeParamsRequest) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
l = len(m.SpaceId)
if l > 0 {
n += 1 + l + sovApi(uint64(l))
}
l = len(m.DocumentId)
if l > 0 {
n += 1 + l + sovApi(uint64(l))
}
return n
}
func (m *TreeParamsResponse) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
l = len(m.RootId)
if l > 0 {
n += 1 + l + sovApi(uint64(l))
}
if len(m.HeadIds) > 0 {
for _, s := range m.HeadIds {
l = len(s)
n += 1 + l + sovApi(uint64(l))
}
}
return n
}
func sovApi(x uint64) (n int) { func sovApi(x uint64) (n int) {
return (math_bits.Len64(x|1) + 6) / 7 return (math_bits.Len64(x|1) + 6) / 7
} }
@ -1330,6 +1551,234 @@ func (m *AllSpacesResponse) Unmarshal(dAtA []byte) error {
} }
return nil return nil
} }
func (m *TreeParamsRequest) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowApi
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: TreeParamsRequest: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: TreeParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field SpaceId", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowApi
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthApi
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthApi
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.SpaceId = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field DocumentId", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowApi
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthApi
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthApi
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.DocumentId = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipApi(dAtA[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthApi
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func (m *TreeParamsResponse) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowApi
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: TreeParamsResponse: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: TreeParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field RootId", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowApi
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthApi
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthApi
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.RootId = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field HeadIds", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowApi
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthApi
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthApi
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.HeadIds = append(m.HeadIds, string(dAtA[iNdEx:postIndex]))
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipApi(dAtA[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthApi
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func skipApi(dAtA []byte) (n int, err error) { func skipApi(dAtA []byte) (n int, err error) {
l := len(dAtA) l := len(dAtA)
iNdEx := 0 iNdEx := 0

View File

@ -41,6 +41,7 @@ type DRPCNodeApiClient interface {
DRPCConn() drpc.Conn DRPCConn() drpc.Conn
DumpTree(ctx context.Context, in *DumpTreeRequest) (*DumpTreeResponse, error) DumpTree(ctx context.Context, in *DumpTreeRequest) (*DumpTreeResponse, error)
TreeParams(ctx context.Context, in *TreeParamsRequest) (*TreeParamsResponse, error)
AllTrees(ctx context.Context, in *AllTreesRequest) (*AllTreesResponse, error) AllTrees(ctx context.Context, in *AllTreesRequest) (*AllTreesResponse, error)
AllSpaces(ctx context.Context, in *AllSpacesRequest) (*AllSpacesResponse, error) AllSpaces(ctx context.Context, in *AllSpacesRequest) (*AllSpacesResponse, error)
} }
@ -64,6 +65,15 @@ func (c *drpcNodeApiClient) DumpTree(ctx context.Context, in *DumpTreeRequest) (
return out, nil return out, nil
} }
func (c *drpcNodeApiClient) TreeParams(ctx context.Context, in *TreeParamsRequest) (*TreeParamsResponse, error) {
out := new(TreeParamsResponse)
err := c.cc.Invoke(ctx, "/nodeapi.NodeApi/TreeParams", drpcEncoding_File_api_apiproto_protos_api_proto{}, in, out)
if err != nil {
return nil, err
}
return out, nil
}
func (c *drpcNodeApiClient) AllTrees(ctx context.Context, in *AllTreesRequest) (*AllTreesResponse, error) { func (c *drpcNodeApiClient) AllTrees(ctx context.Context, in *AllTreesRequest) (*AllTreesResponse, error) {
out := new(AllTreesResponse) out := new(AllTreesResponse)
err := c.cc.Invoke(ctx, "/nodeapi.NodeApi/AllTrees", drpcEncoding_File_api_apiproto_protos_api_proto{}, in, out) err := c.cc.Invoke(ctx, "/nodeapi.NodeApi/AllTrees", drpcEncoding_File_api_apiproto_protos_api_proto{}, in, out)
@ -84,6 +94,7 @@ func (c *drpcNodeApiClient) AllSpaces(ctx context.Context, in *AllSpacesRequest)
type DRPCNodeApiServer interface { type DRPCNodeApiServer interface {
DumpTree(context.Context, *DumpTreeRequest) (*DumpTreeResponse, error) DumpTree(context.Context, *DumpTreeRequest) (*DumpTreeResponse, error)
TreeParams(context.Context, *TreeParamsRequest) (*TreeParamsResponse, error)
AllTrees(context.Context, *AllTreesRequest) (*AllTreesResponse, error) AllTrees(context.Context, *AllTreesRequest) (*AllTreesResponse, error)
AllSpaces(context.Context, *AllSpacesRequest) (*AllSpacesResponse, error) AllSpaces(context.Context, *AllSpacesRequest) (*AllSpacesResponse, error)
} }
@ -94,6 +105,10 @@ func (s *DRPCNodeApiUnimplementedServer) DumpTree(context.Context, *DumpTreeRequ
return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented) return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
} }
func (s *DRPCNodeApiUnimplementedServer) TreeParams(context.Context, *TreeParamsRequest) (*TreeParamsResponse, error) {
return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
}
func (s *DRPCNodeApiUnimplementedServer) AllTrees(context.Context, *AllTreesRequest) (*AllTreesResponse, error) { func (s *DRPCNodeApiUnimplementedServer) AllTrees(context.Context, *AllTreesRequest) (*AllTreesResponse, error) {
return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented) return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
} }
@ -104,7 +119,7 @@ func (s *DRPCNodeApiUnimplementedServer) AllSpaces(context.Context, *AllSpacesRe
type DRPCNodeApiDescription struct{} type DRPCNodeApiDescription struct{}
func (DRPCNodeApiDescription) NumMethods() int { return 3 } func (DRPCNodeApiDescription) NumMethods() int { return 4 }
func (DRPCNodeApiDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver, interface{}, bool) { func (DRPCNodeApiDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver, interface{}, bool) {
switch n { switch n {
@ -118,6 +133,15 @@ func (DRPCNodeApiDescription) Method(n int) (string, drpc.Encoding, drpc.Receive
) )
}, DRPCNodeApiServer.DumpTree, true }, DRPCNodeApiServer.DumpTree, true
case 1: case 1:
return "/nodeapi.NodeApi/TreeParams", drpcEncoding_File_api_apiproto_protos_api_proto{},
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
return srv.(DRPCNodeApiServer).
TreeParams(
ctx,
in1.(*TreeParamsRequest),
)
}, DRPCNodeApiServer.TreeParams, true
case 2:
return "/nodeapi.NodeApi/AllTrees", drpcEncoding_File_api_apiproto_protos_api_proto{}, return "/nodeapi.NodeApi/AllTrees", drpcEncoding_File_api_apiproto_protos_api_proto{},
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) { func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
return srv.(DRPCNodeApiServer). return srv.(DRPCNodeApiServer).
@ -126,7 +150,7 @@ func (DRPCNodeApiDescription) Method(n int) (string, drpc.Encoding, drpc.Receive
in1.(*AllTreesRequest), in1.(*AllTreesRequest),
) )
}, DRPCNodeApiServer.AllTrees, true }, DRPCNodeApiServer.AllTrees, true
case 2: case 3:
return "/nodeapi.NodeApi/AllSpaces", drpcEncoding_File_api_apiproto_protos_api_proto{}, return "/nodeapi.NodeApi/AllSpaces", drpcEncoding_File_api_apiproto_protos_api_proto{},
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) { func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
return srv.(DRPCNodeApiServer). return srv.(DRPCNodeApiServer).
@ -160,6 +184,22 @@ func (x *drpcNodeApi_DumpTreeStream) SendAndClose(m *DumpTreeResponse) error {
return x.CloseSend() return x.CloseSend()
} }
type DRPCNodeApi_TreeParamsStream interface {
drpc.Stream
SendAndClose(*TreeParamsResponse) error
}
type drpcNodeApi_TreeParamsStream struct {
drpc.Stream
}
func (x *drpcNodeApi_TreeParamsStream) SendAndClose(m *TreeParamsResponse) error {
if err := x.MsgSend(m, drpcEncoding_File_api_apiproto_protos_api_proto{}); err != nil {
return err
}
return x.CloseSend()
}
type DRPCNodeApi_AllTreesStream interface { type DRPCNodeApi_AllTreesStream interface {
drpc.Stream drpc.Stream
SendAndClose(*AllTreesResponse) error SendAndClose(*AllTreesResponse) error

View File

@ -5,6 +5,7 @@ option go_package = "api/apiproto";
service NodeApi { service NodeApi {
rpc DumpTree(DumpTreeRequest) returns(DumpTreeResponse); rpc DumpTree(DumpTreeRequest) returns(DumpTreeResponse);
rpc TreeParams(TreeParamsRequest) returns(TreeParamsResponse);
rpc AllTrees(AllTreesRequest) returns(AllTreesResponse); rpc AllTrees(AllTreesRequest) returns(AllTreesResponse);
rpc AllSpaces(AllSpacesRequest) returns(AllSpacesResponse); rpc AllSpaces(AllSpacesRequest) returns(AllSpacesResponse);
} }
@ -37,3 +38,13 @@ message AllSpacesRequest {
message AllSpacesResponse { message AllSpacesResponse {
repeated string spaceIds = 1; repeated string spaceIds = 1;
} }
message TreeParamsRequest {
string spaceId = 1;
string documentId = 2;
}
message TreeParamsResponse {
string rootId = 1;
repeated string headIds = 2;
}

View File

@ -54,3 +54,15 @@ func (r *rpcHandler) AllSpaces(ctx context.Context, request *apiproto.AllSpacesR
resp = &apiproto.AllSpacesResponse{SpaceIds: ids} resp = &apiproto.AllSpacesResponse{SpaceIds: ids}
return return
} }
func (r *rpcHandler) TreeParams(ctx context.Context, request *apiproto.TreeParamsRequest) (resp *apiproto.TreeParamsResponse, err error) {
tree, err := r.treeCache.GetTree(context.Background(), request.SpaceId, request.DocumentId)
if err != nil {
return
}
resp = &apiproto.TreeParamsResponse{
RootId: tree.Root().Id,
HeadIds: tree.Heads(),
}
return
}

View File

@ -20,6 +20,7 @@ type Service interface {
DeleteDocument(ctx context.Context, ip string, request *apiproto.DeleteDocumentRequest) (resp *apiproto.DeleteDocumentResponse, err error) DeleteDocument(ctx context.Context, ip string, request *apiproto.DeleteDocumentRequest) (resp *apiproto.DeleteDocumentResponse, err error)
AddText(ctx context.Context, ip string, request *apiproto.AddTextRequest) (resp *apiproto.AddTextResponse, err error) AddText(ctx context.Context, ip string, request *apiproto.AddTextRequest) (resp *apiproto.AddTextResponse, err error)
DumpTree(ctx context.Context, ip string, request *apiproto.DumpTreeRequest) (resp *apiproto.DumpTreeResponse, err error) DumpTree(ctx context.Context, ip string, request *apiproto.DumpTreeRequest) (resp *apiproto.DumpTreeResponse, err error)
TreeParams(ctx context.Context, ip string, request *apiproto.TreeParamsRequest) (resp *apiproto.TreeParamsResponse, err error)
AllTrees(ctx context.Context, ip string, request *apiproto.AllTreesRequest) (resp *apiproto.AllTreesResponse, err error) AllTrees(ctx context.Context, ip string, request *apiproto.AllTreesRequest) (resp *apiproto.AllTreesResponse, err error)
AllSpaces(ctx context.Context, ip string, request *apiproto.AllSpacesRequest) (resp *apiproto.AllSpacesResponse, err error) AllSpaces(ctx context.Context, ip string, request *apiproto.AllSpacesRequest) (resp *apiproto.AllSpacesResponse, err error)
LoadSpace(ctx context.Context, ip string, request *apiproto.LoadSpaceRequest) (res *apiproto.LoadSpaceResponse, err error) LoadSpace(ctx context.Context, ip string, request *apiproto.LoadSpaceRequest) (res *apiproto.LoadSpaceResponse, err error)
@ -90,6 +91,14 @@ func (s *service) DumpTree(ctx context.Context, ip string, request *apiproto.Dum
return cl.DumpTree(ctx, request) return cl.DumpTree(ctx, request)
} }
func (s *service) TreeParams(ctx context.Context, ip string, request *apiproto.TreeParamsRequest) (resp *apiproto.TreeParamsResponse, err error) {
cl, err := s.client.GetClient(ctx, ip)
if err != nil {
return
}
return cl.TreeParams(ctx, request)
}
func (s *service) AllTrees(ctx context.Context, ip string, request *apiproto.AllTreesRequest) (resp *apiproto.AllTreesResponse, err error) { func (s *service) AllTrees(ctx context.Context, ip string, request *apiproto.AllTreesRequest) (resp *apiproto.AllTreesResponse, err error) {
cl, err := s.client.GetClient(ctx, ip) cl, err := s.client.GetClient(ctx, ip)
if err != nil { if err != nil {

View File

@ -15,6 +15,7 @@ var log = logger.NewNamed(CName)
type Service interface { type Service interface {
app.Component app.Component
DumpTree(ctx context.Context, ip string, request *apiproto.DumpTreeRequest) (resp *apiproto.DumpTreeResponse, err error) DumpTree(ctx context.Context, ip string, request *apiproto.DumpTreeRequest) (resp *apiproto.DumpTreeResponse, err error)
TreeParams(ctx context.Context, ip string, request *apiproto.TreeParamsRequest) (resp *apiproto.TreeParamsResponse, err error)
AllTrees(ctx context.Context, ip string, request *apiproto.AllTreesRequest) (resp *apiproto.AllTreesResponse, err error) AllTrees(ctx context.Context, ip string, request *apiproto.AllTreesRequest) (resp *apiproto.AllTreesResponse, err error)
AllSpaces(ctx context.Context, ip string, request *apiproto.AllSpacesRequest) (resp *apiproto.AllSpacesResponse, err error) AllSpaces(ctx context.Context, ip string, request *apiproto.AllSpacesRequest) (resp *apiproto.AllSpacesResponse, err error)
} }
@ -44,6 +45,14 @@ func (s *service) DumpTree(ctx context.Context, ip string, request *apiproto.Dum
return cl.DumpTree(ctx, request) return cl.DumpTree(ctx, request)
} }
func (s *service) TreeParams(ctx context.Context, ip string, request *apiproto.TreeParamsRequest) (resp *apiproto.TreeParamsResponse, err error) {
cl, err := s.client.GetNode(ctx, ip)
if err != nil {
return
}
return cl.TreeParams(ctx, request)
}
func (s *service) AllTrees(ctx context.Context, ip string, request *apiproto.AllTreesRequest) (resp *apiproto.AllTreesResponse, err error) { func (s *service) AllTrees(ctx context.Context, ip string, request *apiproto.AllTreesRequest) (resp *apiproto.AllTreesResponse, err error) {
cl, err := s.client.GetNode(ctx, ip) cl, err := s.client.GetNode(ctx, ip)
if err != nil { if err != nil {

View File

@ -153,7 +153,7 @@ func (s *service) registerClientCommands() {
return return
}} }}
s.clientCommands["add-text"] = Command{Cmd: func(server peers.Peer, params []string) (res string, err error) { s.clientCommands["add-text"] = Command{Cmd: func(server peers.Peer, params []string) (res string, err error) {
if len(params) != 3 { if len(params) != 3 && len(params) != 4 {
err = ErrIncorrectParamsCount err = ErrIncorrectParamsCount
return return
} }
@ -161,11 +161,12 @@ func (s *service) registerClientCommands() {
SpaceId: params[0], SpaceId: params[0],
DocumentId: params[1], DocumentId: params[1],
Text: params[2], Text: params[2],
IsSnapshot: len(params) == 4,
}) })
if err != nil { if err != nil {
return return
} }
res = resp.DocumentId + "->" + resp.HeadId res = resp.DocumentId + "->" + resp.RootId + "->" + resp.HeadId
return return
}} }}
s.clientCommands["load-space"] = Command{Cmd: func(server peers.Peer, params []string) (res string, err error) { s.clientCommands["load-space"] = Command{Cmd: func(server peers.Peer, params []string) (res string, err error) {
@ -224,6 +225,27 @@ func (s *service) registerClientCommands() {
res = resp.Dump res = resp.Dump
return return
}} }}
s.clientCommands["tree-params"] = Command{Cmd: func(server peers.Peer, params []string) (res string, err error) {
if len(params) != 2 {
err = ErrIncorrectParamsCount
return
}
resp, err := s.client.TreeParams(context.Background(), server.Address, &clientproto.TreeParamsRequest{
SpaceId: params[0],
DocumentId: params[1],
})
if err != nil {
return
}
res = resp.RootId + "->"
for headIdx, head := range resp.HeadIds {
res += head
if headIdx != len(resp.HeadIds)-1 {
res += ","
}
}
return
}}
s.clientCommands["all-spaces"] = Command{Cmd: func(server peers.Peer, params []string) (res string, err error) { s.clientCommands["all-spaces"] = Command{Cmd: func(server peers.Peer, params []string) (res string, err error) {
if len(params) != 0 { if len(params) != 0 {
err = ErrIncorrectParamsCount err = ErrIncorrectParamsCount
@ -286,6 +308,27 @@ func (s *service) registerNodeCommands() {
res = resp.Dump res = resp.Dump
return return
}} }}
s.nodeCommands["tree-params"] = Command{Cmd: func(server peers.Peer, params []string) (res string, err error) {
if len(params) != 2 {
err = ErrIncorrectParamsCount
return
}
resp, err := s.node.TreeParams(context.Background(), server.Address, &nodeproto.TreeParamsRequest{
SpaceId: params[0],
DocumentId: params[1],
})
if err != nil {
return
}
res = resp.RootId + "->"
for headIdx, head := range resp.HeadIds {
res += head
if headIdx != len(resp.HeadIds)-1 {
res += ","
}
}
return
}}
s.nodeCommands["all-spaces"] = Command{Cmd: func(server peers.Peer, params []string) (res string, err error) { s.nodeCommands["all-spaces"] = Command{Cmd: func(server peers.Peer, params []string) (res string, err error) {
if len(params) != 0 { if len(params) != 0 {
err = ErrIncorrectParamsCount err = ErrIncorrectParamsCount