-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathlive_types.go
127 lines (108 loc) · 4.17 KB
/
live_types.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package common
import (
"sync"
sqlite "github.com/gwenn/gosqlite"
)
// JobRequest holds the fields used for sending requests to our job request backend
type JobRequest struct {
Operation string `json:"operation"`
DBOwner string `json:"dbowner"`
DBName string `json:"dbname"`
Data interface{} `json:"data,omitempty"`
RequestingUser string `json:"requesting_user"`
}
// JobRequestRows holds the data used when making a rows request to our job queue backend
type JobRequestRows struct {
DbTable string `json:"db_table"`
SortCol string `json:"sort_col"`
SortDir string `json:"sort_dir"`
CommitID string `json:"commit_id"`
RowOffset int `json:"row_offset"`
MaxRows int `json:"max_rows"`
}
// JobResponseDBColumns holds the fields used for receiving column list responses from our job queue backend
type JobResponseDBColumns struct {
Columns []sqlite.Column `json:"columns"`
Err string `json:"error"`
ErrCode JobQueueErrorCode `json:"error_code"`
PkColumns []string `json:"pkColumns"`
}
// JobResponseDBCreate holds the fields used for receiving database creation responses from our job queue backend
type JobResponseDBCreate struct {
Err string `json:"error"`
NodeName string `json:"node_name"`
}
// JobResponseDBError holds the structure used when our job queue backend only needs to respond with an error field (empty or not)
type JobResponseDBError struct {
Err string `json:"error"`
}
// JobResponseDBExecute holds the fields used for receiving the database execute response from our job queue backend
type JobResponseDBExecute struct {
Err string `json:"error"`
RowsChanged int `json:"rows_changed"`
}
// JobResponseDBIndexes holds the fields used for receiving the database index list from our job queue backend
type JobResponseDBIndexes struct {
Err string `json:"error"`
Indexes []APIJSONIndex `json:"indexes"`
}
// JobResponseDBQuery holds the fields used for receiving database query results from our job queue backend
type JobResponseDBQuery struct {
Err string `json:"error"`
Results SQLiteRecordSet `json:"results"`
}
// JobResponseDBRows holds the fields used for receiving table row data from our job queue backend
type JobResponseDBRows struct {
DatabaseSize int64 `json:"database_size"`
DefaultTable string `json:"default_table"`
Err string `json:"error"`
RowData SQLiteRecordSet `json:"row_data"`
Tables []string `json:"tables"`
}
// JobResponseDBSize holds the fields used for receiving database size responses from our job queue backend
type JobResponseDBSize struct {
Err string `json:"error"`
Size int64 `json:"size"`
}
// JobResponseDBTables holds the fields used for receiving the database table list from our job queue backend
type JobResponseDBTables struct {
Err string `json:"error"`
Tables []string `json:"tables"`
}
// JobResponseDBViews holds the fields used for receiving the database views list from our job queue backend
type JobResponseDBViews struct {
Err string `json:"error"`
Views []string `json:"views"`
}
// ResponseInfo holds job queue responses. Most of the useful info is json encoded in the payload field
type ResponseInfo struct {
jobID int
responseID int
payload string
}
// ResponseReceivers is a simple structure used for matching up job queue responses to the caller who submitted the job
type ResponseReceivers struct {
sync.RWMutex
receivers map[int]*chan ResponseInfo
}
// NewResponseQueue is the constructor function for creating a new ResponseReceivers
func NewResponseQueue() *ResponseReceivers {
z := ResponseReceivers{
RWMutex: sync.RWMutex{},
receivers: nil,
}
z.receivers = make(map[int]*chan ResponseInfo)
return &z
}
// AddReceiver adds a new response receiver
func (r *ResponseReceivers) AddReceiver(jobID int, newReceiver *chan ResponseInfo) {
r.Lock()
r.receivers[jobID] = newReceiver
r.Unlock()
}
// RemoveReceiver removes a response receiver (generally after it has received the response it was waiting for)
func (r *ResponseReceivers) RemoveReceiver(jobID int) {
r.Lock()
delete(r.receivers, jobID)
r.Unlock()
}