Skip to content

Commit

Permalink
Merge branch 'master' into rq-threads-2
Browse files Browse the repository at this point in the history
  • Loading branch information
sreecha committed Aug 9, 2018
2 parents 82f0275 + cb87dd9 commit f63b51b
Show file tree
Hide file tree
Showing 114 changed files with 1,500 additions and 308 deletions.
14 changes: 11 additions & 3 deletions .github/mergeable.yml
@@ -1,6 +1,14 @@
mergeable:
pull_requests:
label:
must_include:
regex: "release notes: yes|release notes: no"
message: "Add release notes yes/no label. For yes, add lang label"
or:
- and:
- must_include:
regex: 'release notes: yes'
message: 'Please include release note: yes'
- must_include:
regex: '^lang\/'
message: 'Please include a language label'
- must_include:
regex: 'release notes: no'
message: 'Please include release note: no'
14 changes: 2 additions & 12 deletions CMakeLists.txt
Expand Up @@ -100,6 +100,8 @@ if (MSVC)
add_definitions(-D_WIN32_WINNT=0x600 -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS)
# needed to compile protobuf
add_definitions(/wd4065 /wd4506)
# TODO(jtattermusch): revisit warnings that were silenced as part of upgrade to protobuf3.6.0
add_definitions(/wd4200 /wd4291 /wd4244)
# TODO(jtattermusch): revisit C4267 occurrences throughout the code
add_definitions(/wd4267)
# TODO(jtattermusch): needed to build boringssl with VS2017, revisit later
Expand Down Expand Up @@ -660,12 +662,8 @@ add_dependencies(buildtests_cxx transport_security_common_api_test)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_cxx writes_per_rpc_test)
endif()
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_cxx resolver_component_test_unsecure)
endif()
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_cxx resolver_component_test)
endif()
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_cxx resolver_component_tests_runner_invoker_unsecure)
endif()
Expand All @@ -674,9 +672,7 @@ add_dependencies(buildtests_cxx resolver_component_tests_runner_invoker)
endif()
add_dependencies(buildtests_cxx address_sorting_test_unsecure)
add_dependencies(buildtests_cxx address_sorting_test)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_cxx cancel_ares_query_test)
endif()

add_custom_target(buildtests
DEPENDS buildtests_c buildtests_cxx)
Expand Down Expand Up @@ -16211,7 +16207,6 @@ target_link_libraries(inproc_nosec_test

endif (gRPC_BUILD_TESTS)
if (gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)

add_executable(resolver_component_test_unsecure
test/cpp/naming/resolver_component_test.cc
Expand Down Expand Up @@ -16251,10 +16246,8 @@ target_link_libraries(resolver_component_test_unsecure
${_gRPC_GFLAGS_LIBRARIES}
)

endif()
endif (gRPC_BUILD_TESTS)
if (gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)

add_executable(resolver_component_test
test/cpp/naming/resolver_component_test.cc
Expand Down Expand Up @@ -16294,7 +16287,6 @@ target_link_libraries(resolver_component_test
${_gRPC_GFLAGS_LIBRARIES}
)

endif()
endif (gRPC_BUILD_TESTS)
if (gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
Expand Down Expand Up @@ -16465,7 +16457,6 @@ target_link_libraries(address_sorting_test

endif (gRPC_BUILD_TESTS)
if (gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)

add_executable(cancel_ares_query_test
test/cpp/naming/cancel_ares_query_test.cc
Expand Down Expand Up @@ -16505,7 +16496,6 @@ target_link_libraries(cancel_ares_query_test
${_gRPC_GFLAGS_LIBRARIES}
)

endif()
endif (gRPC_BUILD_TESTS)
if (gRPC_BUILD_TESTS)

Expand Down
6 changes: 3 additions & 3 deletions bazel/grpc_deps.bzl
Expand Up @@ -116,9 +116,9 @@ def grpc_deps():
if "com_google_protobuf" not in native.existing_rules():
native.http_archive(
name = "com_google_protobuf",
strip_prefix = "protobuf-b5fbb742af122b565925987e65c08957739976a7",
url = "https://github.com/google/protobuf/archive/b5fbb742af122b565925987e65c08957739976a7.tar.gz",
)
strip_prefix = "protobuf-48cb18e5c419ddd23d9badcfe4e9df7bde1979b2",
url = "https://github.com/google/protobuf/archive/48cb18e5c419ddd23d9badcfe4e9df7bde1979b2.tar.gz",
)

if "com_github_nanopb_nanopb" not in native.existing_rules():
native.new_http_archive(
Expand Down
3 changes: 2 additions & 1 deletion doc/csharp/server_reflection.md
Expand Up @@ -30,7 +30,8 @@ server.Start();
```

After starting the server, you can verify that the server reflection
is working properly by using the `grpc_cli` command line tool:
is working properly by using the [`grpc_cli` command line
tool](https://github.com/grpc/grpc/blob/master/doc/command_line_tool.md):

```sh
$ grpc_cli ls localhost:50051
Expand Down
61 changes: 61 additions & 0 deletions doc/python/server_reflection.md
@@ -0,0 +1,61 @@
# gRPC Python Server Reflection

This document shows how to use gRPC Server Reflection in gRPC Python.
Please see [C++ Server Reflection Tutorial](../server_reflection_tutorial.md)
for general information and more examples how to use server reflection.

## Enable server reflection in Python servers

gRPC Python Server Reflection is an add-on library.
To use it, first install the [grpcio-reflection](https://pypi.org/project/grpcio-reflection/)
PyPI package into your project.

Note that with Python you need to manually register the service
descriptors with the reflection service implementation when creating a server
(this isn't necessary with e.g. C++ or Java)
```python
# add the following import statement to use server reflection
from grpc_reflection.v1alpha import reflection
# ...
def serve():
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
# the reflection service will be aware of "Greeter" and "ServerReflection" services.
SERVICE_NAMES = (
helloworld_pb2.DESCRIPTOR.services_by_name['Greeter'].full_name,
reflection.SERVICE_NAME,
)
reflection.enable_server_reflection(SERVICE_NAMES, server)
server.add_insecure_port('[::]:50051')
server.start()
```

Please see
[greeter_server_with_reflection.py](https://github.com/grpc/grpc/blob/master/examples/python/helloworld/greeter_server_with_reflection.py)
in the examples directory for the full example, which extends the gRPC [Python
`Greeter` example](https://github.com/grpc/tree/master/examples/python/helloworld) on a
reflection-enabled server.

After starting the server, you can verify that the server reflection
is working properly by using the [`grpc_cli` command line
tool](https://github.com/grpc/grpc/blob/master/doc/command_line_tool.md):

```sh
$ grpc_cli ls localhost:50051
```

output:
```sh
grpc.reflection.v1alpha.ServerReflection
helloworld.Greeter
```

For more examples and instructions how to use the `grpc_cli` tool,
please refer to the [`grpc_cli` documentation](../command_line_tool.md)
and the [C++ Server Reflection Tutorial](../server_reflection_tutorial.md).

## Additional Resources

The [Server Reflection Protocol](../server-reflection.md) provides detailed
information about how the server reflection works and describes the server reflection
protocol in detail.
52 changes: 52 additions & 0 deletions examples/python/helloworld/greeter_server_with_reflection.py
@@ -0,0 +1,52 @@
# Copyright 2018 The gRPC Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The reflection-enabled version of gRPC helloworld.Greeter server."""

from concurrent import futures
import time

import grpc
from grpc_reflection.v1alpha import reflection

import helloworld_pb2
import helloworld_pb2_grpc

_ONE_DAY_IN_SECONDS = 60 * 60 * 24


class Greeter(helloworld_pb2_grpc.GreeterServicer):

def SayHello(self, request, context):
return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)


def serve():
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
SERVICE_NAMES = (
helloworld_pb2.DESCRIPTOR.services_by_name['Greeter'].full_name,
reflection.SERVICE_NAME,
)
reflection.enable_server_reflection(SERVICE_NAMES, server)
server.add_insecure_port('[::]:50051')
server.start()
try:
while True:
time.sleep(_ONE_DAY_IN_SECONDS)
except KeyboardInterrupt:
server.stop(0)


if __name__ == '__main__':
serve()
1 change: 1 addition & 0 deletions grpc.def
Expand Up @@ -42,6 +42,7 @@ EXPORTS
grpc_census_call_get_context
grpc_channel_get_target
grpc_channel_get_info
grpc_channel_reset_connect_backoff
grpc_insecure_channel_create
grpc_lame_client_channel_create
grpc_channel_destroy
Expand Down
5 changes: 5 additions & 0 deletions include/grpc/grpc.h
Expand Up @@ -274,6 +274,11 @@ GRPCAPI char* grpc_channel_get_target(grpc_channel* channel);
GRPCAPI void grpc_channel_get_info(grpc_channel* channel,
const grpc_channel_info* channel_info);

/** EXPERIMENTAL. Resets the channel's connect backoff.
TODO(roth): When we see whether this proves useful, either promote
to non-experimental or remove it. */
GRPCAPI void grpc_channel_reset_connect_backoff(grpc_channel* channel);

/** Create a client channel to 'target'. Additional channel level configuration
MAY be provided by grpc_channel_args, though the expectation is that most
clients will want to simply pass NULL. The user data in 'args' need only
Expand Down
9 changes: 9 additions & 0 deletions include/grpcpp/channel.h
Expand Up @@ -30,6 +30,14 @@
struct grpc_channel;

namespace grpc {

namespace experimental {
/// Resets the channel's connection backoff.
/// TODO(roth): Once we see whether this proves useful, either create a gRFC
/// and change this to be a method of the Channel class, or remove it.
void ChannelResetConnectionBackoff(Channel* channel);
} // namespace experimental

/// Channels represent a connection to an endpoint. Created by \a CreateChannel.
class Channel final : public ChannelInterface,
public internal::CallHook,
Expand All @@ -52,6 +60,7 @@ class Channel final : public ChannelInterface,
private:
template <class InputMessage, class OutputMessage>
friend class internal::BlockingUnaryCallImpl;
friend void experimental::ChannelResetConnectionBackoff(Channel* channel);
friend std::shared_ptr<Channel> CreateChannelInternal(
const grpc::string& host, grpc_channel* c_channel);
Channel(const grpc::string& host, grpc_channel* c_channel);
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Expand Up @@ -276,11 +276,11 @@ def cython_extensions_and_necessity():
}

INSTALL_REQUIRES = (
"six>=1.5.2",
"futures>=2.2.0 ; python_version<'3.2'",
"enum34>=1.0.4 ; python_version<'3.4'"
'six>=1.5.2',
)

if not PY3:
INSTALL_REQUIRES += ('futures>=2.2.0', 'enum34>=1.0.4')

SETUP_REQUIRES = INSTALL_REQUIRES + (
'sphinx>=1.3',
Expand Down
11 changes: 11 additions & 0 deletions src/core/ext/filters/client_channel/client_channel.cc
Expand Up @@ -622,6 +622,17 @@ static void start_transport_op_locked(void* arg, grpc_error* error_ignored) {
}
GRPC_ERROR_UNREF(op->disconnect_with_error);
}

if (op->reset_connect_backoff) {
if (chand->resolver != nullptr) {
chand->resolver->ResetBackoffLocked();
chand->resolver->RequestReresolutionLocked();
}
if (chand->lb_policy != nullptr) {
chand->lb_policy->ResetBackoffLocked();
}
}

GRPC_CHANNEL_STACK_UNREF(chand->owning_stack, "start_transport_op");

GRPC_CLOSURE_SCHED(op->on_consumed, GRPC_ERROR_NONE);
Expand Down
Expand Up @@ -56,7 +56,7 @@ void grpc_client_channel_init(void) {
grpc_register_http_proxy_mapper();
grpc_subchannel_index_init();
grpc_channel_init_register_stage(
GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, append_filter,
GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_PRIORITY_MAX, append_filter,
(void*)&grpc_client_channel_filter);
grpc_http_connect_register_handshaker_factory();
}
Expand Down
5 changes: 4 additions & 1 deletion src/core/ext/filters/client_channel/lb_policy.h
Expand Up @@ -144,7 +144,10 @@ class LoadBalancingPolicy
/// consider whether this method is still needed.
virtual void ExitIdleLocked() GRPC_ABSTRACT;

/// populates child_subchannels and child_channels with the uuids of this
/// Resets connection backoff.
virtual void ResetBackoffLocked() GRPC_ABSTRACT;

/// Populates child_subchannels and child_channels with the uuids of this
/// LB policy's referenced children. This is not invoked from the
/// client_channel's combiner. The implementation is responsible for
/// providing its own synchronization.
Expand Down
12 changes: 11 additions & 1 deletion src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc
Expand Up @@ -134,6 +134,7 @@ class GrpcLb : public LoadBalancingPolicy {
grpc_error** connectivity_error) override;
void HandOffPendingPicksLocked(LoadBalancingPolicy* new_policy) override;
void ExitIdleLocked() override;
void ResetBackoffLocked() override;
void FillChildRefsForChannelz(ChildRefsList* child_subchannels,
ChildRefsList* child_channels) override;

Expand Down Expand Up @@ -1214,6 +1215,15 @@ void GrpcLb::ExitIdleLocked() {
}
}

void GrpcLb::ResetBackoffLocked() {
if (lb_channel_ != nullptr) {
grpc_channel_reset_connect_backoff(lb_channel_);
}
if (rr_policy_ != nullptr) {
rr_policy_->ResetBackoffLocked();
}
}

bool GrpcLb::PickLocked(PickState* pick, grpc_error** error) {
PendingPick* pp = PendingPickCreate(pick);
bool pick_done = false;
Expand Down Expand Up @@ -1880,7 +1890,7 @@ void grpc_lb_policy_grpclb_init() {
grpc_core::UniquePtr<grpc_core::LoadBalancingPolicyFactory>(
grpc_core::New<grpc_core::GrpcLbFactory>()));
grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
GRPC_CHANNEL_INIT_PRIORITY_LOW,
maybe_add_client_load_reporting_filter,
(void*)&grpc_client_load_reporting_filter);
}
Expand Down
Expand Up @@ -57,6 +57,7 @@ class PickFirst : public LoadBalancingPolicy {
grpc_error** connectivity_error) override;
void HandOffPendingPicksLocked(LoadBalancingPolicy* new_policy) override;
void ExitIdleLocked() override;
void ResetBackoffLocked() override;
void FillChildRefsForChannelz(ChildRefsList* child_subchannels,
ChildRefsList* ignored) override;

Expand Down Expand Up @@ -259,6 +260,13 @@ void PickFirst::ExitIdleLocked() {
}
}

void PickFirst::ResetBackoffLocked() {
subchannel_list_->ResetBackoffLocked();
if (latest_pending_subchannel_list_ != nullptr) {
latest_pending_subchannel_list_->ResetBackoffLocked();
}
}

bool PickFirst::PickLocked(PickState* pick, grpc_error** error) {
// If we have a selected subchannel already, return synchronously.
if (selected_ != nullptr) {
Expand Down

0 comments on commit f63b51b

Please sign in to comment.