-
Notifications
You must be signed in to change notification settings - Fork 594
HDDS-13906. Reduce Bootstrap Write lock time on OM during bootstrapping execution. #9585
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
Draft
sadanand48
wants to merge
15
commits into
apache:master
Choose a base branch
from
sadanand48:HDDS-13906
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+401
−111
Draft
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ae2cd6a
HDDS-13906. Reduce Bootstrap Write lock time on OM during bootstrappi…
4dc3385
fix checkstyle
07ce63f
tranfer on last batch
5c8f0b1
address comment
1919a29
fix checkstyle
824b6c2
fix tests
fb48f48
fix tests 2
e7c9441
fix checkstyle
56bdbda
unit tests
5548eca
Merge branch 'master' into HDDS-13906
ee23af3
fix build issue
eadbe81
fix findbugs
42c3f37
address comments
e760fef
address comments
b76b0e2
checkstyle
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
150 changes: 150 additions & 0 deletions
150
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMDBArchiver.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,150 @@ | ||
| /* | ||
| * 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.ozone.om; | ||
|
|
||
| import static org.apache.hadoop.hdds.utils.Archiver.includeFile; | ||
| import static org.apache.hadoop.hdds.utils.Archiver.tar; | ||
| import static org.apache.hadoop.hdds.utils.HddsServerUtil.includeRatisSnapshotCompleteFlag; | ||
| import static org.apache.hadoop.ozone.om.OMDBCheckpointServletInodeBasedXfer.writeHardlinkFile; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.io.OutputStream; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import org.apache.commons.compress.archivers.ArchiveOutputStream; | ||
| import org.apache.commons.compress.archivers.tar.TarArchiveEntry; | ||
| import org.apache.hadoop.hdds.conf.OzoneConfiguration; | ||
| import org.apache.hadoop.util.Time; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * Class for handling operations relevant to archiving the OM DB tarball. | ||
| * Mainly maintains a map for recording the files collected from reading | ||
| * the checkpoint and snapshot DB's. It temporarily creates hardlinks and stores | ||
| * the link data in the map to release the bootstrap lock quickly | ||
| * and do the actual write at the end outside the lock. | ||
| */ | ||
| public class OMDBArchiver { | ||
|
|
||
| private Path tmpDir; | ||
| private Map<String, File> filesToWriteIntoTarball; | ||
| private Map<String, String> hardLinkFileMap; | ||
| private static final Logger LOG = LoggerFactory.getLogger(OMDBArchiver.class); | ||
| private boolean completed; | ||
|
|
||
| public OMDBArchiver() { | ||
| this.tmpDir = null; | ||
| this.filesToWriteIntoTarball = new HashMap<>(); | ||
| this.hardLinkFileMap = null; | ||
| this.completed = false; | ||
| } | ||
|
|
||
| public void setTmpDir(Path tmpDir) { | ||
| this.tmpDir = tmpDir; | ||
| } | ||
|
|
||
| public Path getTmpDir() { | ||
| return tmpDir; | ||
| } | ||
|
|
||
| public Map<String, String> getHardLinkFileMap() { | ||
sadanand48 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return hardLinkFileMap; | ||
| } | ||
|
|
||
| public Map<String, File> getFilesToWriteIntoTarball() { | ||
sadanand48 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return filesToWriteIntoTarball; | ||
| } | ||
|
|
||
| public void setHardLinkFileMap(Map<String, String> hardLinkFileMap) { | ||
| this.hardLinkFileMap = hardLinkFileMap; | ||
| } | ||
|
|
||
| public boolean isCompleted() { | ||
| return completed; | ||
| } | ||
|
|
||
| public void setCompleted(boolean completed) { | ||
| this.completed = completed; | ||
| } | ||
|
|
||
| /** | ||
| * @param file the file to create a hardlink and record into the map | ||
| * @param entryName name of the entry corresponding to file | ||
| * @return the file size | ||
| * @throws IOException in case of hardlink failure | ||
| * | ||
| * Records the given file entry into the map after taking a hardlink. | ||
sadanand48 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| public long recordFileEntry(File file, String entryName) throws IOException { | ||
sadanand48 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| File link = tmpDir.resolve(entryName).toFile(); | ||
| long bytes = 0; | ||
| try { | ||
| Files.createLink(link.toPath(), file.toPath()); | ||
sadanand48 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| filesToWriteIntoTarball.put(entryName, link); | ||
| bytes = file.length(); | ||
| } catch (IOException ioe) { | ||
| LOG.error("Couldn't create hardlink for file {} while including it in tarball.", | ||
| file.getAbsolutePath(), ioe); | ||
| throw ioe; | ||
| } | ||
| return bytes; | ||
| } | ||
|
|
||
| /** | ||
| * @param conf the configuration object to obtain metadata paths | ||
| * @param outputStream the tarball archive output stream | ||
| * @throws IOException in case of write failure to the archive | ||
| * | ||
| * Writes all the files captured by the map into the archive and | ||
| * also includes the hardlinkFile and the completion marker file. | ||
| */ | ||
|
Comment on lines
126
to
133
|
||
| public void writeToArchive(OzoneConfiguration conf, OutputStream outputStream) | ||
| throws IOException { | ||
| long bytesWritten = 0; | ||
| long lastLoggedTime = Time.now(); | ||
sadanand48 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| long filesWritten = 0; | ||
| try (ArchiveOutputStream<TarArchiveEntry> archiveOutput = tar(outputStream)) { | ||
| for (Map.Entry<String, File> kv : filesToWriteIntoTarball.entrySet()) { | ||
| String entryName = kv.getKey(); | ||
| File link = kv.getValue(); | ||
| try { | ||
| bytesWritten += includeFile(link, entryName, archiveOutput); | ||
| if (Time.monotonicNow() - lastLoggedTime >= 30000) { | ||
| LOG.info("Transferred {} KB, #files {} to checkpoint tarball stream...", | ||
| bytesWritten / (1024), filesWritten); | ||
| lastLoggedTime = Time.monotonicNow(); | ||
sadanand48 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } catch (IOException ioe) { | ||
| LOG.error("Couldn't create hardlink for file {} while including it in tarball.", | ||
sadanand48 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| link.getAbsolutePath(), ioe); | ||
| throw ioe; | ||
| } finally { | ||
| Files.deleteIfExists(link.toPath()); | ||
| } | ||
| } | ||
| if (isCompleted()) { | ||
| writeHardlinkFile(conf, hardLinkFileMap, archiveOutput); | ||
| includeRatisSnapshotCompleteFlag(archiveOutput); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
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.