-
Notifications
You must be signed in to change notification settings - Fork 488
2.1 backport logrecovery #6395
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
base: 2.1
Are you sure you want to change the base?
2.1 backport logrecovery #6395
Changes from 3 commits
687f705
9bfc2c8
8333a39
7d7aa9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ | |
| import org.apache.accumulo.core.data.Value; | ||
| import org.apache.accumulo.core.file.FileOperations; | ||
| import org.apache.accumulo.core.file.FileSKVIterator; | ||
| import org.apache.accumulo.core.file.blockfile.impl.CacheProvider; | ||
| import org.apache.accumulo.core.iterators.IteratorAdapter; | ||
| import org.apache.accumulo.core.spi.crypto.CryptoEnvironment; | ||
| import org.apache.accumulo.core.spi.crypto.CryptoService; | ||
|
|
@@ -50,6 +51,7 @@ | |
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import com.google.common.cache.Cache; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I broke it up into two commits one for RecoveryLogsIterator, which touched 15 files, and the other for the rest of the files using com.google.common.cache.Cache (9 src, 1 test and the manager pom.xml)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've squashed the last 3 commits.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there is anything else that needs to be done, please let me know. This is my first time contributing to any opensource project and I apologize in advance. |
||
| import com.google.common.collect.Iterators; | ||
|
|
||
| /** | ||
|
|
@@ -64,11 +66,17 @@ public class RecoveryLogsIterator | |
| private final Iterator<Entry<Key,Value>> iter; | ||
| private final CryptoEnvironment env = new CryptoEnvironmentImpl(CryptoEnvironment.Scope.RECOVERY); | ||
|
|
||
| public RecoveryLogsIterator(ServerContext context, List<ResolvedSortedLog> recoveryLogDirs, | ||
| LogFileKey start, LogFileKey end, boolean checkFirstKey) throws IOException { | ||
| this(context, recoveryLogDirs, start, end, checkFirstKey, null, null); | ||
| } | ||
|
|
||
| /** | ||
| * Scans the files in each recoveryLogDir over the range [start,end]. | ||
| */ | ||
| public RecoveryLogsIterator(ServerContext context, List<Path> recoveryLogDirs, LogFileKey start, | ||
| LogFileKey end, boolean checkFirstKey) throws IOException { | ||
| public RecoveryLogsIterator(ServerContext context, List<ResolvedSortedLog> recoveryLogDirs, | ||
| LogFileKey start, LogFileKey end, boolean checkFirstKey, Cache<String,Long> fileLenCache, | ||
| CacheProvider cacheProvider) throws IOException { | ||
|
|
||
| List<Iterator<Entry<Key,Value>>> iterators = new ArrayList<>(recoveryLogDirs.size()); | ||
| fileIters = new ArrayList<>(); | ||
|
|
@@ -78,20 +86,20 @@ public RecoveryLogsIterator(ServerContext context, List<Path> recoveryLogDirs, L | |
| final CryptoService cryptoService = context.getCryptoFactory().getService(env, | ||
| context.getConfiguration().getAllCryptoProperties()); | ||
|
|
||
| for (Path logDir : recoveryLogDirs) { | ||
| LOG.debug("Opening recovery log dir {}", logDir.getName()); | ||
| SortedSet<Path> logFiles = getFiles(vm, logDir); | ||
| var fs = vm.getFileSystemByPath(logDir); | ||
| for (ResolvedSortedLog logDir : recoveryLogDirs) { | ||
| LOG.debug("Opening recovery log dir {}", logDir.getDir().getName()); | ||
| SortedSet<Path> logFiles = logDir.getChildren(); | ||
| var fs = vm.getFileSystemByPath(logDir.getDir()); | ||
|
|
||
| // only check the first key once to prevent extra iterator creation and seeking | ||
| if (checkFirstKey && !logFiles.isEmpty()) { | ||
| validateFirstKey(context, cryptoService, fs, logFiles, logDir); | ||
| validateFirstKey(context, cryptoService, fs, logFiles, logDir.getDir(), fileLenCache, | ||
| cacheProvider); | ||
| } | ||
|
|
||
| for (Path log : logFiles) { | ||
| FileSKVIterator fileIter = FileOperations.getInstance().newReaderBuilder() | ||
| .forFile(log.toString(), fs, fs.getConf(), cryptoService) | ||
| .withTableConfiguration(context.getConfiguration()).seekToBeginning().build(); | ||
| FileSKVIterator fileIter = | ||
| openLogFile(context, log, cryptoService, fs, fileLenCache, cacheProvider); | ||
| if (range != null) { | ||
| fileIter.seek(range, Collections.emptySet(), false); | ||
| } | ||
|
|
@@ -134,6 +142,23 @@ public void close() throws IOException { | |
| } | ||
| } | ||
|
|
||
| FileSKVIterator openLogFile(ServerContext context, Path logFile, CryptoService cs, FileSystem fs, | ||
| Cache<String,Long> fileLenCache, CacheProvider cacheProvider) throws IOException { | ||
| var builder = FileOperations.getInstance().newReaderBuilder() | ||
| .forFile(logFile.toString(), fs, fs.getConf(), cs) | ||
| .withTableConfiguration(context.getConfiguration()); | ||
|
|
||
| if (fileLenCache != null) { | ||
| builder = builder.withFileLenCache(fileLenCache); | ||
| } | ||
|
|
||
| if (cacheProvider != null) { | ||
| builder = builder.withCacheProvider(cacheProvider); | ||
| } | ||
|
|
||
| return builder.seekToBeginning().build(); | ||
| } | ||
|
|
||
| /** | ||
| * Check for sorting signal files (finished/failed) and get the logs in the provided directory. | ||
| */ | ||
|
|
@@ -169,10 +194,10 @@ private SortedSet<Path> getFiles(VolumeManager fs, Path directory) throws IOExce | |
| * Check that the first entry in the WAL is OPEN. Only need to do this once. | ||
| */ | ||
| private void validateFirstKey(ServerContext context, CryptoService cs, FileSystem fs, | ||
| SortedSet<Path> logFiles, Path fullLogPath) throws IOException { | ||
| try (FileSKVIterator fileIter = FileOperations.getInstance().newReaderBuilder() | ||
| .forFile(logFiles.first().toString(), fs, fs.getConf(), cs) | ||
| .withTableConfiguration(context.getConfiguration()).seekToBeginning().build()) { | ||
| SortedSet<Path> logFiles, Path fullLogPath, Cache<String,Long> fileLenCache, | ||
| CacheProvider cacheProvider) throws IOException { | ||
| try (FileSKVIterator fileIter = | ||
| openLogFile(context, logFiles.first(), cs, fs, fileLenCache, cacheProvider)) { | ||
| Iterator<Entry<Key,Value>> iterator = new IteratorAdapter(fileIter); | ||
|
|
||
| if (iterator.hasNext()) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the better solution would be to just make the method below
public.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes!