Skip to content

Commit

Permalink
Merge pull request #28 from TopN/master
Browse files Browse the repository at this point in the history
optimize clear ignore status
  • Loading branch information
taowen authored Dec 20, 2018
2 parents a868dd9 + bf78fa8 commit 2d18a73
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions replaying/replaying_match.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ func (replayingSession *ReplayingSession) chunkMatch(
}
countlog.Trace("event!replaying.talks_scored",
"ctx", ctx,
"lastMaxScoreIndex", replayingSession.lastMaxScoreIndex,
"lastMatchedIndex", lastMatchedIndex,
"replayingSession.lastMaxScoreIndex", replayingSession.lastMaxScoreIndex,
"connLastMatchedIndex", lastMatchedIndex,
"maxScoreIndex", maxScoreIndex,
"maxScore", maxScore,
"totalScore", len(chunks),
Expand Down
8 changes: 4 additions & 4 deletions replaying/replaying_similarity_match.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func (replayingSession *ReplayingSession) similarityMatch(

countlog.Trace("event!replaying.similarity_talks_scored",
"ctx", ctx,
"lastMaxScoreIndex", replayingSession.lastMaxScoreIndex,
"lastMatchedIndex", connLastMatchedIndex,
"replaySession.lastMaxScoreIndex", replayingSession.lastMaxScoreIndex,
"connLastMatchedIndex", connLastMatchedIndex,
"maxScoreIndex", maxScoreIndex,
"maxScore", maxScore,
"scores", func() interface{} {
Expand Down Expand Up @@ -100,9 +100,9 @@ func strSlice2Map(str []string) map[string]float64 {

func getFixStartIndex(connLastMatchedIndex int, lastMaxScoreIndex int) int {
if connLastMatchedIndex != -1 {
return connLastMatchedIndex
return connLastMatchedIndex + 1
} else if lastMaxScoreIndex != -1 {
return lastMaxScoreIndex
return lastMaxScoreIndex + 1
}
return -1
}
10 changes: 6 additions & 4 deletions sut/thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,6 @@ func (thread *Thread) OnAccept(serverSocketFD SocketFD, clientSocketFD SocketFD,
addr: addr,
}
setGlobalSock(clientSocketFD, thread.socks[clientSocketFD])

// multiple consecutive requests, each request need clear thread.ignoreSocks
// because clientFD maybe reuse, check fd is in ignoreSockFD and addr is same
// if not same and delete
thread.delReusedIgnoreFD(clientSocketFD, addr)
countlog.Debug("event!sut.accept",
"threadID", thread.threadID,
Expand All @@ -221,6 +217,7 @@ func (thread *Thread) OnAcceptUnix(serverSocketFD SocketFD, clientSocketFD Socke
unixAddr: addr,
}
setGlobalSock(clientSocketFD, thread.socks[clientSocketFD])
thread.delReusedIgnoreFD(clientSocketFD, net.TCPAddr{})
countlog.Debug("event!sut.accept_unix",
"threadID", thread.threadID,
"serverSocketFD", serverSocketFD,
Expand Down Expand Up @@ -267,6 +264,7 @@ func (thread *Thread) OnConnect(socketFD SocketFD, remoteAddr net.TCPAddr) {
}
thread.socks[socketFD].localAddr = localAddr
replaying.StoreTmp(*localAddr, thread.replayingSession)
thread.delReusedIgnoreFD(socketFD, *localAddr)
}
countlog.Trace("event!sut.connect",
"threadID", thread.threadID,
Expand All @@ -291,6 +289,7 @@ func (thread *Thread) OnConnectUnix(socketFD SocketFD, remoteAddr net.UnixAddr)
}
thread.socks[socketFD].localAddr = localAddr
replaying.StoreTmp(*localAddr, thread.replayingSession)
thread.delReusedIgnoreFD(socketFD, *localAddr)
}
countlog.Trace("event!sut.connect",
"threadID", thread.threadID,
Expand Down Expand Up @@ -440,6 +439,9 @@ func (thread *Thread) IgnoreSocketFD(socketFD SocketFD, remoteAddr net.TCPAddr)
}

// in case of fd reused
// multiple consecutive requests, each request need clear thread.ignoreSocks
// because clientFD maybe reuse, check fd is in ignoreSockFD and addr is same
// if not same and delete
func (thread *Thread) delReusedIgnoreFD(socketFD SocketFD, newAddr net.TCPAddr) {
if val, ok := thread.ignoreSocks[socketFD]; ok {
if val.String() != newAddr.String() {
Expand Down

0 comments on commit 2d18a73

Please sign in to comment.