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

Method Close

internal/utils/dbs/db.go:195–243  ·  view source on GitHub ↗

Close the database

()

Source from the content-addressed store, hash-verified

193
194// Close the database
195func (this *DB) Close() error {
196 // check database status
197 this.statusLocker.Lock()
198 if this.isClosing {
199 this.statusLocker.Unlock()
200 return nil
201 }
202 this.isClosing = true
203 this.statusLocker.Unlock()
204
205 // waiting for updating operations to finish
206 var maxLoops = 5_000
207 for {
208 this.statusLocker.Lock()
209 var countUpdating = this.countUpdating
210 this.statusLocker.Unlock()
211 if countUpdating <= 0 {
212 break
213 }
214 time.Sleep(1 * time.Millisecond)
215
216 maxLoops--
217 if maxLoops <= 0 {
218 break
219 }
220 }
221
222 for _, batch := range this.batches {
223 batch.close()
224 }
225
226 events.Remove(fmt.Sprintf("db_%p", this))
227
228 defer func() {
229 if this.locker != nil {
230 _ = this.locker.Release()
231 }
232 }()
233
234 // print log
235 /**if len(this.dsn) > 0 {
236 u, _ := url.Parse(this.dsn)
237 if u != nil && len(u.Path) > 0 {
238 remotelogs.Debug("DB", "close '"+u.Path)
239 }
240 }**/
241
242 return this.rawDB.Close()
243}
244
245func (this *DB) BeginUpdating() bool {
246 this.statusLocker.Lock()

Callers

nothing calls this directly

Calls 6

RemoveFunction · 0.92
closeMethod · 0.80
CloseMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45
ReleaseMethod · 0.45

Tested by

no test coverage detected