This is an automated email from the ASF dual-hosted git repository.
adelapena pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/trunk by this push:
new 77d6bbf25a Save sstable id as string in activity table
77d6bbf25a is described below
commit 77d6bbf25a59d44422f0cbee2631f2fca9170e1a
Author: Jacek Lewandowski <[email protected]>
AuthorDate: Thu Apr 28 06:18:19 2022 +0200
Save sstable id as string in activity table
patch by Jacek Lewandowski; reviewed by Andrés de la Peña and Ekaterina
Dimitrova for CASSANDRA-17585
---
CHANGES.txt | 1 +
src/java/org/apache/cassandra/db/SystemKeyspace.java | 8 ++++----
.../apache/cassandra/db/SystemKeyspaceMigrator41.java | 2 +-
.../cassandra/db/compaction/CompactionLogger.java | 2 +-
.../org/apache/cassandra/io/sstable/Descriptor.java | 2 +-
.../org/apache/cassandra/io/sstable/SSTableId.java | 5 +++--
.../cassandra/io/sstable/SequenceBasedSSTableId.java | 8 +-------
.../cassandra/io/sstable/UUIDBasedSSTableId.java | 7 ++++---
.../distributed/test/SSTableIdGenerationTest.java | 18 ++++++++++++++----
.../cassandra/db/SystemKeyspaceMigrator41Test.java | 2 +-
.../org/apache/cassandra/io/sstable/SSTableIdTest.java | 4 ++--
11 files changed, 33 insertions(+), 26 deletions(-)
diff --git a/CHANGES.txt b/CHANGES.txt
index c36f9d2eda..412e7964f8 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
4.1
+ * Save sstable id as string in activity table (CASSANDRA-17585)
* Implement startup check to prevent Cassandra to potentially spread zombie
data (CASSANDRA-17180)
* Allow failing startup on duplicate config keys (CASSANDRA-17379)
* Migrate threshold for minimum keyspace replication factor to guardrails
(CASSANDRA-17212)
diff --git a/src/java/org/apache/cassandra/db/SystemKeyspace.java
b/src/java/org/apache/cassandra/db/SystemKeyspace.java
index 9b67d22046..789bc15a93 100644
--- a/src/java/org/apache/cassandra/db/SystemKeyspace.java
+++ b/src/java/org/apache/cassandra/db/SystemKeyspace.java
@@ -327,7 +327,7 @@ public final class SystemKeyspace
"CREATE TABLE %s ("
+ "keyspace_name text,"
+ "table_name text,"
- + "id blob,"
+ + "id text,"
+ "rate_120m double,"
+ "rate_15m double,"
+ "PRIMARY KEY ((keyspace_name, table_name, id)))")
@@ -1461,7 +1461,7 @@ public final class SystemKeyspace
public static RestorableMeter getSSTableReadMeter(String keyspace, String
table, SSTableId id)
{
String cql = "SELECT * FROM system.%s WHERE keyspace_name=? and
table_name=? and id=?";
- UntypedResultSet results = executeInternal(format(cql,
SSTABLE_ACTIVITY_V2), keyspace, table, id.asBytes());
+ UntypedResultSet results = executeInternal(format(cql,
SSTABLE_ACTIVITY_V2), keyspace, table, id.toString());
if (results.isEmpty())
return new RestorableMeter();
@@ -1482,7 +1482,7 @@ public final class SystemKeyspace
executeInternal(format(cql, SSTABLE_ACTIVITY_V2),
keyspace,
table,
- id.asBytes(),
+ id.toString(),
meter.fifteenMinuteRate(),
meter.twoHourRate());
@@ -1506,7 +1506,7 @@ public final class SystemKeyspace
public static void clearSSTableReadMeter(String keyspace, String table,
SSTableId id)
{
String cql = "DELETE FROM system.%s WHERE keyspace_name=? AND
table_name=? and id=?";
- executeInternal(format(cql, SSTABLE_ACTIVITY_V2), keyspace, table,
id.asBytes());
+ executeInternal(format(cql, SSTABLE_ACTIVITY_V2), keyspace, table,
id.toString());
if (!DatabaseDescriptor.isUUIDSSTableIdentifiersEnabled() && id
instanceof SequenceBasedSSTableId)
{
// we do this in order to make it possible to downgrade until we
switch in cassandra.yaml to UUID based ids
diff --git a/src/java/org/apache/cassandra/db/SystemKeyspaceMigrator41.java
b/src/java/org/apache/cassandra/db/SystemKeyspaceMigrator41.java
index 753d29eccf..5ee1eba42f 100644
--- a/src/java/org/apache/cassandra/db/SystemKeyspaceMigrator41.java
+++ b/src/java/org/apache/cassandra/db/SystemKeyspaceMigrator41.java
@@ -154,7 +154,7 @@ public class SystemKeyspaceMigrator41
row ->
Collections.singletonList(new Object[]{
row.getString("keyspace_name"),
row.getString("columnfamily_name"),
- new
SequenceBasedSSTableId(row.getInt("generation")).asBytes(),
+ new
SequenceBasedSSTableId(row.getInt("generation")).toString(),
row.has("rate_120m") ? row.getDouble("rate_120m") : null,
row.has("rate_15m") ? row.getDouble("rate_15m") : null
})
diff --git a/src/java/org/apache/cassandra/db/compaction/CompactionLogger.java
b/src/java/org/apache/cassandra/db/compaction/CompactionLogger.java
index 93812424c8..9bf063b726 100644
--- a/src/java/org/apache/cassandra/db/compaction/CompactionLogger.java
+++ b/src/java/org/apache/cassandra/db/compaction/CompactionLogger.java
@@ -171,7 +171,7 @@ public class CompactionLogger
private JsonNode formatSSTable(AbstractCompactionStrategy strategy,
SSTableReader sstable)
{
ObjectNode node = json.objectNode();
- node.put("generation", sstable.descriptor.id.asString());
+ node.put("generation", sstable.descriptor.id.toString());
node.put("version", sstable.descriptor.version.getVersion());
node.put("size", sstable.onDiskLength());
JsonNode logResult = strategy.strategyLogger().sstable(sstable);
diff --git a/src/java/org/apache/cassandra/io/sstable/Descriptor.java
b/src/java/org/apache/cassandra/io/sstable/Descriptor.java
index 2086c7d353..83bafd4ff4 100644
--- a/src/java/org/apache/cassandra/io/sstable/Descriptor.java
+++ b/src/java/org/apache/cassandra/io/sstable/Descriptor.java
@@ -136,7 +136,7 @@ public class Descriptor
private void appendFileName(StringBuilder buff)
{
buff.append(version).append(separator);
- buff.append(id.asString());
+ buff.append(id.toString());
buff.append(separator).append(formatType.name);
}
diff --git a/src/java/org/apache/cassandra/io/sstable/SSTableId.java
b/src/java/org/apache/cassandra/io/sstable/SSTableId.java
index 760b855d1a..a3d95dd887 100644
--- a/src/java/org/apache/cassandra/io/sstable/SSTableId.java
+++ b/src/java/org/apache/cassandra/io/sstable/SSTableId.java
@@ -52,7 +52,8 @@ public interface SSTableId
* Must not contain any {@link Descriptor#FILENAME_SEPARATOR} character as
it is used in the Descriptor
* see {@link Descriptor#fromFilenameWithComponent(File)}
*/
- String asString();
+ @Override
+ String toString();
/**
* Builder that can create instances of certain implementation of {@link
SSTableId}.
@@ -72,7 +73,7 @@ public interface SSTableId
/**
* Creates an identifier instance from its string representation
*
- * @param str string representation as returned by {@link #asString()}
+ * @param str string representation as returned by {@link
SSTableId#toString()}
* @throws IllegalArgumentException when the provided string is not a
valid string representation of the identifier
*/
T fromString(String str) throws IllegalArgumentException;
diff --git
a/src/java/org/apache/cassandra/io/sstable/SequenceBasedSSTableId.java
b/src/java/org/apache/cassandra/io/sstable/SequenceBasedSSTableId.java
index ec371fc123..acb91f8d75 100644
--- a/src/java/org/apache/cassandra/io/sstable/SequenceBasedSSTableId.java
+++ b/src/java/org/apache/cassandra/io/sstable/SequenceBasedSSTableId.java
@@ -77,16 +77,10 @@ public class SequenceBasedSSTableId implements SSTableId,
Comparable<SequenceBas
return bytes;
}
- @Override
- public String asString()
- {
- return String.valueOf(generation);
- }
-
@Override
public String toString()
{
- return asString();
+ return String.valueOf(generation);
}
public static class Builder implements
SSTableId.Builder<SequenceBasedSSTableId>
diff --git a/src/java/org/apache/cassandra/io/sstable/UUIDBasedSSTableId.java
b/src/java/org/apache/cassandra/io/sstable/UUIDBasedSSTableId.java
index 93e6efd137..9cec5879f6 100644
--- a/src/java/org/apache/cassandra/io/sstable/UUIDBasedSSTableId.java
+++ b/src/java/org/apache/cassandra/io/sstable/UUIDBasedSSTableId.java
@@ -42,10 +42,12 @@ public final class UUIDBasedSSTableId implements SSTableId,
Comparable<UUIDBased
public final static int BYTES_LEN = 16;
private final TimeUUID uuid;
+ private final String repr;
public UUIDBasedSSTableId(TimeUUID uuid)
{
this.uuid = uuid;
+ this.repr = asString();
}
@Override
@@ -57,8 +59,7 @@ public final class UUIDBasedSSTableId implements SSTableId,
Comparable<UUIDBased
.putLong(Long.BYTES, uuid.lsb());
}
- @Override
- public String asString()
+ private String asString()
{
long ts = uuid.uuidTimestamp();
long nanoPart = ts % 10_000_000;
@@ -76,7 +77,7 @@ public final class UUIDBasedSSTableId implements SSTableId,
Comparable<UUIDBased
@Override
public String toString()
{
- return uuid.toString();
+ return repr;
}
@Override
diff --git
a/test/distributed/org/apache/cassandra/distributed/test/SSTableIdGenerationTest.java
b/test/distributed/org/apache/cassandra/distributed/test/SSTableIdGenerationTest.java
index bf38077d18..8505638026 100644
---
a/test/distributed/org/apache/cassandra/distributed/test/SSTableIdGenerationTest.java
+++
b/test/distributed/org/apache/cassandra/distributed/test/SSTableIdGenerationTest.java
@@ -28,6 +28,7 @@ import java.util.stream.Collectors;
import com.google.common.collect.ImmutableSet;
import org.apache.commons.io.FileUtils;
+import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -75,16 +76,25 @@ public class SSTableIdGenerationTest extends TestBaseImpl
private int v;
+ private static SecurityManager originalSecurityManager;
+
@BeforeClass
public static void beforeClass() throws Throwable
{
TestBaseImpl.beforeClass();
+ originalSecurityManager = System.getSecurityManager();
// we prevent system exit and convert it to exception becuase this is
one of the expected test outcomes,
// and we want to make an assertion on that
ClusterUtils.preventSystemExit();
}
+ @AfterClass
+ public static void afterClass() throws Throwable
+ {
+ System.setSecurityManager(originalSecurityManager);
+ }
+
/**
* This test verifies that a node with uuid disabled actually creates
sstables with sequential ids and
* both the current and legacy sstable activity tables are updated.
@@ -460,13 +470,13 @@ public class SSTableIdGenerationTest extends TestBaseImpl
assertThat(SystemKeyspace.getSSTableReadMeter("ks", "tab",
seqGenId)).matches(m -> m.fifteenMinuteRate() == meter.fifteenMinuteRate()
&& m.twoHourRate() == meter.twoHourRate());
- checkSSTableActivityRow(SSTABLE_ACTIVITY_V2, seqGenId.asBytes(),
true);
+ checkSSTableActivityRow(SSTABLE_ACTIVITY_V2, seqGenId.toString(),
true);
if (expectLegacyTableIsPopulated)
checkSSTableActivityRow(LEGACY_SSTABLE_ACTIVITY,
seqGenId.generation, true);
SystemKeyspace.clearSSTableReadMeter("ks", "tab", seqGenId);
- checkSSTableActivityRow(SSTABLE_ACTIVITY_V2, seqGenId.asBytes(),
false);
+ checkSSTableActivityRow(SSTABLE_ACTIVITY_V2, seqGenId.toString(),
false);
if (expectLegacyTableIsPopulated)
checkSSTableActivityRow(LEGACY_SSTABLE_ACTIVITY,
seqGenId.generation, false);
@@ -475,11 +485,11 @@ public class SSTableIdGenerationTest extends TestBaseImpl
assertThat(SystemKeyspace.getSSTableReadMeter("ks", "tab",
uuidGenId)).matches(m -> m.fifteenMinuteRate() == meter.fifteenMinuteRate()
&& m.twoHourRate() == meter.twoHourRate());
- checkSSTableActivityRow(SSTABLE_ACTIVITY_V2, uuidGenId.asBytes(),
true);
+ checkSSTableActivityRow(SSTABLE_ACTIVITY_V2, uuidGenId.toString(),
true);
SystemKeyspace.clearSSTableReadMeter("ks", "tab", uuidGenId);
- checkSSTableActivityRow(SSTABLE_ACTIVITY_V2, uuidGenId.asBytes(),
false);
+ checkSSTableActivityRow(SSTABLE_ACTIVITY_V2, uuidGenId.toString(),
false);
});
}
diff --git
a/test/unit/org/apache/cassandra/db/SystemKeyspaceMigrator41Test.java
b/test/unit/org/apache/cassandra/db/SystemKeyspaceMigrator41Test.java
index 1448fc2182..b54367920f 100644
--- a/test/unit/org/apache/cassandra/db/SystemKeyspaceMigrator41Test.java
+++ b/test/unit/org/apache/cassandra/db/SystemKeyspaceMigrator41Test.java
@@ -258,7 +258,7 @@ public class SystemKeyspaceMigrator41Test extends CQLTester
rowCount++;
assertEquals("ks", row.getString("keyspace_name"));
assertEquals("tab", row.getString("table_name"));
- assertEquals(new SequenceBasedSSTableId(5).asBytes(),
row.getBytes("id"));
+ assertEquals(new SequenceBasedSSTableId(5).toString(),
row.getString("id"));
assertEquals(123.234d, row.getDouble("rate_120m"), 0.001d);
assertEquals(345.456d, row.getDouble("rate_15m"), 0.001d);
}
diff --git a/test/unit/org/apache/cassandra/io/sstable/SSTableIdTest.java
b/test/unit/org/apache/cassandra/io/sstable/SSTableIdTest.java
index 0c4812111d..82fbf32537 100644
--- a/test/unit/org/apache/cassandra/io/sstable/SSTableIdTest.java
+++ b/test/unit/org/apache/cassandra/io/sstable/SSTableIdTest.java
@@ -73,7 +73,7 @@ public class SSTableIdTest
List<SSTableId> deserIds =
serIds.stream().map(builder::fromBytes).collect(Collectors.toList());
assertThat(deserIds).containsExactlyElementsOf(ids);
- List<String> stringifiedIds =
ids.stream().map(SSTableId::asString).collect(Collectors.toList());
+ List<String> stringifiedIds =
ids.stream().map(SSTableId::toString).collect(Collectors.toList());
if (!(builder instanceof SequenceBasedSSTableId.Builder))
{
// the legacy string representation is not sortable
@@ -111,7 +111,7 @@ public class SSTableIdTest
private void testStringSerialization(UUIDBasedSSTableId id)
{
- String s = id.asString();
+ String s = id.toString();
assertThat(s).hasSize(UUIDBasedSSTableId.STRING_LEN);
assertThat(s).matches(Pattern.compile("[0-9a-z]{4}_[0-9a-z]{4}_[0-9a-z]{18}"));
assertThat(UUIDBasedSSTableId.Builder.instance.isUniqueIdentifier(s)).isTrue();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]