Skip to content

Commit e95cce5

Browse files
committed
IMDEVOPS-5849 - проверять репликацю у тарантул
1 parent 7eae014 commit e95cce5

File tree

5 files changed

+190
-0
lines changed

5 files changed

+190
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
1010

1111
### Added
1212

13+
- Extend box with replication information (#427).
14+
1315
### Changed
1416

1517
### Fixed

box/info.go

+53
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,59 @@ type Info struct {
2626
Status string `msgpack:"status"`
2727
// LSN - Log sequence number of the instance.
2828
LSN uint64 `msgpack:"lsn"`
29+
// Replication - replication status
30+
Replication map[int]Replication `msgpack:"replication,omitempty"`
31+
}
32+
33+
// Replication section of box.info() is a table with statistics for all instances
34+
// in the replica set that the current instance belongs to.
35+
type Replication struct {
36+
// ID is a short numeric identifier of instance n within the replica set
37+
ID int `msgpack:"id"`
38+
// UUID - Unique identifier of the instance.
39+
UUID string `msgpack:"uuid"`
40+
// LSN - Log sequence number of the instance.
41+
LSN uint64 `msgpack:"lsn"`
42+
// Upstream - information about upstream.
43+
Upstream Upstream `msgpack:"upstream,omitempty"`
44+
// Downstream - information about downstream.
45+
Downstream Downstream `msgpack:"downstream,omitempty"`
46+
}
47+
48+
// Upstream information.
49+
type Upstream struct {
50+
// Status is replication status of the connection with the instance.
51+
Status string `msgpack:"status"`
52+
// Idle is the time (in seconds) since the last event was received.
53+
Idle float64 `msgpack:"idle"`
54+
// Contains instance n’s URI.
55+
Peer string `msgpack:"peer"`
56+
// Lag is the time difference between the local time of instance n,
57+
// recorded when the event was received, and the local time at another master
58+
// recorded when the event was written to the write-ahead log on that master.
59+
Lag float64 `msgpack:"lag"`
60+
// Message contains an error message in case of a degraded state; otherwise, it is nil.
61+
Message string `msgpack:"message,omitempty"`
62+
// SystemMessage contains an error message in case of a degraded state; otherwise, it is nil.
63+
SystemMessage string `msgpack:"system_message,omitempty"`
64+
}
65+
66+
// Downstream information.
67+
type Downstream struct {
68+
// Status is replication status of the connection with the instance.
69+
Status string `msgpack:"status"`
70+
// Idle is the time (in seconds) since the last event was received.
71+
Idle float64 `msgpack:"idle"`
72+
// Contains the vector clock, which is a table of ‘id, lsn’ pairs.
73+
VClock map[int]uint64 `msgpack:"vclock"`
74+
// Lag is the time difference between the local time of instance n,
75+
// recorded when the event was received, and the local time at another master
76+
// recorded when the event was written to the write-ahead log on that master.
77+
Lag float64 `msgpack:"lag"`
78+
// Message contains an error message in case of a degraded state; otherwise, it is nil.
79+
Message string `msgpack:"message,omitempty"`
80+
// SystemMessage contains an error message in case of a degraded state; otherwise, it is nil.
81+
SystemMessage string `msgpack:"system_message,omitempty"`
2982
}
3083

3184
// InfoResponse represents the response structure

box/info_test.go

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
package box
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
"github.com/vmihailenco/msgpack/v5"
8+
)
9+
10+
func TestInfoRequest(t *testing.T) {
11+
id := 1
12+
cases := []struct {
13+
Name string
14+
Struct Info
15+
Data map[string]interface{}
16+
}{
17+
{
18+
Name: "Case: base info struct",
19+
Struct: Info{
20+
Version: "2.11.4-0-g8cebbf2cad",
21+
ID: &id,
22+
RO: false,
23+
UUID: "69360e9b-4641-4ec3-ab51-297f46749849",
24+
PID: 1,
25+
Status: "running",
26+
LSN: 8,
27+
},
28+
Data: map[string]interface{}{
29+
"version": "2.11.4-0-g8cebbf2cad",
30+
"id": 1,
31+
"ro": false,
32+
"uuid": "69360e9b-4641-4ec3-ab51-297f46749849",
33+
"pid": 1,
34+
"status": "running",
35+
"lsn": 8,
36+
},
37+
},
38+
{
39+
Name: "Case: info struct with replication",
40+
Struct: Info{
41+
Version: "2.11.4-0-g8cebbf2cad",
42+
ID: &id,
43+
RO: false,
44+
UUID: "69360e9b-4641-4ec3-ab51-297f46749849",
45+
PID: 1,
46+
Status: "running",
47+
LSN: 8,
48+
Replication: map[int]Replication{
49+
1: {
50+
ID: 1,
51+
UUID: "69360e9b-4641-4ec3-ab51-297f46749849",
52+
LSN: 8,
53+
},
54+
2: {
55+
ID: 2,
56+
UUID: "75f5f5aa-89f0-4d95-b5a9-96a0eaa0ce36",
57+
LSN: 0,
58+
Upstream: Upstream{
59+
Status: "follow",
60+
Idle: 2.4564633660484,
61+
Peer: "other.tarantool:3301",
62+
Lag: 0.00011920928955078,
63+
Message: "'getaddrinfo: Name or service not known: Input/output error'",
64+
SystemMessage: "Input/output error",
65+
},
66+
Downstream: Downstream{
67+
Status: "follow",
68+
Idle: 2.8306158290943,
69+
VClock: map[int]uint64{1: 8},
70+
Lag: 0,
71+
Message: "'unexpected EOF when reading from socket'",
72+
SystemMessage: "Broken pipe",
73+
},
74+
},
75+
},
76+
},
77+
Data: map[string]interface{}{
78+
"version": "2.11.4-0-g8cebbf2cad",
79+
"id": 1,
80+
"ro": false,
81+
"uuid": "69360e9b-4641-4ec3-ab51-297f46749849",
82+
"pid": 1,
83+
"status": "running",
84+
"lsn": 8,
85+
"replication": map[interface{}]interface{}{
86+
1: map[string]interface{}{
87+
"id": 1,
88+
"uuid": "69360e9b-4641-4ec3-ab51-297f46749849",
89+
"lsn": 8,
90+
},
91+
2: map[string]interface{}{
92+
"id": 2,
93+
"uuid": "75f5f5aa-89f0-4d95-b5a9-96a0eaa0ce36",
94+
"lsn": 0,
95+
"upstream": map[string]interface{}{
96+
"status": "follow",
97+
"idle": 2.4564633660484,
98+
"peer": "other.tarantool:3301",
99+
"lag": 0.00011920928955078,
100+
"message": "'getaddrinfo: Name or service not known: Input/output error'",
101+
"system_message": "Input/output error",
102+
},
103+
"downstream": map[string]interface{}{
104+
"status": "follow",
105+
"idle": 2.8306158290943,
106+
"vclock": map[interface{}]interface{}{1: 8},
107+
"lag": 0,
108+
"message": "'unexpected EOF when reading from socket'",
109+
"system_message": "Broken pipe",
110+
},
111+
},
112+
},
113+
},
114+
},
115+
}
116+
for _, tc := range cases {
117+
data, err := msgpack.Marshal(tc.Data)
118+
require.NoError(t, err, tc.Name)
119+
120+
var result Info
121+
err = msgpack.Unmarshal(data, &result)
122+
require.NoError(t, err, tc.Name)
123+
124+
require.Equal(t, tc.Struct, result)
125+
}
126+
}

box/tarantool_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ func validateInfo(t testing.TB, info box.Info) {
3131
require.NotEmpty(t, info.Version)
3232
// Check that pid parsed correctly.
3333
require.NotEqual(t, info.PID, 0)
34+
35+
// Check replication is parsed correctly.
36+
require.NotEmpty(t, info.Replication)
37+
38+
// Check one replica uuid is equal system uuid.
39+
require.Equal(t, info.UUID, info.Replication[1].UUID)
3440
}
3541

3642
func TestBox_Sugar_Info(t *testing.T) {

box/testdata/config.lua

+3
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ box.schema.user.grant('test', 'execute', 'universe', nil, { if_not_exists = true
1010
-- Set listen only when every other thing is configured.
1111
box.cfg{
1212
listen = os.getenv("TEST_TNT_LISTEN"),
13+
replication = {
14+
os.getenv("TEST_TNT_LISTEN"),
15+
};
1316
}

0 commit comments

Comments
 (0)