forked from apache/cassandra
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
STAR-1341 abstract mutations used by CDC (apache#458)
* abstract mutations used by CDC At first, I tried to refactor StorageProxy methods and WritePerformer interface, but since every now and then we want to rebase on OS C*, I reverted all the changes. Instead, a new abstraction level over various mutate methods is introduced - Mutator. The default implementation proxies the calls to the original (default) methods. The users may provide a custom class Mutator implementation to alter the mutation behavior. This solution was chosen to minimize the rebase conflicts, it's a compromise between code structuring and maintenance cost. In the ideal world we could refactor the mutation methods to separate classes. * add ComplexColumnData.hasCells * make currentTimeoutNanos overridable CDCWriteResponseHandler doesn't use the default timeout taken from DatabaseDescriptor * port 'CNDB-3334 CDC counter support' Add applyCounterMutationWithoutLocks method. The method applies the counter without locks (not needed in CDC as all the writes to the same partition are serialized by CDC Service). The mutation is applied with the given id and clockMicros. The values are precomputed and distributed by CDC Service. Writers receive the mutation with the attached values, thanks to this all the writers may apply the mutation as if they were leader replicas. See the ticket description for details on leader and follower replica concepts used by pure Cassandra counter write path. * make RepairedDataInfo public RepairedDataInfo.NO_OP_REPAIRED_DATA_INFO is used by CDC to denote no repair data info. (cherry picked from commit 5191be2) (cherry picked from commit 75b8d12) (cherry picked from commit ba2a0a6)
- Loading branch information
1 parent
6b0c581
commit 22eefdc
Showing
13 changed files
with
378 additions
and
38 deletions.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* 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.service; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import org.apache.cassandra.db.ConsistencyLevel; | ||
import org.apache.cassandra.db.CounterMutation; | ||
import org.apache.cassandra.db.IMutation; | ||
import org.apache.cassandra.db.Mutation; | ||
import org.apache.cassandra.db.WriteType; | ||
import org.apache.cassandra.service.paxos.Commit; | ||
|
||
/** | ||
* Facilitates mutations for counters, simple inserts, unlogged batches and LWTs. | ||
* Used on the coordinator. | ||
* <br/> | ||
* The implementations may choose how and where to send the mutations. | ||
* <br/> | ||
* An instance of this interface implementation must be obtained via {@link MutatorProvider#instance}. | ||
*/ | ||
public interface Mutator | ||
{ | ||
/** | ||
* Used for handling counter mutations on the coordinator level. | ||
*/ | ||
AbstractWriteResponseHandler<IMutation> mutateCounter(CounterMutation cm, String localDataCenter, long queryStartNanoTime); | ||
|
||
/** | ||
* Used for standard inserts and unlogged batchs. | ||
*/ | ||
AbstractWriteResponseHandler<IMutation> mutateStandard(Mutation mutation, | ||
ConsistencyLevel consistencyLevel, | ||
String localDataCenter, | ||
StorageProxy.WritePerformer writePerformer, | ||
Runnable callback, | ||
WriteType writeType, | ||
long queryStartNanoTime); | ||
|
||
/** | ||
* Used for LWT mutation at the last (COMMIT) phase of Paxos. | ||
*/ | ||
@Nullable | ||
AbstractWriteResponseHandler<Commit> mutatePaxos(Commit proposal, ConsistencyLevel consistencyLevel, boolean allowHints, long queryStartNanoTime); | ||
} |
56 changes: 56 additions & 0 deletions
56
src/java/org/apache/cassandra/service/MutatorProvider.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,56 @@ | ||
/* | ||
* 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.service; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
|
||
import org.apache.cassandra.utils.FBUtilities; | ||
|
||
import static org.apache.cassandra.config.CassandraRelevantProperties.CUSTOM_MUTATOR_CLASS; | ||
|
||
/** | ||
* Provides an instance of {@link Mutator} that facilitates mutation writes for standard mutations, unlogged batches, | ||
* counters and paxos commits (LWT)s. | ||
* <br/> | ||
* An implementation may choose to fallback to the default implementation ({@link StorageProxy.DefaultMutator}) | ||
* obtained via {@link #getDefaultMutator()}. | ||
*/ | ||
public abstract class MutatorProvider | ||
{ | ||
static final Mutator instance = getCustomOrDefault(); | ||
|
||
@VisibleForTesting | ||
static Mutator getCustomOrDefault() | ||
{ | ||
if (CUSTOM_MUTATOR_CLASS.isPresent()) | ||
{ | ||
return FBUtilities.construct(CUSTOM_MUTATOR_CLASS.getString(), | ||
"custom mutator class (set with " + CUSTOM_MUTATOR_CLASS.getKey() + ")"); | ||
} | ||
else | ||
{ | ||
return getDefaultMutator(); | ||
} | ||
} | ||
|
||
public static Mutator getDefaultMutator() | ||
{ | ||
return new StorageProxy.DefaultMutator(); | ||
} | ||
} |
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
Oops, something went wrong.