Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log neighbors to database #13

Merged
merged 3 commits into from
Feb 11, 2018
Merged

Conversation

SimonSK
Copy link

@SimonSK SimonSK commented Jan 30, 2018

  • new addresses from NEIGHBORS packets are logged in the neighbors and node_meta_info tables
  • there are some merge conflicts handled

@SimonSK SimonSK requested a review from a team January 30, 2018 23:42
@zzma
Copy link

zzma commented Jan 31, 2018

@SimonSK - did you consider using an Object Relational Mapping framework such as SQLAlchemy? It will require a little bit of initial config, but ultimately should make it simpler to deal with database interactions aka you wouldn't have to write raw SQL.

SQLAlchemy also provides db connection pool management.

@SimonSK
Copy link
Author

SimonSK commented Jan 31, 2018

@zzma A quick search shows different opinions about ORM on go, but yea, I will look into it and change to that if codes become simpler.

As for the db connection pool, I believe the go builtin database/sql provides it as well.

@zzma
Copy link

zzma commented Jan 31, 2018

Gotcha - sorry I brain farted and thought we were using python. I'm not saying that we should definitely use an ORM, but just wanted to make you aware and see if it you think it would be helpful

@SimonSK
Copy link
Author

SimonSK commented Feb 8, 2018

@zzma fyi, there are some changes made to the log message formats and the db table schemes in later commit that will be part of another PR. I will post that PR after this one is merged.

@zzma
Copy link

zzma commented Feb 10, 2018

@SimonSK what's the status of this PR? There are still some unaddressed comments

Copy link

@zzma zzma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments.

}

func (t *udp) addNodeMetaInfo(nodeid string, hash string) {
_, err := t.addNodeMetaInfoStmt.Exec(nodeid, hash)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While technically correct, this is a bit confusing, since it is not clear how many arguments and what arguments should be passed to addNodeMetaInfoStmt.Exec(). It also is different for addNeighborStmt.Exec()

I think an ORM would help with this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this to the TODO list (#15). I implemented all other sql related tasks for p2p hello and eth status in later commits, so I will try to refactor this at once after merging everything done so far.

@@ -286,6 +342,22 @@ func newUDP(priv *ecdsa.PrivateKey, c conn, natm nat.Interface, nodeDBPath strin
func (t *udp) close() {
close(t.closing)
t.conn.Close()

// close prepared sql statements
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the Go way of doing this is to use defer at the point in the code when the object is being opened, so that you don't have to "remember" to do close something at the end. You could refactor this logic into a function closeStmt and call defer closeStmt(t.addNeighborStmt) or something

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I didn't use defer because the statements are prepared when the UDP server is started (in newUDP) and there is a separate logic for closing the server. If I used defer in newUDP, wouldn't the statement be closed as soon as the start logic returns? Anyways, I will make this into a generic closing function as suggested, but I will make the change after the merge to avoid further conflicts. I made a TODO list in #15

func (t *udp) addNeighbor(nodeid string, ip string, tcpPort uint16, udpPort uint16, unixTime float64) {
_, err := t.addNeighborStmt.Exec(nodeid, ip, tcpPort, udpPort, unixTime, unixTime)
if err != nil {
log.Proto("MYSQL", "action", "execute AddNeighbor statement", "result", "fail", "err", err)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we should log errors at a more severe log level, probably log.Error

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I pushed them down to debug/trace level in future commits. This will be part of another PR.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant that it should be a more severe logging level - we don't want things to fail quietly

@SimonSK SimonSK mentioned this pull request Feb 11, 2018
21 tasks
@SimonSK SimonSK merged commit ac2cb9a into node-finder-master Feb 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants