Repository navigation
Conversation
And MetadataUpdateLoop to update it. Master issue: apache#281
|
I want to add more testing to this, but throwing it up so you all can see the shape of it beforehand. |
eolivelli
left a comment
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
Nit: use diamond operator
| } | ||
|
|
||
| static int getExceptionCode(Throwable t, int defaultCode) { | ||
| if (t instanceof BKException) { |
There was a problem hiding this comment.
Don't you loop on the chain? Thinking about ExecutionException for instance...
There was a problem hiding this comment.
I don't understand the question
There was a problem hiding this comment.
Sorry.
This is a generic method, maybe the BKException is wrapped by another exception, like an ExecutionException.
Btw it is not so important
There was a problem hiding this comment.
There was a problem hiding this comment.
add a unit test for this to make sure it capture the right exception code
There was a problem hiding this comment.
Moved to BKException, and added some unit tests
| } | ||
|
|
||
| @Override | ||
| void handleBookieFailure(final Map<Integer, BookieSocketAddress> failedBookies) { |
There was a problem hiding this comment.
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
| (metadata) -> { | ||
| LedgerMetadataBuilder builder = LedgerMetadataBuilder.from(metadata); | ||
| Optional<Long> lastEnsembleKey = metadata.getLastEnsembleKey(); | ||
| checkState(lastEnsembleKey.isPresent(), |
There was a problem hiding this comment.
How an error from this assertion will be handled from the MULoop ?
Will the resulting CompletableFuture fail ?
Do we have test cases ?
There was a problem hiding this comment.
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())) { |
There was a problem hiding this comment.
Do we have a specific test case?
There was a problem hiding this comment.
Ya, I want to test this more, hence the mock reg client (and some more).
eolivelli
left a comment
There was a problem hiding this comment.
Lgtm.
But it would be better to have Sijie or JV's opinion
| */ | ||
| @Override | ||
| void handleBookieFailure(final Map<Integer, BookieSocketAddress> failedBookies) { | ||
| blockAddCompletions.incrementAndGet(); |
There was a problem hiding this comment.
Do we need to do this on a ReadOnlyLedgerHandle?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
| } | ||
|
|
||
| public void initiate() { | ||
| public CompletableFuture<Void> initiate() { |
There was a problem hiding this comment.
return CompletableFuture<LedgerHandle>? so it is easier to chain operations.
| } | ||
| } | ||
|
|
||
| private void closeAndCallback() { |
There was a problem hiding this comment.
I saw this method is removed. then my question is when do we close the ledger?
There was a problem hiding this comment.
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<>(); |
| * It should be returned for BookKeeper#openLedger operations. | ||
| */ | ||
| class ReadOnlyLedgerHandle extends LedgerHandle implements LedgerMetadataListener { | ||
| static final Logger LOG = LoggerFactory.getLogger(ReadOnlyLedgerHandle.class); |
|
|
||
| @Override | ||
| List<BookieSocketAddress> getCurrentEnsemble() { | ||
| if (newEnsemblesFromRecovery.size() > 0) { |
There was a problem hiding this comment.
no synchronization at newEnsemblesFromRecovery?
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
which thread run this? I don't think we have proper synchronization at numEnsemblesFromRecovery
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
sure, will change.
| } | ||
|
|
||
| static int getExceptionCode(Throwable t, int defaultCode) { | ||
| if (t instanceof BKException) { |
There was a problem hiding this comment.
add a unit test for this to make sure it capture the right exception code
|
rerun bookkeeper-server bookie tests |
1 similar comment
|
rerun bookkeeper-server bookie tests |
|
@athanatos @jvrao please review this |
And MetadataUpdateLoop to update it.
Master issue: #281