-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HADOOP-19047: Support InMemory Tracking Of S3A Magic Commits
- Loading branch information
1 parent
f6fea5d
commit 3d0489f
Showing
7 changed files
with
349 additions
and
89 deletions.
There are no files selected for viewing
This file contains 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 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 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
118 changes: 118 additions & 0 deletions
118
...p-aws/src/main/java/org/apache/hadoop/fs/s3a/commit/magic/InMemoryMagicCommitTracker.java
This file contains 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,118 @@ | ||
/* | ||
* 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.fs.s3a.commit.magic; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.hadoop.fs.Path; | ||
import org.apache.hadoop.fs.s3a.WriteOperationHelper; | ||
import org.apache.hadoop.fs.s3a.commit.MagicCommitPaths; | ||
import org.apache.hadoop.fs.s3a.commit.files.SinglePendingCommit; | ||
import org.apache.hadoop.fs.s3a.statistics.PutTrackerStatistics; | ||
import org.apache.hadoop.fs.statistics.IOStatistics; | ||
import org.apache.hadoop.fs.statistics.IOStatisticsSnapshot; | ||
import org.apache.hadoop.thirdparty.com.google.common.base.Preconditions; | ||
import software.amazon.awssdk.services.s3.model.CompletedPart; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import static org.apache.hadoop.util.Preconditions.checkArgument; | ||
|
||
public class InMemoryMagicCommitTracker extends MagicCommitTracker { | ||
|
||
// stores taskAttemptId to commits mapping | ||
public static Map<String, List<SinglePendingCommit>> taskAttemptIdToMpuMetdadataMap | ||
= new ConcurrentHashMap<>(); | ||
|
||
// stores the path to its length in map | ||
public static Map<Path, Long> taskAttemptIdToBytesWritten | ||
= new ConcurrentHashMap<>(); | ||
|
||
// stores taskAttemptId to Path map | ||
public static Map<String, List<Path>> taskAttemptIdToPath = new ConcurrentHashMap(); | ||
|
||
public InMemoryMagicCommitTracker(Path path, | ||
String bucket, | ||
String originalDestKey, | ||
String destKey, | ||
String pendingsetKey, | ||
WriteOperationHelper writer, | ||
PutTrackerStatistics trackerStatistics) { | ||
super(path, bucket, originalDestKey, destKey, pendingsetKey, writer, trackerStatistics); | ||
} | ||
|
||
@Override | ||
public boolean aboutToComplete(String uploadId, | ||
List<CompletedPart> parts, | ||
long bytesWritten, | ||
final IOStatistics iostatistics) | ||
throws IOException { | ||
Preconditions.checkArgument(StringUtils.isNotEmpty(uploadId), "empty/null upload ID: " + uploadId); | ||
Preconditions.checkArgument(parts != null, "No uploaded parts list"); | ||
Preconditions.checkArgument(!parts.isEmpty(), "No uploaded parts to save"); | ||
|
||
// build the commit summary | ||
SinglePendingCommit commitData = new SinglePendingCommit(); | ||
commitData.touch(System.currentTimeMillis()); | ||
commitData.setDestinationKey(getDestKey()); | ||
commitData.setBucket(bucket); | ||
commitData.setUri(path.toUri().toString()); | ||
commitData.setUploadId(uploadId); | ||
commitData.setText(""); | ||
commitData.setLength(bytesWritten); | ||
commitData.bindCommitData(parts); | ||
commitData.setIOStatistics(new IOStatisticsSnapshot(iostatistics)); | ||
|
||
// extract the taskAttemptId from the path | ||
String taskAttemptId = extractTaskAttemptIdFromPath(path); | ||
|
||
// store the commit data with taskAttemptId as the key | ||
taskAttemptIdToMpuMetdadataMap.computeIfAbsent(taskAttemptId, | ||
k -> new ArrayList<>()).add(commitData); | ||
|
||
// store the byteswritten for the corresponding file | ||
taskAttemptIdToBytesWritten.put(path, bytesWritten); | ||
|
||
// store the mapping between taskAttemptId and path | ||
// This information is used for removing entries from | ||
// the map once the taskAttempt is completed/committed. | ||
taskAttemptIdToPath.computeIfAbsent(taskAttemptId, | ||
k -> new ArrayList<>()).add(path); | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* The magic path is of the format, "s3://bucket-name/table-path/__magic_<jobId>/job-id/tasks/taskAttemptId/__base/..." | ||
* So the third child from the "__magic" path will give the task attempt id. | ||
* @param path | ||
* @return taskAttemptId | ||
*/ | ||
private static String extractTaskAttemptIdFromPath(Path path) { | ||
List<String> elementsInPath = MagicCommitPaths.splitPathToElements(path); | ||
List<String> childrenOfMagicPath = MagicCommitPaths.magicPathChildren(elementsInPath); | ||
|
||
// 3rd child of the magic path is the taskAttemptId | ||
checkArgument(childrenOfMagicPath.size() >= 3, "Magic Path is invalid"); | ||
return childrenOfMagicPath.get(3); | ||
} | ||
} |
This file contains 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 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.