You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "Jollyplum (via GitHub)" <gi...@apache.org> on 2024/11/07 23:05:27 UTC
[PR] Use mutation creation time for hint expiry rather than hint submission time [cassandra]
Jollyplum opened a new pull request, #3663:
URL: https://github.com/apache/cassandra/pull/3663
patch by Matt Byrd; reviewed by Blake Eggleston for CASSANDRA-20014
https://issues.apache.org/jira/browse/CASSANDRA-20014
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Use mutation creation time for hint expiry rather than hint submission time [cassandra]
Posted by "clohfink (via GitHub)" <gi...@apache.org>.
clohfink commented on code in PR #3663:
URL: https://github.com/apache/cassandra/pull/3663#discussion_r1833649670
##########
src/java/org/apache/cassandra/config/Config.java:
##########
@@ -452,6 +452,7 @@ public static class SSTableConfig
public ParameterizedClass hints_compression;
public volatile boolean auto_hints_cleanup_enabled = false;
public volatile boolean transfer_hints_on_decommission = true;
+ public volatile boolean hint_ttl_use_mutation_creation_time = true;
Review Comment:
NP: maybe `use_creation_time_for_hint_ttl`
##########
src/java/org/apache/cassandra/service/StorageProxy.java:
##########
@@ -2754,8 +2755,12 @@ public void runMayThrow()
else
logger.debug("Discarding hint for endpoint not part of ring: {}", target);
}
- logger.trace("Adding hints for {}", validTargets);
- HintsService.instance.write(hostIds, Hint.create(mutation, currentTimeMillis()));
+ long creationTime = currentTimeMillis();
+ if (DatabaseDescriptor.isHintTtlUseMutationCreationTime()) {
+ creationTime -= TimeUnit.MILLISECONDS.convert(Math.abs(approxTime.now() - mutation.getApproxCreatedAtNanos()), NANOSECONDS);
Review Comment:
would it make more sense to use the time from the PartitionUpdates DeletionTime inside the mutation instead of the time the mutation is created on the coordinator? I could see where that would be iffy since theres no guarantees client isn't using their own thing for writetimes.
##########
test/distributed/org/apache/cassandra/distributed/test/HintDataReappearingTest.java:
##########
@@ -0,0 +1,267 @@
+/*
+ * 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.distributed.test;
+
+import java.util.*;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+
+import org.apache.cassandra.db.SystemKeyspace;
+import org.apache.cassandra.distributed.api.IIsolatedExecutor;
+import org.apache.cassandra.exceptions.WriteTimeoutException;
+import org.apache.cassandra.hints.HintsService;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.cassandra.distributed.Cluster;
+import org.apache.cassandra.distributed.api.IInvokableInstance;
+import org.apache.cassandra.distributed.api.SimpleQueryResult;
+import org.apache.cassandra.net.Verb;
+import org.assertj.core.api.Assertions;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static java.lang.String.format;
+import static org.apache.cassandra.distributed.api.ConsistencyLevel.ALL;
+import static org.apache.cassandra.distributed.api.ConsistencyLevel.LOCAL_QUORUM;
+import static org.apache.cassandra.distributed.api.Feature.GOSSIP;
+import static org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL;
+import static org.apache.cassandra.distributed.api.Feature.NETWORK;
+import static org.apache.cassandra.utils.AssertionUtils.isThrowable;
+
+public class HintDataReappearingTest extends AbstractHintWindowTest
+{
+ private static final Logger logger = LoggerFactory.getLogger(HintDataReappearingTest.class);
+
+ private static final ScheduledExecutorService scheduler = Executors
+ .newScheduledThreadPool(1,
+ new ThreadFactoryBuilder()
+ .setNameFormat("hint reappearance test")
+ .setDaemon(true)
+ .build());
+
+ @Test
+ public void testHintCausesDataReappearance() throws Exception
+ {
+ doHintReappearData(true, false);
+ }
+
+ @Test
+ public void demonstrateHintCausesDataReappearance() throws Exception
+ {
+ doHintReappearData(false, false);
+ }
+
+ @Test
+ public void testHintCausesDataReappearanceWriteTimeout() throws Exception
+ {
+ doHintReappearData(true, true);
+ }
+
+ @Test
+ public void demonstrateHintCausesDataReappearanceWriteTimeout() throws Exception
+ {
+ doHintReappearData(false, true);
+ }
+
+
Review Comment:
NP: remove blank lines
##########
test/distributed/org/apache/cassandra/distributed/test/HintDataReappearingTest.java:
##########
@@ -0,0 +1,267 @@
+/*
+ * 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.distributed.test;
+
+import java.util.*;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+
+import org.apache.cassandra.db.SystemKeyspace;
+import org.apache.cassandra.distributed.api.IIsolatedExecutor;
+import org.apache.cassandra.exceptions.WriteTimeoutException;
+import org.apache.cassandra.hints.HintsService;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.cassandra.distributed.Cluster;
+import org.apache.cassandra.distributed.api.IInvokableInstance;
+import org.apache.cassandra.distributed.api.SimpleQueryResult;
+import org.apache.cassandra.net.Verb;
+import org.assertj.core.api.Assertions;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static java.lang.String.format;
+import static org.apache.cassandra.distributed.api.ConsistencyLevel.ALL;
+import static org.apache.cassandra.distributed.api.ConsistencyLevel.LOCAL_QUORUM;
+import static org.apache.cassandra.distributed.api.Feature.GOSSIP;
+import static org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL;
+import static org.apache.cassandra.distributed.api.Feature.NETWORK;
+import static org.apache.cassandra.utils.AssertionUtils.isThrowable;
+
+public class HintDataReappearingTest extends AbstractHintWindowTest
+{
+ private static final Logger logger = LoggerFactory.getLogger(HintDataReappearingTest.class);
+
+ private static final ScheduledExecutorService scheduler = Executors
+ .newScheduledThreadPool(1,
+ new ThreadFactoryBuilder()
+ .setNameFormat("hint reappearance test")
+ .setDaemon(true)
+ .build());
+
+ @Test
+ public void testHintCausesDataReappearance() throws Exception
+ {
+ doHintReappearData(true, false);
+ }
+
+ @Test
+ public void demonstrateHintCausesDataReappearance() throws Exception
+ {
+ doHintReappearData(false, false);
+ }
+
+ @Test
+ public void testHintCausesDataReappearanceWriteTimeout() throws Exception
+ {
+ doHintReappearData(true, true);
+ }
+
+ @Test
+ public void demonstrateHintCausesDataReappearanceWriteTimeout() throws Exception
+ {
+ doHintReappearData(false, true);
+ }
+
+
+
+
+ public void doHintReappearData(final boolean preventReappearance, final boolean dropTwoWrites) throws Exception
+ {
+ try (Cluster cluster = init(Cluster.build(3)
+ .withDataDirCount(1)
+
+ .withConfig(config -> config.with(NETWORK, GOSSIP, NATIVE_PROTOCOL)
+ .set("hinted_handoff_enabled", true)
+ .set("max_hints_delivery_threads", "1")
+ .set("hint_ttl_use_mutation_creation_time", preventReappearance ? "true" : "false")
+ .set("write_request_timeout", "30000ms")
+ .set("hints_flush_period", "1s")
+ .set("max_hints_file_size", "10MiB"))
+ .start(), 3))
+ {
+ final IInvokableInstance node1 = cluster.get(1);
+ final IInvokableInstance node2 = cluster.get(2);
+ final IInvokableInstance node3 = cluster.get(3);
+
+ waitForExistingRoles(cluster);
+
+ // We create a table with low gc_grace_seconds to ensure we can check the interactions in a timely manner
+ // Also make compaction fairly proactive in an attempt avoiding to force compact repeatedly
+ final int gc_grace_seconds = 40;
+ final String createTableStatement = format("CREATE TABLE %s.cf (k text PRIMARY KEY, c1 text) " +
+ "WITH gc_grace_seconds = " + gc_grace_seconds +
+ " AND compaction = {'class': 'SizeTieredCompactionStrategy', 'min_threshold': 2, 'max_threshold': 32 } ", KEYSPACE);
+ cluster.schemaChange(createTableStatement);
+
+ // setup a message filter to drop mutations requests from node1 to node2 so it creates hints for those mutations
+ AtomicBoolean dropWritesForNode2 = new AtomicBoolean(true);
+ // toggling this on allows the test to timeout the original write, a slight variation, both cause the problem.
+ AtomicBoolean dropWritesForNode3 = new AtomicBoolean(dropTwoWrites);
+ cluster.filters()
+ .verbs(Verb.MUTATION_REQ.id)
+ .from(1)
+ .messagesMatching((from, to, message) ->
+ (to == 2 && dropWritesForNode2.get()
+ || (to == 3 && dropWritesForNode3.get())))
+ .drop();
+
+
+ logger.info("Pausing hint delivery ");
+ // pause hint delivery to imitate hints being behind/backed up
+ pauseHintsDelivery(node1);
+
+ logger.info("Inserting data");
+
+ List<UUID> keys = IntStream.range(0, 1).mapToObj(x -> UUID.randomUUID()).collect(Collectors.toList());
+
+ scheduler.submit(() -> {
+ if (dropTwoWrites)
+ {
+ Assertions.assertThatThrownBy(() -> insertData(cluster, keys))
+ .is(isThrowable(WriteTimeoutException.class));
+ }
+ else
+ {
+ insertData(cluster, keys);
+ }
+ });
+
+ Thread.sleep(1000);
+ dropWritesForNode2.set(false);
+ dropWritesForNode3.set(false);
+
+ node1.flush(KEYSPACE);
+ node2.flush(KEYSPACE);
+ node3.flush(KEYSPACE);
+
+ logger.info("deleting data ");
+ deleteData(cluster, keys);
+ long afterDelete = System.currentTimeMillis();
+
+ node1.flush(KEYSPACE);
+ node2.flush(KEYSPACE);
+ node3.flush(KEYSPACE);
+
+
+ logger.info("repairing");
+ for (IInvokableInstance node : Arrays.asList(node1, node2, node3))
+ {
+ node.nodetoolResult(ArrayUtils.addAll(new String[]{ "repair", KEYSPACE }, "--full")).asserts().success();
+ }
+ logger.info("done repairing");
+
+
+ for (SimpleQueryResult result : selectData(cluster, keys))
+ {
+ Object[][] objectArrays = result.toObjectArrays();
+ logger.info("result after delete: {} {}", result, Arrays.deepToString(objectArrays));
+ // We expect the data to appear to be deleted initially
+ Assert.assertNull(objectArrays[0][1]);
+ }
+
+ // wait to pass gc_grace_seconds with slight buffer of 2 seconds to ensure delete persisted long enough to be gced
+ long msSinceDelete = Math.abs(System.currentTimeMillis() - afterDelete);
+ long sleepFor = Math.max(0, 1000 * gc_grace_seconds + 2000 - msSinceDelete);
+ logger.info("sleeping {} ms to ensure gc_grace_seconds has ellapsed after tombstone creation", sleepFor);
+ Thread.sleep(sleepFor);
+
+ // ensure tombstone purged on all 3 nodes
+ node1.forceCompact(KEYSPACE, "cf");
+ node3.forceCompact(KEYSPACE, "cf");
+ node2.forceCompact(KEYSPACE, "cf");
+
+
+ IIsolatedExecutor.CallableNoExcept<UUID> node2hostId = node2.callsOnInstance(SystemKeyspace::getLocalHostId);
+
+ transferHints(node1, node2hostId.call());
+
+ // Sleep a bit more to ensure hint is delivered after tombstone is GCed
+ Thread.sleep(20000);
Review Comment:
20s is super long and gonna make this test a bit more of a pain, think we can slim this down some?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Use mutation creation time for hint expiry rather than hint submission time [cassandra]
Posted by "Jollyplum (via GitHub)" <gi...@apache.org>.
Jollyplum commented on PR #3663:
URL: https://github.com/apache/cassandra/pull/3663#issuecomment-2605949320
this was committed here:
https://github.com/apache/cassandra/commit/4f0ad22f122f8233aa99545bc234083690f53ea7
so closing the PR
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Use mutation creation time for hint expiry rather than hint submission time [cassandra]
Posted by "bdeggleston (via GitHub)" <gi...@apache.org>.
bdeggleston commented on code in PR #3663:
URL: https://github.com/apache/cassandra/pull/3663#discussion_r1849192511
##########
src/java/org/apache/cassandra/db/Mutation.java:
##########
@@ -150,6 +150,11 @@ public ImmutableCollection<PartitionUpdate> getPartitionUpdates()
return modifications.values();
}
+ public long getApproxCreatedAtNanos()
+ {
+ return approxCreatedAtNanos;
Review Comment:
`ModificationStatement#executeWithoutCondition` creates the write/delete timestamps before the mutations themselves are created. This means that hints could still be delivered late if enough time passes after creating the timestamps.
This should err on the side of discarding hints early, so we should be recording a timestamp before actually creating mutation timestamps.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Use mutation creation time for hint expiry rather than hint submission time [cassandra]
Posted by "Jollyplum (via GitHub)" <gi...@apache.org>.
Jollyplum commented on PR #3663:
URL: https://github.com/apache/cassandra/pull/3663#issuecomment-2489814784
> Could we also make maxHintTTL settable via JMX?
Given it's a -D system property now, with a max int default, how did you want this to behave?
I see in some places we have -D that falls back on yaml, but they're only a couple of them and they look to be consumed just on startup and not settable via jmx e.g
```
public static String getAllocateTokensForKeyspace()
{
return ALLOCATE_TOKENS_FOR_KEYSPACE.getString(conf.allocate_tokens_for_keyspace);
```
I could make it perhaps a yaml property, which if the system property is set defaults to that? but it's breaking with quite a few conventions. Removing the -D and replacing with yaml only is probably also not feasible for something that's intended to be back-ported.
Maybe allowing either to be set, but complaining if both are set on startup?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Use mutation creation time for hint expiry rather than hint submission time [cassandra]
Posted by "bdeggleston (via GitHub)" <gi...@apache.org>.
bdeggleston commented on PR #3663:
URL: https://github.com/apache/cassandra/pull/3663#issuecomment-2489839387
> Given it's a -D system property now, with a max int default, how did you want this to behave?
Initialization on startup wouldn't change, it would just become volatile and have some methods on StorageService or whatever to change it. I wouldn't add a yaml prop
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Use mutation creation time for hint expiry rather than hint submission time [cassandra]
Posted by "Jollyplum (via GitHub)" <gi...@apache.org>.
Jollyplum commented on code in PR #3663:
URL: https://github.com/apache/cassandra/pull/3663#discussion_r1851157813
##########
src/java/org/apache/cassandra/db/Mutation.java:
##########
@@ -150,6 +150,11 @@ public ImmutableCollection<PartitionUpdate> getPartitionUpdates()
return modifications.values();
}
+ public long getApproxCreatedAtNanos()
+ {
+ return approxCreatedAtNanos;
Review Comment:
Yeah definitely agree that there is still this window(albeit likely much shorter) between mutation timestamp creation and the approximate time generated inside the mutation constructor.
At first glance it's quite a bit more fiddly to get some sort of timestamp pre mutation constructor timestamp and propagate it everywhere, but I can have a go at taking RequestTime.startedAtNanos or RequestTime.enqueuedAtNanos and plumbing it through to the mutation constructor everywhere.
We'll also be adding a long in the Mutation object to solve this issue, so at fairly tiny but non-negligible cost.
Or I suppose slightly alternatively we could try and pull approxCreatedAtNanos out to just before the write/delete timestamps are generated, though this has some downstream effects due to it's other use, which need to be reasoned carefully about.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Use mutation creation time for hint expiry rather than hint submission time [cassandra]
Posted by "bdeggleston (via GitHub)" <gi...@apache.org>.
bdeggleston commented on code in PR #3663:
URL: https://github.com/apache/cassandra/pull/3663#discussion_r1851167624
##########
src/java/org/apache/cassandra/db/Mutation.java:
##########
@@ -150,6 +150,11 @@ public ImmutableCollection<PartitionUpdate> getPartitionUpdates()
return modifications.values();
}
+ public long getApproxCreatedAtNanos()
+ {
+ return approxCreatedAtNanos;
Review Comment:
I probably wouldn't add it to Mutation. For `ModificationStatement#executeWithoutCondition` at least, you can grab nanoTime before the call to getMutations, then just pass it into the StorageProxy call as an argument. From there I think you need to plumb it to AbstractWriteResponseHandler and the call to `hintMutations`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] Use mutation creation time for hint expiry rather than hint submission time [cassandra]
Posted by "Jollyplum (via GitHub)" <gi...@apache.org>.
Jollyplum closed pull request #3663: Use mutation creation time for hint expiry rather than hint submission time
URL: https://github.com/apache/cassandra/pull/3663
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org