Skip to content

Commit

Permalink
-fixed golint errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
tiger5226 committed May 20, 2018
1 parent 5f51015 commit 14b09d9
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 15 deletions.
2 changes: 2 additions & 0 deletions daemon/daemon.go
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions daemon/jobs/healthchecker.go
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions datastore/cache.go
Expand Up @@ -7,40 +7,40 @@ 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
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
Expand Down
12 changes: 6 additions & 6 deletions datastore/datastore.go
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion 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
Expand All @@ -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
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions util/worker.go
Expand Up @@ -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++ {
Expand All @@ -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)
}

0 comments on commit 14b09d9

Please sign in to comment.