MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / Exec

Method Exec

internal/utils/dbs/batch.go:59–134  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

57}
58
59func (this *Batch) Exec() {
60 var n = this.n
61 if n <= 0 {
62 n = 4
63 }
64
65 var ticker = time.NewTicker(100 * time.Millisecond)
66 var count = 0
67 var lastTx *sql.Tx
68For:
69 for {
70 // closed
71 if this.isClosed {
72 if lastTx != nil {
73 _ = this.commitTx(lastTx)
74 lastTx = nil
75 }
76
77 return
78 }
79
80 select {
81 case item := <-this.queue:
82 if lastTx == nil {
83 lastTx = this.beginTx()
84 if lastTx == nil {
85 continue For
86 }
87 }
88
89 err := this.execItem(lastTx, item)
90 if err != nil {
91 if IsClosedErr(err) {
92 return
93 }
94 this.processErr(item.query, err)
95 }
96
97 count++
98
99 if count == n {
100 count = 0
101 err = this.commitTx(lastTx)
102 lastTx = nil
103 if err != nil {
104 if IsClosedErr(err) {
105 return
106 }
107 this.processErr("commit", err)
108 }
109 }
110 case <-ticker.C:
111 if lastTx == nil || count == 0 {
112 continue For
113 }
114 count = 0
115 err := this.commitTx(lastTx)
116 lastTx = nil

Callers 1

execItemMethod · 0.45

Calls 5

commitTxMethod · 0.95
beginTxMethod · 0.95
execItemMethod · 0.95
processErrMethod · 0.95
IsClosedErrFunction · 0.85

Tested by

no test coverage detected