Merge branch 'cassandra-4.1' into cassandra-5.0

This commit is contained in:
Stefan Miklosovic 2024-09-27 14:04:44 +02:00
commit 07c1f93b06
No known key found for this signature in database
GPG Key ID: 32F35CB2F546D93E
3 changed files with 39 additions and 27 deletions

View File

@ -10,6 +10,7 @@
* Add java.base/java.lang.reflect among opens for jvm11-client.options (CASSANDRA-19780) * Add java.base/java.lang.reflect among opens for jvm11-client.options (CASSANDRA-19780)
Merged from 4.1: Merged from 4.1:
Merged from 4.0: Merged from 4.0:
* Ensure thread-safety for CommitLogArchiver in CommitLog (CASSANDRA-19960)
* Fix text containing "/*" being interpreted as multiline comment in cqlsh (CASSANDRA-17667) * Fix text containing "/*" being interpreted as multiline comment in cqlsh (CASSANDRA-17667)
* Fix indexing of a frozen collection that is the clustering key and reversed (CASSANDRA-19889) * Fix indexing of a frozen collection that is the clustering key and reversed (CASSANDRA-19889)
* Emit error when altering a table with non-frozen UDTs with nested non-frozen collections the same way as done upon table creation (CASSANDRA-19925) * Emit error when altering a table with non-frozen UDTs with nested non-frozen collections the same way as done upon table creation (CASSANDRA-19925)

View File

@ -82,7 +82,7 @@ public class CommitLog implements CommitLogMBean
final public AbstractCommitLogSegmentManager segmentManager; final public AbstractCommitLogSegmentManager segmentManager;
public CommitLogArchiver archiver; public final CommitLogArchiver archiver;
public final CommitLogMetrics metrics; public final CommitLogMetrics metrics;
final AbstractCommitLogService executor; final AbstractCommitLogService executor;
@ -412,12 +412,6 @@ public class CommitLog implements CommitLogMBean
return archiver.precision.toString(); return archiver.precision.toString();
} }
@VisibleForTesting
public void setCommitlogArchiver(CommitLogArchiver archiver)
{
this.archiver = archiver;
}
public List<String> getActiveSegmentNames() public List<String> getActiveSegmentNames()
{ {
Collection<CommitLogSegment> segments = segmentManager.getActiveSegments(); Collection<CommitLogSegment> segments = segmentManager.getActiveSegments();

View File

@ -21,10 +21,9 @@ package org.apache.cassandra.db.commitlog;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.HashMap;
import java.util.Properties;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.junit.AfterClass;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.ClassRule; import org.junit.ClassRule;
@ -37,6 +36,8 @@ import org.apache.cassandra.db.Keyspace;
import org.apache.cassandra.db.RowUpdateBuilder; import org.apache.cassandra.db.RowUpdateBuilder;
import org.apache.cassandra.io.util.File; import org.apache.cassandra.io.util.File;
import org.apache.cassandra.io.util.PathUtils; import org.apache.cassandra.io.util.PathUtils;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import static org.apache.cassandra.io.util.PathUtils.forEach; import static org.apache.cassandra.io.util.PathUtils.forEach;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -44,27 +45,44 @@ import static org.junit.Assert.assertTrue;
public class CommitLogArchiverTest extends CQLTester public class CommitLogArchiverTest extends CQLTester
{ {
private static Path dirName; private static Path dirName;
private static final String rpiTime = "2024:03:22 20:43:12.633222"; // "2024:03:22 20:43:12.633222";
private static final long rpiTime = 1711140192633222L;
private File dir; private File dir;
@ClassRule @ClassRule
public static TemporaryFolder temporaryFolder = new TemporaryFolder(); public static TemporaryFolder temporaryFolder = new TemporaryFolder();
private static MockedStatic<CommitLogArchiver> archiverMock;
@BeforeClass @BeforeClass
public static void beforeClass() throws IOException public static void setUpClass()
{ {
dirName = temporaryFolder.newFolder().toPath(); try
CommitLog commitLog = CommitLog.instance; {
Properties properties = new Properties(); dirName = temporaryFolder.newFolder().toPath();
properties.putAll(new HashMap<String, String>() }
{{ catch (IOException ex)
put("archive_command", "/bin/cp %path " + dirName); {
put("restore_command", "/bin/cp -f %from %to"); throw new RuntimeException(ex);
put("restore_directories", dirName.toString()); }
put("restore_point_in_time", rpiTime);
}}); archiverMock = Mockito.mockStatic(CommitLogArchiver.class);
CommitLogArchiver commitLogArchiver = CommitLogArchiver.getArchiverFromProperties(properties); archiverMock.when(CommitLogArchiver::construct)
commitLog.setCommitlogArchiver(commitLogArchiver); .thenReturn(new CommitLogArchiver("/bin/cp %path " + dirName,
"/bin/cp -f %from %to",
dirName.toString(),
1711140192633222L,
CommitLogPosition.NONE,
TimeUnit.MICROSECONDS));
CQLTester.setUpClass();
}
@AfterClass
public static void tearDownClass()
{
CQLTester.tearDownClass();
archiverMock.close();
} }
@Before @Before
@ -81,14 +99,13 @@ public class CommitLogArchiverTest extends CQLTester
{ {
String table = createTable(KEYSPACE, "CREATE TABLE %s (a TEXT PRIMARY KEY, b blob);"); String table = createTable(KEYSPACE, "CREATE TABLE %s (a TEXT PRIMARY KEY, b blob);");
ColumnFamilyStore cfs = Keyspace.open(KEYSPACE).getColumnFamilyStore(table); ColumnFamilyStore cfs = Keyspace.open(KEYSPACE).getColumnFamilyStore(table);
long ts = CommitLogArchiver.getRestorationPointInTimeInMicroseconds(rpiTime);
ByteBuffer value = ByteBuffer.allocate(1024); ByteBuffer value = ByteBuffer.allocate(1024);
// Make sure that new CommitLogSegment will be allocated as the CommitLogSegment size is 5M // Make sure that new CommitLogSegment will be allocated as the CommitLogSegment size is 5M
// and if new CommitLogSegment is allocated then the old CommitLogSegment will be archived. // and if new CommitLogSegment is allocated then the old CommitLogSegment will be archived.
for (int i = 1; i <= 10; ++i) for (int i = 1; i <= 10; ++i)
{ {
new RowUpdateBuilder(cfs.metadata(), ts - i, "name-" + i) new RowUpdateBuilder(cfs.metadata(), rpiTime - i, "name-" + i)
.add("b", value) .add("b", value)
.build() .build()
.apply(); .apply();
@ -97,7 +114,7 @@ public class CommitLogArchiverTest extends CQLTester
CommitLog.instance.forceRecycleAllSegments(); CommitLog.instance.forceRecycleAllSegments();
CommitLog.instance.segmentManager.awaitManagementTasksCompletion(); CommitLog.instance.segmentManager.awaitManagementTasksCompletion();
// If the number of files that under backup dir is bigger than 1, that means the // If the number of files that under backup dir is bigger than 1, that means the
// arhiver for commitlog is effective. // archiver for commitlog is effective.
assertTrue(dir.isDirectory() && dir.tryList().length > 0); assertTrue(dir.isDirectory() && dir.tryList().length > 0);
} }
@ -106,7 +123,7 @@ public class CommitLogArchiverTest extends CQLTester
{ {
createTable(KEYSPACE, "CREATE TABLE %s (a INT , b INT, c INT, PRIMARY KEY(a, b));"); createTable(KEYSPACE, "CREATE TABLE %s (a INT , b INT, c INT, PRIMARY KEY(a, b));");
// default level is microsecond // default level is microsecond
long timeInMicroSecond1 = CommitLogArchiver.getRestorationPointInTimeInMicroseconds(rpiTime); long timeInMicroSecond1 = rpiTime;
execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?) USING TIMESTAMP ? ", 3, 0, 0, timeInMicroSecond1); execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?) USING TIMESTAMP ? ", 3, 0, 0, timeInMicroSecond1);
execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?) USING TIMESTAMP ? ", 3, 1, 1, timeInMicroSecond1); execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?) USING TIMESTAMP ? ", 3, 1, 1, timeInMicroSecond1);