Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ReadLastConfirmedOp implements ReadEntryCallback {
LedgerHandle lh;
BookieClient bookieClient;
int numResponsesPending;
int numSuccessfulResponse;
RecoveryData maxRecoveredData;
volatile boolean completed = false;
int lastSeenError = BKException.Code.ReadException;
Expand All @@ -59,6 +60,7 @@ public ReadLastConfirmedOp(LedgerHandle lh, BookieClient bookieClient,
this.bookieClient = bookieClient;
this.maxRecoveredData = new RecoveryData(LedgerHandle.INVALID_ENTRY_ID, 0);
this.lh = lh;
this.numSuccessfulResponse = 0;
this.numResponsesPending = lh.getLedgerMetadata().getEnsembleSize();
this.coverageSet = lh.distributionSchedule.getCoverageSet();
this.currentEnsemble = ensemble;
Expand Down Expand Up @@ -99,6 +101,7 @@ public synchronized void readEntryComplete(final int rc, final long ledgerId, fi
maxRecoveredData = recoveryData;
}
heardValidResponse = true;
numSuccessfulResponse++;
} catch (BKDigestMatchException e) {
// Too bad, this bookie didn't give us a valid answer, we
// still might be able to recover though so continue
Expand Down Expand Up @@ -137,8 +140,15 @@ public synchronized void readEntryComplete(final int rc, final long ledgerId, fi
}

if (numResponsesPending == 0 && !completed) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@eolivelli @sijie

This fix is the wrong fix. This problem is the same problem as #2273 , and we've also seen internally. The root cause is that quorum coverage is broken. 5e399df broke it. 5e399df was a change in the write path, so why it touched the quorum coverage in the read path is a mystery. dcdd1e8 supplemented the break which and added a test case. The test case tests exactly the wrong behaviour Pre-5e399df it worked correctly.

It seems there is confusion as to what the quorum coverage is supposed to do.

The quorum coverage set is there to check if we have received a valid response from enough nodes that there cannot exist an entry which has been acknowledged to the client which has not touched at least one of these nodes. In other words, there cannot exist an entry which formed an ack quorum without touching one of the nodes we have talked to.

The quorum coverage set should only have two states for a node, known or unknown. The known state means that we know definitely than an entry does or does not exist on that node. So, an OK, NoSuchLedger and NoSuchEntry response will move the node into a known state. Anything else is an unknown state. No response from node is unknown state. Node had an IOException is an unknown state.

Take the test supplied with dcdd1e8:

        RoundRobinDistributionSchedule schedule = new RoundRobinDistributionSchedule(
            5, 3, 5);
        DistributionSchedule.QuorumCoverageSet covSet = schedule.getCoverageSet();
        covSet.addBookie(0, BKException.Code.NoSuchLedgerExistsException);
        covSet.addBookie(1, BKException.Code.NoSuchEntryException);
        covSet.addBookie(2, BKException.Code.NoSuchLedgerExistsException);
        covSet.addBookie(3, BKException.Code.UNINITIALIZED);
        covSet.addBookie(4, BKException.Code.UNINITIALIZED);
        assertFalse(covSet.checkCovered());

For clarify, w is 5, a is 3, e is 5. RoundRobinDistributionSchedule parameters are messed up.

This test is simply wrong. The coverage set is covered. There is no way an entry can have ack quorum in any write quorum. There is no set of 3 bookies in the unknown state.

Anyhow, I have a fix going through CI internally. I'll push up a PR on monday.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes makes sense. provided test in dcdd1e8 is not correct and it should cover the coverage and if that covers the coverage then we won't need this fix.

int totalExepctedResponse = lh.getLedgerMetadata().getWriteQuorumSize()
- lh.getLedgerMetadata().getAckQuorumSize() + 1;
if (numSuccessfulResponse >= totalExepctedResponse) {
cb.readLastConfirmedDataComplete(BKException.Code.OK, maxRecoveredData);
return;
}
// Have got all responses back but was still not enough, just fail the operation
LOG.error("While readLastConfirmed ledger: {} did not hear success responses from all quorums", ledgerId);
LOG.error("While readLastConfirmed ledger: {} did not hear success responses from all quorums {}", ledgerId,
lastSeenError);
cb.readLastConfirmedDataComplete(lastSeenError, maxRecoveredData);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.apache.bookkeeper.util.ByteBufList;
import org.apache.bookkeeper.versioning.Version;
import org.apache.bookkeeper.versioning.Versioned;
import org.apache.commons.lang3.mutable.MutableInt;
import org.apache.zookeeper.AsyncCallback.VoidCallback;
import org.apache.zookeeper.KeeperException;
import org.junit.After;
Expand Down Expand Up @@ -693,4 +694,93 @@ public void readLastConfirmedDataComplete(int rc, DigestManager.RecoveryData dat
readBk.close();
}

/**
* Validate ledger can recover with response: (Qw - Qa)+1.
* @throws Exception
*/
@Test
public void testRecoveryWithUnavailableBookie() throws Exception {

byte[] passwd = "".getBytes(UTF_8);
ClientConfiguration newConf = new ClientConfiguration();
newConf.addConfiguration(baseClientConf);
final BookKeeper readBk = new BookKeeper(newConf);
final BookKeeper newBk0 = new BookKeeper(newConf);

/**
* Test Group-1 : Expected Response for recovery: Qr = (Qw - Qa)+1 = (3
* -2) + 1 = 2
*/
int ensembleSize = 3;
int writeQuorumSize = 3;
int ackQuormSize = 2;
LedgerHandle lh0 = newBk0.createLedger(ensembleSize, writeQuorumSize, ackQuormSize, DigestType.DUMMY, passwd);
LedgerHandle readLh = readBk.openLedgerNoRecovery(lh0.getId(), DigestType.DUMMY, passwd);
// Test 1: bookie response: OK, NO_SUCH_LEDGER_EXISTS, NOT_AVAILABLE
// Expected: Recovery successful Q(response) = 2
int responseCode = readLACFromQuorum(readLh, BKException.Code.BookieHandleNotAvailableException,
BKException.Code.OK, BKException.Code.NoSuchLedgerExistsException);
assertEquals(responseCode, BKException.Code.OK);
// Test 2: bookie response: OK, NOT_AVAILABLE, NOT_AVAILABLE
// Expected: Recovery fail Q(response) = 1
responseCode = readLACFromQuorum(readLh, BKException.Code.BookieHandleNotAvailableException,
BKException.Code.OK, BKException.Code.BookieHandleNotAvailableException);
assertEquals(responseCode, BKException.Code.BookieHandleNotAvailableException);

/**
* Test Group-2 : Expected Response for recovery: Qr = (Qw - Qa)+1 = (2
* -2) + 1 = 1
*/
ensembleSize = 2;
writeQuorumSize = 2;
ackQuormSize = 2;
lh0 = newBk0.createLedger(ensembleSize, writeQuorumSize, ackQuormSize, DigestType.DUMMY, passwd);
readLh = readBk.openLedgerNoRecovery(lh0.getId(), DigestType.DUMMY, passwd);
// Test 1: bookie response: OK, NOT_AVAILABLE
// Expected: Recovery successful Q(response) = 1
responseCode = readLACFromQuorum(readLh, BKException.Code.BookieHandleNotAvailableException,
BKException.Code.OK);
assertEquals(responseCode, BKException.Code.OK);

// Test 1: bookie response: OK, NO_SUCH_LEDGER_EXISTS
// Expected: Recovery successful Q(response) = 2
responseCode = readLACFromQuorum(readLh, BKException.Code.NoSuchLedgerExistsException, BKException.Code.OK);
assertEquals(responseCode, BKException.Code.OK);

// Test 3: bookie response: NOT_AVAILABLE, NOT_AVAILABLE
// Expected: Recovery fail Q(response) = 0
responseCode = readLACFromQuorum(readLh, BKException.Code.BookieHandleNotAvailableException,
BKException.Code.BookieHandleNotAvailableException);
assertEquals(responseCode, BKException.Code.BookieHandleNotAvailableException);

newBk0.close();
readBk.close();
}

private int readLACFromQuorum(LedgerHandle ledger, int... bookieLACResponse) throws Exception {
MutableInt responseCode = new MutableInt(100);
CountDownLatch responseLatch = new CountDownLatch(1);
ReadLastConfirmedOp readLCOp = new ReadLastConfirmedOp(ledger, bkc.getBookieClient(),
ledger.getLedgerMetadata().getAllEnsembles().lastEntry().getValue(),
new ReadLastConfirmedOp.LastConfirmedDataCallback() {
@Override
public void readLastConfirmedDataComplete(int rc, DigestManager.RecoveryData data) {
System.out.println("response = " + rc);
responseCode.setValue(rc);
responseLatch.countDown();
}
});
byte[] lac = new byte[Long.SIZE * 3];
ByteBuf data = Unpooled.wrappedBuffer(lac, 0, lac.length);
int writerIndex = data.writerIndex();
data.resetWriterIndex();
data.writeLong(ledger.getId());
data.writeLong(0L);
data.writerIndex(writerIndex);
for (int i = 0; i < bookieLACResponse.length; i++) {
readLCOp.readEntryComplete(bookieLACResponse[i], 0, 0, data, i);
}
responseLatch.await();
return responseCode.intValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,9 @@ public void testLedgerNoRecoveryOpenAfterBKCrashed() throws Exception {
killBookie(0);

// try to open ledger no recovery
try {
bkc.openLedgerNoRecovery(beforelh2.getId(), digestType, "".getBytes());
fail("Should have thrown exception");
} catch (BKException.BKReadException e) {
// correct behaviour
}
// should be able to open ledger with one bookie down:
// Total bookies available 3 >= 1 (Qw(4) - Qa(4) + 1)
bkc.openLedgerNoRecovery(beforelh2.getId(), digestType, "".getBytes());
}

@Test
Expand Down Expand Up @@ -351,12 +348,9 @@ public void testLedgerOpenAfterBKCrashed() throws Exception {
killBookie(0);

// try to open ledger no recovery
try {
bkc.openLedger(beforelh2.getId(), digestType, "".getBytes());
fail("Should have thrown exception");
} catch (BKException.BKLedgerRecoveryException e) {
// correct behaviour
}
// should be able to open ledger with one bookie down:
// Total bookies available 3 >= 1 (Qw(4) - Qa(4) + 1)
bkc.openLedger(beforelh2.getId(), digestType, "".getBytes());
}

/**
Expand Down