Skip to content

Commit ec4022a

Browse files
authored
Simplify Driver data classes (#123373)
1 parent 1e82621 commit ec4022a

File tree

13 files changed

+150
-468
lines changed

13 files changed

+150
-468
lines changed

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/Driver.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public class Driver implements Releasable, Describable {
7777
private final DriverContext driverContext;
7878
private final Supplier<String> description;
7979
private final List<Operator> activeOperators;
80-
private final List<DriverStatus.OperatorStatus> statusOfCompletedOperators = new ArrayList<>();
80+
private final List<OperatorStatus> statusOfCompletedOperators = new ArrayList<>();
8181
private final Releasable releasable;
8282
private final long statusNanos;
8383

@@ -329,7 +329,7 @@ private void closeEarlyFinishedOperators() {
329329
Iterator<Operator> itr = finishedOperators.iterator();
330330
while (itr.hasNext()) {
331331
Operator op = itr.next();
332-
statusOfCompletedOperators.add(new DriverStatus.OperatorStatus(op.toString(), op.status()));
332+
statusOfCompletedOperators.add(new OperatorStatus(op.toString(), op.status()));
333333
op.close();
334334
itr.remove();
335335
}
@@ -555,7 +555,7 @@ private void updateStatus(long extraCpuNanos, int extraIterations, DriverStatus.
555555
prev.iterations() + extraIterations,
556556
status,
557557
statusOfCompletedOperators,
558-
activeOperators.stream().map(op -> new DriverStatus.OperatorStatus(op.toString(), op.status())).toList(),
558+
activeOperators.stream().map(op -> new OperatorStatus(op.toString(), op.status())).toList(),
559559
sleeps
560560
);
561561
});

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/DriverProfile.java

Lines changed: 32 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -21,98 +21,42 @@
2121
import java.io.IOException;
2222
import java.util.Iterator;
2323
import java.util.List;
24-
import java.util.Objects;
2524

2625
/**
2726
* Profile results from a single {@link Driver}.
27+
*
28+
* @param taskDescription Description of the task this driver is running. This description should be short and meaningful
29+
* as a grouping identifier. We use the phase of the query right now: "data", "node_reduce", "final".
30+
* @param startMillis Millis since epoch when the driver started.
31+
* @param stopMillis Millis since epoch when the driver stopped.
32+
* @param tookNanos Nanos between creation and completion of the {@link Driver}.
33+
* @param cpuNanos Nanos this {@link Driver} has been running on the cpu. Does not include async or waiting time.
34+
* @param iterations The number of times the driver has moved a single page up the chain of operators as far as it'll go.
35+
* @param operators Status of each {@link Operator} in the driver when it finished.
2836
*/
29-
public class DriverProfile implements Writeable, ChunkedToXContentObject {
30-
/**
31-
* Description of the task this driver is running. This description should be
32-
* short and meaningful as a grouping identifier. We use the phase of the
33-
* query right now: "data", "node_reduce", "final".
34-
*/
35-
private final String taskDescription;
36-
37-
/**
38-
* Millis since epoch when the driver started.
39-
*/
40-
private final long startMillis;
41-
42-
/**
43-
* Millis since epoch when the driver stopped.
44-
*/
45-
private final long stopMillis;
46-
47-
/**
48-
* Nanos between creation and completion of the {@link Driver}.
49-
*/
50-
private final long tookNanos;
51-
52-
/**
53-
* Nanos this {@link Driver} has been running on the cpu. Does not
54-
* include async or waiting time.
55-
*/
56-
private final long cpuNanos;
57-
58-
/**
59-
* The number of times the driver has moved a single page up the
60-
* chain of operators as far as it'll go.
61-
*/
62-
private final long iterations;
63-
64-
/**
65-
* Status of each {@link Operator} in the driver when it finished.
66-
*/
67-
private final List<DriverStatus.OperatorStatus> operators;
68-
69-
private final DriverSleeps sleeps;
70-
71-
public DriverProfile(
72-
String taskDescription,
73-
long startMillis,
74-
long stopMillis,
75-
long tookNanos,
76-
long cpuNanos,
77-
long iterations,
78-
List<DriverStatus.OperatorStatus> operators,
79-
DriverSleeps sleeps
80-
) {
81-
this.taskDescription = taskDescription;
82-
this.startMillis = startMillis;
83-
this.stopMillis = stopMillis;
84-
this.tookNanos = tookNanos;
85-
this.cpuNanos = cpuNanos;
86-
this.iterations = iterations;
87-
this.operators = operators;
88-
this.sleeps = sleeps;
89-
}
90-
91-
public DriverProfile(StreamInput in) throws IOException {
92-
if (in.getTransportVersion().onOrAfter(TransportVersions.ESQL_DRIVER_TASK_DESCRIPTION)
93-
|| in.getTransportVersion().isPatchFrom(TransportVersions.ESQL_DRIVER_TASK_DESCRIPTION_90)) {
94-
this.taskDescription = in.readString();
95-
} else {
96-
this.taskDescription = "";
97-
}
98-
if (in.getTransportVersion().onOrAfter(TransportVersions.V_8_16_0)) {
99-
this.startMillis = in.readVLong();
100-
this.stopMillis = in.readVLong();
101-
} else {
102-
this.startMillis = 0;
103-
this.stopMillis = 0;
104-
}
105-
if (in.getTransportVersion().onOrAfter(TransportVersions.V_8_14_0)) {
106-
this.tookNanos = in.readVLong();
107-
this.cpuNanos = in.readVLong();
108-
this.iterations = in.readVLong();
109-
} else {
110-
this.tookNanos = 0;
111-
this.cpuNanos = 0;
112-
this.iterations = 0;
113-
}
114-
this.operators = in.readCollectionAsImmutableList(DriverStatus.OperatorStatus::new);
115-
this.sleeps = DriverSleeps.read(in);
37+
public record DriverProfile(
38+
String taskDescription,
39+
long startMillis,
40+
long stopMillis,
41+
long tookNanos,
42+
long cpuNanos,
43+
long iterations,
44+
List<OperatorStatus> operators,
45+
DriverSleeps sleeps
46+
) implements Writeable, ChunkedToXContentObject {
47+
48+
public static DriverProfile readFrom(StreamInput in) throws IOException {
49+
return new DriverProfile(
50+
in.getTransportVersion().onOrAfter(TransportVersions.ESQL_DRIVER_TASK_DESCRIPTION)
51+
|| in.getTransportVersion().isPatchFrom(TransportVersions.ESQL_DRIVER_TASK_DESCRIPTION_90) ? in.readString() : "",
52+
in.getTransportVersion().onOrAfter(TransportVersions.V_8_16_0) ? in.readVLong() : 0,
53+
in.getTransportVersion().onOrAfter(TransportVersions.V_8_16_0) ? in.readVLong() : 0,
54+
in.getTransportVersion().onOrAfter(TransportVersions.V_8_14_0) ? in.readVLong() : 0,
55+
in.getTransportVersion().onOrAfter(TransportVersions.V_8_14_0) ? in.readVLong() : 0,
56+
in.getTransportVersion().onOrAfter(TransportVersions.V_8_14_0) ? in.readVLong() : 0,
57+
in.readCollectionAsImmutableList(OperatorStatus::readFrom),
58+
DriverSleeps.read(in)
59+
);
11660
}
11761

11862
@Override
@@ -134,64 +78,6 @@ public void writeTo(StreamOutput out) throws IOException {
13478
sleeps.writeTo(out);
13579
}
13680

137-
/**
138-
* Description of the task this driver is running.
139-
*/
140-
public String taskDescription() {
141-
return taskDescription;
142-
}
143-
144-
/**
145-
* Millis since epoch when the driver started.
146-
*/
147-
public long startMillis() {
148-
return startMillis;
149-
}
150-
151-
/**
152-
* Millis since epoch when the driver stopped.
153-
*/
154-
public long stopMillis() {
155-
return stopMillis;
156-
}
157-
158-
/**
159-
* Nanos between creation and completion of the {@link Driver}.
160-
*/
161-
public long tookNanos() {
162-
return tookNanos;
163-
}
164-
165-
/**
166-
* Nanos this {@link Driver} has been running on the cpu. Does not
167-
* include async or waiting time.
168-
*/
169-
public long cpuNanos() {
170-
return cpuNanos;
171-
}
172-
173-
/**
174-
* The number of times the driver has moved a single page up the
175-
* chain of operators as far as it'll go.
176-
*/
177-
public long iterations() {
178-
return iterations;
179-
}
180-
181-
/**
182-
* Status of each {@link Operator} in the driver when it finished.
183-
*/
184-
public List<DriverStatus.OperatorStatus> operators() {
185-
return operators;
186-
}
187-
188-
/**
189-
* Records of the times the driver has slept.
190-
*/
191-
public DriverSleeps sleeps() {
192-
return sleeps;
193-
}
194-
19581
@Override
19682
public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params) {
19783
return Iterators.concat(ChunkedToXContentHelper.startObject(), Iterators.single((b, p) -> {
@@ -215,30 +101,6 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params
215101
);
216102
}
217103

218-
@Override
219-
public boolean equals(Object o) {
220-
if (this == o) {
221-
return true;
222-
}
223-
if (o == null || getClass() != o.getClass()) {
224-
return false;
225-
}
226-
DriverProfile that = (DriverProfile) o;
227-
return taskDescription.equals(that.taskDescription)
228-
&& startMillis == that.startMillis
229-
&& stopMillis == that.stopMillis
230-
&& tookNanos == that.tookNanos
231-
&& cpuNanos == that.cpuNanos
232-
&& iterations == that.iterations
233-
&& Objects.equals(operators, that.operators)
234-
&& sleeps.equals(that.sleeps);
235-
}
236-
237-
@Override
238-
public int hashCode() {
239-
return Objects.hash(taskDescription, startMillis, stopMillis, tookNanos, cpuNanos, iterations, operators, sleeps);
240-
}
241-
242104
@Override
243105
public String toString() {
244106
return Strings.toString(this);

0 commit comments

Comments
 (0)