-
Notifications
You must be signed in to change notification settings - Fork 588
HDDS-11068. Move SstFiltered flag to a file in the snapshot directory #6965
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
Show all changes
7 commits
Select commit
Hold shift + click to select a range
25d178f
HDDS-11068. Move SstFiltered flag to a file in the snapshot directory
swamirishi b0f7f6b
HDDS-11068. Fix checkstyle
swamirishi 97649b0
Merge remote-tracking branch 'apache/master' into HEAD
swamirishi 71884e0
HDDS-11068. Fix tests
swamirishi 4723c2e
HDDS-11068. Address review comments
swamirishi d091dbf
HDDS-11068. Fix comments
swamirishi 6423746
HDDS-11068. Fix comments
swamirishi 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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |||||
| package org.apache.hadoop.ozone.om; | ||||||
|
|
||||||
| import com.google.common.annotations.VisibleForTesting; | ||||||
| import org.apache.hadoop.hdds.StringUtils; | ||||||
| import org.apache.hadoop.hdds.conf.OzoneConfiguration; | ||||||
| import org.apache.hadoop.hdds.utils.BackgroundService; | ||||||
| import org.apache.hadoop.hdds.utils.BackgroundTask; | ||||||
|
|
@@ -38,6 +39,9 @@ | |||||
| import org.slf4j.LoggerFactory; | ||||||
|
|
||||||
| import java.io.IOException; | ||||||
| import java.nio.file.Files; | ||||||
| import java.nio.file.Path; | ||||||
| import java.nio.file.Paths; | ||||||
| import java.util.Map; | ||||||
| import java.util.Optional; | ||||||
| import java.util.concurrent.TimeUnit; | ||||||
|
|
@@ -69,6 +73,10 @@ public class SstFilteringService extends BackgroundService | |||||
| // multiple times. | ||||||
| private static final int SST_FILTERING_CORE_POOL_SIZE = 1; | ||||||
|
|
||||||
| public static final String SST_FILTERED_FILE = "sstFiltered"; | ||||||
| private static final byte[] SST_FILTERED_FILE_CONTENT = StringUtils.string2Bytes("This file holds information " + | ||||||
| "if a particular snapshot has filtered out the relevant sst files or not.\nDO NOT add, change or delete " + | ||||||
| "any files in this directory unless you know what you are doing.\n"); | ||||||
|
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.
Suggested change
Contributor
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. This file is inside the rocksdb directory. The statement is correct right isn't? Basically asking people not to change any file in this directory. |
||||||
| private final OzoneManager ozoneManager; | ||||||
|
|
||||||
| // Number of files to be batched in an iteration. | ||||||
|
|
@@ -78,6 +86,12 @@ public class SstFilteringService extends BackgroundService | |||||
|
|
||||||
| private AtomicBoolean running; | ||||||
|
|
||||||
| public static boolean isSstFiltered(OzoneConfiguration ozoneConfiguration, SnapshotInfo snapshotInfo) { | ||||||
| Path sstFilteredFile = Paths.get(OmSnapshotManager.getSnapshotPath(ozoneConfiguration, | ||||||
| snapshotInfo), SST_FILTERED_FILE); | ||||||
| return snapshotInfo.isSstFiltered() || sstFilteredFile.toFile().exists(); | ||||||
| } | ||||||
|
|
||||||
| public SstFilteringService(long interval, TimeUnit unit, long serviceTimeout, | ||||||
| OzoneManager ozoneManager, OzoneConfiguration configuration) { | ||||||
| super("SstFilteringService", interval, unit, SST_FILTERING_CORE_POOL_SIZE, | ||||||
|
|
@@ -112,33 +126,35 @@ public void resume() { | |||||
|
|
||||||
| private class SstFilteringTask implements BackgroundTask { | ||||||
|
|
||||||
| private boolean isSnapshotDeleted(SnapshotInfo snapshotInfo) { | ||||||
| return snapshotInfo == null || snapshotInfo.getSnapshotStatus() == SnapshotInfo.SnapshotStatus.SNAPSHOT_DELETED; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| /** | ||||||
| * Marks the SSTFiltered flag corresponding to the snapshot. | ||||||
| * @param volume Volume name of the snapshot | ||||||
| * @param bucket Bucket name of the snapshot | ||||||
| * @param snapshotName Snapshot name | ||||||
| * Marks the snapshot as SSTFiltered by creating a file in snapshot directory. | ||||||
| * @param snapshotInfo snapshotInfo | ||||||
| * @throws IOException | ||||||
| */ | ||||||
| private void markSSTFilteredFlagForSnapshot(String volume, String bucket, | ||||||
| String snapshotName) throws IOException { | ||||||
| private void markSSTFilteredFlagForSnapshot(SnapshotInfo snapshotInfo) throws IOException { | ||||||
| // Acquiring read lock to avoid race condition with the snapshot directory deletion occurring | ||||||
| // in OmSnapshotPurgeResponse. Any operation apart from delete can run in parallel along with this operation. | ||||||
| //TODO. Revisit other SNAPSHOT_LOCK and see if we can change write locks to read locks to further optimize it. | ||||||
| OMLockDetails omLockDetails = ozoneManager.getMetadataManager().getLock() | ||||||
hemantk-12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| .acquireWriteLock(SNAPSHOT_LOCK, volume, bucket, snapshotName); | ||||||
| .acquireReadLock(SNAPSHOT_LOCK, snapshotInfo.getVolumeName(), snapshotInfo.getBucketName(), | ||||||
hemantk-12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| snapshotInfo.getName()); | ||||||
| boolean acquiredSnapshotLock = omLockDetails.isLockAcquired(); | ||||||
| if (acquiredSnapshotLock) { | ||||||
| Table<String, SnapshotInfo> snapshotInfoTable = | ||||||
| ozoneManager.getMetadataManager().getSnapshotInfoTable(); | ||||||
| String snapshotDir = OmSnapshotManager.getSnapshotPath(ozoneManager.getConfiguration(), snapshotInfo); | ||||||
| try { | ||||||
| // mark the snapshot as filtered by writing to the file | ||||||
| String snapshotTableKey = SnapshotInfo.getTableKey(volume, bucket, | ||||||
| snapshotName); | ||||||
| SnapshotInfo snapshotInfo = snapshotInfoTable.get(snapshotTableKey); | ||||||
|
|
||||||
| snapshotInfo.setSstFiltered(true); | ||||||
| snapshotInfoTable.put(snapshotTableKey, snapshotInfo); | ||||||
| // mark the snapshot as filtered by creating a file. | ||||||
| if (Files.exists(Paths.get(snapshotDir))) { | ||||||
| Files.write(Paths.get(snapshotDir, SST_FILTERED_FILE), SST_FILTERED_FILE_CONTENT); | ||||||
| } | ||||||
| } finally { | ||||||
| ozoneManager.getMetadataManager().getLock() | ||||||
| .releaseWriteLock(SNAPSHOT_LOCK, volume, bucket, snapshotName); | ||||||
| .releaseReadLock(SNAPSHOT_LOCK, snapshotInfo.getVolumeName(), | ||||||
| snapshotInfo.getBucketName(), snapshotInfo.getName()); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
@@ -163,12 +179,11 @@ public BackgroundTaskResult call() throws Exception { | |||||
| long snapshotLimit = snapshotLimitPerTask; | ||||||
|
|
||||||
| while (iterator.hasNext() && snapshotLimit > 0 && running.get()) { | ||||||
| Table.KeyValue<String, SnapshotInfo> keyValue = iterator.next(); | ||||||
| String snapShotTableKey = keyValue.getKey(); | ||||||
| SnapshotInfo snapshotInfo = keyValue.getValue(); | ||||||
| try { | ||||||
| Table.KeyValue<String, SnapshotInfo> keyValue = iterator.next(); | ||||||
| String snapShotTableKey = keyValue.getKey(); | ||||||
| SnapshotInfo snapshotInfo = keyValue.getValue(); | ||||||
|
|
||||||
| if (snapshotInfo.isSstFiltered()) { | ||||||
| if (isSstFiltered(ozoneManager.getConfiguration(), snapshotInfo)) { | ||||||
| continue; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -194,6 +209,9 @@ public BackgroundTaskResult call() throws Exception { | |||||
| .lock()) { | ||||||
| db.deleteFilesNotMatchingPrefix(columnFamilyNameToPrefixMap); | ||||||
| } | ||||||
| markSSTFilteredFlagForSnapshot(snapshotInfo); | ||||||
| snapshotLimit--; | ||||||
| snapshotFilteredCount.getAndIncrement(); | ||||||
| } catch (OMException ome) { | ||||||
| // FILE_NOT_FOUND is obtained when the snapshot is deleted | ||||||
| // In this case, get the snapshotInfo from the db, check if | ||||||
|
|
@@ -202,20 +220,22 @@ public BackgroundTaskResult call() throws Exception { | |||||
| SnapshotInfo snapshotInfoToCheck = | ||||||
| ozoneManager.getMetadataManager().getSnapshotInfoTable() | ||||||
| .get(snapShotTableKey); | ||||||
| if (snapshotInfoToCheck.getSnapshotStatus() == | ||||||
| SnapshotInfo.SnapshotStatus.SNAPSHOT_DELETED) { | ||||||
| if (isSnapshotDeleted(snapshotInfoToCheck)) { | ||||||
| LOG.info("Snapshot with name: '{}', id: '{}' has been " + | ||||||
| "deleted.", snapshotInfo.getName(), snapshotInfo | ||||||
| .getSnapshotId()); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| markSSTFilteredFlagForSnapshot(snapshotInfo.getVolumeName(), | ||||||
| snapshotInfo.getBucketName(), snapshotInfo.getName()); | ||||||
| snapshotLimit--; | ||||||
| snapshotFilteredCount.getAndIncrement(); | ||||||
| } catch (RocksDBException | IOException e) { | ||||||
| LOG.error("Exception encountered while filtering a snapshot", e); | ||||||
| if (isSnapshotDeleted(snapshotInfoTable.get(snapShotTableKey))) { | ||||||
| LOG.info("Exception encountered while filtering a snapshot: {} since it was deleted midway", | ||||||
| snapShotTableKey, e); | ||||||
| } else { | ||||||
| LOG.error("Exception encountered while filtering a snapshot", e); | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| } | ||||||
| } | ||||||
| } catch (IOException e) { | ||||||
|
|
||||||
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
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.
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.
nit: should we have
.txtor any other text file extension?