remove redisDB dependency #25
Labels
No labels
area: devops
area: discovery
area: docs
area: livestream
area: proposal
consider soon
dependencies
Epic
good first issue
hacktoberfest
help wanted
icebox
level: 1
level: 2
level: 3
level: 4
needs: exploration
needs: grooming
needs: priority
needs: repro
needs: tech design
on hold
priority: blocker
priority: high
priority: low
priority: medium
resilience
Tom's Wishlist
type: bug
type: discussion
type: improvement
type: new feature
type: refactor
type: task
type: testing
unplanned
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: LBRYCommunity/lbry.go#25
Loading…
Reference in a new issue
No description provided.
Delete branch "use_video_statuses"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR aims at removing the local redisdb dependency that makes it impossible to redistribute work across different servers.
Further work has been put in, here's a summary:
@ -152,1 +162,3 @@
var response apiSyncUpdateResponse
var response struct {
Success bool `json:"success"`
Error null.String `json:"error"`
you don't have to create a named struct for this if its only used in one place. you can inline it as
@ -40,3 +40,4 @@
}
numOnSource = int(n)
}
log.Debugf("Source channel has %d videos", numOnSource)
why are all these cast to floats? they can be ints here
@ -65,3 +64,1 @@
claimAddress string
videoDirectory string
db *redisdb.DB
daemon *jsonrpc.Client
if you have multiple mutexes, you can't call one of them just
mux
. its not clear what that's for. it could be something likewalletSetupMux
. though once you name it that, it becomes clear that something might be wrong with wrapping the whole wallet setup in a single mutex. does the whole thing actually need to be locked?the mutexes should be pointers, so new copies are not created if the Sync struct is copied
its clearer if you put the mutex right above the thing the mutex is locking, and leave newlines on either side. so in this example, upt
videosMapMux
right abovesyncedVideos
. and then maybe rename it tosyncedVideosMux
, like so:this should also be a pointer. but more importantly, you don't need this if you already have a stop.Group. stop.Group works as a combo WaitGroup + channel that will be closed to indicate stopping (and can be closed safely multiple times). so use
grp.Add()
andgrp.Wait()
insteadit won't let me comment below, so I'm commenting here:
you call
Add()
andDone()
insidestartWorker(workerNum int)
, but the correct pattern is to make those calls outside the function. startWorker() doesn't know if its being run asynchronously or not. you only need a waitgroup if it is. there are also subtle concurrency issues with calling it inside the function. so the right way to go is to remove Add and Done from inside startWorker, and do this:you can use a read/write lock to lock the map for reading when you read it, and writing when you write to it. this lets multiple threads read the data at once, which is safe and blocks less. use
*sync.RWMutex
instead, and callmux.RLock()
andmux.RUnlock()
when you're only reading from the variable. leavemux.Lock()
for writingwhy is this code all the way down here, so far from line 125 where syncedVideos is first declared?
how often does this happen, and do you know why? is it within our control?
the first happens due to youtube restrictions (either region, age or deleted videos)
the second happens when we hit the defined size limit (it's in our control).
While we can't do anything about the first, we can raise the limits for the second, but as per several discussions we'll keep it at 2GB or less.
out of 100k published videos we have about 1% that failed for those two (leading) reasons: https://scrn.storni.info/2018-08-09_12-24-24-339707393.png
@ -40,3 +40,4 @@
}
numOnSource = int(n)
}
log.Debugf("Source channel has %d videos", numOnSource)
no clue. but you're completely right. Will fix
the only reason i put it there is because there were a bunch of assignments there and i wanted to keep them grouped, but I agree it's not very read-able this way. I'll move them up
@ -65,3 +64,1 @@
claimAddress string
videoDirectory string
db *redisdb.DB
daemon *jsonrpc.Client
I need to look into that, this is from your original code and I don't remember ever changing it. Thanks for the pointers there.
@ -65,3 +64,1 @@
claimAddress string
videoDirectory string
db *redisdb.DB
daemon *jsonrpc.Client
Will rename and move the mutexes.
The reason I didn't use read/write locks is that i don't want the application to read when it's being written to, plus the locks are held for a very very short time so there would be no noticeable improvement, only a higher risk of race conditions happening during wallet refills.
@ -152,1 +162,3 @@
var response apiSyncUpdateResponse
var response struct {
Success bool `json:"success"`
Error null.String `json:"error"`
ok, will look into that
@ -65,3 +64,1 @@
claimAddress string
videoDirectory string
db *redisdb.DB
daemon *jsonrpc.Client
I looked more into why we need to lock the whole walletSetup function. The reason I'm doing that is to avoid multiple threads from refilling the wallet concurrently. I don't think I can easily break up the the function to lock fewer lines of code. I think it's fair to leave it like that.
I removed the wait group in favor of the stop group
addressed reviews
why are we not using the aligned code in the api package? I would make sure we are making things DRY.
api.Response
@ -19,2 +17,4 @@
s.walletMux.Lock()
defer s.walletMux.Unlock()
err := s.ensureChannelOwnership()
if err != nil {
why are we using a mutex lock? What is wrong with concurrent execution? A mutex is not the standard way to handle synchronization. It can cause deadlocks. Ideally if you want things to run synchronously from different go routines, you use channels in golang.
@ -41,4 +42,4 @@
}
log.Debugf("Source channel has %d videos", numOnSource)
if numOnSource == 0 {
return nil
why change this to an int? It better to be more specific than more general.
@ -43,4 +44,4 @@
if numOnSource == 0 {
return nil
}
what is this?! not part of the PR but this is not good to have in the code base.
so is this ok? If there is a problem it would be an infinite loop no? Maybe have a
maxit
?@ -187,4 +185,4 @@
return publishAndRetryExistingNames(daemon, v.title, v.getFilename(), amount, options)
}
Why is the author UC Berkley? should this function be called publishUCBerkley?
ahhh,
ucbVideo
Seems odd to have a struct type for a specific author.@ -74,3 +84,4 @@
}
}
// SendErrorToSlack Sends an error message to the default channel and to the process log.
I don't understand why we have a mutex lock here. Why would this get called twice in different go routines on the same sync instance?
we should not do this here. Please use the stopper pattern grin built in the stop package.
Last comment on mutex locks. We should discuss the pattern you are using here, as I am almost positive using channels is a better and more robust solution design.
@ -65,3 +64,1 @@
claimAddress string
videoDirectory string
db *redisdb.DB
daemon *jsonrpc.Client
a read/write lock does not allow reading during writing. thats the point of every lock. what it does allow is multiple concurrent reads. when you do RLock, others can RLock at the same time. when you Lock (for writing), no one's allowed to Lock or RLock at the same time.
i agree with most of beamer's comments, and none are major blockers, so im fine with merging this now and cleaning up as you continue to work with the code.
in general im trying to be less strict on PRs when the code works but has little nits in it.
@ -65,3 +64,1 @@
claimAddress string
videoDirectory string
db *redisdb.DB
daemon *jsonrpc.Client
Oh yes, you're right, not sure what was going in my mind. I'll swap that
@ -19,2 +17,4 @@
s.walletMux.Lock()
defer s.walletMux.Unlock()
err := s.ensureChannelOwnership()
if err != nil {
this is the only place the lock is used and no multiple locks are being held that can cause a deadlock here.
However I would like to discuss channels with you to understand how they could be used here (not sure they can)
@ -41,4 +42,4 @@
}
log.Debugf("Source channel has %d videos", numOnSource)
if numOnSource == 0 {
return nil
Grins previous review outlined a mess with casts here and there to make simple math.
I changed everything to int as it's reasonable for the values they represent.
@ -43,4 +44,4 @@
if numOnSource == 0 {
return nil
}
I can explain the berkeley stuff to you via DM, it's all good as it will be eventually removed from here. Not worth changing now
@ -74,3 +84,4 @@
}
}
// SendErrorToSlack Sends an error message to the default channel and to the process log.
videos end concurrently, that's why