Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions src/java/org/apache/cassandra/config/DataStorageSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ public String toString()
*/
public final static class LongBytesBound extends DataStorageSpec
{
private final long bytes;

/**
* Creates a {@code DataStorageSpec.LongBytesBound} of the specified amount.
*
Expand All @@ -178,6 +180,7 @@ public final static class LongBytesBound extends DataStorageSpec
public LongBytesBound(String value)
{
super(value, BYTES, Long.MAX_VALUE);
bytes = unit().toBytes(quantity());
}

/**
Expand All @@ -189,6 +192,7 @@ public LongBytesBound(String value)
public LongBytesBound(long quantity, DataStorageUnit unit)
{
super(quantity, unit, BYTES, Long.MAX_VALUE, quantity + unit.symbol);
bytes = unit().toBytes(quantity());
}

/**
Expand All @@ -206,7 +210,7 @@ public LongBytesBound(long bytes)
*/
public long toBytes()
{
return unit().toBytes(quantity());
return bytes;
}

/**
Expand All @@ -225,6 +229,8 @@ public int toMebibytesInt()
*/
public final static class IntBytesBound extends DataStorageSpec
{
private final int bytes;

/**
* Creates a {@code DataStorageSpec.IntBytesBound} of the specified amount.
*
Expand All @@ -233,6 +239,7 @@ public final static class IntBytesBound extends DataStorageSpec
public IntBytesBound(String value)
{
super(value, BYTES, Integer.MAX_VALUE);
bytes = Ints.saturatedCast(unit().toBytes(quantity()));
}

/**
Expand All @@ -244,6 +251,7 @@ public IntBytesBound(String value)
public IntBytesBound(long quantity, DataStorageUnit unit)
{
super(quantity, unit, BYTES, Integer.MAX_VALUE, quantity + unit.symbol);
bytes = Ints.saturatedCast(unit().toBytes(quantity()));
}

/**
Expand All @@ -263,7 +271,7 @@ public IntBytesBound(long bytes)
*/
public int toBytes()
{
return Ints.saturatedCast(unit().toBytes(quantity()));
return bytes;
}
}

Expand All @@ -274,6 +282,8 @@ public int toBytes()
*/
public final static class IntKibibytesBound extends DataStorageSpec
{
private final int bytes;

/**
* Creates a {@code DataStorageSpec.IntKibibytesBound} of the specified amount.
*
Expand All @@ -282,6 +292,7 @@ public final static class IntKibibytesBound extends DataStorageSpec
public IntKibibytesBound(String value)
{
super(value, KIBIBYTES, Integer.MAX_VALUE);
bytes = Ints.saturatedCast(unit().toBytes(quantity()));
}

/**
Expand All @@ -293,6 +304,7 @@ public IntKibibytesBound(String value)
public IntKibibytesBound(long quantity, DataStorageUnit unit)
{
super(quantity, unit, KIBIBYTES, Integer.MAX_VALUE, quantity + unit.symbol);
bytes = Ints.saturatedCast(unit().toBytes(quantity()));
}

/**
Expand All @@ -312,7 +324,7 @@ public IntKibibytesBound(long kibibytes)
*/
public int toBytes()
{
return Ints.saturatedCast(unit().toBytes(quantity()));
return bytes;
}

/**
Expand Down Expand Up @@ -341,6 +353,8 @@ public long toBytesInLong()
*/
public final static class LongMebibytesBound extends DataStorageSpec
{
private final long bytes;

/**
* Creates a {@code DataStorageSpec.LongMebibytesBound} of the specified amount.
*
Expand All @@ -349,6 +363,7 @@ public final static class LongMebibytesBound extends DataStorageSpec
public LongMebibytesBound(String value)
{
super(value, MEBIBYTES, Long.MAX_VALUE);
bytes = unit().toBytes(quantity());
}

/**
Expand All @@ -360,6 +375,7 @@ public LongMebibytesBound(String value)
public LongMebibytesBound(long quantity, DataStorageUnit unit)
{
super(quantity, unit, MEBIBYTES, Long.MAX_VALUE, quantity + unit.symbol);
bytes = unit().toBytes(quantity());
}

/**
Expand All @@ -377,7 +393,7 @@ public LongMebibytesBound(long mebibytes)
*/
public long toBytes()
{
return unit().toBytes(quantity());
return bytes;
}

/**
Expand All @@ -404,6 +420,7 @@ public long toMebibytes()
*/
public final static class IntMebibytesBound extends DataStorageSpec
{
private final int bytes;
/**
* Creates a {@code DataStorageSpec.IntMebibytesBound} of the specified amount.
*
Expand All @@ -412,6 +429,7 @@ public final static class IntMebibytesBound extends DataStorageSpec
public IntMebibytesBound(String value)
{
super(value, MEBIBYTES, Integer.MAX_VALUE);
bytes = Ints.saturatedCast(unit().toBytes(quantity()));
Comment thread
netudima marked this conversation as resolved.
}

/**
Expand All @@ -423,6 +441,7 @@ public IntMebibytesBound(String value)
public IntMebibytesBound(long quantity, DataStorageUnit unit)
{
super(quantity, unit, MEBIBYTES, Integer.MAX_VALUE, quantity + unit.symbol);
bytes = Ints.saturatedCast(unit().toBytes(quantity()));
}

/**
Expand All @@ -442,7 +461,7 @@ public IntMebibytesBound(long mebibytes)
*/
public int toBytes()
{
return Ints.saturatedCast(unit().toBytes(quantity()));
return bytes;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2322,7 +2322,7 @@ public static int getMaxSecurityLabelLength()

public static int getMaxValueSize()
{
return Ints.saturatedCast(conf.max_value_size.toMebibytes() * 1024L * 1024);
return conf.max_value_size.toBytes();
}

public static void setMaxValueSize(int maxValueSizeInBytes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public void testConversions()
assertEquals(10240, new DataStorageSpec.LongMebibytesBound("10MiB").toKibibytes());
assertEquals(1024 * 1024 * 1024, new DataStorageSpec.IntBytesBound("1GiB").toBytes());
assertEquals(10240, new DataStorageSpec.IntKibibytesBound("10MiB").toKibibytes());
assertEquals(10 * 1024 * 1024, new DataStorageSpec.IntKibibytesBound("10MiB").toBytes());
assertEquals(1024, new DataStorageSpec.IntMebibytesBound("1GiB").toMebibytes());
assertEquals(1024 * 1024 * 1024, new DataStorageSpec.IntMebibytesBound("1GiB").toBytes());

assertEquals(10, new DataStorageSpec.LongBytesBound(10, BYTES).toBytes());
assertEquals(10240, new DataStorageSpec.LongBytesBound(10, KIBIBYTES).toBytes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1067,4 +1067,11 @@ else if (mode == Config.DiskAccessMode.auto)
assertThat(DatabaseDescriptor.getCommitLogWriteDiskAccessMode()).isEqualTo(mode);
}
}

@Test
public void testMaxValueSize()
{
Config config = DatabaseDescriptor.loadConfig();
Assert.assertEquals(config.max_value_size.toMebibytes() * 1024 * 1024, DatabaseDescriptor.getMaxValueSize());
}
}