Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CCR] Sync mappings between leader and follow index #30115

Merged
merged 12 commits into from
May 28, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -156,28 +156,36 @@ public int hashCode() {

public static final class Response extends ActionResponse {

private long indexMetadataVersion;
private Translog.Operation[] operations;

Response() {
}

Response(final Translog.Operation[] operations) {
Response(long indexMetadataVersion, final Translog.Operation[] operations) {
this.indexMetadataVersion = indexMetadataVersion;
this.operations = operations;
}

public long getIndexMetadataVersion() {
return indexMetadataVersion;
}

public Translog.Operation[] getOperations() {
return operations;
}

@Override
public void readFrom(final StreamInput in) throws IOException {
super.readFrom(in);
indexMetadataVersion = in.readVLong();
operations = in.readArray(Translog.Operation::readOperation, Translog.Operation[]::new);
}

@Override
public void writeTo(final StreamOutput out) throws IOException {
super.writeTo(out);
out.writeVLong(indexMetadataVersion);
out.writeArray(Translog.Operation::writeOperation, operations);
}

Expand All @@ -186,12 +194,16 @@ public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final Response response = (Response) o;
return Arrays.equals(operations, response.operations);
return indexMetadataVersion == response.indexMetadataVersion &&
Arrays.equals(operations, response.operations);
}

@Override
public int hashCode() {
return Arrays.hashCode(operations);
int result = 1;
result += Objects.hashCode(indexMetadataVersion);
result += Arrays.hashCode(operations);
return result;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that Object.hash(indexMetadataVersion, operations) is fine here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately Object.hash(...) doesn't handle arrays correctly, so I changed it back to use Arrays.hashCode(...).

}
}

Expand Down Expand Up @@ -224,8 +236,11 @@ protected Response shardOperation(Request request, ShardId shardId) throws IOExc
IndexService indexService = indicesService.indexServiceSafe(request.getShard().getIndex());
IndexShard indexShard = indexService.getShard(request.getShard().id());

final long indexMetaDataVersion = clusterService.state().metaData().index(shardId.getIndex()).getVersion();
request.maxSeqNo = Math.min(request.maxSeqNo, indexShard.getGlobalCheckpoint());
return getOperationsBetween(indexShard, request.minSeqNo, request.maxSeqNo, request.maxTranslogsBytes);
final Translog.Operation[] operations =
getOperationsBetween(indexShard, request.minSeqNo, request.maxSeqNo, request.maxTranslogsBytes);
return new Response(indexMetaDataVersion, operations);
}

@Override
Expand All @@ -250,7 +265,8 @@ protected Response newResponse() {

private static final Translog.Operation[] EMPTY_OPERATIONS_ARRAY = new Translog.Operation[0];

static Response getOperationsBetween(IndexShard indexShard, long minSeqNo, long maxSeqNo, long byteLimit) throws IOException {
static Translog.Operation[] getOperationsBetween(IndexShard indexShard, long minSeqNo, long maxSeqNo,
long byteLimit) throws IOException {
if (indexShard.state() != IndexShardState.STARTED) {
throw new IndexShardNotStartedException(indexShard.shardId(), indexShard.state());
}
Expand All @@ -266,6 +282,6 @@ static Response getOperationsBetween(IndexShard indexShard, long minSeqNo, long
}
}
}
return new Response(operations.toArray(EMPTY_OPERATIONS_ARRAY));
return operations.toArray(EMPTY_OPERATIONS_ARRAY);
}
}
Loading