-
Notifications
You must be signed in to change notification settings - Fork 9.1k
HDFS-16689. Standby NameNode crashes when transitioning to Active with in-progress tailer #4744
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
...ect/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/client/SpyQJournalUtil.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.hadoop.hdfs.qjournal.client; | ||
|
||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.GetJournaledEditsResponseProto; | ||
import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo; | ||
import org.apache.hadoop.thirdparty.com.google.common.util.concurrent.ListenableFuture; | ||
import org.mockito.Mockito; | ||
import org.mockito.stubbing.Answer; | ||
|
||
import java.io.IOException; | ||
import java.net.InetSocketAddress; | ||
import java.net.URI; | ||
import java.util.List; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Semaphore; | ||
|
||
/** | ||
* One Util class to mock QJM for some UTs not in this package. | ||
*/ | ||
public final class SpyQJournalUtil { | ||
|
||
private SpyQJournalUtil() { | ||
} | ||
|
||
/** | ||
* Mock a QuorumJournalManager with input uri, nsInfo and namServiceId. | ||
* @param conf input configuration. | ||
* @param uri input uri. | ||
* @param nsInfo input nameservice info. | ||
* @param nameServiceId input nameservice Id. | ||
* @return one mocked QuorumJournalManager. | ||
* @throws IOException throw IOException. | ||
*/ | ||
public static QuorumJournalManager createSpyingQJM(Configuration conf, | ||
URI uri, NamespaceInfo nsInfo, String nameServiceId) throws IOException { | ||
AsyncLogger.Factory spyFactory = new AsyncLogger.Factory() { | ||
@Override | ||
public AsyncLogger createLogger(Configuration conf, NamespaceInfo nsInfo, | ||
String journalId, String nameServiceId, InetSocketAddress addr) { | ||
AsyncLogger logger = new IPCLoggerChannel(conf, nsInfo, journalId, | ||
nameServiceId, addr) { | ||
protected ExecutorService createSingleThreadExecutor() { | ||
// Don't parallelize calls to the quorum in the tests. | ||
// This makes the tests more deterministic. | ||
return new DirectExecutorService(); | ||
} | ||
}; | ||
return Mockito.spy(logger); | ||
} | ||
}; | ||
return new QuorumJournalManager(conf, uri, nsInfo, nameServiceId, spyFactory); | ||
} | ||
|
||
/** | ||
* Mock Journals with different response for getJournaledEdits rpc with the input startTxid. | ||
* 1. First journal with one empty response. | ||
* 2. Second journal with one normal response. | ||
* 3. Third journal with one slow response. | ||
* @param manager input QuorumJournalManager. | ||
* @param startTxid input start txid. | ||
*/ | ||
public static void mockJNWithEmptyOrSlowResponse(QuorumJournalManager manager, long startTxid) { | ||
List<AsyncLogger> spies = manager.getLoggerSetForTests().getLoggersForTests(); | ||
Semaphore semaphore = new Semaphore(0); | ||
|
||
// Mock JN0 return an empty response. | ||
Mockito.doAnswer(invocation -> { | ||
semaphore.release(); | ||
return GetJournaledEditsResponseProto.newBuilder().setTxnCount(0).build(); | ||
}).when(spies.get(0)) | ||
.getJournaledEdits(startTxid, QuorumJournalManager.QJM_RPC_MAX_TXNS_DEFAULT); | ||
|
||
// Mock JN1 return a normal response. | ||
spyGetJournaledEdits(spies, 1, startTxid, () -> semaphore.release(1)); | ||
|
||
// Mock JN2 return a slow response | ||
spyGetJournaledEdits(spies, 2, startTxid, () -> semaphore.acquireUninterruptibly(2)); | ||
} | ||
|
||
public static void spyGetJournaledEdits(List<AsyncLogger> spies, | ||
int jnSpyIdx, long fromTxId, Runnable preHook) { | ||
Mockito.doAnswer((Answer<ListenableFuture<GetJournaledEditsResponseProto>>) invocation -> { | ||
preHook.run(); | ||
@SuppressWarnings("unchecked") | ||
ListenableFuture<GetJournaledEditsResponseProto> result = | ||
(ListenableFuture<GetJournaledEditsResponseProto>) invocation.callRealMethod(); | ||
return result; | ||
}).when(spies.get(jnSpyIdx)).getJournaledEdits(fromTxId, | ||
QuorumJournalManager.QJM_RPC_MAX_TXNS_DEFAULT); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.