Skip to content

Commit 67be4f6

Browse files
committed
Temp commented out finalize code
1 parent a33a2cf commit 67be4f6

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

pkg/sqlite3/cache_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ func Test_Cache_001(t *testing.T) {
2626

2727
// Perform caching in a transaction
2828
conn.Do(context.Background(), 0, func(txn SQTransaction) error {
29-
// SELECT n between 0-9 over 100 executions in parallel should
29+
// SELECT n between 0-9 over 1000 executions in parallel should
3030
// return the same result, with a perfect cache hit rate of 9 in 10?
3131
var wg sync.WaitGroup
32-
for i := 0; i < 10000; i++ {
32+
for i := 0; i < 1000; i++ {
3333
wg.Add(1)
3434
go func() {
3535
txn.Lock()
3636
defer txn.Unlock()
3737
defer wg.Done()
38-
n := rand.Uint32() % 200
38+
n := rand.Uint32() % 10
3939
r, err := txn.Query(Q("SELECT ", n))
4040
if err != nil {
4141
t.Error("Query Error: ", err)

pkg/sqlite3/pool_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ func Test_Pool_002(t *testing.T) {
3333
} else {
3434
t.Log(pool)
3535
}
36-
pool.SetMax(5000)
36+
pool.SetMax(500)
3737

3838
// Get/put connections
3939
var wg sync.WaitGroup
40-
for i := 0; i < 5000; i++ {
40+
for i := 0; i < 500; i++ {
4141
wg.Add(1)
4242
go func(i int) {
4343
defer wg.Done()

pkg/sqlite3/results.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (r *Results) Close() error {
3838
if !r.st.Cached() {
3939
return r.st.Close()
4040
} else {
41-
return nil
41+
return r.st.Close()
4242
}
4343
}
4444

sys/sqlite3/statementex.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package sqlite3
33
import (
44
"errors"
55
"fmt"
6-
"runtime"
76
"strings"
87
"sync"
98
"sync/atomic"
@@ -19,7 +18,7 @@ type StatementEx struct {
1918
sync.Mutex
2019
st []*Statement
2120
cached bool
22-
n uint32
21+
n uint64
2322
ts int64
2423
}
2524

@@ -45,13 +44,15 @@ func (c *ConnEx) Prepare(q string) (*StatementEx, error) {
4544
s.ts = time.Now().UnixNano()
4645

4746
// Report on missing close
48-
_, file, line, _ := runtime.Caller(2)
49-
runtime.SetFinalizer(s, func(s *StatementEx) {
50-
if s.st != nil {
51-
fmt.Println(s, s.cached)
52-
panic(fmt.Sprintf("%s:%d: Prepare() missing call to Close()", file, line))
53-
}
54-
})
47+
/*
48+
_, file, line, _ := runtime.Caller(2)
49+
runtime.SetFinalizer(s, func(s *StatementEx) {
50+
if s.st != nil {
51+
fmt.Println(s, s.cached)
52+
panic(fmt.Sprintf("%s:%d: Prepare() missing call to Close()", file, line))
53+
}
54+
})
55+
*/
5556

5657
// Return statement
5758
return s, nil
@@ -142,14 +143,14 @@ func (s *StatementEx) Exec(n uint, v ...interface{}) (*Results, error) {
142143
}
143144

144145
// Increment adds n to the statement counter and updates the timestamp
145-
func (s *StatementEx) Inc(n uint32) uint32 {
146+
func (s *StatementEx) Inc(n uint64) uint64 {
146147
atomic.StoreInt64(&s.ts, time.Now().UnixNano())
147-
return atomic.AddUint32(&s.n, n)
148+
return atomic.AddUint64(&s.n, n)
148149
}
149150

150151
// Returns current count. Used to count the frequency of calls for caching purposes.
151-
func (s *StatementEx) Count() uint32 {
152-
return atomic.LoadUint32(&s.n)
152+
func (s *StatementEx) Count() uint64 {
153+
return atomic.LoadUint64(&s.n)
153154
}
154155

155156
// Returns last accessed timestamp for caching purposes as an int64

0 commit comments

Comments
 (0)