-
Notifications
You must be signed in to change notification settings - Fork 0
/
shellstate.go
76 lines (59 loc) · 1.28 KB
/
shellstate.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
package main
import (
"github.com/zetabase/zetabase-client/zbprotocol"
"sync"
)
type ShellState struct {
keyBuffer []string
keyBufferTblId *string
tblIdHistMap map[string]bool
lock *sync.Mutex
}
func NewShellState() *ShellState {
return &ShellState{
keyBuffer: nil,
keyBufferTblId: nil,
tblIdHistMap: map[string]bool{},
lock: &sync.Mutex{},
}
}
func (s *ShellState) SetKeyBuffer(tblId string, ks []string) {
s.lock.Lock()
defer s.lock.Unlock()
s.keyBuffer = ks
s.keyBufferTblId = &tblId
}
func (s *ShellState) AddTableIdToHistory(tblId string) {
s.lock.Lock()
defer s.lock.Unlock()
s.tblIdHistMap[tblId] = true
}
func (s *ShellState) GetKeyBufferTable() string {
s.lock.Lock()
defer s.lock.Unlock()
if s.keyBufferTblId != nil {
return *s.keyBufferTblId
}
return ""
}
func (s *ShellState) GetKeyBuffer() []string {
s.lock.Lock()
defer s.lock.Unlock()
return s.keyBuffer
}
func (s *ShellState) GetUsedTableIds() []string {
s.lock.Lock()
defer s.lock.Unlock()
var res []string
for k, _ := range s.tblIdHistMap {
res = append(res, k)
}
return res
}
func (s *ShellState) IngestTablesData(res []*zbprotocol.TableCreate) {
if res != nil {
for _, defn := range res {
s.AddTableIdToHistory(defn.GetTableId())
}
}
}