aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Craig Tiller <craig.tiller@gmail.com>2015-07-31 07:46:50 -0700
committerGravatar Craig Tiller <craig.tiller@gmail.com>2015-07-31 07:46:50 -0700
commit86d1f1325ddfd5824ec988a899006c38016ca3cb (patch)
tree6c7aa2f97c267468159f763f7bd06714a34b5653 /src
parent0613e5835b30367d7e60c934044a9a074df109d8 (diff)
parent909917955c99f6b32f34b4966c252daca0fe7061 (diff)
Merge github.com:grpc/grpc into insolent-pork-chop
Diffstat (limited to 'src')
-rw-r--r--src/core/census/grpc_context.c3
-rw-r--r--src/core/census/grpc_context.h57
-rw-r--r--src/core/client_config/subchannel.c65
-rw-r--r--src/core/surface/call.c17
-rw-r--r--src/cpp/client/channel.cc1
-rw-r--r--src/cpp/server/server_context.cc1
-rw-r--r--src/csharp/buildall.bat2
-rw-r--r--src/python/src/.gitignore4
-rw-r--r--src/python/src/MANIFEST.in1
-rw-r--r--src/python/src/commands.py75
-rw-r--r--src/python/src/setup.cfg2
-rw-r--r--src/python/src/setup.py28
12 files changed, 173 insertions, 83 deletions
diff --git a/src/core/census/grpc_context.c b/src/core/census/grpc_context.c
index d4243cb246..11f1eb3d5d 100644
--- a/src/core/census/grpc_context.c
+++ b/src/core/census/grpc_context.c
@@ -32,7 +32,8 @@
*/
#include <grpc/census.h>
-#include "src/core/census/grpc_context.h"
+#include <grpc/grpc.h>
+#include "src/core/surface/call.h"
static void grpc_census_context_destroy(void *context) {
census_context_destroy((census_context *)context);
diff --git a/src/core/census/grpc_context.h b/src/core/census/grpc_context.h
deleted file mode 100644
index 4637e7218e..0000000000
--- a/src/core/census/grpc_context.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- *
- * Copyright 2015, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-/* GRPC <--> CENSUS context interface */
-
-#ifndef CENSUS_GRPC_CONTEXT_H
-#define CENSUS_GRPC_CONTEXT_H
-
-#include <grpc/census.h>
-#include "src/core/surface/call.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Set census context for the call; Must be called before first call to
- grpc_call_start_batch(). */
-void grpc_census_call_set_context(grpc_call *call, census_context *context);
-
-/* Retrieve the calls current census context. */
-census_context *grpc_census_call_get_context(grpc_call *call);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* CENSUS_GRPC_CONTEXT_H */
diff --git a/src/core/client_config/subchannel.c b/src/core/client_config/subchannel.c
index 8db0361ead..17773bd2f4 100644
--- a/src/core/client_config/subchannel.c
+++ b/src/core/client_config/subchannel.c
@@ -44,6 +44,12 @@
#include "src/core/transport/connectivity_state.h"
#include "src/core/surface/channel.h"
+#define GRPC_SUBCHANNEL_MIN_CONNECT_TIMEOUT_SECONDS 20
+#define GRPC_SUBCHANNEL_INITIAL_CONNECT_BACKOFF_SECONDS 1
+#define GRPC_SUBCHANNEL_RECONNECT_BACKOFF_MULTIPLIER 1.6
+#define GRPC_SUBCHANNEL_RECONNECT_MAX_BACKOFF_SECONDS 120
+#define GRPC_SUBCHANNEL_RECONNECT_JITTER 0.2
+
typedef struct {
/* all fields protected by subchannel->mu */
/** refcount */
@@ -125,6 +131,8 @@ struct grpc_subchannel {
int have_alarm;
/** our alarm */
grpc_alarm alarm;
+ /** current random value */
+ gpr_uint32 random;
};
struct grpc_subchannel_call {
@@ -264,6 +272,10 @@ void grpc_subchannel_del_interested_party(grpc_subchannel *c,
grpc_pollset_set_del_pollset(c->pollset_set, pollset);
}
+static gpr_uint32 random_seed() {
+ return (gpr_uint32)(gpr_time_to_millis(gpr_now(GPR_CLOCK_MONOTONIC)));
+}
+
grpc_subchannel *grpc_subchannel_create(grpc_connector *connector,
grpc_subchannel_args *args) {
grpc_subchannel *c = gpr_malloc(sizeof(*c));
@@ -284,6 +296,7 @@ grpc_subchannel *grpc_subchannel_create(grpc_connector *connector,
c->mdctx = args->mdctx;
c->master = args->master;
c->pollset_set = grpc_client_channel_get_connecting_pollset_set(parent_elem);
+ c->random = random_seed();
grpc_mdctx_ref(c->mdctx);
grpc_iomgr_closure_init(&c->connected, subchannel_connected, c);
grpc_connectivity_state_init(&c->state_tracker, GRPC_CHANNEL_IDLE,
@@ -307,10 +320,10 @@ static void continue_connect(grpc_subchannel *c) {
}
static void start_connect(grpc_subchannel *c) {
- gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC);
- c->next_attempt = now;
- c->backoff_delta = gpr_time_from_seconds(1, GPR_TIMESPAN);
-
+ c->backoff_delta = gpr_time_from_seconds(
+ GRPC_SUBCHANNEL_INITIAL_CONNECT_BACKOFF_SECONDS, GPR_TIMESPAN);
+ c->next_attempt = gpr_time_add(
+ gpr_now(GPR_CLOCK_MONOTONIC), c->backoff_delta);
continue_connect(c);
}
@@ -576,6 +589,35 @@ static void publish_transport(grpc_subchannel *c) {
}
}
+/* Generate a random number between 0 and 1. */
+static double generate_uniform_random_number(grpc_subchannel *c) {
+ c->random = (1103515245 * c->random + 12345) % ((gpr_uint32)1 << 31);
+ return c->random / (double)((gpr_uint32)1 << 31);
+}
+
+/* Update backoff_delta and next_attempt in subchannel */
+static void update_reconnect_parameters(grpc_subchannel *c) {
+ gpr_int32 backoff_delta_millis, jitter;
+ gpr_int32 max_backoff_millis =
+ GRPC_SUBCHANNEL_RECONNECT_MAX_BACKOFF_SECONDS * 1000;
+ double jitter_range;
+ backoff_delta_millis =
+ (gpr_int32)(gpr_time_to_millis(c->backoff_delta) *
+ GRPC_SUBCHANNEL_RECONNECT_BACKOFF_MULTIPLIER);
+ if (backoff_delta_millis > max_backoff_millis) {
+ backoff_delta_millis = max_backoff_millis;
+ }
+ c->backoff_delta = gpr_time_from_millis(backoff_delta_millis, GPR_TIMESPAN);
+ c->next_attempt =
+ gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), c->backoff_delta);
+
+ jitter_range = GRPC_SUBCHANNEL_RECONNECT_JITTER * backoff_delta_millis;
+ jitter =
+ (gpr_int32)((2 * generate_uniform_random_number(c) - 1) * jitter_range);
+ c->next_attempt =
+ gpr_time_add(c->next_attempt, gpr_time_from_millis(jitter, GPR_TIMESPAN));
+}
+
static void on_alarm(void *arg, int iomgr_success) {
grpc_subchannel *c = arg;
gpr_mu_lock(&c->mu);
@@ -586,6 +628,7 @@ static void on_alarm(void *arg, int iomgr_success) {
connectivity_state_changed_locked(c, "alarm");
gpr_mu_unlock(&c->mu);
if (iomgr_success) {
+ update_reconnect_parameters(c);
continue_connect(c);
} else {
GRPC_CHANNEL_INTERNAL_UNREF(c->master, "connecting");
@@ -603,18 +646,20 @@ static void subchannel_connected(void *arg, int iomgr_success) {
GPR_ASSERT(!c->have_alarm);
c->have_alarm = 1;
connectivity_state_changed_locked(c, "connect_failed");
- c->next_attempt = gpr_time_add(c->next_attempt, c->backoff_delta);
- if (gpr_time_cmp(c->backoff_delta,
- gpr_time_from_seconds(60, GPR_TIMESPAN)) < 0) {
- c->backoff_delta = gpr_time_add(c->backoff_delta, c->backoff_delta);
- }
grpc_alarm_init(&c->alarm, c->next_attempt, on_alarm, c, now);
gpr_mu_unlock(&c->mu);
}
}
static gpr_timespec compute_connect_deadline(grpc_subchannel *c) {
- return gpr_time_add(c->next_attempt, c->backoff_delta);
+ gpr_timespec current_deadline =
+ gpr_time_add(c->next_attempt, c->backoff_delta);
+ gpr_timespec min_deadline = gpr_time_add(
+ gpr_now(GPR_CLOCK_MONOTONIC),
+ gpr_time_from_seconds(GRPC_SUBCHANNEL_MIN_CONNECT_TIMEOUT_SECONDS,
+ GPR_TIMESPAN));
+ return gpr_time_cmp(current_deadline, min_deadline) > 0 ? current_deadline
+ : min_deadline;
}
static grpc_connectivity_state compute_connectivity_locked(grpc_subchannel *c) {
diff --git a/src/core/surface/call.c b/src/core/surface/call.c
index 12378f0066..327a096ffb 100644
--- a/src/core/surface/call.c
+++ b/src/core/surface/call.c
@@ -40,7 +40,6 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
-#include "src/core/census/grpc_context.h"
#include "src/core/channel/channel_stack.h"
#include "src/core/iomgr/alarm.h"
#include "src/core/profiling/timers.h"
@@ -348,7 +347,8 @@ grpc_call *grpc_call_create(grpc_channel *channel, grpc_completion_queue *cq,
}
grpc_call_stack_init(channel_stack, server_transport_data, initial_op_ptr,
CALL_STACK_FROM_CALL(call));
- if (gpr_time_cmp(send_deadline, gpr_inf_future(send_deadline.clock_type)) != 0) {
+ if (gpr_time_cmp(send_deadline, gpr_inf_future(send_deadline.clock_type)) !=
+ 0) {
set_deadline_alarm(call, send_deadline);
}
return call;
@@ -1283,8 +1283,9 @@ static void set_deadline_alarm(grpc_call *call, gpr_timespec deadline) {
}
GRPC_CALL_INTERNAL_REF(call, "alarm");
call->have_alarm = 1;
- grpc_alarm_init(&call->alarm, gpr_convert_clock_type(deadline, GPR_CLOCK_MONOTONIC), call_alarm, call,
- gpr_now(GPR_CLOCK_MONOTONIC));
+ grpc_alarm_init(&call->alarm,
+ gpr_convert_clock_type(deadline, GPR_CLOCK_MONOTONIC),
+ call_alarm, call, gpr_now(GPR_CLOCK_MONOTONIC));
}
/* we offset status by a small amount when storing it into transport metadata
@@ -1319,15 +1320,17 @@ static gpr_uint32 decode_compression(grpc_mdelem *md) {
grpc_compression_algorithm algorithm;
void *user_data = grpc_mdelem_get_user_data(md, destroy_compression);
if (user_data) {
- algorithm = ((grpc_compression_level)(gpr_intptr)user_data) - COMPRESS_OFFSET;
+ algorithm =
+ ((grpc_compression_level)(gpr_intptr)user_data) - COMPRESS_OFFSET;
} else {
const char *md_c_str = grpc_mdstr_as_c_string(md->value);
if (!grpc_compression_algorithm_parse(md_c_str, &algorithm)) {
gpr_log(GPR_ERROR, "Invalid compression algorithm: '%s'", md_c_str);
assert(0);
}
- grpc_mdelem_set_user_data(md, destroy_compression,
- (void *)(gpr_intptr)(algorithm + COMPRESS_OFFSET));
+ grpc_mdelem_set_user_data(
+ md, destroy_compression,
+ (void *)(gpr_intptr)(algorithm + COMPRESS_OFFSET));
}
return algorithm;
}
diff --git a/src/cpp/client/channel.cc b/src/cpp/client/channel.cc
index 9c2b0b1dbc..5df81e641e 100644
--- a/src/cpp/client/channel.cc
+++ b/src/cpp/client/channel.cc
@@ -39,7 +39,6 @@
#include <grpc/support/log.h>
#include <grpc/support/slice.h>
-#include "src/core/census/grpc_context.h"
#include "src/core/profiling/timers.h"
#include <grpc++/channel_arguments.h>
#include <grpc++/client_context.h>
diff --git a/src/cpp/server/server_context.cc b/src/cpp/server/server_context.cc
index f54ed8aa29..f6c073040b 100644
--- a/src/cpp/server/server_context.cc
+++ b/src/cpp/server/server_context.cc
@@ -39,7 +39,6 @@
#include <grpc++/impl/sync.h>
#include <grpc++/time.h>
-#include "src/core/census/grpc_context.h"
#include "src/core/channel/compress_filter.h"
#include "src/cpp/common/create_auth_context.h"
diff --git a/src/csharp/buildall.bat b/src/csharp/buildall.bat
index e73feb87b9..d85896c255 100644
--- a/src/csharp/buildall.bat
+++ b/src/csharp/buildall.bat
@@ -9,7 +9,7 @@ cd /d %~dp0
@call "%VS120COMNTOOLS%\..\..\vc\vcvarsall.bat" x86
@rem Build the C# native extension
-msbuild ..\..\vsprojects\grpc.sln /t:grpc_csharp_ext /p:PlatformToolset=v120 || goto :error
+msbuild ..\..\vsprojects\grpc_csharp_ext.sln /p:PlatformToolset=v120 || goto :error
msbuild Grpc.sln /p:Configuration=Debug || goto :error
msbuild Grpc.sln /p:Configuration=Release || goto :error
diff --git a/src/python/src/.gitignore b/src/python/src/.gitignore
index 144e501237..d89f3db999 100644
--- a/src/python/src/.gitignore
+++ b/src/python/src/.gitignore
@@ -2,3 +2,7 @@ MANIFEST
grpcio.egg-info/
build/
dist/
+*.egg
+*.egg/
+*.eggs/
+doc/
diff --git a/src/python/src/MANIFEST.in b/src/python/src/MANIFEST.in
index 6f32db0548..498b55f20a 100644
--- a/src/python/src/MANIFEST.in
+++ b/src/python/src/MANIFEST.in
@@ -1 +1,2 @@
graft grpc
+include commands.py
diff --git a/src/python/src/commands.py b/src/python/src/commands.py
new file mode 100644
index 0000000000..8e87855011
--- /dev/null
+++ b/src/python/src/commands.py
@@ -0,0 +1,75 @@
+# Copyright 2015, Google Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"""Provides distutils command classes for the GRPC Python setup process."""
+
+import os
+import os.path
+import sys
+
+import setuptools
+
+_CONF_PY_ADDENDUM = """
+extensions.append('sphinx.ext.napoleon')
+napoleon_google_docstring = True
+napoleon_numpy_docstring = True
+
+html_theme = 'sphinx_rtd_theme'
+"""
+
+class SphinxDocumentation(setuptools.Command):
+ """Command to generate documentation via sphinx."""
+
+ description = ''
+ user_options = []
+
+ def initialize_options(self):
+ pass
+
+ def finalize_options(self):
+ pass
+
+ def run(self):
+ # We import here to ensure that setup.py has had a chance to install the
+ # relevant package eggs first.
+ import sphinx
+ import sphinx.apidoc
+ metadata = self.distribution.metadata
+ src_dir = os.path.join(
+ os.getcwd(), self.distribution.package_dir['grpc'])
+ sys.path.append(src_dir)
+ sphinx.apidoc.main([
+ '', '--force', '--full', '-H', metadata.name, '-A', metadata.author,
+ '-V', metadata.version, '-R', metadata.version,
+ '-o', os.path.join('doc', 'src'), src_dir])
+ conf_filepath = os.path.join('doc', 'src', 'conf.py')
+ with open(conf_filepath, 'a') as conf_file:
+ conf_file.write(_CONF_PY_ADDENDUM)
+ sphinx.main(['', os.path.join('doc', 'src'), os.path.join('doc', 'build')])
+
diff --git a/src/python/src/setup.cfg b/src/python/src/setup.cfg
new file mode 100644
index 0000000000..8f69613632
--- /dev/null
+++ b/src/python/src/setup.cfg
@@ -0,0 +1,2 @@
+[build_ext]
+inplace=1
diff --git a/src/python/src/setup.py b/src/python/src/setup.py
index a857ae98cc..0310a83a7b 100644
--- a/src/python/src/setup.py
+++ b/src/python/src/setup.py
@@ -30,11 +30,17 @@
"""A setup module for the GRPC Python package."""
import os
+import os.path
import sys
from distutils import core as _core
import setuptools
+# Ensure we're in the proper directory whether or not we're being used by pip.
+os.chdir(os.path.dirname(os.path.abspath(__file__)))
+
+# Break import-style to ensure we can actually find our commands module.
+import commands
# Use environment variables to determine whether or not the Cython extension
# should *use* Cython or use the generated C files. Note that this requires the
@@ -98,15 +104,27 @@ _PACKAGE_DIRECTORIES = {
'grpc.framework': 'grpc/framework',
}
+_INSTALL_REQUIRES = (
+ 'enum34==1.0.4',
+ 'futures==2.2.0',
+ 'protobuf==3.0.0a3'
+)
+
+_SETUP_REQUIRES = (
+ 'sphinx>=1.3',
+) + _INSTALL_REQUIRES
+
+_COMMAND_CLASS = {
+ 'doc': commands.SphinxDocumentation
+}
+
setuptools.setup(
name='grpcio',
version='0.10.0a0',
ext_modules=_EXTENSION_MODULES,
packages=list(_PACKAGES),
package_dir=_PACKAGE_DIRECTORIES,
- install_requires=[
- 'enum34==1.0.4',
- 'futures==2.2.0',
- 'protobuf==3.0.0a3'
- ]
+ install_requires=_INSTALL_REQUIRES,
+ setup_requires=_SETUP_REQUIRES,
+ cmdclass=_COMMAND_CLASS
)