Skip to content

Commit aa61536

Browse files
committed
Merge branch 'cassandra-6.0' into trunk
* cassandra-6.0: Avoid unit conversion in DatabaseDescriptor.getMaxValueSize() for every deserializing Cell
2 parents cbbd401 + 3e75652 commit aa61536

5 files changed

Lines changed: 35 additions & 6 deletions

File tree

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Merged from 6.0:
77
* Introduce minimum_threshold for data resurrection startup check (CASSANDRA-21293)
88

99
6.0-alpha2
10+
* Avoid unit conversion in DatabaseDescriptor.getMaxValueSize() for every deserializing Cell (CASSANDRA-21295)
1011
* Fix single token batch atomicity with Accord/non-Accord batches by using the batch log (CASSANDRA-20588)
1112
* Avoid CompactionOptions parsing for every read by WithoutPurgeableTombstones (CASSANDRA-21294)
1213
* Synchronously publish changes to local gossip state following metadata updates (CASSANDRA-21239)

src/java/org/apache/cassandra/config/DataStorageSpec.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ public String toString()
170170
*/
171171
public final static class LongBytesBound extends DataStorageSpec
172172
{
173+
private final long bytes;
174+
173175
/**
174176
* Creates a {@code DataStorageSpec.LongBytesBound} of the specified amount.
175177
*
@@ -178,6 +180,7 @@ public final static class LongBytesBound extends DataStorageSpec
178180
public LongBytesBound(String value)
179181
{
180182
super(value, BYTES, Long.MAX_VALUE);
183+
bytes = unit().toBytes(quantity());
181184
}
182185

183186
/**
@@ -189,6 +192,7 @@ public LongBytesBound(String value)
189192
public LongBytesBound(long quantity, DataStorageUnit unit)
190193
{
191194
super(quantity, unit, BYTES, Long.MAX_VALUE, quantity + unit.symbol);
195+
bytes = unit().toBytes(quantity());
192196
}
193197

194198
/**
@@ -206,7 +210,7 @@ public LongBytesBound(long bytes)
206210
*/
207211
public long toBytes()
208212
{
209-
return unit().toBytes(quantity());
213+
return bytes;
210214
}
211215

212216
/**
@@ -225,6 +229,8 @@ public int toMebibytesInt()
225229
*/
226230
public final static class IntBytesBound extends DataStorageSpec
227231
{
232+
private final int bytes;
233+
228234
/**
229235
* Creates a {@code DataStorageSpec.IntBytesBound} of the specified amount.
230236
*
@@ -233,6 +239,7 @@ public final static class IntBytesBound extends DataStorageSpec
233239
public IntBytesBound(String value)
234240
{
235241
super(value, BYTES, Integer.MAX_VALUE);
242+
bytes = Ints.saturatedCast(unit().toBytes(quantity()));
236243
}
237244

238245
/**
@@ -244,6 +251,7 @@ public IntBytesBound(String value)
244251
public IntBytesBound(long quantity, DataStorageUnit unit)
245252
{
246253
super(quantity, unit, BYTES, Integer.MAX_VALUE, quantity + unit.symbol);
254+
bytes = Ints.saturatedCast(unit().toBytes(quantity()));
247255
}
248256

249257
/**
@@ -263,7 +271,7 @@ public IntBytesBound(long bytes)
263271
*/
264272
public int toBytes()
265273
{
266-
return Ints.saturatedCast(unit().toBytes(quantity()));
274+
return bytes;
267275
}
268276
}
269277

@@ -274,6 +282,8 @@ public int toBytes()
274282
*/
275283
public final static class IntKibibytesBound extends DataStorageSpec
276284
{
285+
private final int bytes;
286+
277287
/**
278288
* Creates a {@code DataStorageSpec.IntKibibytesBound} of the specified amount.
279289
*
@@ -282,6 +292,7 @@ public final static class IntKibibytesBound extends DataStorageSpec
282292
public IntKibibytesBound(String value)
283293
{
284294
super(value, KIBIBYTES, Integer.MAX_VALUE);
295+
bytes = Ints.saturatedCast(unit().toBytes(quantity()));
285296
}
286297

287298
/**
@@ -293,6 +304,7 @@ public IntKibibytesBound(String value)
293304
public IntKibibytesBound(long quantity, DataStorageUnit unit)
294305
{
295306
super(quantity, unit, KIBIBYTES, Integer.MAX_VALUE, quantity + unit.symbol);
307+
bytes = Ints.saturatedCast(unit().toBytes(quantity()));
296308
}
297309

298310
/**
@@ -312,7 +324,7 @@ public IntKibibytesBound(long kibibytes)
312324
*/
313325
public int toBytes()
314326
{
315-
return Ints.saturatedCast(unit().toBytes(quantity()));
327+
return bytes;
316328
}
317329

318330
/**
@@ -341,6 +353,8 @@ public long toBytesInLong()
341353
*/
342354
public final static class LongMebibytesBound extends DataStorageSpec
343355
{
356+
private final long bytes;
357+
344358
/**
345359
* Creates a {@code DataStorageSpec.LongMebibytesBound} of the specified amount.
346360
*
@@ -349,6 +363,7 @@ public final static class LongMebibytesBound extends DataStorageSpec
349363
public LongMebibytesBound(String value)
350364
{
351365
super(value, MEBIBYTES, Long.MAX_VALUE);
366+
bytes = unit().toBytes(quantity());
352367
}
353368

354369
/**
@@ -360,6 +375,7 @@ public LongMebibytesBound(String value)
360375
public LongMebibytesBound(long quantity, DataStorageUnit unit)
361376
{
362377
super(quantity, unit, MEBIBYTES, Long.MAX_VALUE, quantity + unit.symbol);
378+
bytes = unit().toBytes(quantity());
363379
}
364380

365381
/**
@@ -377,7 +393,7 @@ public LongMebibytesBound(long mebibytes)
377393
*/
378394
public long toBytes()
379395
{
380-
return unit().toBytes(quantity());
396+
return bytes;
381397
}
382398

383399
/**
@@ -404,6 +420,7 @@ public long toMebibytes()
404420
*/
405421
public final static class IntMebibytesBound extends DataStorageSpec
406422
{
423+
private final int bytes;
407424
/**
408425
* Creates a {@code DataStorageSpec.IntMebibytesBound} of the specified amount.
409426
*
@@ -412,6 +429,7 @@ public final static class IntMebibytesBound extends DataStorageSpec
412429
public IntMebibytesBound(String value)
413430
{
414431
super(value, MEBIBYTES, Integer.MAX_VALUE);
432+
bytes = Ints.saturatedCast(unit().toBytes(quantity()));
415433
}
416434

417435
/**
@@ -423,6 +441,7 @@ public IntMebibytesBound(String value)
423441
public IntMebibytesBound(long quantity, DataStorageUnit unit)
424442
{
425443
super(quantity, unit, MEBIBYTES, Integer.MAX_VALUE, quantity + unit.symbol);
444+
bytes = Ints.saturatedCast(unit().toBytes(quantity()));
426445
}
427446

428447
/**
@@ -442,7 +461,7 @@ public IntMebibytesBound(long mebibytes)
442461
*/
443462
public int toBytes()
444463
{
445-
return Ints.saturatedCast(unit().toBytes(quantity()));
464+
return bytes;
446465
}
447466

448467
/**

src/java/org/apache/cassandra/config/DatabaseDescriptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2322,7 +2322,7 @@ public static int getMaxSecurityLabelLength()
23222322

23232323
public static int getMaxValueSize()
23242324
{
2325-
return Ints.saturatedCast(conf.max_value_size.toMebibytes() * 1024L * 1024);
2325+
return conf.max_value_size.toBytes();
23262326
}
23272327

23282328
public static void setMaxValueSize(int maxValueSizeInBytes)

test/unit/org/apache/cassandra/config/DataStorageSpecTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ public void testConversions()
4949
assertEquals(10240, new DataStorageSpec.LongMebibytesBound("10MiB").toKibibytes());
5050
assertEquals(1024 * 1024 * 1024, new DataStorageSpec.IntBytesBound("1GiB").toBytes());
5151
assertEquals(10240, new DataStorageSpec.IntKibibytesBound("10MiB").toKibibytes());
52+
assertEquals(10 * 1024 * 1024, new DataStorageSpec.IntKibibytesBound("10MiB").toBytes());
5253
assertEquals(1024, new DataStorageSpec.IntMebibytesBound("1GiB").toMebibytes());
54+
assertEquals(1024 * 1024 * 1024, new DataStorageSpec.IntMebibytesBound("1GiB").toBytes());
5355

5456
assertEquals(10, new DataStorageSpec.LongBytesBound(10, BYTES).toBytes());
5557
assertEquals(10240, new DataStorageSpec.LongBytesBound(10, KIBIBYTES).toBytes());

test/unit/org/apache/cassandra/config/DatabaseDescriptorTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,4 +1067,11 @@ else if (mode == Config.DiskAccessMode.auto)
10671067
assertThat(DatabaseDescriptor.getCommitLogWriteDiskAccessMode()).isEqualTo(mode);
10681068
}
10691069
}
1070+
1071+
@Test
1072+
public void testMaxValueSize()
1073+
{
1074+
Config config = DatabaseDescriptor.loadConfig();
1075+
Assert.assertEquals(config.max_value_size.toMebibytes() * 1024 * 1024, DatabaseDescriptor.getMaxValueSize());
1076+
}
10701077
}

0 commit comments

Comments
 (0)