github.com/cloud-foundations/dominator@v0.0.0-20221004181915-6e4fee580046/sub/scanner/update.go (about)

     1  package scanner
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/Cloud-Foundations/Dominator/lib/objectcache"
     7  )
     8  
     9  func (fsh *FileSystemHistory) update(newFS *FileSystem) {
    10  	now := time.Now()
    11  	if newFS == nil {
    12  		fsh.timeOfLastScan = now
    13  		return
    14  	}
    15  	same := false
    16  	if fsh.fileSystem != nil {
    17  		same = CompareFileSystems(fsh.fileSystem, newFS, nil)
    18  	}
    19  	fsh.rwMutex.Lock()
    20  	defer fsh.rwMutex.Unlock()
    21  	fsh.durationOfLastScan = now.Sub(fsh.timeOfLastScan)
    22  	scanTimeDistribution.Add(fsh.durationOfLastScan)
    23  	fsh.scanCount++
    24  	fsh.timeOfLastScan = now
    25  	if fsh.fileSystem == nil {
    26  		fsh.fileSystem = newFS
    27  		fsh.generationCount = 1
    28  		fsh.timeOfLastChange = fsh.timeOfLastScan
    29  	} else {
    30  		if !same {
    31  			fsh.generationCount++
    32  			fsh.fileSystem = newFS
    33  			fsh.timeOfLastChange = fsh.timeOfLastScan
    34  		}
    35  	}
    36  }
    37  
    38  func (fsh *FileSystemHistory) updateObjectCacheOnly() error {
    39  	if fsh.fileSystem == nil {
    40  		return nil
    41  	}
    42  	oldObjectCache := fsh.fileSystem.ObjectCache
    43  	if err := fsh.fileSystem.ScanObjectCache(); err != nil {
    44  		return err
    45  	}
    46  	same := objectcache.CompareObjects(oldObjectCache,
    47  		fsh.fileSystem.ObjectCache, nil)
    48  	fsh.rwMutex.Lock()
    49  	defer fsh.rwMutex.Unlock()
    50  	fsh.scanCount++
    51  	if !same {
    52  		fsh.generationCount++
    53  	}
    54  	return nil
    55  }