Skip to content

Commit b2442f7

Browse files
committed
Merge branch 'main' into feature/production_docker_image
Signed-off-by: pco <pasquale.convertini@ibm.com>
2 parents 2daf3d6 + aca8b95 commit b2442f7

119 files changed

Lines changed: 2513 additions & 3797 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.apilinter.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright IBM Corp. All Rights Reserved.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
6+
---
7+
- disabled_rules:
8+
- core::0192::only-leading-comments # Forbid inline comments
9+
- core::0192::has-comments # Required comment in every service, message, and field
10+
- core::0141::forbidden-types # E.g., uint is forbidden
11+
- core::0215::versioned-packages # E.g., applicationpb.v1
12+
- core::0131::method-signature # A google.api.method_signature annotation should be present
13+
- core::0215::foreign-type-reference # We require foreign types.
14+
- core::0127::http-annotation # HTTP annotations (might be added in the future)
15+
- core::0203::field-behavior-required # E.g., [(google.api.field_behavior) = REQUIRED]
16+
- core::0123::resource-annotation # Forces resources annotation (not applicable)
17+
# Enforces connection between method names to the request/reposne message name.
18+
- core::0136::response-message-name
19+
- core::0131::response-message-name
20+
- core::0136::request-message-name
21+
- core::0131::request-message-name
22+
# Grammar related issues (e.g., forbid use "of" and "with").
23+
- core::0140::prepositions
24+
- core::0136::prepositions
25+
- core::0134::synonyms
26+
- core::0216::synonyms
27+
# Java related issues (might be addressed in the future if required)
28+
- core::0191::java-multiple-files
29+
- core::0191::java-package
30+
- core::0191::java-outer-classnam
31+
- core::0191::java-outer-classname

Makefile

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ env ?= env GOOS=$(os) GOARCH=$(arch)
5454
build_flags ?= -buildvcs=false -o
5555
go_build ?= $(env) $(go_cmd) build $(build_flags)
5656
go_test ?= $(go_cmd) test -json -v -timeout 30m
57-
proto_path ?=
57+
proto_flags ?=
5858

5959
ifneq ("$(wildcard /usr/include)","")
60-
proto_path += "/usr/include"
60+
proto_flags += --proto_path="/usr/include"
6161
endif
6262

6363
arch_output_dir_rel = $(arch_output_dir:${project_dir}/%=%)
@@ -151,8 +151,7 @@ clean: FORCE
151151
@rm -rf $(arch_output_dir)
152152

153153
kill-test-docker: FORCE
154-
$(docker_cmd) ps -aq -f name=sc_yugabyte_unit_tests | xargs $(docker_cmd) rm -f
155-
$(docker_cmd) ps -aq -f name=sc_postgres_unit_tests | xargs $(docker_cmd) rm -f
154+
$(docker_cmd) ps -aq -f "name=sc_test" | xargs $(docker_cmd) rm -f
156155

157156
#########################
158157
# Benchmarks
@@ -182,20 +181,25 @@ bench-sidecar: FORCE
182181
# Generate protos
183182
#########################
184183

185-
PROTO_TARGETS ?= $(shell find ./api \
186-
-name '*.proto' -print0 | \
187-
xargs -0 -n 1 dirname | xargs -n 1 basename | \
188-
sort -u | sed -E "s/^(.*)$$/proto-\1/" \
189-
)
190-
191-
proto: $(PROTO_TARGETS)
192-
193-
proto-%: FORCE
194-
@echo "Compiling: $*"
195-
@protoc --proto_path="${PWD}" \
196-
--proto_path="${proto_path}" \
197-
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
198-
--go_out=paths=source_relative:. ${PWD}/api/$*/*.proto
184+
proto: FORCE
185+
@echo "Generating protobufs: $(shell find ${project_dir}/api -name '*.proto' -print0 \
186+
| xargs -0 -n 1 dirname | xargs -n 1 basename | sort -u)"
187+
@protoc \
188+
--go-grpc_out=. \
189+
--go-grpc_opt=paths=source_relative \
190+
--go_out=paths=source_relative:. \
191+
--proto_path="${project_dir}" \
192+
${proto_flags} \
193+
${project_dir}/api/*/*.proto
194+
195+
lint-proto: FORCE
196+
@echo "Running protobuf linters..."
197+
@api-linter \
198+
-I="${project_dir}/api" \
199+
--config .apilinter.yaml \
200+
--set-exit-status \
201+
--output-format github \
202+
$(shell find ${project_dir}/api -name '*.proto' -exec realpath --relative-to ${project_dir}/api {} \;)
199203

200204
#########################
201205
# Binaries
@@ -259,7 +263,7 @@ build-test-genesis-block: $(output_dir) build-cli-loadgen
259263
# Linter
260264
#########################
261265

262-
lint: FORCE
266+
lint: lint-proto FORCE
263267
@echo "Running Go Linters..."
264268
golangci-lint run --color=always --new-from-rev=main --timeout=4m
265269
@echo "Running SQL Linters..."

api/applicationpb/asn1.go

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package applicationpb
8+
9+
import (
10+
"encoding/asn1"
11+
12+
"github.com/cockroachdb/errors"
13+
)
14+
15+
// ASN1Marshal marshals a transactions for a given namespace index.
16+
// It uses the schema described in asn1_tx_schema.asn.
17+
func (ns *TxNamespace) ASN1Marshal(txID string) ([]byte, error) {
18+
ret, err := asn1.Marshal(*ns.translate(txID))
19+
return ret, errors.Wrap(err, "failed to marshal tx namespace")
20+
}
21+
22+
// translate translates a [TxNamespace] to a stab struct for asn1_tx_schema.asn.
23+
// Any change to [TxNamespace] requires a change to this method.
24+
func (ns *TxNamespace) translate(txID string) *asn1Namespace {
25+
n := asn1Namespace{
26+
TxID: txID,
27+
NamespaceID: ns.NsId,
28+
NamespaceVersion: protoToAsnVersion(&ns.NsVersion),
29+
ReadsOnly: make([]asn1Read, len(ns.ReadsOnly)),
30+
ReadWrites: make([]asn1ReadWrite, len(ns.ReadWrites)),
31+
BlindWrites: make([]asn1Write, len(ns.BlindWrites)),
32+
}
33+
for i, r := range ns.ReadsOnly {
34+
n.ReadsOnly[i] = asn1Read{
35+
Key: r.Key,
36+
Version: protoToAsnVersion(r.Version),
37+
}
38+
}
39+
for i, rw := range ns.ReadWrites {
40+
n.ReadWrites[i] = asn1ReadWrite{
41+
Key: rw.Key,
42+
Version: protoToAsnVersion(rw.Version),
43+
Value: rw.Value,
44+
}
45+
}
46+
for i, w := range ns.BlindWrites {
47+
n.BlindWrites[i] = asn1Write{
48+
Key: w.Key,
49+
Value: w.Value,
50+
}
51+
}
52+
return &n
53+
}
54+
55+
// protoToAsnVersion converts the proto version to ASN.1 version.
56+
// ASN.1 uses -1 to encode nil version.
57+
func protoToAsnVersion(ver *uint64) int64 {
58+
if ver == nil {
59+
return -1
60+
}
61+
return int64(*ver) //nolint:gosec // ASN.1 does not support unsigned numbers.
62+
}
63+
64+
// asnToProtoVersion converts the ASN.1 version to proto version.
65+
// ASN.1 uses -1 to encode nil version.
66+
func asnToProtoVersion(ver int64) *uint64 {
67+
if ver < 0 {
68+
return nil
69+
}
70+
protoVer := uint64(ver)
71+
return &protoVer
72+
}
73+
74+
type (
75+
// asn1Namespace is a stab for [Tx] and [TxNamespace].
76+
// Any change to these protobuf requires a change to these structures.
77+
// It conforms with asn1_tx_schema.asn.
78+
// We force the ASN.1 library to use UTF8 strings to avoid incompatibility with the schema.
79+
// If not specified, the library choose to use ASCII (PrintableString) for simple strings,
80+
// and UTF8 otherwise.
81+
asn1Namespace struct {
82+
TxID string `asn1:"utf8"`
83+
NamespaceID string `asn1:"utf8"`
84+
NamespaceVersion int64
85+
ReadsOnly []asn1Read
86+
ReadWrites []asn1ReadWrite
87+
BlindWrites []asn1Write
88+
}
89+
// asn1Read is a stab for [Read].
90+
// Any change to this protobuf requires a change to these structures.
91+
asn1Read struct {
92+
Key []byte
93+
Version int64 `asn1:"optional,default:-1"`
94+
}
95+
// asn1ReadWrite is a stab for [ReadWrite].
96+
// Any change to this protobuf requires a change to these structures.
97+
asn1ReadWrite struct {
98+
Key []byte
99+
Value []byte
100+
Version int64 `asn1:"optional,default:-1"`
101+
}
102+
// asn1Write is a stab for [Write].
103+
// Any change to this protobuf requires a change to these structures.
104+
asn1Write struct {
105+
Key []byte
106+
Value []byte
107+
}
108+
)

0 commit comments

Comments
 (0)