Skip to content

Commit ef045eb

Browse files
authored
CNDB-15716: register sensors in paxos v2 (#2070)
### What is the issue Paxos v2 doesn't have sensors ### What does this PR fix and why was it fixed Register sensors in paxos v2
1 parent 1944b30 commit ef045eb

File tree

2 files changed

+62
-6
lines changed

2 files changed

+62
-6
lines changed

src/java/org/apache/cassandra/service/paxos/PaxosPrepare.java

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@
5252
import org.apache.cassandra.schema.Schema;
5353
import org.apache.cassandra.schema.TableId;
5454
import org.apache.cassandra.schema.TableMetadata;
55+
import org.apache.cassandra.sensors.Context;
56+
import org.apache.cassandra.sensors.RequestSensors;
57+
import org.apache.cassandra.sensors.RequestTracker;
58+
import org.apache.cassandra.sensors.SensorsCustomParams;
59+
import org.apache.cassandra.sensors.SensorsFactory;
60+
import org.apache.cassandra.sensors.Type;
5561
import org.apache.cassandra.service.PendingRangeCalculatorService;
5662
import org.apache.cassandra.service.paxos.PaxosPrepare.Status.Outcome;
5763
import org.apache.cassandra.tracing.Tracing;
@@ -1021,11 +1027,33 @@ public static class RequestHandler implements IVerbHandler<Request>
10211027
@Override
10221028
public void doVerb(Message<Request> message)
10231029
{
1030+
// Initialize the sensor and set ExecutorLocals
1031+
RequestSensors sensors = SensorsFactory.instance.createRequestSensors(message.payload.table.keyspace);
1032+
Context context = Context.from(message.payload.table);
1033+
1034+
// Prepare phase incorporates a read to check the cas condition, so a read sensor is registered in addition to the write sensor
1035+
sensors.registerSensor(context, Type.READ_BYTES);
1036+
sensors.registerSensor(context, Type.WRITE_BYTES);
1037+
sensors.registerSensor(context, Type.INTERNODE_BYTES);
1038+
sensors.incrementSensor(context, Type.INTERNODE_BYTES, message.payloadSize(MessagingService.current_version));
1039+
RequestTracker.instance.set(sensors);
1040+
10241041
Response response = execute(message.payload, message.from());
1025-
if (response == null)
1026-
MessagingService.instance().respondWithFailure(UNKNOWN, message);
1042+
1043+
// calculate outbound internode bytes before adding the sensor to the response
1044+
if (response != null)
1045+
{
1046+
Message.Builder<Response> reply = message.responseWithBuilder(response);
1047+
int size = reply.currentPayloadSize(MessagingService.current_version);
1048+
sensors.incrementSensor(context, Type.INTERNODE_BYTES, size);
1049+
sensors.syncAllSensors();
1050+
SensorsCustomParams.addSensorsToInternodeResponse(sensors, reply);
1051+
MessagingService.instance().send(reply.build(), message.from());
1052+
}
10271053
else
1028-
MessagingService.instance().respond(response, message);
1054+
{
1055+
MessagingService.instance().respondWithFailure(UNKNOWN, message);
1056+
}
10291057
}
10301058

10311059
static Response execute(AbstractRequest<?> request, InetAddressAndPort from)

src/java/org/apache/cassandra/service/paxos/PaxosPropose.java

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
import org.apache.cassandra.net.IVerbHandler;
3838
import org.apache.cassandra.net.Message;
3939
import org.apache.cassandra.net.MessagingService;
40+
import org.apache.cassandra.sensors.Context;
41+
import org.apache.cassandra.sensors.RequestSensors;
42+
import org.apache.cassandra.sensors.RequestTracker;
43+
import org.apache.cassandra.sensors.SensorsCustomParams;
44+
import org.apache.cassandra.sensors.SensorsFactory;
45+
import org.apache.cassandra.sensors.Type;
4046
import org.apache.cassandra.service.paxos.Commit.Proposal;
4147
import org.apache.cassandra.utils.concurrent.ConditionAsConsumer;
4248

@@ -408,11 +414,33 @@ public static class RequestHandler implements IVerbHandler<Request>
408414
@Override
409415
public void doVerb(Message<Request> message)
410416
{
417+
// Initialize the sensor and set ExecutorLocals
418+
RequestSensors sensors = SensorsFactory.instance.createRequestSensors(message.payload.proposal.update.metadata().keyspace);
419+
Context context = Context.from(message.payload.proposal.update.metadata());
420+
421+
// Propose phase consults the Paxos table for more recent promises, so a read sensor is registered in addition to the write sensor
422+
sensors.registerSensor(context, Type.READ_BYTES);
423+
sensors.registerSensor(context, Type.WRITE_BYTES);
424+
sensors.registerSensor(context, Type.INTERNODE_BYTES);
425+
sensors.incrementSensor(context, Type.INTERNODE_BYTES, message.payloadSize(MessagingService.current_version));
426+
RequestTracker.instance.set(sensors);
427+
411428
Response response = execute(message.payload.proposal, message.from());
412-
if (response == null)
413-
MessagingService.instance().respondWithFailure(UNKNOWN, message);
429+
430+
// calculate outbound internode bytes before adding the sensor to the response
431+
if (response != null)
432+
{
433+
Message.Builder<Response> reply = message.responseWithBuilder(response);
434+
int size = reply.currentPayloadSize(MessagingService.current_version);
435+
sensors.incrementSensor(context, Type.INTERNODE_BYTES, size);
436+
sensors.syncAllSensors();
437+
SensorsCustomParams.addSensorsToInternodeResponse(sensors, reply);
438+
MessagingService.instance().send(reply.build(), message.from());
439+
}
414440
else
415-
MessagingService.instance().respond(response, message);
441+
{
442+
MessagingService.instance().respondWithFailure(UNKNOWN, message);
443+
}
416444
}
417445

418446
public static Response execute(Proposal proposal, InetAddressAndPort from)

0 commit comments

Comments
 (0)