forked from Instagram/cassandra
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve the performance of CAS operation
Combine the paxos prepare and quorum read stage together
- Loading branch information
Showing
11 changed files
with
500 additions
and
42 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
170 changes: 137 additions & 33 deletions
170
src/java/org/apache/cassandra/service/StorageProxy.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
58 changes: 58 additions & 0 deletions
58
src/java/org/apache/cassandra/service/paxos/PrepareAndReadCallback.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,58 @@ | ||
/* | ||
* 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.paxos; | ||
|
||
import org.apache.cassandra.db.partitions.PartitionIterator; | ||
import org.apache.cassandra.net.IAsyncCallback; | ||
import org.apache.cassandra.net.MessageIn; | ||
import org.apache.cassandra.service.reads.DataResolver; | ||
import org.apache.cassandra.service.reads.ReadCallback; | ||
|
||
public class PrepareAndReadCallback implements IAsyncCallback<PrepareAndReadResponse> | ||
{ | ||
public final PrepareCallback prepareCallback; | ||
public final ReadCallback readCallback; | ||
public PartitionIterator iterator = null; | ||
|
||
public PrepareAndReadCallback(PrepareCallback prepareCallback, ReadCallback readCallback) | ||
{ | ||
this.prepareCallback = prepareCallback; | ||
this.readCallback = readCallback; | ||
} | ||
|
||
@Override | ||
public void response(MessageIn<PrepareAndReadResponse> msg) | ||
{ | ||
PrepareAndReadResponse response = msg.payload; | ||
prepareCallback.response(response.prepareResponse, msg.from); | ||
readCallback.response(response.readResponse); | ||
} | ||
|
||
@Override | ||
public boolean isLatencyForSnitch() | ||
{ | ||
return false; | ||
} | ||
|
||
public void await() | ||
{ | ||
readCallback.awaitResults(); | ||
iterator = ((DataResolver)readCallback.resolver).getData(); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/java/org/apache/cassandra/service/paxos/PrepareAndReadCommand.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,65 @@ | ||
/* | ||
* 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.paxos; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.cassandra.db.ReadCommand; | ||
import org.apache.cassandra.io.IVersionedSerializer; | ||
import org.apache.cassandra.io.util.DataInputPlus; | ||
import org.apache.cassandra.io.util.DataOutputPlus; | ||
|
||
public class PrepareAndReadCommand | ||
{ | ||
public static final CASPrepareCommandSerializer serializer = new CASPrepareCommandSerializer(); | ||
|
||
public final Commit commit; | ||
public final ReadCommand readCommand; | ||
|
||
public PrepareAndReadCommand(Commit commit, ReadCommand readCommand) | ||
{ | ||
this.commit = commit; | ||
this.readCommand = readCommand; | ||
} | ||
|
||
public static class CASPrepareCommandSerializer implements IVersionedSerializer<PrepareAndReadCommand> | ||
{ | ||
@Override | ||
public void serialize(PrepareAndReadCommand prepareAndReadCommand, DataOutputPlus out, int version) throws IOException | ||
{ | ||
Commit.serializer.serialize(prepareAndReadCommand.commit, out, version); | ||
ReadCommand.serializer.serialize(prepareAndReadCommand.readCommand, out, version); | ||
} | ||
|
||
@Override | ||
public PrepareAndReadCommand deserialize(DataInputPlus in, int version) throws IOException | ||
{ | ||
Commit commit = Commit.serializer.deserialize(in, version); | ||
ReadCommand readCommand = ReadCommand.serializer.deserialize(in, version); | ||
return new PrepareAndReadCommand(commit, readCommand); | ||
} | ||
|
||
@Override | ||
public long serializedSize(PrepareAndReadCommand prepareAndReadCommand, int version) | ||
{ | ||
return Commit.serializer.serializedSize(prepareAndReadCommand.commit, version) + | ||
ReadCommand.serializer.serializedSize(prepareAndReadCommand.readCommand, version); | ||
} | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/java/org/apache/cassandra/service/paxos/PrepareAndReadResponse.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,68 @@ | ||
/* | ||
* 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.paxos; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.cassandra.db.ReadResponse; | ||
import org.apache.cassandra.io.IVersionedSerializer; | ||
import org.apache.cassandra.io.util.DataInputPlus; | ||
import org.apache.cassandra.io.util.DataOutputPlus; | ||
|
||
public class PrepareAndReadResponse | ||
{ | ||
public static final PrepareResponseSerializer serializer = new PrepareResponseSerializer(); | ||
|
||
public final PrepareResponse prepareResponse; | ||
public final ReadResponse readResponse; | ||
|
||
public PrepareAndReadResponse(PrepareResponse prepareResponse, ReadResponse readResponse) | ||
{ | ||
this.prepareResponse = prepareResponse; | ||
this.readResponse = readResponse; | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return String.format("PrepareAndReadResponse(%s, %s)", prepareResponse, readResponse); | ||
} | ||
|
||
public static class PrepareResponseSerializer implements IVersionedSerializer<PrepareAndReadResponse> | ||
{ | ||
public void serialize(PrepareAndReadResponse response, DataOutputPlus out, int version) throws IOException | ||
{ | ||
ReadResponse.serializer.serialize(response.readResponse, out, version); | ||
PrepareResponse.serializer.serialize(response.prepareResponse, out, version); | ||
} | ||
|
||
public PrepareAndReadResponse deserialize(DataInputPlus in, int version) throws IOException | ||
{ | ||
ReadResponse readResponse = ReadResponse.serializer.deserialize(in, version); | ||
PrepareResponse prepareResponse = PrepareResponse.serializer.deserialize(in, version); | ||
return new PrepareAndReadResponse(prepareResponse, readResponse); | ||
} | ||
|
||
public long serializedSize(PrepareAndReadResponse response, int version) | ||
{ | ||
return PrepareResponse.serializer.serializedSize(response.prepareResponse, version) + | ||
ReadResponse.serializer.serializedSize(response.readResponse, version); | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/java/org/apache/cassandra/service/paxos/PrepareAndReadVerbHandler.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,54 @@ | ||
/* | ||
* 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.paxos; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.cassandra.db.ReadCommand; | ||
import org.apache.cassandra.db.ReadExecutionController; | ||
import org.apache.cassandra.db.ReadResponse; | ||
import org.apache.cassandra.db.partitions.UnfilteredPartitionIterator; | ||
import org.apache.cassandra.net.IVerbHandler; | ||
import org.apache.cassandra.net.MessageIn; | ||
import org.apache.cassandra.net.MessageOut; | ||
import org.apache.cassandra.net.MessagingService; | ||
|
||
public class PrepareAndReadVerbHandler implements IVerbHandler<PrepareAndReadCommand> | ||
{ | ||
@Override | ||
public void doVerb(MessageIn<PrepareAndReadCommand> message, int id) throws IOException | ||
{ | ||
PrepareAndReadCommand prepareCommand = message.payload; | ||
PrepareResponse paxosResponse = PaxosState.prepare(prepareCommand.commit); | ||
ReadCommand command = prepareCommand.readCommand; | ||
|
||
ReadResponse readResponse; | ||
|
||
try (ReadExecutionController executionController = command.executionController(); | ||
UnfilteredPartitionIterator iterator = command.executeLocally(executionController)) | ||
{ | ||
readResponse = command.createResponse(iterator); | ||
} | ||
|
||
PrepareAndReadResponse response = new PrepareAndReadResponse(paxosResponse, readResponse); | ||
|
||
MessageOut<PrepareAndReadResponse> reply = new MessageOut<>(MessagingService.Verb.REQUEST_RESPONSE, response, PrepareAndReadResponse.serializer); | ||
MessagingService.instance().sendReply(reply, id, message.from); | ||
} | ||
} |
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.