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

Method syncLoop

internal/utils/bfs/fs.go:196–240  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

194}
195
196func (this *FS) syncLoop() {
197 if this.isClosed {
198 return
199 }
200
201 if this.opt.SyncTimeout <= 0 {
202 return
203 }
204
205 var maxSyncFiles = this.opt.MaxSyncFiles
206 if maxSyncFiles <= 0 {
207 maxSyncFiles = 32
208 }
209
210 var bFiles []*BlocksFile
211
212 this.mu.RLock()
213 for _, bFile := range this.bMap {
214 if time.Since(bFile.SyncAt()) > this.opt.SyncTimeout {
215 bFiles = append(bFiles, bFile)
216 maxSyncFiles--
217 if maxSyncFiles <= 0 {
218 break
219 }
220 }
221 }
222 this.mu.RUnlock()
223
224 for _, bFile := range bFiles {
225 if bFile.IsClosing() {
226 continue
227 }
228
229 err := bFile.ForceSync()
230 if err != nil {
231 // check again
232 if bFile.IsClosing() {
233 continue
234 }
235
236 // TODO 可以在options自定义一个logger
237 log.Println("BFS", "sync failed: "+err.Error())
238 }
239 }
240}
241
242func (this *FS) openBFileForHashWriting(hash string) (*BlocksFile, error) {
243 err := CheckHashErr(hash)

Callers 1

initMethod · 0.95

Calls 6

RLockMethod · 0.80
SyncAtMethod · 0.80
RUnlockMethod · 0.80
IsClosingMethod · 0.80
ForceSyncMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected