Skip to content

Commit

Permalink
Do not mutable RecoveryResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
dnhatn committed Jan 7, 2019
1 parent e34658e commit 1ca6666
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,7 @@ public String executor() {

@Override
public RecoveryResponse read(StreamInput in) throws IOException {
RecoveryResponse recoveryResponse = new RecoveryResponse();
recoveryResponse.readFrom(in);
return recoveryResponse;
return new RecoveryResponse(in);
}
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,62 +19,57 @@

package org.elasticsearch.indices.recovery;

import org.elasticsearch.Version;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.transport.TransportResponse;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

class RecoveryResponse extends TransportResponse {
final class RecoveryResponse extends TransportResponse {

List<String> phase1FileNames = new ArrayList<>();
List<Long> phase1FileSizes = new ArrayList<>();
List<String> phase1ExistingFileNames = new ArrayList<>();
List<Long> phase1ExistingFileSizes = new ArrayList<>();
long phase1TotalSize;
long phase1ExistingTotalSize;
long phase1Time;
long phase1ThrottlingWaitTime;
final List<String> phase1FileNames;
final List<Long> phase1FileSizes;
final List<String> phase1ExistingFileNames;
final List<Long> phase1ExistingFileSizes;
final long phase1TotalSize;
final long phase1ExistingTotalSize;
final long phase1Time;
final long phase1ThrottlingWaitTime = 0L; // not used

long startTime;
final long startTime;

int phase2Operations;
long phase2Time;
final int phase2Operations;
final long phase2Time;

RecoveryResponse() {
RecoveryResponse(List<String> phase1FileNames, List<Long> phase1FileSizes, List<String> phase1ExistingFileNames,
List<Long> phase1ExistingFileSizes, long phase1TotalSize, long phase1ExistingTotalSize,
long phase1Time, long startTime, int phase2Operations, long phase2Time) {
this.phase1FileNames = phase1FileNames;
this.phase1FileSizes = phase1FileSizes;
this.phase1ExistingFileNames = phase1ExistingFileNames;
this.phase1ExistingFileSizes = phase1ExistingFileSizes;
this.phase1TotalSize = phase1TotalSize;
this.phase1ExistingTotalSize = phase1ExistingTotalSize;
this.phase1Time = phase1Time;
this.startTime = startTime;
this.phase2Operations = phase2Operations;
this.phase2Time = phase2Time;
}

@Override
public void readFrom(StreamInput in) throws IOException {
RecoveryResponse(StreamInput in) throws IOException {
super.readFrom(in);
int size = in.readVInt();
phase1FileNames = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
phase1FileNames.add(in.readString());
}
size = in.readVInt();
phase1FileSizes = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
phase1FileSizes.add(in.readVLong());
}

size = in.readVInt();
phase1ExistingFileNames = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
phase1ExistingFileNames.add(in.readString());
}
size = in.readVInt();
phase1ExistingFileSizes = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
phase1ExistingFileSizes.add(in.readVLong());
}

phase1FileNames = in.readList(StreamInput::readString);
phase1FileSizes = in.readList(StreamInput::readVLong);
phase1ExistingFileNames = in.readList(StreamInput::readString);
phase1ExistingFileSizes = in.readList(StreamInput::readVLong);
phase1TotalSize = in.readVLong();
phase1ExistingTotalSize = in.readVLong();
phase1Time = in.readVLong();
phase1ThrottlingWaitTime = in.readVLong();
if (in.getVersion().before(Version.V_7_0_0)) {
in.readVLong(); // phase1ThrottlingWaitTime - not used
}
startTime = in.readVLong();
phase2Operations = in.readVInt();
phase2Time = in.readVLong();
Expand All @@ -83,28 +78,16 @@ public void readFrom(StreamInput in) throws IOException {
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeVInt(phase1FileNames.size());
for (String name : phase1FileNames) {
out.writeString(name);
}
out.writeVInt(phase1FileSizes.size());
for (long size : phase1FileSizes) {
out.writeVLong(size);
}

out.writeVInt(phase1ExistingFileNames.size());
for (String name : phase1ExistingFileNames) {
out.writeString(name);
}
out.writeVInt(phase1ExistingFileSizes.size());
for (long size : phase1ExistingFileSizes) {
out.writeVLong(size);
}

out.writeStringList(phase1FileNames);
out.writeCollection(phase1FileSizes, StreamOutput::writeVLong);
out.writeStringList(phase1ExistingFileNames);
out.writeCollection(phase1ExistingFileSizes, StreamOutput::writeVLong);
out.writeVLong(phase1TotalSize);
out.writeVLong(phase1ExistingTotalSize);
out.writeVLong(phase1Time);
out.writeVLong(phase1ThrottlingWaitTime);
if (out.getVersion().before(Version.V_7_0_0)) {
out.writeVLong(0L); // phase1ThrottlingWaitTime - not used
}
out.writeVLong(startTime);
out.writeVInt(phase2Operations);
out.writeVLong(phase2Time);
Expand Down
Loading

0 comments on commit 1ca6666

Please sign in to comment.