forked from apache/cassandra
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
STAR-1902: Option to disable call to NativeLibrary.trySkipCache (#932)
STAR-1902: Option to disable call to NativeLibrary.trySkipCache Introduce system property "cassandra.commitlog.skip_file_advice" that allows to skip the native call to "fadvise" with "FADV_DONTNEED" argument. The native call is not skipped by default. This patch was originally implemented in DSE 5.1 under DSP-22315. (cherry picked from commit 5c78e1d)
- Loading branch information
1 parent
ee61b4b
commit 410c0ec
Showing
4 changed files
with
167 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
test/distributed/org/apache/cassandra/db/commitlog/MemoryMappedSegmentStartupTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.cassandra.db.commitlog; | ||
|
||
import java.io.IOException; | ||
|
||
import org.junit.After; | ||
import org.junit.Test; | ||
|
||
import org.apache.cassandra.distributed.Cluster; | ||
|
||
import static org.apache.cassandra.config.CassandraRelevantProperties.COMMITLOG_SKIP_FILE_ADVICE; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
public class MemoryMappedSegmentStartupTest | ||
{ | ||
@After | ||
public void tearDown() throws Exception | ||
{ | ||
COMMITLOG_SKIP_FILE_ADVICE.reset(); | ||
} | ||
|
||
@Test | ||
public void shouldSetSkipFileAdviceTrueWithParameterTrue() throws IOException | ||
{ | ||
COMMITLOG_SKIP_FILE_ADVICE.setBoolean(true); | ||
try (Cluster cluster = Cluster.build(1).start()) | ||
{ | ||
assertEquals(true, cluster.get(1).callOnInstance(() -> MemoryMappedSegment.skipFileAdviseToFreePageCache)); | ||
} | ||
} | ||
|
||
@Test | ||
public void shouldSetSkipFileAdviceFalseWithParameterFalse() throws IOException | ||
{ | ||
COMMITLOG_SKIP_FILE_ADVICE.setBoolean(false); | ||
try (Cluster cluster = Cluster.build(1).start()) | ||
{ | ||
assertEquals(false, cluster.get(1).callOnInstance(() -> MemoryMappedSegment.skipFileAdviseToFreePageCache)); | ||
} | ||
} | ||
|
||
@Test | ||
public void shouldSetSkipFileAdviceFalseWithParameterMissing() throws IOException | ||
{ | ||
try (Cluster cluster = Cluster.build(1).start()) | ||
{ | ||
assertEquals(false, cluster.get(1).callOnInstance(() -> MemoryMappedSegment.skipFileAdviseToFreePageCache)); | ||
} | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
test/unit/org/apache/cassandra/db/commitlog/MemoryMappedSegmentTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.cassandra.db.commitlog; | ||
|
||
|
||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import org.apache.cassandra.SchemaLoader; | ||
import org.apache.cassandra.io.util.File; | ||
import org.mockito.Mockito; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyInt; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.verify; | ||
|
||
public class MemoryMappedSegmentTest | ||
{ | ||
@BeforeClass | ||
public static void beforeClass() throws Exception | ||
{ | ||
SchemaLoader.prepareServer(); | ||
} | ||
|
||
@Test | ||
public void shouldNotSkipFileAdviseToFreeSystemCache() | ||
{ | ||
//given | ||
MemoryMappedSegment.skipFileAdviseToFreePageCache = false; | ||
MemoryMappedSegment memoryMappedSegment = memoryMappedSegment(); | ||
int startMarker = 0; | ||
int nextMarker = 1024; | ||
|
||
//when | ||
memoryMappedSegment.flush(startMarker, nextMarker); | ||
|
||
//then | ||
verify(memoryMappedSegment) | ||
.adviceOnFileToFreePageCache(eq(memoryMappedSegment.fd), eq(startMarker), eq(nextMarker), eq(memoryMappedSegment.logFile)); | ||
} | ||
|
||
@Test | ||
public void shouldSkipFileAdviseToFreeSystemCache() | ||
{ | ||
//given | ||
MemoryMappedSegment.skipFileAdviseToFreePageCache = true; | ||
MemoryMappedSegment memoryMappedSegment = memoryMappedSegment(); | ||
|
||
//when | ||
memoryMappedSegment.flush(0, 1024); | ||
|
||
//then | ||
verify(memoryMappedSegment, never()) | ||
.adviceOnFileToFreePageCache(anyInt(), anyInt(), anyInt(), any(File.class)); | ||
} | ||
|
||
private MemoryMappedSegment memoryMappedSegment() | ||
{ | ||
return Mockito.spy(new MemoryMappedSegment(CommitLog.instance, CommitLog.instance.getSegmentManager())); | ||
} | ||
} |