MCPcopy Create free account
hub / github.com/plexdrive/plexdrive / Load

Method Load

chunk/storage.go:335–359  ·  view source on GitHub ↗

Load a chunk from ram or creates it

(id RequestID)

Source from the content-addressed store, hash-verified

333
334// Load a chunk from ram or creates it
335func (s *Storage) Load(id RequestID) []byte {
336 s.lock.RLock()
337 chunk := s.fetch(id)
338 if nil == chunk {
339 Log.Tracef("Load chunk %v (missing)", id)
340 s.lock.RUnlock()
341 return nil
342 }
343 if chunk.clean {
344 Log.Tracef("Load chunk %v (clean)", id)
345 defer s.lock.RUnlock()
346 return chunk.bytes
347 }
348 s.lock.RUnlock()
349 // Switch to write lock to avoid races on crc verification
350 s.lock.Lock()
351 defer s.lock.Unlock()
352 if chunk.valid(id) {
353 Log.Debugf("Load chunk %v (verified)", id)
354 return chunk.bytes
355 }
356 Log.Warningf("Load chunk %v (bad checksum: %08x <> %08x)", id, chunk.checksum, chunk.calculateChecksum())
357 s.stack.Purge(chunk.item)
358 return nil
359}
360
361// Store stores a chunk in the RAM and adds it to the disk storage queue
362func (s *Storage) Store(id RequestID, bytes []byte) (err error) {

Callers 1

checkChunkMethod · 0.80

Calls 4

fetchMethod · 0.95
validMethod · 0.80
calculateChecksumMethod · 0.80
PurgeMethod · 0.80

Tested by

no test coverage detected