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

Flush old indices on primary promotion and relocation #27580

Merged
merged 29 commits into from
Nov 30, 2017
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
41d27c8
add testRecoveryWithConcurrentIndexing
bleskes Nov 28, 2017
e99de20
fix for promotion
bleskes Nov 28, 2017
277c87a
relax. You can't guarantee what you want
bleskes Nov 28, 2017
d77e00a
assert we ship what we want to ship
bleskes Nov 28, 2017
af3f815
verify we ship the right ops
bleskes Nov 28, 2017
04cbccf
logging
bleskes Nov 28, 2017
eb3bd72
doh
bleskes Nov 28, 2017
0a75735
lint
bleskes Nov 28, 2017
4c4a1bc
more intuitive range indication
bleskes Nov 28, 2017
a29acf2
fix testSendSnapshotSendsOps
bleskes Nov 28, 2017
895b78b
add primary relocation test
bleskes Nov 29, 2017
8782377
index specific ensure green
bleskes Nov 29, 2017
b77d4e8
fix counts
bleskes Nov 29, 2017
22d5bfa
tighten testRelocationWithConcurrentIndexing
bleskes Nov 29, 2017
b2082b0
flush on relocation
bleskes Nov 29, 2017
9935225
simplify relation ship between flush and roll
bleskes Nov 29, 2017
10fbb3e
add explicit index names to health check
bleskes Nov 29, 2017
fb8a105
beef up testSendSnapshotSendsOps
bleskes Nov 29, 2017
c1a0cc7
fix testWaitForPendingSeqNo
bleskes Nov 29, 2017
e8f65f3
feedback
bleskes Nov 29, 2017
6c5140c
more feedback
bleskes Nov 29, 2017
dce71ab
last feedback round
bleskes Nov 29, 2017
6989d52
reduce the ensure green
bleskes Nov 29, 2017
c09e419
fix testSendSnapshotSendsOps as we always send at least one (potentia…
bleskes Nov 29, 2017
53869b3
extra space?
bleskes Nov 29, 2017
9467758
add empty shard test
bleskes Nov 30, 2017
09f7133
make sure seq no info is in commit if recovering an old index
bleskes Nov 30, 2017
1501d4a
add assertions that commit point in store always has sequence numbers…
bleskes Nov 30, 2017
e5a734c
hard -> shard
bleskes Nov 30, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feedback
  • Loading branch information
bleskes committed Nov 29, 2017
commit e8f65f320df031ac65b3d9e7f62b206dc612dba3
Original file line number Diff line number Diff line change
@@ -168,8 +168,6 @@ public RecoveryResponse recoverToTarget() throws IOException {
// but we must have everything above the local checkpoint in the commit
requiredSeqNoRangeStart =
Long.parseLong(phase1Snapshot.getIndexCommit().getUserData().get(SequenceNumbers.LOCAL_CHECKPOINT_KEY)) + 1;
assert requiredSeqNoRangeStart >= 0 :
"base commit contains an illegal local checkpoint " + (requiredSeqNoRangeStart - 1);
try {
phase1(phase1Snapshot.getIndexCommit(), translog::totalOperations);
} catch (final Exception e) {
@@ -182,6 +180,9 @@ public RecoveryResponse recoverToTarget() throws IOException {
}
}
}
assert startingSeqNo >= 0 : "startingSeqNo must be non negative. got: " + startingSeqNo;
assert requiredSeqNoRangeStart >= startingSeqNo : "requiredSeqNoRangeStart [" + requiredSeqNoRangeStart + "] is lower than ["
+ startingSeqNo + "]";

runUnderPrimaryPermit(() -> shard.initiateTracking(request.targetAllocationId()));

@@ -190,7 +191,15 @@ public RecoveryResponse recoverToTarget() throws IOException {
} catch (final Exception e) {
throw new RecoveryEngineException(shard.shardId(), 1, "prepare target for translog failed", e);
}
final long endingSeqNo = determineEndingSeqNo();

final long endingSeqNo = shard.seqNoStats().getMaxSeqNo();
/*
* We need to wait for all operations up to the current max to complete, otherwise we can not guarantee that all
* operations in the required range will be available for replaying from the translog of the source.
*/
cancellableThreads.execute(() -> shard.waitForOpsToComplete(endingSeqNo));

logger.trace("all operations up to [{}] completed, which will be used as an ending sequence number", endingSeqNo);

logger.trace("snapshot translog for recovery; current size is [{}]", translog.estimateTotalOperationsFromMinSeq(startingSeqNo));
final long targetLocalCheckpoint;
@@ -227,18 +236,6 @@ private void runUnderPrimaryPermit(CancellableThreads.Interruptable runnable) {
});
}

private long determineEndingSeqNo() {
final long endingSeqNo = shard.seqNoStats().getMaxSeqNo();
/*
* We need to wait for all operations up to the current max to complete, otherwise we can not guarantee that all
* operations in the required range will be available for replaying from the translog of the source.
*/
cancellableThreads.execute(() -> shard.waitForOpsToComplete(endingSeqNo));

logger.trace("all operations up to [{}] completed, which will be used as an ending sequence number", endingSeqNo);
return endingSeqNo + 1;
}

/**
* Determines if the source translog is ready for a sequence-number-based peer recovery. The main condition here is that the source
* translog contains all operations above the local checkpoint on the target. We already know the that translog contains or will contain
@@ -525,16 +522,16 @@ static class SendSnapshotResult {
* Operations are bulked into a single request depending on an operation count limit or size-in-bytes limit.
*
* @param startingSeqNo the sequence number for which only operations with a sequence number greater than this will be sent
* @param requiredSeqNoRangeStart the lower sequence number of the required range (ending with endingSeqNo - 1)
* @param endingSeqNo the upper bound of the sequence number range to be sent (exclusive)
* @param requiredSeqNoRangeStart the lower sequence number of the required range
Copy link
Member

Choose a reason for hiding this comment

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

nit: we may need to reformat this javadocs

* @param endingSeqNo the upper bound of the sequence number range to be sent (inclusive)
* @param snapshot the translog snapshot to replay operations from @return the local checkpoint on the target and the total
* number of operations sent
* @throws IOException if an I/O exception occurred reading the translog snapshot
*/
protected SendSnapshotResult sendSnapshot(final long startingSeqNo, long requiredSeqNoRangeStart, long endingSeqNo,
final Translog.Snapshot snapshot) throws IOException {
assert requiredSeqNoRangeStart <= endingSeqNo :
"requiredSeqNoRangeStart " + requiredSeqNoRangeStart + " is larger than endingSeqNo" + endingSeqNo;
assert requiredSeqNoRangeStart <= endingSeqNo + 1:
"requiredSeqNoRangeStart " + requiredSeqNoRangeStart + " is larger than endingSeqNo " + endingSeqNo;
assert startingSeqNo <= requiredSeqNoRangeStart :
"startingSeqNo " + startingSeqNo + " is larger than requiredSeqNoRangeStart " + requiredSeqNoRangeStart;
int ops = 0;
@@ -562,7 +559,7 @@ protected SendSnapshotResult sendSnapshot(final long startingSeqNo, long require
cancellableThreads.checkForCancel();

final long seqNo = operation.seqNo();
if (seqNo < startingSeqNo || seqNo >= endingSeqNo) {
if (seqNo < startingSeqNo || seqNo > endingSeqNo) {
skippedOps++;
continue;
}
@@ -587,7 +584,7 @@ protected SendSnapshotResult sendSnapshot(final long startingSeqNo, long require
cancellableThreads.executeIO(sendBatch);
}

if (requiredOpsTracker.getCheckpoint() < endingSeqNo - 1) {
if (requiredOpsTracker.getCheckpoint() < endingSeqNo) {
throw new IllegalStateException("translog replay failed to covered required sequence numbers" +
Copy link
Contributor

Choose a reason for hiding this comment

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

covered -> cover

" (required range [" + requiredSeqNoRangeStart + ":" + endingSeqNo + "). first missing op is ["
+ (requiredOpsTracker.getCheckpoint() + 1) + "]");
Original file line number Diff line number Diff line change
@@ -188,7 +188,7 @@ public void testSendSnapshotSendsOps() throws IOException {
operations.add(null);
final long startingSeqNo = randomIntBetween(0, numberOfDocsWithValidSequenceNumbers - 1);
final long requiredStartingSeqNo = randomIntBetween((int) startingSeqNo, numberOfDocsWithValidSequenceNumbers - 1);
final long endingSeqNo = randomIntBetween((int) requiredStartingSeqNo, numberOfDocsWithValidSequenceNumbers);
final long endingSeqNo = randomIntBetween((int) requiredStartingSeqNo, numberOfDocsWithValidSequenceNumbers - 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

It can start from requiredStartingSeqNo - 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes.

// todo add proper tests
Copy link
Contributor

Choose a reason for hiding this comment

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

is this proper enough now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

:)

RecoverySourceHandler.SendSnapshotResult result = handler.sendSnapshot(startingSeqNo, requiredStartingSeqNo,
endingSeqNo, new Translog.Snapshot() {
@@ -209,7 +209,7 @@ public Translog.Operation next() throws IOException {
return operations.get(counter++);
}
});
final int expectedOps = (int) (endingSeqNo - startingSeqNo);
final int expectedOps = (int) (endingSeqNo - startingSeqNo + 1);
assertThat(result.totalOperations, equalTo(expectedOps));
final ArgumentCaptor<List> shippedOpsCaptor = ArgumentCaptor.forClass(List.class);
if (expectedOps > 0) {
@@ -227,7 +227,7 @@ public Translog.Operation next() throws IOException {
if (endingSeqNo >= requiredStartingSeqNo + 1) {
// check that missing ops blows up
List<Translog.Operation> requiredOps = operations.subList(0, operations.size() - 1).stream() // remove last null marker
.filter(o -> o.seqNo() >= requiredStartingSeqNo && o.seqNo() < endingSeqNo).collect(Collectors.toList());
.filter(o -> o.seqNo() >= requiredStartingSeqNo && o.seqNo() <= endingSeqNo).collect(Collectors.toList());
List<Translog.Operation> opsToSkip = randomSubsetOf(randomIntBetween(1, requiredOps.size()), requiredOps);
expectThrows(IllegalStateException.class, () ->
handler.sendSnapshot(startingSeqNo, requiredStartingSeqNo,