Skip to content

Commit

Permalink
add example service for go-vshard-router with tarantool example from …
Browse files Browse the repository at this point in the history
…origin vshard lib (#3)

* init example app

* fix gitignore

* ready to work

* rm test real

* fix readme

* add make enter storage and router

* start makefile for go service

* fix go mod for example

* add make run for customer example

* use local library for example

* rm lock and add more information in log

* add fix

* fix multiple result of tarantool response #2

* small changes

* init topology provider logic

* fix topology provider

* update tags

* update vhsard to 0.1.26

* fix invalid bucket per rs

* enable raft

* add readme and how much discovered

* init swagger

* add 1 more instance for rs1

* fix go service config

* add ru doc

* fix ru doc

* revert to master

* add to main doc example service

---------

Co-authored-by: maxim-konovalov <maksim.konovalov@vk.team>
  • Loading branch information
KaymeKaydex and maxim-konovalov committed Apr 30, 2024
1 parent 118a7b4 commit 1ba6866
Show file tree
Hide file tree
Showing 25 changed files with 1,195 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ func main() {
fmt.Printf("get typed result: %v", info)
}
```
### Learn more examples
#### [Customer service](examples/customer/README.md)
Service with go-vshard-router on top of the tarantool example from the original vshard library using raft

## Benchmarks
Topology:
Expand Down
3 changes: 3 additions & 0 deletions README_ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ func main() {
}

```
### Ознакомьтесь с другими примерами
#### [Customer service](examples/customer/README.ru.md)
Сервис с go-vshard-router поверх примера тарантула из оригинальной библиотеки vshard с использованием raft

## Бенчмарки

Expand Down
26 changes: 26 additions & 0 deletions examples/customer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Customer service
## What it is?

This example is taken directly from the vshard repository example. A go service was written on top.
Includes only 2 endpoints (see [swagger](go-service/docs/swagger.yaml)): count, record sales information.
Only a few changes have been made:

- slightly modified Makefile
- by default, the example was created for fault tolerance according to Raft (only for replicaset 1, since there are 3 instances)
- the number of buckets is set to 10k
- minor fixes to critical errors (for example, the “transaction” attempt was replaced by box.atomic)
- added 1 more instance to replicaset 1 so that raft could select a new master
## How to start?

1. Start the cluster

```sh
$ cd tarantool
$ make start
```

2. Launch the service
```sh
$ cd go-service # from the customer directory
$ make start
```
26 changes: 26 additions & 0 deletions examples/customer/README.ru.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Customer service
## Что это такое?

Этот пример взят напрямую из примера репозитория vshard. Поверх был написан сервис на go.
Включает лишь 2 эндпоинта (см. [swagger](go-service/docs/swagger.yaml)): считать, записать информацию о продаже.
Допущены лишь несколько изменений:

- несколько модифицирован Makefile
- по умолчанию пример создан для отказоустойчивости по Raft(только для репликасета 1, поскольку там 3 инстанса)
- количество бакетов установлено в 10k
- минорные исправления критических ошибок (например попытка "транзакции" заменена на box.atomic)
- добавлен еще 1 инстанс в репликасет 1, чтобы raft мог выбрать нового мастера
## Как запустить?

1. Запускаем кластер

```sh
$ cd tarantool
$ make start
```

2. Запускаем сервис
```sh
$ cd go-service # из директории customer
$ make start
```
14 changes: 14 additions & 0 deletions examples/customer/go-service/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.PHONY: install-swaggo
install-swaggo:
ifeq ($(wildcard $(SWAGGO_BIN)),)
$(info #Downloading swaggo latest)
go install github.com/swaggo/swag/cmd/swag@latest
endif

start:
go run main.go config.yaml

# генерирует свагер
.PHONY: generate
generate: install-swaggo
swag init -g main.go
40 changes: 40 additions & 0 deletions examples/customer/go-service/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
listener:
address: :8096
routers:
addrs:
- "127.0.0.1:12002"
storage:
direct: true
total_bucket_count: 10000
topology:
clusters:
storage_1:
replicaset_uuid: cbf06940-0790-498b-948d-042b62cf3d29
storage_2:
replicaset_uuid: ac522f65-aa94-4134-9f64-51ee384f1a54
instances:
storage_1_a:
cluster: storage_1
box:
listen: '127.0.0.1:3301'
instance_uuid: '6E35AC64-1241-0001-0001-000000000000'
storage_1_b:
cluster: storage_1
box:
listen: '127.0.0.1:3302'
instance_uuid: '6E35AC64-1241-0001-0002-000000000000'
storage_1_c:
cluster: storage_1
box:
listen: '127.0.0.1:3305'
instance_uuid: '6E35AC64-1241-0001-0003-000000000000'
storage_2_a:
cluster: storage_2
box:
listen: '127.0.0.1:3303'
instance_uuid: '6E35AC64-1241-0002-0001-000000000000'
storage_2_b:
cluster: storage_2
box:
listen: '127.0.0.1:3304'
instance_uuid: '6E35AC64-1241-0002-0002-000000000000'
156 changes: 156 additions & 0 deletions examples/customer/go-service/docs/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
// Package docs Code generated by swaggo/swag. DO NOT EDIT
package docs

import "github.com/swaggo/swag"

const docTemplate = `{
"schemes": {{ marshal .Schemes }},
"swagger": "2.0",
"info": {
"description": "{{escape .Description}}",
"title": "{{.Title}}",
"termsOfService": "http://swagger.io/terms/",
"contact": {
"name": "API Support",
"url": "http://quedafoe.ru",
"email": "djassange@ya.ru"
},
"version": "{{.Version}}"
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/customer_add": {
"post": {
"description": "Todo",
"produces": [
"application/json"
],
"tags": [
"Set"
],
"summary": "Todo",
"parameters": [
{
"description": "Обязательно не должно быть пустым",
"name": "Request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/main.CustomerAddRequest"
}
}
],
"responses": {
"200": {
"description": "ok",
"schema": {
"type": "string"
}
}
}
}
},
"/customer_lookup": {
"get": {
"description": "Todo",
"produces": [
"application/json"
],
"tags": [
"Get"
],
"summary": "Todo",
"parameters": [
{
"type": "string",
"description": "id of customer",
"name": "id",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/main.CustomerLookupResponse"
}
}
}
}
}
},
"definitions": {
"main.CustomerAddRequest": {
"type": "object",
"properties": {
"accounts": {
"type": "array",
"items": {
"type": "object",
"properties": {
"account_id": {
"type": "integer"
},
"name": {
"type": "string"
}
}
}
},
"customer_id": {
"type": "integer"
},
"name": {
"type": "string"
}
}
},
"main.CustomerLookupResponse": {
"type": "object",
"properties": {
"accounts": {
"type": "array",
"items": {
"type": "object",
"properties": {
"account_id": {
"type": "integer"
},
"balance": {
"type": "integer"
},
"name": {
"type": "string"
}
}
}
},
"customer_id": {
"type": "integer"
},
"name": {
"type": "string"
}
}
}
}
}`

// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "1.0",
Host: "localhost:8096",
BasePath: "",
Schemes: []string{},
Title: "Example customer service Swagger API",
Description: "Just example :)",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
RightDelim: "}}",
}

func init() {
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
}

0 comments on commit 1ba6866

Please sign in to comment.