-
Notifications
You must be signed in to change notification settings - Fork 219
Expand file tree
/
Copy pathsession.go
More file actions
85 lines (71 loc) · 1.72 KB
/
session.go
File metadata and controls
85 lines (71 loc) · 1.72 KB
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
81
82
83
84
85
/*
* Radon
*
* Copyright 2018 The Radon Authors.
* Code is licensed under the GPLv3.
*
*/
package proxy
import (
"sync"
"time"
"backend"
"github.com/xelabs/go-mysqlstack/driver"
"github.com/xelabs/go-mysqlstack/sqlparser"
"github.com/xelabs/go-mysqlstack/xlog"
)
type bitmask uint32
// session variables capabilities.
const (
cap_streaming_fetch bitmask = 1 << iota // streaming fetch for this session
)
type session struct {
log *xlog.Log
mu sync.Mutex // Race with snapshot
node sqlparser.Statement
query string
session *driver.Session
timestamp int64
capabilities bitmask
transaction backend.Transaction
}
func (s *session) setStreamingFetchVar(r bool) {
if r {
s.capabilities |= cap_streaming_fetch
} else {
s.capabilities &= ^cap_streaming_fetch
}
}
func (s *session) getStreamingFetchVar() bool {
return s.capabilities&cap_streaming_fetch != 0
}
func newSession(log *xlog.Log, s *driver.Session) *session {
log.Debug("session[%v].created", s.ID())
return &session{
log: log,
session: s,
timestamp: time.Now().Unix(),
}
}
func (s *session) close() {
log := s.log
id := s.session.ID()
// close the session connection from the server side.
s.session.Close()
s.mu.Lock()
node := s.node
transaction := s.transaction
s.mu.Unlock()
log.Warning("session[%v].close.txn:%+v.node:%+v", id, transaction, node)
// If transaction is not nil, means we can abort it when the session exit.
// Here there is some races:
// 1. if txn has finished, abort do nothing.
// 2. if txn has aborted, finished do nothing.
//
if transaction != nil {
if err := transaction.Abort(); err != nil {
log.Error("session.close.txn.abort.error:%+v", err)
return
}
}
}