1 /* 2 * LatencyBandConfig.h 3 * 4 * This source file is part of the FoundationDB open source project 5 * 6 * Copyright 2013-2019 Apple Inc. and the FoundationDB project authors 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 21 #ifndef FDBSERVER_LATENCYBANDCONFIG_H 22 #define FDBSERVER_LATENCYBANDCONFIG_H 23 #pragma once 24 25 #include "fdbclient/FDBTypes.h" 26 #include "fdbclient/JSONDoc.h" 27 28 struct LatencyBandConfig { 29 struct RequestConfig { 30 std::set<double> bands; 31 32 friend bool operator==(RequestConfig const& lhs, RequestConfig const& rhs); 33 friend bool operator!=(RequestConfig const& lhs, RequestConfig const& rhs); 34 35 virtual void fromJson(JSONDoc json); 36 37 template <class Ar> serializeLatencyBandConfig::RequestConfig38 void serialize(Ar& ar) { 39 uint64_t bandsSize = (uint64_t)bands.size(); 40 serializer(ar, bandsSize); 41 42 if(ar.isDeserializing) { 43 double band; 44 for(uint64_t i = 0; i < bandsSize; i++) { 45 serializer(ar, band); 46 bands.insert(band); 47 } 48 } 49 else { 50 for(double band : bands) { 51 serializer(ar, band); 52 } 53 } 54 } 55 56 protected: 57 virtual bool isEqual(RequestConfig const& r) const; 58 }; 59 60 struct GrvConfig : RequestConfig {}; 61 62 struct ReadConfig : RequestConfig { 63 Optional<int> maxReadBytes; 64 Optional<int> maxKeySelectorOffset; 65 66 virtual void fromJson(JSONDoc json); 67 68 template <class Ar> serializeLatencyBandConfig::ReadConfig69 void serialize(Ar& ar) { 70 serializer(ar, *(RequestConfig*)this, maxReadBytes, maxKeySelectorOffset); 71 } 72 73 protected: 74 virtual bool isEqual(RequestConfig const& r) const; 75 }; 76 77 struct CommitConfig : RequestConfig { 78 Optional<int> maxCommitBytes; 79 80 virtual void fromJson(JSONDoc json); 81 82 template <class Ar> serializeLatencyBandConfig::CommitConfig83 void serialize(Ar& ar) { 84 serializer(ar, *(RequestConfig*)this, maxCommitBytes); 85 } 86 87 protected: 88 virtual bool isEqual(RequestConfig const& r) const; 89 }; 90 91 GrvConfig grvConfig; 92 ReadConfig readConfig; 93 CommitConfig commitConfig; 94 95 template <class Ar> serializeLatencyBandConfig96 void serialize(Ar& ar) { 97 serializer(ar, grvConfig, readConfig, commitConfig); 98 } 99 100 static Optional<LatencyBandConfig> parse(ValueRef configurationString); 101 102 bool operator==(LatencyBandConfig const& r) const; 103 bool operator!=(LatencyBandConfig const& r) const; 104 }; 105 106 #endif 107