-
Notifications
You must be signed in to change notification settings - Fork 154
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
Use Echo method to send inactivity probe #368
Open
pperiyasamy
wants to merge
4
commits into
ovn-org:main
Choose a base branch
from
pperiyasamy:send-echo-async-for-inactivity-check
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,7 @@ type ovsdbClient struct { | |
metrics metrics | ||
connected bool | ||
rpcClient *rpc2.Client | ||
conn net.Conn | ||
rpcMutex sync.RWMutex | ||
// endpoints contains all possible endpoints; the first element is | ||
// the active endpoint if connected=true | ||
|
@@ -427,6 +428,7 @@ func (o *ovsdbClient) createRPC2Client(conn net.Conn) { | |
if o.options.inactivityTimeout > 0 { | ||
o.trafficSeen = make(chan struct{}) | ||
} | ||
o.conn = conn | ||
o.rpcClient = rpc2.NewClientWithCodec(jsonrpc.NewJSONCodec(conn)) | ||
o.rpcClient.SetBlocking(true) | ||
o.rpcClient.Handle("echo", func(_ *rpc2.Client, args []interface{}, reply *[]interface{}) error { | ||
|
@@ -748,7 +750,7 @@ func (o *ovsdbClient) update3(params []json.RawMessage, reply *[]interface{}) er | |
func (o *ovsdbClient) getSchema(ctx context.Context, dbName string) (ovsdb.DatabaseSchema, error) { | ||
args := ovsdb.NewGetSchemaArgs(dbName) | ||
var reply ovsdb.DatabaseSchema | ||
err := o.rpcClient.CallWithContext(ctx, "get_schema", args, &reply) | ||
err := o.CallWithContext(ctx, "get_schema", args, &reply) | ||
if err != nil { | ||
if err == rpc2.ErrShutdown { | ||
return ovsdb.DatabaseSchema{}, ErrNotConnected | ||
|
@@ -763,7 +765,7 @@ func (o *ovsdbClient) getSchema(ctx context.Context, dbName string) (ovsdb.Datab | |
// Should only be called when mutex is held | ||
func (o *ovsdbClient) listDbs(ctx context.Context) ([]string, error) { | ||
var dbs []string | ||
err := o.rpcClient.CallWithContext(ctx, "list_dbs", nil, &dbs) | ||
err := o.CallWithContext(ctx, "list_dbs", nil, &dbs) | ||
if err != nil { | ||
if err == rpc2.ErrShutdown { | ||
return nil, ErrNotConnected | ||
|
@@ -836,7 +838,7 @@ func (o *ovsdbClient) transact(ctx context.Context, dbName string, skipChWrite b | |
if dbgLogger.Enabled() { | ||
dbgLogger.Info("transacting operations", "operations", fmt.Sprintf("%+v", operation)) | ||
} | ||
err := o.rpcClient.CallWithContext(ctx, "transact", args, &reply) | ||
err := o.CallWithContext(ctx, "transact", args, &reply) | ||
if err != nil { | ||
if err == rpc2.ErrShutdown { | ||
return nil, ErrNotConnected | ||
|
@@ -869,7 +871,7 @@ func (o *ovsdbClient) MonitorCancel(ctx context.Context, cookie MonitorCookie) e | |
if o.rpcClient == nil { | ||
return ErrNotConnected | ||
} | ||
err := o.rpcClient.CallWithContext(ctx, "monitor_cancel", args, &reply) | ||
err := o.CallWithContext(ctx, "monitor_cancel", args, &reply) | ||
if err != nil { | ||
if err == rpc2.ErrShutdown { | ||
return ErrNotConnected | ||
|
@@ -981,15 +983,15 @@ func (o *ovsdbClient) monitor(ctx context.Context, cookie MonitorCookie, reconne | |
switch monitor.Method { | ||
case ovsdb.MonitorRPC: | ||
var reply ovsdb.TableUpdates | ||
err = o.rpcClient.CallWithContext(ctx, monitor.Method, args, &reply) | ||
err = o.CallWithContext(ctx, monitor.Method, args, &reply) | ||
tableUpdates = reply | ||
case ovsdb.ConditionalMonitorRPC: | ||
var reply ovsdb.TableUpdates2 | ||
err = o.rpcClient.CallWithContext(ctx, monitor.Method, args, &reply) | ||
err = o.CallWithContext(ctx, monitor.Method, args, &reply) | ||
tableUpdates = reply | ||
case ovsdb.ConditionalMonitorSinceRPC: | ||
var reply ovsdb.MonitorCondSinceReply | ||
err = o.rpcClient.CallWithContext(ctx, monitor.Method, args, &reply) | ||
err = o.CallWithContext(ctx, monitor.Method, args, &reply) | ||
if err == nil && reply.Found { | ||
monitor.LastTransactionID = reply.LastTransactionID | ||
lastTransactionFound = true | ||
|
@@ -1080,7 +1082,7 @@ func (o *ovsdbClient) Echo(ctx context.Context) error { | |
if o.rpcClient == nil { | ||
return ErrNotConnected | ||
} | ||
err := o.rpcClient.CallWithContext(ctx, "echo", args, &reply) | ||
err := o.CallWithContext(ctx, "echo", args, &reply) | ||
if err != nil { | ||
if err == rpc2.ErrShutdown { | ||
return ErrNotConnected | ||
|
@@ -1439,3 +1441,19 @@ func (o *ovsdbClient) WhereAll(m model.Model, conditions ...model.Condition) Con | |
func (o *ovsdbClient) WhereCache(predicate interface{}) ConditionalAPI { | ||
return o.primaryDB().api.WhereCache(predicate) | ||
} | ||
|
||
// CallWithContext invokes the named function, waits for it to complete, and | ||
// returns its error status, or an error from Context timeout. | ||
func (o *ovsdbClient) CallWithContext(ctx context.Context, method string, args interface{}, reply interface{}) error { | ||
// Set up read/write deadline for tcp connection before making | ||
// a rpc request to the server. | ||
if tcpConn, ok := o.conn.(*net.TCPConn); ok { | ||
if o.options.timeout > 0 { | ||
err := tcpConn.SetDeadline(time.Now().Add(o.options.timeout * 3)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why |
||
if err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
return o.rpcClient.CallWithContext(ctx, method, args, reply) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to
SetDeadline
for each call? If so, there requires a mutex.BTW: How does this affect
rpcClient.CallWithContext
? DoesrpcClient
discard the timeout context?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, The
SetDeadline
looks to be needed for every read/write on tcp channel. This method is always invoked after o.rpcMutex is acquired. so we're safe here.correct, The
rpcClient.CallWithContext
method is not fully timebound call, so fixing it here based on feedback from a PR raised there.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a related issue in
grpc-go
maybe you can take a look.issue: grpc/grpc#15889
pr: https://github.com/grpc/grpc-go/pull/2307/files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @halfcrazy , yes, it's the same issue that we are trying to fix in libovsdb client as well.
added a commit 3867774 to set up tcp user timeout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pperiyasamy have you considered @halfcrazy concerns about needing a mutex?