From 14b09d9b9ccb9050f56e93a4bfa0dce7e1b48921 Mon Sep 17 00:00:00 2001 From: Mark Beamer Jr Date: Sun, 20 May 2018 11:31:43 -0400 Subject: [PATCH] -fixed golint errors. --- daemon/daemon.go | 2 ++ daemon/jobs/healthchecker.go | 4 ++++ datastore/cache.go | 16 ++++++++-------- datastore/datastore.go | 12 ++++++------ meta/meta.go | 7 ++++++- util/worker.go | 11 +++++++++++ 6 files changed, 37 insertions(+), 15 deletions(-) diff --git a/daemon/daemon.go b/daemon/daemon.go index 31d8cd6..31cf08e 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -138,6 +138,8 @@ func initBlockWorkers(nrWorkers int, jobs <-chan uint64) { } } +// BlockProcessor takes a channel of block heights to process. When a new one comes in it runs block processing for +// the block height func BlockProcessor(blocks <-chan uint64) { for block := range blocks { processing.RunBlockProcessing(&block) diff --git a/daemon/jobs/healthchecker.go b/daemon/jobs/healthchecker.go index 774bfbf..7694d1c 100644 --- a/daemon/jobs/healthchecker.go +++ b/daemon/jobs/healthchecker.go @@ -31,6 +31,10 @@ var timeout uint = 60 //seconds var timeout64 uint64 = 60 //seconds var running bool +// CheckDHTHealth is job that runs in the background and traverses over claims to check their file status on lbrynet +// via the lbrynet daemon. It stores peers and the associations to claims. It also stores checkpoints for claims and +// peers. For claims it is if they are generally available, for peers it is if their associated files are available +// from them. func CheckDHTHealth() { if !running { running = true diff --git a/datastore/cache.go b/datastore/cache.go index 80c052d..ba4c8b3 100644 --- a/datastore/cache.go +++ b/datastore/cache.go @@ -7,9 +7,9 @@ type txAddressKey struct { txID uint64 addrID uint64 } -type TACache map[txAddressKey]bool +type tACache map[txAddressKey]bool -var txAddrCache = TACache{} +var txAddrCache = tACache{} var tcAddrLock = sync.RWMutex{} // Output Caching @@ -17,30 +17,30 @@ type outputKey struct { txHash string vout uint } -type OCache map[outputKey]bool +type oCache map[outputKey]bool -var outputCache = OCache{} +var outputCache = oCache{} var outputLock = sync.RWMutex{} -func CheckTxAddrCache(key txAddressKey) bool { +func checkTxAddrCache(key txAddressKey) bool { tcAddrLock.RLock() defer tcAddrLock.RUnlock() return txAddrCache[key] } -func CheckOutputCache(key outputKey) bool { +func checkOutputCache(key outputKey) bool { outputLock.RLock() defer outputLock.RUnlock() return outputCache[key] } -func AddToTxAddrCache(key txAddressKey) { +func addToTxAddrCache(key txAddressKey) { tcAddrLock.Lock() defer tcAddrLock.Unlock() txAddrCache[key] = true } -func AddToOuputCache(key outputKey) { +func addToOuputCache(key outputKey) { outputLock.Lock() defer outputLock.Unlock() outputCache[key] = true diff --git a/datastore/datastore.go b/datastore/datastore.go index 817abfb..7c8673e 100644 --- a/datastore/datastore.go +++ b/datastore/datastore.go @@ -17,7 +17,7 @@ func GetOutput(txHash string, vout uint) *model.Output { vOutMatch := qm.And(model.OutputColumns.Vout+"=?", vout) key := outputKey{txHash: txHash, vout: vout} - if CheckOutputCache(key) || model.OutputsG(txHashMatch, vOutMatch).ExistsP() { + if checkOutputCache(key) || model.OutputsG(txHashMatch, vOutMatch).ExistsP() { output, err := model.OutputsG(txHashMatch, vOutMatch).One() if err != nil { logrus.Error("Datastore(GETOUTPUT): ", err) @@ -36,12 +36,12 @@ func PutOutput(output *model.Output, whitelist ...string) error { txHashMatch := qm.Where(model.OutputColumns.TransactionHash+"=?", output.TransactionHash) vOutMatch := qm.And(model.OutputColumns.Vout+"=?", output.Vout) var err error - if CheckOutputCache(key) || model.OutputsG(txHashMatch, vOutMatch).ExistsP() { + if checkOutputCache(key) || model.OutputsG(txHashMatch, vOutMatch).ExistsP() { output.Modified = time.Now() err = output.UpdateG(whitelist...) } else { err = output.InsertG() - AddToOuputCache(key) + addToOuputCache(key) } if err != nil { err = errors.Prefix("Datastore(PUTOUTPUT): ", err) @@ -143,7 +143,7 @@ func PutAddress(address *model.Address) error { func GetTxAddress(txID uint64, addrID uint64) *model.TransactionAddress { defer util.TimeTrack(time.Now(), "GetTxAddress", "mysqlprofile") key := txAddressKey{txID: txID, addrID: addrID} - if CheckTxAddrCache(key) || model.TransactionAddressExistsGP(txID, addrID) { + if checkTxAddrCache(key) || model.TransactionAddressExistsGP(txID, addrID) { txAddress, err := model.FindTransactionAddressG(txID, addrID) if err != nil { @@ -160,11 +160,11 @@ func PutTxAddress(txAddress *model.TransactionAddress) error { if txAddress != nil { key := txAddressKey{txID: txAddress.TransactionID, addrID: txAddress.AddressID} var err error - if CheckTxAddrCache(key) || model.TransactionAddressExistsGP(txAddress.TransactionID, txAddress.AddressID) { + if checkTxAddrCache(key) || model.TransactionAddressExistsGP(txAddress.TransactionID, txAddress.AddressID) { err = txAddress.UpdateG() } else { err = txAddress.InsertG() - AddToTxAddrCache(key) + addToTxAddrCache(key) } if err != nil { err = errors.Prefix("Datastore(PUTTXADDRESS): ", err) diff --git a/meta/meta.go b/meta/meta.go index 483e066..98ee739 100644 --- a/meta/meta.go +++ b/meta/meta.go @@ -1,10 +1,13 @@ package meta -// version and commitMsg get filled in using -ldflags when the binary gets built +// version and commitMsg get filled in using -ldflags when the binary gets built with /scripts/build.sh var version string var versionLong string var commitMsg string +// GetVersion returns the version of the application. If it is tagged it will be the semver, otherwise it will contain +// the number of commits since the last one, the short hash of the commit and whether or not the directory was dirty +// at build time. func GetVersion() string { if version != "" { return version @@ -13,6 +16,7 @@ func GetVersion() string { return "unknown" } +// GetVersionLong returns what GetVersion returns but will always return the long version. func GetVersionLong() string { if versionLong != "" { return versionLong @@ -21,6 +25,7 @@ func GetVersionLong() string { return "unknown" } +// GetCommitMessage returns the commit message of the commit used to build the binary. func GetCommitMessage() string { if commitMsg != "" { return commitMsg diff --git a/util/worker.go b/util/worker.go index 0d4eaa6..88de3d0 100644 --- a/util/worker.go +++ b/util/worker.go @@ -2,13 +2,21 @@ package util import "sync" +// PieceOfWork is an interface type for representing a atomic piece of work that can be done independently. type PieceOfWork interface { + // BeforeExecute will always be executed before the piece of work's execution. BeforeExecute() + // Execute is the execution of the actual work. Execute() error + // AfterExecute will always be executed after the piece of work's execution if successful. AfterExecute() + // OnError will execute in the event an error is returned from the Execute function. OnError(err error) } +// InitWorkers creates a worker pool that execute pieces of work. It is a way of controlling the number go routines to +// optimize parallelism. It is recommended that this stay around the number of cores unless there is significant blocking +// time associated with the work involved. func InitWorkers(numworkers int, jobs chan PieceOfWork) *sync.WaitGroup { wg := sync.WaitGroup{} for i := 0; i < numworkers; i++ { @@ -25,6 +33,9 @@ func InitWorkers(numworkers int, jobs chan PieceOfWork) *sync.WaitGroup { return &wg } +// NewQueue creates a bi-directional channel that can take in pieces of work. This is leveraged with the worker pool +// and is what they pull from while active. The worker pool will end once this channel is closed. The intention is that +// this channel will be passed into the initialization of the worker pool. func NewQueue() chan PieceOfWork { return make(chan PieceOfWork) }