Skip to content

Commit 5e128fb

Browse files
committed
rename RequestTrackingInfo to SessionRequestInfo and HostTrackingInfo to NodeRequestInfo, add PrepareRequest to NodeRequestInfo
1 parent 1884532 commit 5e128fb

23 files changed

+348
-328
lines changed

src/Cassandra.Tests/OpenTelemetryTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public async Task OpenTelemetryRequestTrackerOnStartAsync_StatementIsNull_DbQuer
4444
var cassandraInstrumentationOptions = new CassandraInstrumentationOptions { IncludeDatabaseStatement = true };
4545
var requestTracker = new OpenTelemetryRequestTracker(cassandraInstrumentationOptions);
4646
IStatement statement = null;
47-
var requestTrackingInfo = new RequestTrackingInfo(statement, null);
47+
var requestTrackingInfo = new SessionRequestInfo(statement, null);
4848

4949
await requestTracker.OnStartAsync(requestTrackingInfo).ConfigureAwait(false);
5050

@@ -72,7 +72,7 @@ public async Task OpenTelemetryRequestTrackerOnStartAsync_ListenerNotSampling_Ac
7272
var cassandraInstrumentationOptions = new CassandraInstrumentationOptions { IncludeDatabaseStatement = true };
7373
var requestTracker = new OpenTelemetryRequestTracker(cassandraInstrumentationOptions);
7474
IStatement statement = null;
75-
var requestTrackingInfo = new RequestTrackingInfo(statement, null);
75+
var requestTrackingInfo = new SessionRequestInfo(statement, null);
7676

7777
await requestTracker.OnStartAsync(requestTrackingInfo).ConfigureAwait(false);
7878

@@ -99,10 +99,10 @@ public async Task OpenTelemetryRequestTrackerOnNodeStartAsync_StatementIsNull_Db
9999
var requestTracker = new OpenTelemetryRequestTracker(cassandraInstrumentationOptions);
100100

101101
IStatement statement = null;
102-
var requestTrackingInfo = new RequestTrackingInfo(statement, null);
102+
var requestTrackingInfo = new SessionRequestInfo(statement, null);
103103

104104
var host = new Host(new System.Net.IPEndPoint(1, 9042), new ConstantReconnectionPolicy(1));
105-
var hostTrackingInfo = new HostTrackingInfo(host, Guid.NewGuid());
105+
var hostTrackingInfo = new NodeRequestInfo(host, null);
106106

107107
await requestTracker.OnStartAsync(requestTrackingInfo).ConfigureAwait(false);
108108
await requestTracker.OnNodeStartAsync(requestTrackingInfo, hostTrackingInfo).ConfigureAwait(false);
@@ -132,10 +132,10 @@ public async Task OpenTelemetryRequestTrackerOnNodeStartAsync_ListenerNotSamplin
132132
var requestTracker = new OpenTelemetryRequestTracker(cassandraInstrumentationOptions);
133133

134134
IStatement statement = null;
135-
var requestTrackingInfo = new RequestTrackingInfo(statement, null);
135+
var requestTrackingInfo = new SessionRequestInfo(statement, null);
136136

137137
var host = new Host(new System.Net.IPEndPoint(1, 9042), new ConstantReconnectionPolicy(1));
138-
var hostTrackingInfo = new HostTrackingInfo(host, Guid.NewGuid());
138+
var hostTrackingInfo = new NodeRequestInfo(host, null);
139139

140140
await requestTracker.OnStartAsync(requestTrackingInfo).ConfigureAwait(false);
141141
await requestTracker.OnNodeStartAsync(requestTrackingInfo, hostTrackingInfo).ConfigureAwait(false);

src/Cassandra.Tests/RequestExecutionTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void Should_ThrowException_When_NoValidHosts(bool currentHostRetry)
3939
var mockSession = Mock.Of<IInternalSession>();
4040
var mockStatement = Mock.Of<IStatement>();
4141
var requestHandlerFactory = Mock.Of<IRequestHandlerFactory>();
42-
var requestTrackingInfo = new RequestTrackingInfo(mockStatement, null);
42+
var requestTrackingInfo = new SessionRequestInfo(mockStatement, null);
4343
Mock.Get(requestHandlerFactory)
4444
.Setup(r => r.CreateAsync(
4545
It.IsAny<IInternalSession>(),
@@ -69,7 +69,7 @@ public void Should_NotThrowException_When_AValidHostIsObtained(bool currentHostR
6969
var mockSession = Mock.Of<IInternalSession>();
7070
var requestHandlerFactory = Mock.Of<IRequestHandlerFactory>();
7171
var mockStatement = Mock.Of<IStatement>();
72-
var requestTrackingInfo = new RequestTrackingInfo(mockStatement, null);
72+
var requestTrackingInfo = new SessionRequestInfo(mockStatement, null);
7373
Mock.Get(requestHandlerFactory)
7474
.Setup(r => r.CreateAsync(
7575
It.IsAny<IInternalSession>(),
@@ -106,7 +106,7 @@ public void Should_SendRequest_When_AConnectionIsObtained(bool currentHostRetry)
106106
var mockSession = Mock.Of<IInternalSession>();
107107
var requestHandlerFactory = Mock.Of<IRequestHandlerFactory>();
108108
var mockStatement = Mock.Of<IStatement>();
109-
var requestTrackingInfo = new RequestTrackingInfo(mockStatement, null);
109+
var requestTrackingInfo = new SessionRequestInfo(mockStatement, null);
110110
Mock.Get(requestHandlerFactory)
111111
.Setup(r => r.CreateAsync(
112112
It.IsAny<IInternalSession>(),
@@ -157,7 +157,7 @@ public void Should_RetryRequestToSameHost_When_ConnectionFailsAndRetryDecisionIs
157157
var mockSession = Mock.Of<IInternalSession>();
158158
var requestHandlerFactory = Mock.Of<IRequestHandlerFactory>();
159159
var mockStatement = Mock.Of<IStatement>();
160-
var requestTrackingInfo = new RequestTrackingInfo(mockStatement, null);
160+
var requestTrackingInfo = new SessionRequestInfo(mockStatement, null);
161161
Mock.Get(requestHandlerFactory)
162162
.Setup(r => r.CreateAsync(
163163
It.IsAny<IInternalSession>(),

src/Cassandra.Tests/RequestHandlerMockTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private static Configuration GetConfig(ILoadBalancingPolicy lbp)
5454
It.IsAny<IInternalSession>(),
5555
It.IsAny<IRequest>(),
5656
It.IsAny<IRequestObserver>(),
57-
It.IsAny<RequestTrackingInfo>()))
57+
It.IsAny<SessionRequestInfo>()))
5858
.Returns(Mock.Of<IRequestExecution>());
5959

6060
return new TestConfigurationBuilder

src/Cassandra/HostTrackingInfo.cs

Lines changed: 0 additions & 70 deletions
This file was deleted.

src/Cassandra/IRequestTracker.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,56 +27,56 @@ public interface IRequestTracker
2727
/// <summary>
2828
/// Triggered when the request starts.
2929
/// </summary>
30-
/// <param name="request"></param>
30+
/// <param name="sessionRequestInfo"></param>
3131
/// <returns>Contextual task.</returns>
32-
Task OnStartAsync(RequestTrackingInfo request);
32+
Task OnStartAsync(SessionRequestInfo sessionRequestInfo);
3333

3434
/// <summary>
3535
/// Triggered when the session level request finishes successfully.
3636
/// </summary>
37-
/// <param name="request"></param>
37+
/// <param name="sessionRequestInfo"></param>
3838
/// <returns>Contextual task.</returns>
39-
Task OnSuccessAsync(RequestTrackingInfo request);
39+
Task OnSuccessAsync(SessionRequestInfo sessionRequestInfo);
4040

4141
/// <summary>
4242
/// Triggered when the session level request finishes unsuccessfully.
4343
/// </summary>
44-
/// <param name="request">Request contextual information.</param>
44+
/// <param name="sessionRequestInfo">Request contextual information.</param>
4545
/// <param name="ex">Request exception.</param>
4646
/// <returns>Contextual task.</returns>
47-
Task OnErrorAsync(RequestTrackingInfo request, Exception ex);
47+
Task OnErrorAsync(SessionRequestInfo sessionRequestInfo, Exception ex);
4848

4949
/// <summary>
5050
/// Triggered when the node level request finishes successfully.
5151
/// </summary>
52-
/// <param name="request">Request contextual information.</param>
53-
/// <param name="hostInfo">Struct with host contextual information.</param>
52+
/// <param name="sessionRequestInfo">Request contextual information.</param>
53+
/// <param name="nodeRequestInfo">Struct with host contextual information.</param>
5454
/// <returns>Contextual task.</returns>
55-
Task OnNodeSuccessAsync(RequestTrackingInfo request, HostTrackingInfo hostInfo);
55+
Task OnNodeSuccessAsync(SessionRequestInfo sessionRequestInfo, NodeRequestInfo nodeRequestInfo);
5656

5757
/// <summary>
5858
/// Triggered when the node request finishes unsuccessfully.
5959
/// </summary>
60-
/// <param name="request"><see cref="RequestTrackingInfo"/> object with contextual information.</param>
61-
/// <param name="hostInfo">Struct with host contextual information.</param>
60+
/// <param name="sessionRequestInfo"><see cref="SessionRequestInfo"/> object with contextual information.</param>
61+
/// <param name="nodeRequestInfo">Struct with host contextual information.</param>
6262
/// <param name="ex">Exception information.</param>
6363
/// <returns>Contextual task.</returns>
64-
Task OnNodeErrorAsync(RequestTrackingInfo request, HostTrackingInfo hostInfo, Exception ex);
64+
Task OnNodeErrorAsync(SessionRequestInfo sessionRequestInfo, NodeRequestInfo nodeRequestInfo, Exception ex);
6565

6666
/// <summary>
6767
/// Triggered when the node request is aborted (e.g. pending speculative execution that was canceled due to another execution completing).
6868
/// </summary>
69-
/// <param name="request"><see cref="RequestTrackingInfo"/> object with contextual information.</param>
70-
/// <param name="hostInfo">Struct with host contextual information.</param>
69+
/// <param name="sessionRequestInfo"><see cref="SessionRequestInfo"/> object with contextual information.</param>
70+
/// <param name="nodeRequestInfo">Struct with host contextual information.</param>
7171
/// <returns>Contextual task.</returns>
72-
Task OnNodeAborted(RequestTrackingInfo request, HostTrackingInfo hostInfo);
72+
Task OnNodeAborted(SessionRequestInfo sessionRequestInfo, NodeRequestInfo nodeRequestInfo);
7373

7474
/// <summary>
7575
/// Triggered when the node request starts.
7676
/// </summary>
77-
/// <param name="request"><see cref="RequestTrackingInfo"/> object with contextual information.</param>
78-
/// <param name="hostInfo">Struct with host contextual information.</param>
77+
/// <param name="sessionRequestInfo"><see cref="SessionRequestInfo"/> object with contextual information.</param>
78+
/// <param name="nodeRequestInfo">Struct with host contextual information.</param>
7979
/// <returns>Contextual task.</returns>
80-
Task OnNodeStartAsync(RequestTrackingInfo request, HostTrackingInfo hostInfo);
80+
Task OnNodeStartAsync(SessionRequestInfo sessionRequestInfo, NodeRequestInfo nodeRequestInfo);
8181
}
8282
}

src/Cassandra/NodeRequestInfo.cs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//
2+
// Copyright (C) DataStax Inc.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
using System;
18+
19+
namespace Cassandra
20+
{
21+
/// <summary>
22+
/// Class used to hold data that is passed to implementations of <see cref="IRequestTracker"/>.
23+
/// </summary>
24+
public class NodeRequestInfo : IEquatable<NodeRequestInfo>
25+
{
26+
/// <summary>
27+
/// Host that this node request is being sent to.
28+
/// </summary>
29+
public Host Host { get; }
30+
31+
/// <summary>
32+
/// Each node request has a unique ID so that <see cref="IRequestTracker"/> implementations can maintain context per node request.
33+
/// </summary>
34+
public Guid ExecutionId { get; }
35+
36+
/// <summary>
37+
/// Note that this can be different to the parent's <see cref="SessionRequestInfo.PrepareRequest"/>.
38+
/// An example case where this can happen is if the session request is a <see cref="BoundStatement"/> (so <see cref="SessionRequestInfo.PrepareRequest"/> is null)
39+
/// and this node request is a PREPARE because the server replied with an UNPREPARED response so the driver has to re-prepare the statement before retrying the <see cref="BoundStatement"/>.
40+
/// </summary>
41+
public PrepareRequest PrepareRequest { get; }
42+
43+
internal NodeRequestInfo(Host host, PrepareRequest prepareRequest)
44+
{
45+
Host = host;
46+
ExecutionId = Guid.NewGuid();
47+
PrepareRequest = prepareRequest;
48+
}
49+
50+
public bool Equals(NodeRequestInfo other)
51+
{
52+
return other != null && other.ExecutionId.Equals(ExecutionId);
53+
}
54+
55+
public static bool operator ==(NodeRequestInfo a, NodeRequestInfo b)
56+
{
57+
if (a == null)
58+
{
59+
return b == null;
60+
}
61+
62+
return a.Equals(b);
63+
}
64+
65+
public static bool operator !=(NodeRequestInfo a, NodeRequestInfo b)
66+
{
67+
return !(a == b);
68+
}
69+
70+
public override bool Equals(object obj)
71+
{
72+
if (!(obj is NodeRequestInfo info))
73+
{
74+
return false;
75+
}
76+
return Equals(info);
77+
}
78+
79+
public override int GetHashCode()
80+
{
81+
unchecked
82+
{
83+
return ((Host != null ? Host.GetHashCode() : 0) * 397) ^ ExecutionId.GetHashCode();
84+
}
85+
}
86+
}
87+
}

src/Cassandra/Observers/Abstractions/IRequestObserver.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ internal interface IRequestObserver
2828
{
2929
void OnSpeculativeExecution(Host host, long delay);
3030

31-
Task OnNodeStartAsync(RequestTrackingInfo requestTrackingInfo, HostTrackingInfo hostTrackingInfo);
31+
Task OnNodeStartAsync(SessionRequestInfo sessionRequestInfo, NodeRequestInfo nodeRequestInfo);
3232

33-
Task OnNodeRequestErrorAsync(RequestErrorType errorType, RetryDecision.RetryDecisionType decision, RequestTrackingInfo r, HostTrackingInfo hostTrackingInfo, Exception ex);
33+
Task OnNodeRequestErrorAsync(RequestErrorType errorType, RetryDecision.RetryDecisionType decision, SessionRequestInfo r, NodeRequestInfo nodeRequestInfo, Exception ex);
3434

35-
Task OnNodeRequestErrorAsync(IRequestError error, RequestTrackingInfo r, HostTrackingInfo hostTrackingInfo);
35+
Task OnNodeRequestErrorAsync(IRequestError error, SessionRequestInfo r, NodeRequestInfo nodeRequestInfo);
3636

37-
Task OnNodeSuccessAsync(RequestTrackingInfo requestTrackingInfo, HostTrackingInfo hostTrackingInfo);
37+
Task OnNodeSuccessAsync(SessionRequestInfo sessionRequestInfo, NodeRequestInfo nodeRequestInfo);
3838

39-
Task OnNodeRequestAbortedAsync(RequestTrackingInfo requestTrackingInfo, HostTrackingInfo hostTrackingInfo);
39+
Task OnNodeRequestAbortedAsync(SessionRequestInfo sessionRequestInfo, NodeRequestInfo nodeRequestInfo);
4040

41-
Task OnRequestStartAsync(RequestTrackingInfo requestTrackingInfo);
41+
Task OnRequestStartAsync(SessionRequestInfo sessionRequestInfo);
4242

43-
Task OnRequestFailureAsync(Exception ex, RequestTrackingInfo requestTrackingInfo);
43+
Task OnRequestFailureAsync(Exception ex, SessionRequestInfo sessionRequestInfo);
4444

45-
Task OnRequestSuccessAsync(RequestTrackingInfo requestTrackingInfo);
45+
Task OnRequestSuccessAsync(SessionRequestInfo sessionRequestInfo);
4646
}
4747
}

0 commit comments

Comments
 (0)