-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
111 lines (81 loc) · 2.4 KB
/
main.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
package main
import (
"fmt"
"github.com/chaitya62/noobdb/buffer"
"github.com/chaitya62/noobdb/schema"
"github.com/chaitya62/noobdb/storage/disk"
"github.com/chaitya62/noobdb/storage/page"
"time"
//"github.com/chaitya62/noobdb/type"
)
func printTuple(tuple page.TupleImpl) {
tuple.PrintTuple()
}
func accessMemory(i int, bpm *buffer.BufferPoolManager, schema_schema []string, tupleChannel chan<- page.TupleImpl) {
time.Sleep(100 * time.Millisecond)
Page := bpm.GetPage(uint32(i)).(*page.PageImpl)
//Page := dmi.ReadPage(uint32(i)).(*page.PageImpl)
schemaPageR := page.SchemaPage{PageImpl: *Page}
if schemaPageR.GetPageId() == page.INVALID_PAGE_ID {
return
}
//fmt.Println(schemaPageR.GetData())
tuple := schemaPageR.ReadTuple(0)
tuple2 := schemaPageR.ReadTuple(1)
//fmt.Println(tuple)
//fmt.Println(tuple2)
if i >= 7 {
bpm.PinPage(uint32(i))
}
var schemaTupleR page.TupleImpl
schemaTupleR.Init(schema_schema[:])
schemaTupleR.ReadTuple(tuple)
//schemaTupleR.PrintTuple()
//tupleChannel <- schemaTupleR
schemaTupleR.ReadTuple(tuple2)
//schemaTupleR.PrintTuple()
tupleChannel <- schemaTupleR
}
func testBufferPoolManagerAsync() {
var TupleChannel chan page.TupleImpl
dmi := diskio.NewDiskManagerImpl("schema.txt")
bpm := new(buffer.BufferPoolManager)
bpm.Init(5, dmi)
// move this logic to schema module
schema_schema := [6]string{"INTEGER", "INTEGER", "VARCHAR", "INTEGER", "VARCHAR", "VARCHAR"}
// Read Schema table from a page
TupleChannel = make(chan page.TupleImpl, 1)
go func() {
count := 0
for {
select {
case tuple := <-TupleChannel:
fmt.Println("cnt", count)
count = count + 1
printTuple(tuple)
default:
println("Waiting for data")
time.Sleep(100 * time.Millisecond)
}
}
}()
for i := 0; i < 10; i++ {
accessMemory(i, bpm, schema_schema[:], TupleChannel)
}
}
func main() {
schema_table := new(schema.SchemaTable)
schema_table.Init()
//for i := 0; i < 1000; i++ {
// tuple := schema_table.GetDefaultRow()
// tuple.SetValueFor(schema.SCHEMA_ID, int64(i))
// tuple.SetValueFor(schema.SCHEMA_TABLE_ID, int64(0i))
// tuple.SetValueFor(schema.SCHEMA_TABLE_NAME, "first_table")
// tuple.SetValueFor(schema.SCHEMA_COLUMN_NAME, "id")
// tuple.SetValueFor(schema.SCHEMA_COLUMN_POSITION, int64(1))
// tuple.SetValueFor(schema.SCHEMA_COLUMN_TYPE, "INTEGER")
// schema_table.Insert(tuple)
//}
schema_table.Close()
schema_table.Iterator()
}