-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.go
More file actions
144 lines (105 loc) · 3.18 KB
/
Copy pathapp.go
File metadata and controls
144 lines (105 loc) · 3.18 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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
A trivial application to illustrate distributed DBMS works
Usage:
In another terminal:
go run lbs.go 0.0.0.0:9990
In another terminal:
go run server.go 0.0.0.0:9991 0.0.0.0:9990
In this terminal
go run app.go
*/
package main
import (
"./client"
"./dbStructs"
"./shared"
"fmt"
"os"
"strconv"
"time"
"bufio"
)
func main() {
// TODO provide as cmd arguments
if len(os.Args[1:]) < 2 {
panic("Incorrect number of arguments given")
}
lbsAddr := os.Args[1]
localIP := os.Args[2]
crashPointArg := os.Args[3]
crashPoint, _ := strconv.Atoi(crashPointArg)
_, err := client.StartClient(lbsAddr, localIP)
if shared.CheckError(err) != nil {
fmt.Println(err)
return
}
time.Sleep(time.Second * 1)
op0 := dbStructs.Operation{
Type: dbStructs.SelectAll,
TableName: "A"}
op1 := dbStructs.Operation{
Type: dbStructs.SelectAll,
TableName: "B"}
op2 := dbStructs.Operation{
Type: dbStructs.Join,
TableName: "A",
SecondTableName: "B",
FirstTableColumn: "key",
SecondTableColumn: "emp_id"}
op3 := dbStructs.Operation{
Type: dbStructs.Delete,
TableName: "A",
Key: "test1"}
op4 := dbStructs.Operation{
Type: dbStructs.Delete,
TableName: "B",
Key: "k1"}
newRow0 := map[string]string{"name": "Jim", "age": "30", "gender": "M"}
newRow1 := map[string]string{"company": "Facebook", "emp_id": "test3"}
op5 := dbStructs.Operation{
Type: dbStructs.Set,
TableName: "A",
Key: "test3",
Value: dbStructs.Row{Key: "test3", Data: newRow0}}
op6 := dbStructs.Operation{
Type: dbStructs.Set,
TableName: "B",
Key: "k3",
Value: dbStructs.Row{Key: "k3", Data: newRow1}}
txn0 := dbStructs.Transaction{Operations: []dbStructs.Operation{op0, op1, op2, op3, op4, op5, op6}}
client.NewTransaction(txn0, shared.CrashPoint(crashPoint))
fmt.Println("Finished Transaction 1")
fmt.Print("Press 'Enter' to continue... \n")
bufio.NewReader(os.Stdin).ReadBytes('\n')
//Transaction 2
newRow2 := map[string]string{"name": "Jim", "age": "50", "gender": "M"}
newRow3 := map[string]string{"company": "Microsoft", "emp_id": "test3"}
op7 := dbStructs.Operation{
Type: dbStructs.Set,
TableName: "A",
Key: "test3",
Value: dbStructs.Row{Key: "test3", Data: newRow2}}
op8 := dbStructs.Operation{
Type: dbStructs.Set,
TableName: "B",
Key: "k3",
Value: dbStructs.Row{Key: "k3", Data: newRow3}}
txn1 := dbStructs.Transaction{Operations: []dbStructs.Operation{op7, op8, op0, op1, op2}}
client.NewTransaction(txn1, shared.CrashPoint(crashPoint))
fmt.Println("Finished Transaction 2")
fmt.Print("Press 'Enter' to continue... \n")
bufio.NewReader(os.Stdin).ReadBytes('\n')
//Transaction 3
newRow := map[string]string{"tv_show": "The Office"}
op9 := dbStructs.Operation{
Type: dbStructs.Set,
TableName: "C",
Key: "newRow",
Value: dbStructs.Row{Key: "newRow", Data: newRow}}
op10 := dbStructs.Operation{
Type: dbStructs.SelectAll,
TableName: "C"}
txn2 := dbStructs.Transaction{Operations: []dbStructs.Operation{op9, op10, op0, op1}}
client.NewTransaction(txn2, shared.CrashPoint(crashPoint))
fmt.Println("Finished Transaction 3")
}