@@ -96,6 +96,71 @@ class EvictionPolicy(NamedTuple):
9696 60
9797 )
9898
99+ def validate (self ) -> None :
100+ assert self .eviction_trigger_mode in [0 , 1 , 2 , 3 ], (
101+ "eviction_trigger_mode must be 0, 1, 2, or 3, "
102+ f"actual { self .eviction_trigger_mode } "
103+ )
104+ if self .eviction_trigger_mode == 0 :
105+ return
106+
107+ assert self .eviction_strategy in [0 , 1 , 2 , 3 ], (
108+ "eviction_strategy must be 0, 1, 2, or 3, "
109+ f"actual { self .eviction_strategy } "
110+ )
111+ if self .eviction_trigger_mode == 1 :
112+ assert (
113+ self .eviction_step_intervals is not None
114+ and self .eviction_step_intervals > 0
115+ ), (
116+ "eviction_step_intervals must be positive if eviction_trigger_mode is 1, "
117+ f"actual { self .eviction_step_intervals } "
118+ )
119+ elif self .eviction_trigger_mode == 2 :
120+ assert (
121+ self .eviction_mem_threshold_gb is not None
122+ ), "eviction_mem_threshold_gb must be set if eviction_trigger_mode is 2"
123+
124+ if self .eviction_strategy == 0 :
125+ assert self .ttls_in_mins is not None , (
126+ "ttls_in_mins must be set if eviction_strategy is 0, "
127+ f"actual { self .ttls_in_mins } "
128+ )
129+ elif self .eviction_strategy == 1 :
130+ assert self .counter_thresholds is not None , (
131+ "counter_thresholds must be set if eviction_strategy is 1, "
132+ f"actual { self .counter_thresholds } "
133+ )
134+ assert self .counter_decay_rates is not None , (
135+ "counter_decay_rates must be set if eviction_strategy is 1, "
136+ f"actual { self .counter_decay_rates } "
137+ )
138+ assert len (self .counter_thresholds ) == len (self .counter_decay_rates ), (
139+ "counter_thresholds and counter_decay_rates must have the same length, "
140+ f"actual { self .counter_thresholds } vs { self .counter_decay_rates } "
141+ )
142+ elif self .eviction_strategy == 2 :
143+ assert self .counter_thresholds is not None , (
144+ "counter_thresholds must be set if eviction_strategy is 2, "
145+ f"actual { self .counter_thresholds } "
146+ )
147+ assert self .counter_decay_rates is not None , (
148+ "counter_decay_rates must be set if eviction_strategy is 2, "
149+ f"actual { self .counter_decay_rates } "
150+ )
151+ assert self .ttls_in_mins is not None , (
152+ "ttls_in_mins must be set if eviction_strategy is 2, "
153+ f"actual { self .ttls_in_mins } "
154+ )
155+ assert len (self .counter_thresholds ) == len (self .counter_decay_rates ), (
156+ "counter_thresholds and counter_decay_rates must have the same length, "
157+ f"actual { self .counter_thresholds } vs { self .counter_decay_rates } "
158+ )
159+ assert len (self .counter_thresholds ) == len (self .ttls_in_mins ), (
160+ "counter_thresholds and ttls_in_mins must have the same length, "
161+ f"actual { self .counter_thresholds } vs { self .ttls_in_mins } "
162+ )
163+
99164
100165class KVZCHParams (NamedTuple ):
101166 # global bucket id start and global bucket id end offsets for each logical table,
@@ -113,6 +178,8 @@ def validate(self) -> None:
113178 "bucket_offsets and bucket_sizes must have the same length, "
114179 f"actual { self .bucket_offsets } vs { self .bucket_sizes } "
115180 )
181+ if self .eviction_policy is not None :
182+ self .eviction_policy .validate ()
116183
117184
118185class BackendType (enum .IntEnum ):
0 commit comments