xref: /aosp_15_r20/external/grpc-grpc/src/core/load_balancing/ring_hash/ring_hash.h (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1 //
2 // Copyright 2018 gRPC authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #ifndef GRPC_SRC_CORE_LOAD_BALANCING_RING_HASH_RING_HASH_H
18 #define GRPC_SRC_CORE_LOAD_BALANCING_RING_HASH_RING_HASH_H
19 
20 #include <grpc/support/port_platform.h>
21 
22 #include <stdint.h>
23 
24 #include "src/core/lib/gprpp/unique_type_name.h"
25 #include "src/core/lib/gprpp/validation_errors.h"
26 #include "src/core/lib/json/json.h"
27 #include "src/core/lib/json/json_args.h"
28 #include "src/core/lib/json/json_object_loader.h"
29 #include "src/core/service_config/service_config_call_data.h"
30 
31 namespace grpc_core {
32 
33 class RequestHashAttribute final
34     : public ServiceConfigCallData::CallAttributeInterface {
35  public:
36   static UniqueTypeName TypeName();
37 
RequestHashAttribute(uint64_t request_hash)38   explicit RequestHashAttribute(uint64_t request_hash)
39       : request_hash_(request_hash) {}
40 
request_hash()41   uint64_t request_hash() const { return request_hash_; }
42 
43  private:
type()44   UniqueTypeName type() const override { return TypeName(); }
45 
46   uint64_t request_hash_;
47 };
48 
49 // Helper Parsing method to parse ring hash policy configs; for example, ring
50 // hash size validity.
51 struct RingHashConfig {
52   uint64_t min_ring_size = 1024;
53   uint64_t max_ring_size = 4096;
54 
55   static const JsonLoaderInterface* JsonLoader(const JsonArgs&);
56   void JsonPostLoad(const Json& json, const JsonArgs&,
57                     ValidationErrors* errors);
58 };
59 
60 }  // namespace grpc_core
61 
62 #endif  // GRPC_SRC_CORE_LOAD_BALANCING_RING_HASH_RING_HASH_H
63