Server endpoints goroutine refactor #69
No reviewers
Labels
No labels
consider soon
documentation
good first issue
hacktoberfest
help wanted
priority: blocker
priority: high
priority: low
priority: medium
type: bug
type: discussion
type: improvement
type: new feature
type: refactor
type: task
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: LBRYCommunity/herald.go#69
Loading…
Reference in a new issue
No description provided.
Delete branch "server-endpoints-goroutine-refactor"
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?
@ -59,11 +59,7 @@ type ReadOnlyDBColumnFamily struct {
BlockedChannels map[string][]byte
FilteredStreams map[string][]byte
FilteredChannels map[string][]byte
OpenIterator
s,ItMut
not needed anymore.@ -354,1 +338,3 @@
}
// Check if we've been told to shutdown in between getting created and getting here
if opts.Grp != nil && interruptRequested(opts.Grp.Ch()) {
opts.Grp.Done()
if opts.Grp != nil && interruptRequested(opts.Grp.Ch()) {
This simplification eliminating
ShutdownCalled
is possible (I think) because you register the iterator with the stop group earlier. Now the registration happens inopts.WithDB()
Looks like this can be eliminated too. Only
opts.Grp
is really being used. As mentioned earlier,opts.DB.ShutdownCalled
can be eliminated.Not needed.
@ -146,3 +244,4 @@
// flags for disabling features
debug := parser.Flag("", "debug", &argparse.Options{Required: false, Help: "enable debug logging", Default: false})
disableEs := parser.Flag("", "disable-es", &argparse.Options{Required: false, Help: "Disable elastic search, for running/testing independently", Default: false})
disableLoadPeers := parser.Flag("", "disable-load-peers", &argparse.Options{Required: false, Help: "Disable load peers from disk at startup", Default: DefaultDisableLoadPeers})
What is the reason to move/rename this? The package
server_test
seems like a fine location for it. Is it because it was infederation_test.go
and shared by other test files?Please do the same registrations in session.go. It's in
addSession()
toward the bottom.I don't think you need separate service for each RPC. The reason we had to create them for
blockchain.xxx.yyy
RPCs was because there are TWO dots in the name.Here the service would be named simply "server".
@ -272,4 +270,4 @@
if err != nil {
logrus.Warning(err)
}
}
Ahaa. So this is how it gets set. You might consider passing
grp
down intoLoadDatabase()
. So it gets initialized ASAP. Also, don't forget theReadonlyDBColumnFamilies
instance constructed in db_test.go.@ -146,3 +244,4 @@
// flags for disabling features
debug := parser.Flag("", "debug", &argparse.Options{Required: false, Help: "enable debug logging", Default: false})
disableEs := parser.Flag("", "disable-es", &argparse.Options{Required: false, Help: "Disable elastic search, for running/testing independently", Default: false})
disableLoadPeers := parser.Flag("", "disable-load-peers", &argparse.Options{Required: false, Help: "Disable load peers from disk at startup", Default: DefaultDisableLoadPeers})
I think you could create util_test.go and put it there if the file name (federation_test.go) is the concern.
This is great in that it enables other simplifications. However, we've got to be careful now about the use of IterOptions objects. Anytime one is constructed, it MUST later be used in
IterCF()
. Otherwise the refcount of active iterators leaks +1.@ -146,3 +244,4 @@
// flags for disabling features
debug := parser.Flag("", "debug", &argparse.Options{Required: false, Help: "enable debug logging", Default: false})
disableEs := parser.Flag("", "disable-es", &argparse.Options{Required: false, Help: "Disable elastic search, for running/testing independently", Default: false})
disableLoadPeers := parser.Flag("", "disable-load-peers", &argparse.Options{Required: false, Help: "Disable load peers from disk at startup", Default: DefaultDisableLoadPeers})
Yes, this seems a little more general than to just be in
federation_test.go
I agree there's probably a need for a util_test package, I'll look at what we can add into something like that.Yeah, I'm trying to weigh the pros and cons between requiring them in the "constructor" versus the flexibility of not requiring you have them in cases when they aren't needed.
Is this for the goroutine created in
RunDetectChanges()
? If so, I suggest placing it there.db.Cleanup
is already set insideGetProdDB()
, so not needed. I suggest standardizing on that approach. HaveGetProdDB
,OpenAndFillTmpDBColumnFamilies
, etc all setdb.Cleanup
and eliminate thetoDefer
return.Every time
GetProdDB
and others are called, dodefer db.Shutdown()
as you are doing here.@ -303,3 +302,3 @@
url := "lbry://@Styxhexenhammer666#2/legacy-media-baron-les-moonves-(cbs#9"
filePath := "../testdata/FULL_resolve.csv"
db, _, toDefer, err := OpenAndFillTmpDBColumnFamlies(filePath)
db, _, err := OpenAndFillTmpDBColumnFamlies(filePath)
Have
OpenAndFillTmpDBColumnFamilies()
assigndb.Cleanup = toDefer
inside to simplify this....Ditto all the other places calling
OpenAndFillTmpDBColumnFamilies()
.Should this be
NewDebug()
like other tests? Ditto all tests in this file.Is this needed?
@ -281,8 +288,9 @@ func TestHeadersSubscribe(t *testing.T) {
func TestGetBalance(t *testing.T) {
secondaryPath := "asdf"
defer db.Shutdown()
to match style elsewhere.@ -269,3 +268,2 @@
// var dbShutdown = func() {}
if !args.DisableResolve {
myDB, err = LoadDatabase(args)
myDB, err = LoadDatabase(args, grp)
Not needed.
sm.grp.Done()
here, andsm.grp.Add(1)
in(sm *SessionManager) start()
to account for goroutine runningmanage()
.RegisterTCPService
->RegisterName
Reminder: Remove commented code.
Agreed. Originally when I was developing this I was using the using the lower level db in some of the tests... I still might be actually I need to check. that's why I had a separate cleanup function I think I called it directly in the tests? Either way it's messy now and needs to be cleaned up.
@ -146,3 +244,4 @@
// flags for disabling features
debug := parser.Flag("", "debug", &argparse.Options{Required: false, Help: "enable debug logging", Default: false})
disableEs := parser.Flag("", "disable-es", &argparse.Options{Required: false, Help: "Disable elastic search, for running/testing independently", Default: false})
disableLoadPeers := parser.Flag("", "disable-load-peers", &argparse.Options{Required: false, Help: "Disable load peers from disk at startup", Default: DefaultDisableLoadPeers})
So I'm actually not going to do this right now. I just realized that the jsonrpc_blockchain_test.go is in the server package, and relies heavily on using non-exported functions and structs. Technically I think the idiom is supposed to be that we put the tests in a "server_test" package and then use the server_test_pkg.go as a pivot to wrap and export all the parts in the server package that need it. This will be a pretty significant change in jsonrpc_blockchain_test.go though, so let's go that in a separate pr.
Latest looks good, and all my comments are addressed, but I would encourage you to move away from creating separate
server_test
andserver
packages. Avoids the need to wrestle with creating exported versions of private methods. I think lbcd puts tests in the same package as the code they test.So I think maybe this is a bit to do with style, but also around how we imagine this being used, a lot of places mention that it's best practices to put the tests in their own package, i.e. https://medium.com/@matryer/5-simple-tips-and-tricks-for-writing-unit-tests-in-golang-619653f90742 but that's more I guess if we imagined other people importing our library and using it from the outside, anything internal it makes sense to be in the same package I suppose.