1
1
package tech .ydb .topic .write ;
2
2
3
+ import java .time .Duration ;
4
+
3
5
/**
4
6
* @author Nikolay Perfilov
5
7
*/
6
8
public class WriteAck {
7
9
private final long seqNo ;
8
10
private final State state ;
9
11
private final Details details ;
12
+ private final Statistics statistics ;
10
13
11
- public WriteAck (long seqNo , State state , Details details ) {
14
+ public WriteAck (long seqNo , State state , Details details , Statistics statistics ) {
12
15
this .seqNo = seqNo ;
13
16
this .state = state ;
14
17
this .details = details ;
18
+ this .statistics = statistics ;
15
19
}
16
20
17
21
public enum State {
@@ -20,18 +24,6 @@ public enum State {
20
24
WRITTEN_IN_TX
21
25
}
22
26
23
- public static class Details {
24
- private final long offset ;
25
-
26
- public Details (long offset ) {
27
- this .offset = offset ;
28
- }
29
-
30
- public long getOffset () {
31
- return offset ;
32
- }
33
- }
34
-
35
27
public long getSeqNo () {
36
28
return seqNo ;
37
29
}
@@ -47,4 +39,95 @@ public State getState() {
47
39
public Details getDetails () {
48
40
return details ;
49
41
}
42
+
43
+ /**
44
+ * Returns write statistics associated with this write confirmation.
45
+ * Note: The statistics may cover multiple messages confirmed together by the server.
46
+ * Although this WriteAck corresponds to a single written message, the server may confirm several messages in a single response.
47
+ * Therefore, the returned statistics may represent the combined data for all messages included in the same write confirmation from the server.
48
+ * @return {@link Statistics} with timings if statistics are available or null otherwise
49
+ */
50
+ public Statistics getStatistics () {
51
+ return statistics ;
52
+ }
53
+
54
+ public static class Details {
55
+ private final long offset ;
56
+
57
+ public Details (long offset ) {
58
+ this .offset = offset ;
59
+ }
60
+
61
+ public long getOffset () {
62
+ return offset ;
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Messages batch statistics.
68
+ * All messages within the batch are persisted together so write
69
+ * statistics is for the whole messages batch.
70
+ */
71
+ public static class Statistics {
72
+ private final Duration persistingTime ;
73
+ private final Duration partitionQuotaWaitTime ;
74
+ private final Duration topicQuotaWaitTime ;
75
+ private final Duration maxQueueWaitTime ;
76
+ private final Duration minQueueWaitTime ;
77
+
78
+ /**
79
+ * Create the messages batch statistics object, for a single messages batch.
80
+ *
81
+ * @param persistingTime
82
+ * @param partitionQuotaWaitTime
83
+ * @param topicQuotaWaitTime
84
+ * @param maxQueueWaitTime
85
+ * @param minQueueWaitTime
86
+ */
87
+ public Statistics (Duration persistingTime ,
88
+ Duration partitionQuotaWaitTime , Duration topicQuotaWaitTime ,
89
+ Duration maxQueueWaitTime , Duration minQueueWaitTime ) {
90
+ this .persistingTime = persistingTime ;
91
+ this .partitionQuotaWaitTime = partitionQuotaWaitTime ;
92
+ this .topicQuotaWaitTime = topicQuotaWaitTime ;
93
+ this .maxQueueWaitTime = maxQueueWaitTime ;
94
+ this .minQueueWaitTime = minQueueWaitTime ;
95
+ }
96
+
97
+ /**
98
+ * @return Time spent in persisting of data.
99
+ */
100
+ public Duration getPersistingTime () {
101
+ return persistingTime ;
102
+ }
103
+
104
+ /**
105
+ * @return Time spent awaiting for partition write quota.
106
+ */
107
+ public Duration getPartitionQuotaWaitTime () {
108
+ return partitionQuotaWaitTime ;
109
+ }
110
+
111
+ /**
112
+ * @return Time spent awaiting for topic write quota.
113
+ */
114
+ public Duration getTopicQuotaWaitTime () {
115
+ return topicQuotaWaitTime ;
116
+ }
117
+
118
+ /**
119
+ * @return Time spent in queue before persisting, maximal of all messages in response.
120
+ */
121
+ public Duration getMaxQueueWaitTime () {
122
+ return maxQueueWaitTime ;
123
+ }
124
+
125
+ /**
126
+ * @return Time spent in queue before persisting, minimal of all messages in response.
127
+ */
128
+ public Duration getMinQueueWaitTime () {
129
+ return minQueueWaitTime ;
130
+ }
131
+ }
132
+
50
133
}
0 commit comments