You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ha...@apache.org on 2021/07/27 09:18:27 UTC

[skywalking-banyandb] 08/11: merge

This is an automated email from the ASF dual-hosted git repository.

hanahmily pushed a commit to branch gao-feat/rpc
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git

commit be0686d75bd45e30553f8ab2b1237f3cdc9bac11
Merge: 00db37b 392bac0
Author: Qiuxia Fan <fi...@outlook.com>
AuthorDate: Tue Jul 27 10:56:39 2021 +0800

    merge

 .github/workflows/go.yml                           |    6 +-
 .gitignore                                         |    1 +
 .licenserc.yaml                                    |    2 +
 Makefile                                           |   27 +-
 {banyand => api}/Makefile                          |   15 +-
 api/{fbs/Makefile => buf.gen.yaml}                 |   14 +-
 api/{fbs/Makefile => buf.yaml}                     |   22 +-
 api/common/id.go                                   |   32 -
 api/common/metadata.go                             |    8 +-
 api/data/trace.go                                  |    2 +-
 api/event/discovery.go                             |    2 +-
 api/fbs/v1/database.fbs                            |   62 -
 api/fbs/v1/database_generated.go                   |  484 -------
 api/fbs/v1/query.fbs                               |  142 ---
 api/fbs/v1/query_generated.go                      |  894 -------------
 api/fbs/v1/rpc_generated.go                        |    3 -
 api/fbs/v1/schema.fbs                              |  162 ---
 api/fbs/v1/schema_generated.go                     |  954 --------------
 api/fbs/v1/write_generated.go                      |  546 --------
 api/proto/banyandb/v1/database.pb.go               |  644 ++++++++++
 api/proto/banyandb/v1/database.proto               |   68 +
 api/proto/banyandb/v1/query.pb.go                  | 1132 +++++++++++++++++
 api/proto/banyandb/v1/query.proto                  |  147 +++
 api/proto/banyandb/v1/rpc.pb.go                    |  111 ++
 .../v1/rpc.fbs => proto/banyandb/v1/rpc.proto}     |   21 +-
 .../banyandb/v1/rpc_grpc.pb.go}                    |   74 +-
 api/proto/banyandb/v1/schema.pb.go                 | 1339 ++++++++++++++++++++
 api/proto/banyandb/v1/schema.proto                 |  187 +++
 api/proto/banyandb/v1/write.pb.go                  |  712 +++++++++++
 api/proto/banyandb/v1/write.proto                  |   76 ++
 api/schema/index.go                                |    6 +-
 api/schema/series.go                               |    4 +-
 banyand/Makefile                                   |    2 +
 banyand/discovery/discovery.go                     |   14 +-
 banyand/index/index.go                             |    7 +-
 banyand/liaison/grpc/grpc.go                       |   36 +-
 banyand/liaison/grpc/grpc_test.go                  |    5 +-
 banyand/series/idgen.go                            |   20 +-
 banyand/series/schema/sw/index_rule.bin            |  Bin 560 -> 342 bytes
 banyand/series/schema/sw/index_rule.json           |   81 --
 banyand/series/schema/sw/index_rule.textproto      |   89 ++
 banyand/series/schema/sw/index_rule_binding.bin    |  Bin 224 -> 103 bytes
 banyand/series/schema/sw/index_rule_binding.json   |   22 -
 .../series/schema/sw/index_rule_binding.textproto  |   31 +
 banyand/series/schema/sw/sw.go                     |   31 +-
 banyand/series/schema/sw/trace_series.bin          |  Bin 856 -> 423 bytes
 banyand/series/schema/sw/trace_series.json         |  101 --
 banyand/series/schema/sw/trace_series.textproto    |  101 ++
 banyand/series/series.go                           |    9 +-
 banyand/series/trace/common_test.go                |   80 +-
 banyand/series/trace/query.go                      |  137 +-
 banyand/series/trace/query_test.go                 |   83 +-
 banyand/series/trace/schema.go                     |   46 +-
 banyand/series/trace/schema_test.go                |   63 +-
 banyand/series/trace/trace.go                      |  187 +--
 banyand/series/trace/write.go                      |   42 +-
 banyand/series/trace/write_test.go                 |   24 +-
 banyand/storage/storage.go                         |    2 +-
 go.mod                                             |   18 +-
 go.sum                                             |  432 +++++--
 {banyand => pkg}/Makefile                          |    8 +-
 pkg/convert/number.go                              |   10 +
 pkg/fb/api.go                                      |  438 -------
 pkg/fb/database.go                                 |   86 --
 pkg/fb/util.go                                     |  228 ----
 pkg/partition/route.go                             |    5 +-
 pkg/pb/database.go                                 |  165 +++
 pkg/pb/fields.go                                   |   56 +
 pkg/pb/query.go                                    |  263 ++++
 pkg/pb/write.go                                    |  145 +++
 api/data/trace.go => pkg/posting/posting.go        |   55 +-
 pkg/posting/roaring/roaring.go                     |  194 +++
 pkg/query/logical/analyzer.go                      |  122 +-
 pkg/query/logical/analyzer_test.go                 |  178 ++-
 pkg/query/logical/common_test.go                   |   75 +-
 pkg/query/logical/expr.go                          |   74 +-
 pkg/query/logical/expr_literal.go                  |   18 +-
 pkg/query/logical/format.go                        |    2 +-
 pkg/query/logical/interface.go                     |    8 +-
 pkg/query/logical/plan.go                          |    6 +-
 pkg/query/logical/plan_execution_test.go           |   74 +-
 pkg/query/logical/plan_indexscan.go                |   44 +-
 pkg/query/logical/plan_orderby.go                  |   56 +-
 pkg/query/logical/plan_tablescan.go                |   27 +-
 pkg/query/logical/plan_traceid.go                  |    8 +-
 pkg/query/logical/schema.go                        |   36 +-
 pkg/run/run.go                                     |    4 +-
 scripts/build/base.mk                              |   87 ++
 scripts/build/build.mk                             |    4 +-
 api/fbs/Makefile => scripts/build/generate_go.mk   |   11 +-
 scripts/build/lint.mk                              |   10 +-
 scripts/build/test.mk                              |    4 +-
 scripts/ci/install_fb.sh                           |   47 -
 93 files changed, 6816 insertions(+), 5294 deletions(-)

diff --cc banyand/liaison/grpc/grpc.go
index 631e1b1,9288b82..43efff6
--- a/banyand/liaison/grpc/grpc.go
+++ b/banyand/liaison/grpc/grpc.go
@@@ -53,9 -45,9 +54,9 @@@ type Server struct 
  type shardInfo struct {
  	log *logger.Logger
  }
 -
 +var shardEventData *v1.ShardEvent
  func (s *shardInfo) Rev(message bus.Message) (resp bus.Message) {
- 	data, ok := message.Data().([]byte)
+ 	shardEvent, ok := message.Data().(*v1.ShardEvent)
  	if !ok {
  		s.log.Warn().Msg("invalid event data type")
  		return
@@@ -73,9 -63,8 +72,9 @@@ type seriesInfo struct 
  	log *logger.Logger
  }
  
 +var seriesEventData *v1.SeriesEvent
  func (s *seriesInfo) Rev(message bus.Message) (resp bus.Message) {
- 	data, ok := message.Data().([]byte)
+ 	seriesEvent, ok := message.Data().(*v1.SeriesEvent)
  	if !ok {
  		s.log.Warn().Msg("invalid event data type")
  		return
diff --cc banyand/liaison/grpc/grpc_test.go
index 5a2a529,0000000..252d0d6
mode 100644,000000..100644
--- a/banyand/liaison/grpc/grpc_test.go
+++ b/banyand/liaison/grpc/grpc_test.go
@@@ -1,127 -1,0 +1,126 @@@
 +// Licensed to Apache Software Foundation (ASF) under one or more contributor
 +// license agreements. See the NOTICE file distributed with
 +// this work for additional information regarding copyright
 +// ownership. Apache Software Foundation (ASF) licenses this file to you under
 +// the Apache License, Version 2.0 (the "License"); you may
 +// not use this file except in compliance with the License.
 +// You may obtain a copy of the License at
 +//
 +//     http://www.apache.org/licenses/LICENSE-2.0
 +//
 +// Unless required by applicable law or agreed to in writing,
 +// software distributed under the License is distributed on an
 +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 +// KIND, either express or implied.  See the License for the
 +// specific language governing permissions and limitations
 +// under the License.
 +
 +package grpc_test
 +
 +import (
 +	"context"
++	flatbuffers "github.com/google/flatbuffers/go"
 +	"io"
 +	"log"
 +	"net"
 +	"testing"
 +	"time"
 +
- 	flatbuffers "github.com/google/flatbuffers/go"
 +	grpclib "google.golang.org/grpc"
++	apiv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/v1"
 +
- 	v1 "github.com/apache/skywalking-banyandb/api/fbs/v1"
 +	"github.com/apache/skywalking-banyandb/banyand/liaison/grpc"
- 	"github.com/apache/skywalking-banyandb/pkg/fb"
 +)
 +
 +var serverAddr = "localhost:17912"
 +
 +func Test_server_start(t *testing.T) {
 +	go func() {
 +		lis, err := net.Listen("tcp", serverAddr)
 +		if err != nil {
 +			log.Fatalf("failed to listen: %v", err)
 +		}
 +		ser := grpclib.NewServer(grpclib.CustomCodec(flatbuffers.FlatbuffersCodec{}))
 +		v1.RegisterTraceServer(ser, &grpc.TraceServer{})
 +		if err := ser.Serve(lis); err != nil {
 +			log.Fatalf("Failed to serve: %v", err)
 +		}
 +	}()
 +}
 +
 +func Test_trace_write(t *testing.T) {
 +	conn, err := grpclib.Dial(serverAddr, grpclib.WithInsecure(), grpclib.WithDefaultCallOptions(grpclib.CustomCodecCallOption{Codec: flatbuffers.FlatbuffersCodec{}}))
 +	if err != nil {
 +		log.Fatalf("Failed to connect: %v", err)
 +	}
 +	defer conn.Close()
 +
 +	client := v1.NewTraceClient(conn)
 +	ctx := context.Background()
 +	b := fb.NewWriteEntityBuilder()
 +	binary := byte(12)
 +	criteria, e := b.BuildWriteEntity(
 +		b.BuildEntity("entityId", []byte{binary}, "service_instance_id", "service_id_1234", "service_instance_id_43543"),
 +		b.BuildMetaData("default", "trace"),
 +	)
 +	if e != nil {
 +		log.Fatalf("Failed to connect: %v", e)
 +	}
 +	stream, errorWrite := client.Write(ctx)
 +	if errorWrite != nil {
 +		log.Fatalf("%v.runWrite(_) = _, %v", client, errorWrite)
 +	}
 +	waitc := make(chan struct{})
 +	go func() {
 +		for {
 +			writeResponse, errRecv := stream.Recv()
 +			if errRecv == io.EOF {
 +				// read done.
 +				close(waitc)
 +				return
 +			}
 +			if errRecv != nil {
 +				log.Fatalf("Failed to receive data : %v", errRecv)
 +			}
 +			log.Println("writeResponse: ", writeResponse)
 +		}
 +	}()
 +	if errSend := stream.Send(criteria); errSend != nil {
 +		log.Fatalf("Failed to send a note: %v", errSend)
 +	}
 +	if errorSend := stream.CloseSend(); errorSend != nil {
 +		log.Fatalf("Failed to send a note: %v", errorSend)
 +	}
 +	<-waitc
 +}
 +func Test_trace_query(t *testing.T) {
 +	conn, err := grpclib.Dial(serverAddr, grpclib.WithInsecure(), grpclib.WithDefaultCallOptions(grpclib.CustomCodecCallOption{Codec: flatbuffers.FlatbuffersCodec{}}))
 +	if err != nil {
 +		log.Fatalf("Failed to connect: %v", err)
 +	}
 +	defer conn.Close()
 +
 +	client := v1.NewTraceClient(conn)
 +	ctx := context.Background()
 +	sT, eT := time.Now().Add(-3*time.Hour), time.Now()
 +
 +	b := fb.NewCriteriaBuilder()
 +	builder, e := b.BuildQueryEntity(
 +		fb.AddLimit(5),
 +		fb.AddOffset(10),
 +		b.BuildMetaData("default", "trace"),
 +		b.BuildTimeStampNanoSeconds(sT, eT),
 +		b.BuildFields("service_id", "=", "my_app", "http.method", "=", "GET"),
 +		b.BuildProjection("http.method", "service_id", "service_instance_id"),
 +		b.BuildOrderBy("service_instance_id", v1.SortDESC),
 +	)
 +	if e != nil {
 +		log.Fatalf("Failed to connect: %v", e)
 +	}
 +	stream, errRev := client.Query(ctx, builder)
 +	if errRev != nil {
 +		log.Fatalf("Retrieve client failed: %v", errRev)
 +	}
 +
 +	log.Println("QueryResponse: ", stream)
 +}
diff --cc pkg/partition/route.go
index b20226d,9b4d93c..2928eb7
--- a/pkg/partition/route.go
+++ b/pkg/partition/route.go
@@@ -17,15 -17,9 +17,12 @@@
  
  package partition
  
 -import "github.com/apache/skywalking-banyandb/pkg/convert"
 +import (
 +	"github.com/apache/skywalking-banyandb/pkg/convert"
 +	"github.com/pkg/errors"
 +)
  
- func ShardID(key []byte, shardNum uint) (uint, error) {
- 	if shardNum < 1 {
- 		return 0, errors.New("invalid shardNum")
- 	}
+ func ShardID(key []byte, shardNum uint32) uint {
  	encodeKey := convert.Hash(key)
 -	return uint(encodeKey % uint64(shardNum))
 +	return uint(encodeKey % uint64(shardNum)), nil
  }