forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
success.go
80 lines (70 loc) · 2.24 KB
/
success.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2015 Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package services
import (
"golang.org/x/net/context"
"github.com/youtube/vitess/go/vt/vtgate/vtgateservice"
topodatapb "github.com/youtube/vitess/go/vt/proto/topodata"
vtgatepb "github.com/youtube/vitess/go/vt/proto/vtgate"
)
// successClient implements vtgateservice.VTGateService
// and returns specific values. It is meant to test all possible success cases,
// and make sure all clients handle any corner case correctly.
type successClient struct {
fallbackClient
}
func newSuccessClient(fallback vtgateservice.VTGateService) *successClient {
return &successClient{
fallbackClient: newFallbackClient(fallback),
}
}
func (c *successClient) Begin(ctx context.Context) (*vtgatepb.Session, error) {
return &vtgatepb.Session{
InTransaction: true,
}, nil
}
func (c *successClient) Commit(ctx context.Context, session *vtgatepb.Session) error {
if session != nil && session.InTransaction {
return nil
}
return c.fallback.Commit(ctx, session)
}
func (c *successClient) Rollback(ctx context.Context, session *vtgatepb.Session) error {
if session != nil && session.InTransaction {
return nil
}
return c.fallback.Rollback(ctx, session)
}
func (c *successClient) GetSrvKeyspace(ctx context.Context, keyspace string) (*topodatapb.SrvKeyspace, error) {
if keyspace == "big" {
return &topodatapb.SrvKeyspace{
Partitions: []*topodatapb.SrvKeyspace_KeyspacePartition{
{
ServedType: topodatapb.TabletType_REPLICA,
ShardReferences: []*topodatapb.ShardReference{
{
Name: "shard0",
KeyRange: &topodatapb.KeyRange{
Start: []byte{0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
End: []byte{0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
},
},
},
},
},
ShardingColumnName: "sharding_column_name",
ShardingColumnType: topodatapb.KeyspaceIdType_UINT64,
ServedFrom: []*topodatapb.SrvKeyspace_ServedFrom{
{
TabletType: topodatapb.TabletType_MASTER,
Keyspace: "other_keyspace",
},
},
}, nil
}
if keyspace == "small" {
return &topodatapb.SrvKeyspace{}, nil
}
return c.fallback.GetSrvKeyspace(ctx, keyspace)
}