Skip to content

Recovery uses immutable metadata - #1621

Closed
ivankelly wants to merge 4 commits into
apache:masterfrom
ivankelly:recovery-immutable
Closed

ivankelly wants to merge 4 commits into
apache:masterfrom
ivankelly:recovery-immutable

Conversation

@ivankelly

Copy link
Copy Markdown
Contributor

And MetadataUpdateLoop to update it.

Master issue: #281

And MetadataUpdateLoop to update it.

Master issue: apache#281
@ivankelly ivankelly self-assigned this Aug 23, 2018
@ivankelly

Copy link
Copy Markdown
Contributor Author

I want to add more testing to this, but throwing it up so you all can see the shape of it beforehand.

@eolivelli eolivelli left a comment

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.

Overall looks good.
Left some minor comment

int ackQ = metadata.getAckQuorumSize();
Map<String, byte[]> customMetadata = metadata.getCustomMetadata();

Set<BookieSocketAddress> exclude = new HashSet<BookieSocketAddress>(failedBookies.values());

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.

Nit: use diamond operator

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.

changed

}

static int getExceptionCode(Throwable t, int defaultCode) {
if (t instanceof BKException) {

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.

Don't you loop on the chain? Thinking about ExecutionException for instance...

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.

I don't understand the question

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.

Sorry.
This is a generic method, maybe the BKException is wrapped by another exception, like an ExecutionException.

Btw it is not so important

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

add a unit test for this to make sure it capture the right exception code

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.

Moved to BKException, and added some unit tests

}

@Override
void handleBookieFailure(final Map<Integer, BookieSocketAddress> failedBookies) {

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.

Can we add a comment explaining that we are in ReadOnlyLedgerHandle and this method will trigger only on recovery.
I am referring to @jvrao questions on slack

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.

Added

(metadata) -> {
LedgerMetadataBuilder builder = LedgerMetadataBuilder.from(metadata);
Optional<Long> lastEnsembleKey = metadata.getLastEnsembleKey();
checkState(lastEnsembleKey.isPresent(),

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.

How an error from this assertion will be handled from the MULoop ?
Will the resulting CompletableFuture fail ?
Do we have test cases ?

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.

checkState throws an IllegalStateException, which will be caught by the loop. The returned future will be completed with it.
MetadataUpdateLoopTest#testNewestValueCannotBeUsedAfterReadBack tests this functionality.

newEnsemblesFromRecovery.entrySet().forEach(
(e) -> {
// Occurs when a bookie need to be replaced at very start of recovery
if (lastEnsembleKey.get().equals(e.getKey())) {

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.

Do we have a specific test case?

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.

Ya, I want to test this more, hence the mock reg client (and some more).

@eolivelli eolivelli left a comment

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.

Lgtm.

But it would be better to have Sijie or JV's opinion

*/
@Override
void handleBookieFailure(final Map<Integer, BookieSocketAddress> failedBookies) {
blockAddCompletions.incrementAndGet();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do we need to do this on a ReadOnlyLedgerHandle?

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.

Technically, I think not, as this should run in the same thread as the completions occur in. This is all implicit though, so we can't be 100% sure, and someone could change it in the future and break everything. Same thing for the synchronized. I have some other suggestions for cleaning up the thread model that I'll post to dev@ later this week, but for now I'd like to leave this here.

}

static int getExceptionCode(Throwable t, int defaultCode) {
if (t instanceof BKException) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

}

public void initiate() {
public CompletableFuture<Void> initiate() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

return CompletableFuture<LedgerHandle>? so it is easier to chain operations.

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.

Sure

}
}

private void closeAndCallback() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I saw this method is removed. then my question is when do we close the ledger?

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.

I guess you found it below?

class ReadOnlyLedgerHandle extends LedgerHandle implements LedgerMetadataListener {
static final Logger LOG = LoggerFactory.getLogger(ReadOnlyLedgerHandle.class);

private NavigableMap<Long, List<BookieSocketAddress>> newEnsemblesFromRecovery = new TreeMap<>();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

final

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.

changed

* It should be returned for BookKeeper#openLedger operations.
*/
class ReadOnlyLedgerHandle extends LedgerHandle implements LedgerMetadataListener {
static final Logger LOG = LoggerFactory.getLogger(ReadOnlyLedgerHandle.class);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

private

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.

changed


@Override
List<BookieSocketAddress> getCurrentEnsemble() {
if (newEnsemblesFromRecovery.size() > 0) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

no synchronization at newEnsemblesFromRecovery?

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.

I don't think any synchronization is needed here either. newEnsemblesFromRecovery will only ever be greater than 0 during the recovery process, and during the recovery process, getCurrentEnsemble is only called in a callback (which run in the handle's executor, same as handleBookieFailure. That said, the whole threading model is a mess, so I'll add defensive synchronization until we clear it up.

Optional<Long> lastEnsembleKey = metadata.getLastEnsembleKey();
checkState(lastEnsembleKey.isPresent(),
"Metadata shouldn't have been created without at least one ensemble");
newEnsemblesFromRecovery.entrySet().forEach(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would suggest being more strict here for safety concerns.

for check:

the first key in the NewEnsembleFromRecovery should exist in the LedgerMetadata read from zookeeper.

for updating:

  • drop any ensembles before lastEnsembleKey
  • replace ensemble lastEnsembleKey
  • append ensembles after lastEnsembleKey

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.

First key in newEnsembleFromRecovery doesn't have to exist in the read metadata. For example, if a bookie fails during the recovery process.

I would exit screaming if there is any ensemble in newEnsembleFromRecovery before lastEnsembleKey. That would mean that, during the recovery process, something updated the last ensemble in ledger, yet didn't close the ledger. The only thing that can do that is a writing client. A writing client should never do this, as they should see that they are being fenced, and bail out.

I'll add more sanity checks here though.

Optional<Long> lastEnsembleKey = metadata.getLastEnsembleKey();
checkState(lastEnsembleKey.isPresent(),
"Metadata shouldn't have been created without at least one ensemble");
newEnsemblesFromRecovery.entrySet().forEach(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

which thread run this? I don't think we have proper synchronization at numEnsemblesFromRecovery

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.

by the time this runs, no other thread will be adding anything to numEnsemblesFromRecovery. there could be cpu cache delays though, so will make it a synchronized treemap.


@Override
List<BookieSocketAddress> getCurrentEnsemble() {
if (newEnsemblesFromRecovery.size() > 0) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: it is typically recommended to use isEmpty for size checking rather than calling size. because size on some data structures can be an expensive operation.

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.

sure, will change.

}

static int getExceptionCode(Throwable t, int defaultCode) {
if (t instanceof BKException) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

add a unit test for this to make sure it capture the right exception code

@ivankelly

Copy link
Copy Markdown
Contributor Author

rerun bookkeeper-server bookie tests
rerun integration tests

1 similar comment
@ivankelly

Copy link
Copy Markdown
Contributor Author

rerun bookkeeper-server bookie tests
rerun integration tests

@sijie

sijie commented Sep 1, 2018

Copy link
Copy Markdown
Member

@athanatos @jvrao please review this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants