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

[ISSIUE #75] support shutdown mehtod #97

Merged
merged 9 commits into from
Jul 9, 2019
Merged

[ISSIUE #75] support shutdown mehtod #97

merged 9 commits into from
Jul 9, 2019

Conversation

gaufung
Copy link
Contributor

@gaufung gaufung commented Jul 7, 2019

What is the purpose of the change

fix remote timeout uint and add shutdown method

Brief changelog

  1. use duration as all timeout unit
  2. add RemotingClient's shutdown method

Verifying this change

XXXX

Follow this checklist to help us incorporate your contribution quickly and easily. Notice, it would be helpful if you could finish the following 5 checklist(the last one is not necessary)before request the community to review your PR.

  • Make sure there is a Github issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test(over 80% coverage) to verify your logic correction, more mock a little better when a cross-module dependency exists.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

@wenfengwang wenfengwang mentioned this pull request Jul 8, 2019
20 tasks
}
}()
})
}

func (c *RMQClient) Shutdown() {
// TODO
Copy link
Member

Choose a reason for hiding this comment

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

it seems that if I shutdown the RMQClient, I remain send message by RMQClient.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but it cancel four goroutines in the Start methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but it cancels four goroutines in the Start method.

Copy link
Member

@wenfengwang wenfengwang Jul 8, 2019

Choose a reason for hiding this comment

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

IMO, could we add a field like state instead of cancel, which is updated to shutdown when Shutdown() called, and return a error like errors.New("client closed") when Send*() called

How about this?

@@ -95,6 +95,7 @@ type RMQClient struct {

remoteClient *remote.RemotingClient
hbMutex sync.Mutex
cancel context.CancelFunc
Copy link
Member

@wenfengwang wenfengwang Jul 8, 2019

Choose a reason for hiding this comment

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

IMO, could we add a field like state instead of cancel, which is updated to shutdown when Shutdown() called, and return a error like errors.New("client closed") when Send*() called

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK,I will adjust the implementation and make it sensible.

@@ -367,3 +368,64 @@ func TestInvokeOneWay(t *testing.T) {
}
wg.Done()
}


func TestInvokeAsync2(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

extra test for why?

@@ -95,6 +95,7 @@ type RMQClient struct {

remoteClient *remote.RemotingClient
hbMutex sync.Mutex
state bool
Copy link
Member

Choose a reason for hiding this comment

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

use close make more readable

@@ -125,44 +129,64 @@ func (c *RMQClient) Start() {
// delay
time.Sleep(50 * time.Millisecond)
for {
Copy link
Member

Choose a reason for hiding this comment

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

below is better?

for !c.close {
  c.UpdateTopicRouteInfo()
  time.Sleep(_PullNameServerInterval)
}

time.Sleep(_PullNameServerInterval)
} else {
return
}
}
}()

// TODO cleanOfflineBroker & sendHeartbeatToAllBrokerWithLock
go func() {
for {
Copy link
Member

Choose a reason for hiding this comment

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

below is better?

for !c.close {
  c.UpdateTopicRouteInfo()
  time.Sleep(_PullNameServerInterval)
}

} else {
return
}

}
}()

// schedule persist offset
go func() {
//time.Sleep(10 * time.Second)
for {
Copy link
Member

Choose a reason for hiding this comment

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

below is better?

for !c.close {
  c.UpdateTopicRouteInfo()
  time.Sleep(_PullNameServerInterval)
}

}
}()

go func() {
for {
c.RebalanceImmediately()
Copy link
Member

Choose a reason for hiding this comment

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

below is better?

for !c.close {
  c.UpdateTopicRouteInfo()
  time.Sleep(_PullNameServerInterval)
}

return c.remoteClient.InvokeSync(addr, request, timeoutMillis)
if c.state {
return c.remoteClient.InvokeSync(addr, request, timeoutMillis)
} else {
Copy link
Member

Choose a reason for hiding this comment

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

else is not needed.

if c.close {
  return nil, ErrServiceState
}
return return c.remoteClient.InvokeSync(addr, request, timeoutMillis)

return c.remoteClient.InvokeAsync(addr, request, timeoutMillis, func(future *remote.ResponseFuture) {
f(future.ResponseCommand, future.Err)
})
} else {
Copy link
Member

Choose a reason for hiding this comment

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

else is not needed.

if c.close {
  return nil, ErrServiceState
}
return return c.remoteClient.InvokeSync(addr, request, timeoutMillis)

if c.state {
return c.remoteClient.InvokeOneWay(addr, request, timeoutMillis)

} else {
Copy link
Member

Choose a reason for hiding this comment

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

else is not needed.

if c.close {
  return nil, ErrServiceState
}
return return c.remoteClient.InvokeSync(addr, request, timeoutMillis)

@gaufung gaufung changed the title fix remote timeout unit and add shutdown method [ISSIUE #75] support shutdown mehtod Jul 9, 2019
@wenfengwang
Copy link
Member

LGTM, @ShannonDing @zongtanghu @jonnxu please merge the PR

@zongtanghu zongtanghu merged commit e696fd8 into apache:native Jul 9, 2019
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.

None yet

4 participants