Removed compression levels from clients and _experimental_'d signature of methods manipulating compression algorithms

pull/2135/head
David Garcia Quintas 10 years ago
parent 7c4fdb5628
commit cadbf22467
  1. 5
      include/grpc++/channel_arguments.h
  2. 12
      include/grpc++/client_context.h
  3. 2
      include/grpc/compression.h
  4. 14
      src/core/channel/channel_args.c
  5. 12
      src/core/channel/channel_args.h
  6. 24
      src/core/channel/compress_filter.c
  7. 6
      src/core/channel/compress_filter.h
  8. 5
      src/cpp/client/channel_arguments.cc
  9. 8
      src/cpp/client/client_context.cc
  10. 8
      test/core/end2end/fixtures/chttp2_fullstack_compression.c
  11. 26
      test/core/end2end/tests/request_with_compressed_payload.c
  12. 2
      test/cpp/end2end/end2end_test.cc
  13. 2
      test/cpp/end2end/generic_end2end_test.cc

@ -59,8 +59,9 @@ class ChannelArguments {
void SetSslTargetNameOverride(const grpc::string& name);
// TODO(yangg) add flow control options
// Set the compression level for the channel.
void SetCompressionLevel(grpc_compression_level level);
// Set the compression algorithm for the channel.
void _Experimental_SetCompressionAlgorithm(
grpc_compression_algorithm algorithm);
// Generic channel argument setters. Only for advanced use cases.
void SetInt(const grpc::string& key, int value);

@ -110,15 +110,12 @@ class ClientContext {
creds_ = creds;
}
grpc_compression_level get_compression_level() const {
return compression_level_;
}
void set_compression_level(grpc_compression_level level);
grpc_compression_algorithm get_compression_algorithm() const {
grpc_compression_algorithm _experimental_get_compression_algorithm() const {
return compression_algorithm_;
}
void set_compression_algorithm(grpc_compression_algorithm algorithm);
void _experimental_set_compression_algorithm(
grpc_compression_algorithm algorithm);
std::shared_ptr<const AuthContext> auth_context() const;
@ -179,7 +176,6 @@ class ClientContext {
std::multimap<grpc::string, grpc::string> recv_initial_metadata_;
std::multimap<grpc::string, grpc::string> trailing_metadata_;
grpc_compression_level compression_level_;
grpc_compression_algorithm compression_algorithm_;
};

@ -39,7 +39,7 @@ extern "C" {
#endif
/** To be used in channel arguments */
#define GRPC_COMPRESSION_LEVEL_ARG "grpc.compression_level"
#define GRPC_COMPRESSION_ALGORITHM_ARG "grpc.compression_algorithm"
/* The various compression algorithms supported by GRPC */
typedef enum {

@ -124,25 +124,25 @@ int grpc_channel_args_is_census_enabled(const grpc_channel_args *a) {
return 0;
}
grpc_compression_level grpc_channel_args_get_compression_level(
grpc_compression_algorithm grpc_channel_args_get_compression_algorithm(
const grpc_channel_args *a) {
size_t i;
if (a == NULL) return 0;
for (i = 0; i < a->num_args; ++i) {
if (a->args[i].type == GRPC_ARG_INTEGER &&
!strcmp(GRPC_COMPRESSION_LEVEL_ARG, a->args[i].key)) {
!strcmp(GRPC_COMPRESSION_ALGORITHM_ARG, a->args[i].key)) {
return a->args[i].value.integer;
break;
}
}
return GRPC_COMPRESS_LEVEL_NONE;
return GRPC_COMPRESS_NONE;
}
grpc_channel_args *grpc_channel_args_set_compression_level(
grpc_channel_args *a, grpc_compression_level level) {
grpc_channel_args *grpc_channel_args_set_compression_algorithm(
grpc_channel_args *a, grpc_compression_algorithm algorithm) {
grpc_arg tmp;
tmp.type = GRPC_ARG_INTEGER;
tmp.key = GRPC_COMPRESSION_LEVEL_ARG;
tmp.value.integer = level;
tmp.key = GRPC_COMPRESSION_ALGORITHM_ARG;
tmp.value.integer = algorithm;
return grpc_channel_args_copy_and_add(a, &tmp, 1);
}

@ -57,14 +57,14 @@ void grpc_channel_args_destroy(grpc_channel_args *a);
* is specified in channel args, otherwise returns 0. */
int grpc_channel_args_is_census_enabled(const grpc_channel_args *a);
/** Returns the compression level set in \a a. */
grpc_compression_level grpc_channel_args_get_compression_level(
/** Returns the compression algorithm set in \a a. */
grpc_compression_algorithm grpc_channel_args_get_compression_algorithm(
const grpc_channel_args *a);
/** Returns a channel arg instance with compression enabled. If \a a is
* non-NULL, its args are copied. N.B. GRPC_COMPRESS_LEVEL_NONE disables
* compression for the channel. */
grpc_channel_args *grpc_channel_args_set_compression_level(
grpc_channel_args *a, grpc_compression_level level);
* non-NULL, its args are copied. N.B. GRPC_COMPRESS_NONE disables compression
* for the channel. */
grpc_channel_args *grpc_channel_args_set_compression_algorithm(
grpc_channel_args *a, grpc_compression_algorithm algorithm);
#endif /* GRPC_INTERNAL_CORE_CHANNEL_CHANNEL_ARGS_H */

@ -31,6 +31,26 @@
*
*/
/** Compression filter for outgoing data.
*
* Compression settings may come from:
* - Channel configuration, as established at channel creation time.
* - The metadata accompanying the outgoing data to be compressed. This is
* taken as a request only. We may choose not to honor it. The metadata key
* is given by \a GRPC_COMPRESS_REQUEST_ALGORITHM_KEY.
*
* Compression can be disabled for concrete messages (for instance in order to
* prevent CRIME/BEAST type attacks) by having the GRPC_WRITE_NO_COMPRESS set in
* the BEGIN_MESSAGE flags.
*
* The attempted compression mechanism is added to the resulting initial
* metadata under the'grpc-encoding' key.
*
* If compression is actually performed, BEGIN_MESSAGE's flag is modified to
* incorporate GRPC_WRITE_INTERNAL_COMPRESS. Otherwise, and regardless of the
* aforementioned 'grpc-encoding' metadata value, data will pass through
* uncompressed. */
#include <assert.h>
#include <string.h>
@ -277,11 +297,9 @@ static void init_channel_elem(grpc_channel_element *elem, grpc_channel *master,
int is_first, int is_last) {
channel_data *channeld = elem->channel_data;
grpc_compression_algorithm algo_idx;
const grpc_compression_level clevel =
grpc_channel_args_get_compression_level(args);
channeld->default_compression_algorithm =
grpc_compression_algorithm_for_level(clevel);
grpc_channel_args_get_compression_algorithm(args);
channeld->mdstr_request_compression_algorithm_key =
grpc_mdstr_from_string(mdctx, GRPC_COMPRESS_REQUEST_ALGORITHM_KEY);

@ -40,11 +40,7 @@
/** Message-level compression filter.
*
* See <grpc/compression.h> for the available compression levels.
*
* Use grpc_channel_args_set_compression_level and
* grpc_channel_args_get_compression_level to interact with the compression
* settings for a channel.
* See <grpc/compression.h> for the available compression settings.
*
* grpc_op instances of type GRPC_OP_SEND_MESSAGE can have the bit specified by
* the GRPC_WRITE_NO_COMPRESS mask in order to disable compression in an

@ -37,8 +37,9 @@
namespace grpc {
void ChannelArguments::SetCompressionLevel(grpc_compression_level level) {
SetInt(GRPC_COMPRESSION_LEVEL_ARG, level);
void ChannelArguments::_Experimental_SetCompressionAlgorithm(
grpc_compression_algorithm algorithm) {
SetInt(GRPC_COMPRESSION_ALGORITHM_ARG, algorithm);
}
void ChannelArguments::SetInt(const grpc::string& key, int value) {

@ -79,13 +79,7 @@ void ClientContext::set_call(grpc_call* call,
}
}
void ClientContext::set_compression_level(grpc_compression_level level) {
const grpc_compression_algorithm algorithm_for_level =
grpc_compression_algorithm_for_level(level);
set_compression_algorithm(algorithm_for_level);
}
void ClientContext::set_compression_algorithm(
void ClientContext::_experimental_set_compression_algorithm(
grpc_compression_algorithm algorithm) {
char* algorithm_name = NULL;
if (!grpc_compression_algorithm_name(algorithm, &algorithm_name)) {

@ -80,8 +80,8 @@ void chttp2_init_client_fullstack_compression(grpc_end2end_test_fixture *f,
if (ffd->client_args_compression != NULL) {
grpc_channel_args_destroy(ffd->client_args_compression);
}
ffd->client_args_compression = grpc_channel_args_set_compression_level(
client_args, GRPC_COMPRESS_LEVEL_HIGH);
ffd->client_args_compression = grpc_channel_args_set_compression_algorithm(
client_args, GRPC_COMPRESS_GZIP);
f->client = grpc_channel_create(ffd->localaddr, ffd->client_args_compression);
}
@ -91,8 +91,8 @@ void chttp2_init_server_fullstack_compression(grpc_end2end_test_fixture *f,
if (ffd->server_args_compression != NULL) {
grpc_channel_args_destroy(ffd->server_args_compression);
}
ffd->server_args_compression = grpc_channel_args_set_compression_level(
server_args, GRPC_COMPRESS_LEVEL_HIGH);
ffd->server_args_compression = grpc_channel_args_set_compression_algorithm(
server_args, GRPC_COMPRESS_GZIP);
if (f->server) {
grpc_server_destroy(f->server);
}

@ -104,7 +104,7 @@ static void end_test(grpc_end2end_test_fixture *f) {
static void request_with_payload_template(
grpc_end2end_test_config config, const char *test_name,
gpr_uint32 send_flags_bitmask,
grpc_compression_level requested_compression_level,
grpc_compression_algorithm requested_compression_algorithm,
grpc_compression_algorithm expected_compression_algorithm,
grpc_metadata *client_metadata) {
grpc_call *c;
@ -133,10 +133,10 @@ static void request_with_payload_template(
request_payload_slice = gpr_slice_from_copied_string(str);
request_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1);
client_args = grpc_channel_args_set_compression_level(
NULL, requested_compression_level);
server_args = grpc_channel_args_set_compression_level(
NULL, requested_compression_level);
client_args = grpc_channel_args_set_compression_algorithm(
NULL, requested_compression_algorithm);
server_args = grpc_channel_args_set_compression_algorithm(
NULL, requested_compression_algorithm);
f = begin_test(config, test_name, client_args, server_args);
cqv = cq_verifier_create(f.cq);
@ -256,7 +256,7 @@ static void test_invoke_request_with_exceptionally_uncompressed_payload(
grpc_end2end_test_config config) {
request_with_payload_template(
config, "test_invoke_request_with_exceptionally_uncompressed_payload",
GRPC_WRITE_NO_COMPRESS, GRPC_COMPRESS_LEVEL_HIGH, GRPC_COMPRESS_NONE,
GRPC_WRITE_NO_COMPRESS, GRPC_COMPRESS_GZIP, GRPC_COMPRESS_NONE,
NULL);
}
@ -264,16 +264,14 @@ static void test_invoke_request_with_uncompressed_payload(
grpc_end2end_test_config config) {
request_with_payload_template(
config, "test_invoke_request_with_uncompressed_payload", 0,
GRPC_COMPRESS_LEVEL_NONE,
grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_NONE), NULL);
GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE, NULL);
}
static void test_invoke_request_with_compressed_payload(
grpc_end2end_test_config config) {
request_with_payload_template(
config, "test_invoke_request_with_compressed_payload", 0,
GRPC_COMPRESS_LEVEL_HIGH,
grpc_compression_algorithm_for_level(GRPC_COMPRESS_LEVEL_HIGH), NULL);
GRPC_COMPRESS_GZIP, GRPC_COMPRESS_GZIP, NULL);
}
static void test_invoke_request_with_compressed_payload_md_override(
@ -296,19 +294,17 @@ static void test_invoke_request_with_compressed_payload_md_override(
/* Channel default NONE, call override to GZIP */
request_with_payload_template(
config, "test_invoke_request_with_compressed_payload_md_override_1", 0,
GRPC_COMPRESS_LEVEL_NONE, GRPC_COMPRESS_GZIP, &gzip_compression_override);
GRPC_COMPRESS_NONE, GRPC_COMPRESS_GZIP, &gzip_compression_override);
/* Channel default DEFLATE, call override to GZIP */
request_with_payload_template(
config, "test_invoke_request_with_compressed_payload_md_override_2", 0,
grpc_compression_level_for_algorithm(GRPC_COMPRESS_DEFLATE),
GRPC_COMPRESS_GZIP, &gzip_compression_override);
GRPC_COMPRESS_DEFLATE, GRPC_COMPRESS_GZIP, &gzip_compression_override);
/* Channel default DEFLATE, call override to NONE */
request_with_payload_template(
config, "test_invoke_request_with_compressed_payload_md_override_3", 0,
grpc_compression_level_for_algorithm(GRPC_COMPRESS_DEFLATE),
GRPC_COMPRESS_NONE, &none_compression_override);
GRPC_COMPRESS_DEFLATE, GRPC_COMPRESS_NONE, &none_compression_override);
}
void grpc_end2end_tests(grpc_end2end_test_config config) {

@ -271,7 +271,7 @@ static void SendRpc(grpc::cpp::test::util::TestService::Stub* stub,
for (int i = 0; i < num_rpcs; ++i) {
ClientContext context;
context.set_compression_level(GRPC_COMPRESS_LEVEL_HIGH);
context._experimental_set_compression_algorithm(GRPC_COMPRESS_GZIP);
Status s = stub->Echo(&context, request, &response);
EXPECT_EQ(response.message(), request.message());
EXPECT_TRUE(s.ok());

@ -227,7 +227,7 @@ TEST_F(GenericEnd2endTest, SimpleBidiStreaming) {
GenericServerContext srv_ctx;
GenericServerAsyncReaderWriter srv_stream(&srv_ctx);
cli_ctx.set_compression_level(GRPC_COMPRESS_LEVEL_HIGH);
cli_ctx._experimental_set_compression_algorithm(GRPC_COMPRESS_GZIP);
send_request.set_message("Hello");
std::unique_ptr<GenericClientAsyncReaderWriter> cli_stream =
generic_stub_->Call(&cli_ctx, kMethodName, &cli_cq_, tag(1));

Loading…
Cancel
Save