diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/channel/client_channel.c | 4 | ||||
-rw-r--r-- | src/core/surface/call.c | 4 | ||||
-rw-r--r-- | src/core/surface/server.c | 12 | ||||
-rw-r--r-- | src/csharp/ext/grpc_csharp_ext.c | 26 | ||||
-rw-r--r-- | src/node/ext/call.cc | 1 | ||||
-rw-r--r-- | src/php/ext/grpc/call.c | 1 | ||||
-rw-r--r-- | src/python/grpcio/grpc/_adapter/_c/utility.c | 1 | ||||
-rw-r--r-- | src/python/grpcio/grpc/early_adopter/implementations.py | 30 | ||||
-rw-r--r-- | src/ruby/ext/grpc/rb_call.c | 1 |
9 files changed, 68 insertions, 12 deletions
diff --git a/src/core/channel/client_channel.c b/src/core/channel/client_channel.c index a73458821e..2e25033813 100644 --- a/src/core/channel/client_channel.c +++ b/src/core/channel/client_channel.c @@ -505,13 +505,13 @@ static void cc_on_config_changed(void *arg, int iomgr_success) { if (iomgr_success && chand->resolver) { grpc_resolver *resolver = chand->resolver; GRPC_RESOLVER_REF(resolver, "channel-next"); + grpc_connectivity_state_set(&chand->state_tracker, state, + "new_lb+resolver"); gpr_mu_unlock(&chand->mu_config); GRPC_CHANNEL_INTERNAL_REF(chand->master, "resolver"); grpc_resolver_next(resolver, &chand->incoming_configuration, &chand->on_config_changed); GRPC_RESOLVER_UNREF(resolver, "channel-next"); - grpc_connectivity_state_set(&chand->state_tracker, state, - "new_lb+resolver"); if (lb_policy != NULL) { watch_lb_policy(chand, lb_policy, state); } diff --git a/src/core/surface/call.c b/src/core/surface/call.c index a6153b479d..33f277da46 100644 --- a/src/core/surface/call.c +++ b/src/core/surface/call.c @@ -1573,7 +1573,8 @@ grpc_call_error grpc_call_start_batch(grpc_call *call, const grpc_op *ops, const grpc_op *op; grpc_ioreq *req; void (*finish_func)(grpc_call *, int, void *) = finish_batch; - GPR_ASSERT(!reserved); + + if (reserved != NULL) return GRPC_CALL_ERROR; GRPC_CALL_LOG_BATCH(GPR_INFO, call, ops, nops, tag); @@ -1588,6 +1589,7 @@ grpc_call_error grpc_call_start_batch(grpc_call *call, const grpc_op *ops, /* rewrite batch ops into ioreq ops */ for (in = 0, out = 0; in < nops; in++) { op = &ops[in]; + if (op->reserved != NULL) return GRPC_CALL_ERROR; switch (op->op) { case GRPC_OP_SEND_INITIAL_METADATA: /* Flag validation: currently allow no flags */ diff --git a/src/core/surface/server.c b/src/core/surface/server.c index f399aa69f2..1c402418e8 100644 --- a/src/core/surface/server.c +++ b/src/core/surface/server.c @@ -975,6 +975,11 @@ void grpc_server_setup_transport(grpc_server *s, grpc_transport *transport, grpc_transport_perform_op(transport, &op); } +void done_published_shutdown(void *done_arg, grpc_cq_completion *storage) { + (void) done_arg; + gpr_free(storage); +} + void grpc_server_shutdown_and_notify(grpc_server *server, grpc_completion_queue *cq, void *tag) { listener *l; @@ -986,6 +991,12 @@ void grpc_server_shutdown_and_notify(grpc_server *server, /* lock, and gather up some stuff to do */ gpr_mu_lock(&server->mu_global); grpc_cq_begin_op(cq); + if (server->shutdown_published) { + grpc_cq_end_op(cq, tag, 1, done_published_shutdown, NULL, + gpr_malloc(sizeof(grpc_cq_completion))); + gpr_mu_unlock(&server->mu_global); + return; + } server->shutdown_tags = gpr_realloc(server->shutdown_tags, sizeof(shutdown_tag) * (server->num_shutdown_tags + 1)); @@ -1135,6 +1146,7 @@ grpc_call_error grpc_server_request_call( return GRPC_CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE; } grpc_cq_begin_op(cq_for_notification); + details->reserved = NULL; rc->type = BATCH_CALL; rc->server = server; rc->tag = tag; diff --git a/src/csharp/ext/grpc_csharp_ext.c b/src/csharp/ext/grpc_csharp_ext.c index bf2bbd873b..fc9470f93f 100644 --- a/src/csharp/ext/grpc_csharp_ext.c +++ b/src/csharp/ext/grpc_csharp_ext.c @@ -510,22 +510,27 @@ grpcsharp_call_start_unary(grpc_call *call, grpcsharp_batch_context *ctx, ops[0].data.send_initial_metadata.metadata = ctx->send_initial_metadata.metadata; ops[0].flags = 0; + ops[0].reserved = NULL; ops[1].op = GRPC_OP_SEND_MESSAGE; ctx->send_message = string_to_byte_buffer(send_buffer, send_buffer_len); ops[1].data.send_message = ctx->send_message; ops[1].flags = write_flags; + ops[1].reserved = NULL; ops[2].op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; ops[2].flags = 0; + ops[2].reserved = NULL; ops[3].op = GRPC_OP_RECV_INITIAL_METADATA; ops[3].data.recv_initial_metadata = &(ctx->recv_initial_metadata); ops[3].flags = 0; + ops[3].reserved = NULL; ops[4].op = GRPC_OP_RECV_MESSAGE; ops[4].data.recv_message = &(ctx->recv_message); ops[4].flags = 0; + ops[4].reserved = NULL; ops[5].op = GRPC_OP_RECV_STATUS_ON_CLIENT; ops[5].data.recv_status_on_client.trailing_metadata = @@ -538,6 +543,7 @@ grpcsharp_call_start_unary(grpc_call *call, grpcsharp_batch_context *ctx, ops[5].data.recv_status_on_client.status_details_capacity = &(ctx->recv_status_on_client.status_details_capacity); ops[5].flags = 0; + ops[5].reserved = NULL; return grpc_call_start_batch(call, ops, sizeof(ops) / sizeof(ops[0]), ctx, NULL); @@ -556,14 +562,17 @@ grpcsharp_call_start_client_streaming(grpc_call *call, ops[0].data.send_initial_metadata.metadata = ctx->send_initial_metadata.metadata; ops[0].flags = 0; + ops[0].reserved = NULL; ops[1].op = GRPC_OP_RECV_INITIAL_METADATA; ops[1].data.recv_initial_metadata = &(ctx->recv_initial_metadata); ops[1].flags = 0; + ops[1].reserved = NULL; ops[2].op = GRPC_OP_RECV_MESSAGE; ops[2].data.recv_message = &(ctx->recv_message); ops[2].flags = 0; + ops[2].reserved = NULL; ops[3].op = GRPC_OP_RECV_STATUS_ON_CLIENT; ops[3].data.recv_status_on_client.trailing_metadata = @@ -576,6 +585,7 @@ grpcsharp_call_start_client_streaming(grpc_call *call, ops[3].data.recv_status_on_client.status_details_capacity = &(ctx->recv_status_on_client.status_details_capacity); ops[3].flags = 0; + ops[3].reserved = NULL; return grpc_call_start_batch(call, ops, sizeof(ops) / sizeof(ops[0]), ctx, NULL); @@ -593,18 +603,22 @@ GPR_EXPORT grpc_call_error GPR_CALLTYPE grpcsharp_call_start_server_streaming( ops[0].data.send_initial_metadata.metadata = ctx->send_initial_metadata.metadata; ops[0].flags = 0; + ops[0].reserved = NULL; ops[1].op = GRPC_OP_SEND_MESSAGE; ctx->send_message = string_to_byte_buffer(send_buffer, send_buffer_len); ops[1].data.send_message = ctx->send_message; ops[1].flags = write_flags; + ops[1].reserved = NULL; ops[2].op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; ops[2].flags = 0; + ops[2].reserved = NULL; ops[3].op = GRPC_OP_RECV_INITIAL_METADATA; ops[3].data.recv_initial_metadata = &(ctx->recv_initial_metadata); ops[3].flags = 0; + ops[3].reserved = NULL; ops[4].op = GRPC_OP_RECV_STATUS_ON_CLIENT; ops[4].data.recv_status_on_client.trailing_metadata = @@ -617,6 +631,7 @@ GPR_EXPORT grpc_call_error GPR_CALLTYPE grpcsharp_call_start_server_streaming( ops[4].data.recv_status_on_client.status_details_capacity = &(ctx->recv_status_on_client.status_details_capacity); ops[4].flags = 0; + ops[4].reserved = NULL; return grpc_call_start_batch(call, ops, sizeof(ops) / sizeof(ops[0]), ctx, NULL); @@ -635,10 +650,12 @@ grpcsharp_call_start_duplex_streaming(grpc_call *call, ops[0].data.send_initial_metadata.metadata = ctx->send_initial_metadata.metadata; ops[0].flags = 0; + ops[0].reserved = NULL; ops[1].op = GRPC_OP_RECV_INITIAL_METADATA; ops[1].data.recv_initial_metadata = &(ctx->recv_initial_metadata); ops[1].flags = 0; + ops[1].reserved = NULL; ops[2].op = GRPC_OP_RECV_STATUS_ON_CLIENT; ops[2].data.recv_status_on_client.trailing_metadata = @@ -651,6 +668,7 @@ grpcsharp_call_start_duplex_streaming(grpc_call *call, ops[2].data.recv_status_on_client.status_details_capacity = &(ctx->recv_status_on_client.status_details_capacity); ops[2].flags = 0; + ops[2].reserved = NULL; return grpc_call_start_batch(call, ops, sizeof(ops) / sizeof(ops[0]), ctx, NULL); @@ -668,10 +686,12 @@ grpcsharp_call_send_message(grpc_call *call, grpcsharp_batch_context *ctx, ctx->send_message = string_to_byte_buffer(send_buffer, send_buffer_len); ops[0].data.send_message = ctx->send_message; ops[0].flags = write_flags; + ops[0].reserved = NULL; ops[1].op = GRPC_OP_SEND_INITIAL_METADATA; ops[1].data.send_initial_metadata.count = 0; ops[1].data.send_initial_metadata.metadata = NULL; ops[1].flags = 0; + ops[1].reserved = NULL; return grpc_call_start_batch(call, ops, nops, ctx, NULL); } @@ -683,6 +703,7 @@ grpcsharp_call_send_close_from_client(grpc_call *call, grpc_op ops[1]; ops[0].op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; ops[0].flags = 0; + ops[0].reserved = NULL; return grpc_call_start_batch(call, ops, sizeof(ops) / sizeof(ops[0]), ctx, NULL); @@ -706,10 +727,12 @@ GPR_EXPORT grpc_call_error GPR_CALLTYPE grpcsharp_call_send_status_from_server( ops[0].data.send_status_from_server.trailing_metadata = ctx->send_status_from_server.trailing_metadata.metadata; ops[0].flags = 0; + ops[0].reserved = NULL; ops[1].op = GRPC_OP_SEND_INITIAL_METADATA; ops[1].data.send_initial_metadata.count = 0; ops[1].data.send_initial_metadata.metadata = NULL; ops[1].flags = 0; + ops[1].reserved = NULL; return grpc_call_start_batch(call, ops, nops, ctx, NULL); } @@ -721,6 +744,7 @@ grpcsharp_call_recv_message(grpc_call *call, grpcsharp_batch_context *ctx) { ops[0].op = GRPC_OP_RECV_MESSAGE; ops[0].data.recv_message = &(ctx->recv_message); ops[0].flags = 0; + ops[0].reserved = NULL; return grpc_call_start_batch(call, ops, sizeof(ops) / sizeof(ops[0]), ctx, NULL); } @@ -733,6 +757,7 @@ grpcsharp_call_start_serverside(grpc_call *call, grpcsharp_batch_context *ctx) { ops[0].data.recv_close_on_server.cancelled = (&ctx->recv_close_on_server_cancelled); ops[0].flags = 0; + ops[0].reserved = NULL; return grpc_call_start_batch(call, ops, sizeof(ops) / sizeof(ops[0]), ctx, NULL); @@ -751,6 +776,7 @@ grpcsharp_call_send_initial_metadata(grpc_call *call, ops[0].data.send_initial_metadata.metadata = ctx->send_initial_metadata.metadata; ops[0].flags = 0; + ops[0].reserved = NULL; return grpc_call_start_batch(call, ops, sizeof(ops) / sizeof(ops[0]), ctx, NULL); diff --git a/src/node/ext/call.cc b/src/node/ext/call.cc index 705c80ffc1..a79a47427f 100644 --- a/src/node/ext/call.cc +++ b/src/node/ext/call.cc @@ -581,6 +581,7 @@ NAN_METHOD(Call::StartBatch) { uint32_t type = keys->Get(i)->Uint32Value(); ops[i].op = static_cast<grpc_op_type>(type); ops[i].flags = 0; + ops[i].reserved = NULL; switch (type) { case GRPC_OP_SEND_INITIAL_METADATA: op.reset(new SendMetadataOp()); diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c index 1cf766c312..4e40dc43ce 100644 --- a/src/php/ext/grpc/call.c +++ b/src/php/ext/grpc/call.c @@ -398,6 +398,7 @@ PHP_METHOD(Call, startBatch) { } ops[op_num].op = (grpc_op_type)index; ops[op_num].flags = 0; + ops[op_num].reserved = NULL; op_num++; } error = grpc_call_start_batch(call->wrapped, ops, op_num, call->wrapped, diff --git a/src/python/grpcio/grpc/_adapter/_c/utility.c b/src/python/grpcio/grpc/_adapter/_c/utility.c index 2eea0e18ef..590f7e013a 100644 --- a/src/python/grpcio/grpc/_adapter/_c/utility.c +++ b/src/python/grpcio/grpc/_adapter/_c/utility.c @@ -184,6 +184,7 @@ int pygrpc_produce_op(PyObject *op, grpc_op *result) { return 0; } c_op.op = type; + c_op.reserved = NULL; c_op.flags = PyInt_AsLong(PyTuple_GET_ITEM(op, WRITE_FLAGS_INDEX)); if (PyErr_Occurred()) { return 0; diff --git a/src/python/grpcio/grpc/early_adopter/implementations.py b/src/python/grpcio/grpc/early_adopter/implementations.py index 10919fae69..9c396aa7ad 100644 --- a/src/python/grpcio/grpc/early_adopter/implementations.py +++ b/src/python/grpcio/grpc/early_adopter/implementations.py @@ -41,13 +41,15 @@ from grpc.framework.base import util as _base_utilities from grpc.framework.face import implementations as _face_implementations from grpc.framework.foundation import logging_pool -_THREAD_POOL_SIZE = 8 +_DEFAULT_THREAD_POOL_SIZE = 8 _ONE_DAY_IN_SECONDS = 24 * 60 * 60 class _Server(interfaces.Server): - def __init__(self, breakdown, port, private_key, certificate_chain): + def __init__( + self, breakdown, port, private_key, certificate_chain, + thread_pool_size=_DEFAULT_THREAD_POOL_SIZE): self._lock = threading.Lock() self._breakdown = breakdown self._port = port @@ -56,6 +58,7 @@ class _Server(interfaces.Server): else: self._key_chain_pairs = ((private_key, certificate_chain),) + self._pool_size = thread_pool_size self._pool = None self._back = None self._fore_link = None @@ -63,7 +66,7 @@ class _Server(interfaces.Server): def _start(self): with self._lock: if self._pool is None: - self._pool = logging_pool.pool(_THREAD_POOL_SIZE) + self._pool = logging_pool.pool(self._pool_size) servicer = _face_implementations.servicer( self._pool, self._breakdown.implementations, None) self._back = _base_implementations.back_link( @@ -114,7 +117,8 @@ class _Stub(interfaces.Stub): def __init__( self, breakdown, host, port, secure, root_certificates, private_key, - certificate_chain, metadata_transformer=None, server_host_override=None): + certificate_chain, metadata_transformer=None, server_host_override=None, + thread_pool_size=_DEFAULT_THREAD_POOL_SIZE): self._lock = threading.Lock() self._breakdown = breakdown self._host = host @@ -126,6 +130,7 @@ class _Stub(interfaces.Stub): self._metadata_transformer = metadata_transformer self._server_host_override = server_host_override + self._pool_size = thread_pool_size self._pool = None self._front = None self._rear_link = None @@ -134,7 +139,7 @@ class _Stub(interfaces.Stub): def __enter__(self): with self._lock: if self._pool is None: - self._pool = logging_pool.pool(_THREAD_POOL_SIZE) + self._pool = logging_pool.pool(self._pool_size) self._front = _base_implementations.front_link( self._pool, self._pool, self._pool) self._rear_link = _rear.RearLink( @@ -193,7 +198,7 @@ class _Stub(interfaces.Stub): def stub( service_name, methods, host, port, metadata_transformer=None, secure=False, root_certificates=None, private_key=None, certificate_chain=None, - server_host_override=None): + server_host_override=None, thread_pool_size=_DEFAULT_THREAD_POOL_SIZE): """Constructs an interfaces.Stub. Args: @@ -216,6 +221,8 @@ def stub( certificate chain should be used. server_host_override: (For testing only) the target name used for SSL host name checking. + thread_pool_size: The maximum number of threads to allow in the backing + thread pool. Returns: An interfaces.Stub affording RPC invocation. @@ -224,11 +231,13 @@ def stub( return _Stub( breakdown, host, port, secure, root_certificates, private_key, certificate_chain, server_host_override=server_host_override, - metadata_transformer=metadata_transformer) + metadata_transformer=metadata_transformer, + thread_pool_size=thread_pool_size) def server( - service_name, methods, port, private_key=None, certificate_chain=None): + service_name, methods, port, private_key=None, certificate_chain=None, + thread_pool_size=_DEFAULT_THREAD_POOL_SIZE): """Constructs an interfaces.Server. Args: @@ -242,9 +251,12 @@ def server( private_key: A pem-encoded private key, or None for an insecure server. certificate_chain: A pem-encoded certificate chain, or None for an insecure server. + thread_pool_size: The maximum number of threads to allow in the backing + thread pool. Returns: An interfaces.Server that will serve secure traffic. """ breakdown = _face_utilities.break_down_service(service_name, methods) - return _Server(breakdown, port, private_key, certificate_chain) + return _Server(breakdown, port, private_key, certificate_chain, + thread_pool_size=thread_pool_size) diff --git a/src/ruby/ext/grpc/rb_call.c b/src/ruby/ext/grpc/rb_call.c index b09d4e2cd9..36c6818a7e 100644 --- a/src/ruby/ext/grpc/rb_call.c +++ b/src/ruby/ext/grpc/rb_call.c @@ -526,6 +526,7 @@ static void grpc_run_batch_stack_fill_ops(run_batch_stack *st, VALUE ops_hash) { }; st->ops[st->op_num].op = (grpc_op_type)NUM2INT(this_op); st->ops[st->op_num].flags = 0; + st->ops[st->op_num].reserved = NULL; st->op_num++; } } |