Skip to content

Commit e2cc7fa

Browse files
committed
driver: implement tcs driver for tarantool support
- New Tarantool Config Storage (TCS) driver package (driver/tcs). - Integration testing for TCS. - Updated .golangci.yml. - Modified core driver interfaces to be compatible with tcs. - Update go module dependencies. Closes #TNTP-4188
1 parent 6961faf commit e2cc7fa

32 files changed

+4462
-120
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: "Prepare test environment with Tarantool EE"
2+
description: "Prepares test environment with Tarantool EE"
3+
4+
inputs:
5+
sdk-version:
6+
required: true
7+
type: string
8+
sdk-build:
9+
required: false
10+
type: string
11+
default: release
12+
sdk-gc:
13+
required: false
14+
type: string
15+
default: gc64
16+
sdk-download-token:
17+
required: true
18+
type: string
19+
20+
runs:
21+
using: "composite"
22+
steps:
23+
- name: Cache Tarantool SDK
24+
id: cache-sdk
25+
uses: actions/cache@v3
26+
with:
27+
path: tarantool-enterprise
28+
key: ${{ matrix.sdk-version }}
29+
30+
- name: Download Tarantool SDK
31+
run: |
32+
ARCHIVE_NAME=tarantool-enterprise-sdk-${{ inputs.sdk-gc }}-${{ inputs.sdk-version }}.tar.gz
33+
ARCHIVE_PATH=$(echo ${{ inputs.sdk-version }} | sed -rn \
34+
's/^([0-9]+)\.([0-9]+)\.([0-9]+-){2}([a-z0-9]+-)?r[0-9]+\.([a-z]+)\.([a-z0-9_]+)$/${{ inputs.sdk-build }}\/\5\/\6\/\1\.\2/p')
35+
curl -O -L \
36+
https://${{ inputs.sdk-download-token }}@download.tarantool.io/enterprise/${ARCHIVE_PATH}/${ARCHIVE_NAME}
37+
if [ $(stat -c%s "${ARCHIVE_NAME}") -eq 0 ]; then
38+
echo "Failed to download Tarantool EE SDK: '${ARCHIVE_PATH}/${ARCHIVE_NAME}'"
39+
exit 1
40+
fi
41+
tar -xzf ${ARCHIVE_NAME}
42+
rm -f ${ARCHIVE_NAME}
43+
source tarantool-enterprise/env.sh
44+
shell: bash
45+
46+
- name: Add SDK to PATH and set TARANTOOL_SDK_PATH variable
47+
run: |
48+
SDK_PATH="$(realpath tarantool-enterprise)"
49+
echo "${SDK_PATH}" >> ${GITHUB_PATH}
50+
echo "TARANTOOL_SDK_PATH=${SDK_PATH}" >> ${GITHUB_ENV}
51+
shell: bash

.github/workflows/tcs.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: tcs.yaml
2+
on:
3+
pull_request_target:
4+
types: [ labeled ]
5+
6+
env:
7+
# Note: Use exactly match version of tool, to avoid unexpected issues with test on CI.
8+
GO_VERSION: '1.24.9'
9+
10+
jobs:
11+
full-ci-ee:
12+
# Tests will run only when the pull request is labeled with `full-ci`. To
13+
# avoid security problems, the label must be reset manually for every run.
14+
#
15+
# We need to use `pull_request_target` because it has access to base
16+
# repository secrets unlike `pull_request`.
17+
if: (github.event_name == 'push') ||
18+
(github.event_name == 'pull_request_target' &&
19+
github.event.action == 'labeled' &&
20+
github.event.label.name == 'full-ci') ||
21+
(github.event_name == 'pull_request' &&
22+
github.event.action == 'synchronize' &&
23+
github.event.pull_request.head.repo.full_name == github.repository &&
24+
contains(github.event.pull_request.labels.*.name, 'full-ci'))
25+
runs-on: ubuntu-22.04
26+
strategy:
27+
matrix:
28+
sdk-version:
29+
- "3.5.0-0-r70.linux.x86_64"
30+
fail-fast: false
31+
steps:
32+
# `ref` as merge request is needed for pull_request_target because this
33+
# target runs in the context of the base commit of the pull request.
34+
- uses: actions/checkout@v4
35+
if: github.event_name == 'pull_request_target'
36+
with:
37+
fetch-depth: 0
38+
ref: ${{ github.event.pull_request.head.sha }}
39+
40+
- uses: actions/checkout@v4
41+
if: github.event_name != 'pull_request_target'
42+
with:
43+
fetch-depth: 0
44+
45+
- name: Prepare EE env
46+
uses: ./.github/actions/prepare-ee-test-env
47+
with:
48+
sdk-version: '${{ matrix.sdk-version }}'
49+
sdk-download-token: '${{ secrets.SDK_DOWNLOAD_TOKEN }}'
50+
51+
- name: Integration tests
52+
run:
53+
go test ./... -count=1 -v
54+
55+
- name: Integration tests
56+
run:
57+
go test ./... -count=100 -v -race

.golangci.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,16 @@ linters:
2525
- path: _test.go
2626
linters:
2727
- wrapcheck
28+
- err113
29+
- funlen
2830

2931
settings:
32+
varnamelen:
33+
ignore-names:
34+
- tt
35+
ignore-decls:
36+
- mc *minimock.Controller
37+
- t T
3038
godot:
3139
scope: all
3240
lll:
@@ -50,10 +58,16 @@ linters:
5058
- "go.etcd.io/etcd/client/v3"
5159
- "github.com/tarantool/go-tarantool/v2"
5260
- "github.com/tarantool/go-option"
61+
- "github.com/vmihailenco/msgpack/v5"
62+
- "github.com/tarantool/go-iproto"
5363
test:
5464
files:
5565
- "$test"
5666
allow:
5767
- $gostd
5868
- "github.com/tarantool/go-storage"
5969
- "github.com/stretchr/testify"
70+
- "github.com/tarantool/go-tarantool/v2"
71+
- "github.com/tarantool/go-iproto"
72+
- "github.com/vmihailenco/msgpack/v5"
73+
- "github.com/gojuno/minimock/v3"

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ codespell:
1010
.PHONY: test
1111
test:
1212
@echo "Running tests"
13-
@go test ./... -count=1
13+
@go test ./... -count=1 -v
1414

1515
.PHONY: testrace
1616
testrace:
1717
@echo "Running tests with race flag"
18-
@go test ./... -count=100 -race
18+
@go test ./... -count=100 -race -v -failfast
1919

2020
.PHONY: coverage
2121
coverage:

driver/driver.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@ type Driver interface {
2626

2727
// Watch establishes a watch stream for changes to a specific key or prefix.
2828
// The returned channel will receive events as changes occur.
29-
Watch(ctx context.Context, key []byte, opts ...watch.Option) <-chan watch.Event
29+
// The returned cleanup function should be called to stop the watch and release resources.
30+
// An error is returned if the watch could not be established.
31+
Watch(ctx context.Context, key []byte, opts ...watch.Option) (<-chan watch.Event, func(), error)
3032
}

driver/etcd/etcd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ func (d Driver) Execute(
6969

7070
// Watch monitors changes to a specific key and returns a stream of events.
7171
// It supports optional watch configuration through the opts parameter.
72-
func (d Driver) Watch(_ context.Context, _ []byte, _ ...watch.Option) <-chan watch.Event {
72+
func (d Driver) Watch(_ context.Context, _ []byte, _ ...watch.Option) (<-chan watch.Event, func(), error) {
7373
panic("implement me")
7474
}

driver/tcs/error.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package tcs
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
// DecodingError represents an error that occurs during decoding operations.
8+
type DecodingError struct {
9+
ObjectType string
10+
Text string
11+
Err error
12+
}
13+
14+
// Error returns the error message.
15+
func (e DecodingError) Error() string {
16+
suffix := e.ObjectType
17+
if e.Text != "" {
18+
suffix = fmt.Sprintf("%s, %s", suffix, e.Text)
19+
}
20+
21+
return fmt.Sprintf("failed to decode %s: %s", suffix, e.Err)
22+
}
23+
24+
func (e DecodingError) Unwrap() error {
25+
return e.Err
26+
}
27+
28+
// NewTxnOpResponseDecodingError returns a new txnOpResponse decoding error.
29+
func NewTxnOpResponseDecodingError(err error) error {
30+
if err == nil {
31+
return nil
32+
}
33+
34+
return DecodingError{
35+
ObjectType: "txnOpResponse",
36+
Text: "",
37+
Err: err,
38+
}
39+
}
40+
41+
// EncodingError represents an error that occurs during encoding operations.
42+
type EncodingError struct {
43+
ObjectType string
44+
Text string
45+
Err error
46+
}
47+
48+
// Error returns the error message.
49+
func (e EncodingError) Error() string {
50+
if e.Text == "" {
51+
return fmt.Sprintf("failed to encode %s: %s", e.ObjectType, e.Err)
52+
}
53+
54+
return fmt.Sprintf("failed to encode %s, %s: %s", e.ObjectType, e.Text, e.Err)
55+
}
56+
57+
func (e EncodingError) Unwrap() error {
58+
return e.Err
59+
}
60+
61+
// NewOperationEncodingError returns a new operation encoding error.
62+
func NewOperationEncodingError(text string, err error) error {
63+
if err == nil {
64+
return nil
65+
}
66+
67+
return EncodingError{
68+
ObjectType: "operation",
69+
Text: text,
70+
Err: err,
71+
}
72+
}
73+
74+
// NewPredicateEncodingError returns a new predicate encoding error.
75+
func NewPredicateEncodingError(text string, err error) error {
76+
if err == nil {
77+
return nil
78+
}
79+
80+
return EncodingError{
81+
ObjectType: "predicate",
82+
Text: text,
83+
Err: err,
84+
}
85+
}

0 commit comments

Comments
 (0)