@@ -66,6 +66,10 @@ public abstract class TableOptions<T extends TableOptions> extends SchemaStateme
66
66
67
67
private Optional <Boolean > replicateOnWrite = Optional .absent ();
68
68
69
+ private Optional <Integer > maxReadsPerSecond = Optional .absent ();
70
+
71
+ private Optional <Integer > maxWritesPerSecond = Optional .absent ();
72
+
69
73
private Optional <SpeculativeRetryValue > speculativeRetry = Optional .absent ();
70
74
71
75
private Optional <Boolean > cdc = Optional .absent ();
@@ -348,6 +352,36 @@ public T replicateOnWrite(Boolean replicateOnWrite) {
348
352
return self ;
349
353
}
350
354
355
+ /**
356
+ * Sets rate limit for read operations in table option "per_partition_rate_limit". NOTE: Due to
357
+ * ScyllaDB’s distributed nature, tracking per-partition request rates is not perfect and the
358
+ * actual rate of accepted requests may be higher up to a factor of keyspace’s RF. This feature
359
+ * should not be used to enforce precise limits but rather serve as an overload protection
360
+ * feature.
361
+ *
362
+ * @param maxReadsPerSecond rate limit for read operations
363
+ * @return this {@code TableOptions} object.
364
+ */
365
+ public T maxReadsPerSecond (int maxReadsPerSecond ) {
366
+ this .maxReadsPerSecond = Optional .of (maxReadsPerSecond );
367
+ return self ;
368
+ }
369
+
370
+ /**
371
+ * Sets rate limit for write operations in table option "per_partition_rate_limit". NOTE: Due to
372
+ * ScyllaDB’s distributed nature, tracking per-partition request rates is not perfect and the
373
+ * actual rate of accepted requests may be higher up to a factor of keyspace’s RF. This feature
374
+ * should not be used to enforce precise limits but rather serve as an overload protection
375
+ * feature.
376
+ *
377
+ * @param maxWritesPerSecond rate limit for write operations
378
+ * @return this {@code TableOptions} object.
379
+ */
380
+ public T maxWritesPerSecond (int maxWritesPerSecond ) {
381
+ this .maxWritesPerSecond = Optional .of (maxWritesPerSecond );
382
+ return self ;
383
+ }
384
+
351
385
/**
352
386
* To override normal read timeout when read_repair_chance is not 1.0, sending another request to
353
387
* read, choose one of these values and use the property to create or alter the table:
@@ -518,6 +552,25 @@ private List<String> buildCommonOptions() {
518
552
options .add ("replicate_on_write = " + replicateOnWrite .get ());
519
553
}
520
554
555
+ if (maxReadsPerSecond .isPresent () || maxWritesPerSecond .isPresent ()) {
556
+ StringBuilder sBuilder = new StringBuilder ("per_partition_rate_limit = {" );
557
+
558
+ if (maxReadsPerSecond .isPresent ()) {
559
+ sBuilder .append ("'max_reads_per_second': " ).append (maxReadsPerSecond .get ());
560
+
561
+ if (maxWritesPerSecond .isPresent ()) {
562
+ sBuilder .append (", " );
563
+ }
564
+ }
565
+
566
+ if (maxWritesPerSecond .isPresent ()) {
567
+ sBuilder .append ("'max_writes_per_second': " ).append (maxWritesPerSecond .get ());
568
+ }
569
+
570
+ sBuilder .append ("}" );
571
+ options .add (sBuilder .toString ());
572
+ }
573
+
521
574
if (speculativeRetry .isPresent ()) {
522
575
options .add ("speculative_retry = " + speculativeRetry .get ().value ());
523
576
}
0 commit comments