steveloughran commented on a change in pull request #951: HADOOP-15183. S3Guard store becomes inconsistent after partial failure of rename URL: https://github.com/apache/hadoop/pull/951#discussion_r293077850
########## File path: hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/impl/StoreContext.java ########## @@ -0,0 +1,328 @@ +/* + * 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.impl; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.util.function.Function; + +import com.google.common.util.concurrent.ListeningExecutorService; + +import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.classification.InterfaceStability; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.s3a.Invoker; +import org.apache.hadoop.fs.s3a.S3AInputPolicy; +import org.apache.hadoop.fs.s3a.S3AInstrumentation; +import org.apache.hadoop.fs.s3a.S3AStorageStatistics; +import org.apache.hadoop.fs.s3a.Statistic; +import org.apache.hadoop.fs.s3a.s3guard.MetadataStore; +import org.apache.hadoop.security.UserGroupInformation; +import org.apache.hadoop.util.SemaphoredDelegatingExecutor; + +/** + * This class provides the core context of the S3A filesystem to subsidiary + * components, without exposing the entire parent class. + * This is eliminate explicit recursive coupling. + * + * Where methods on the FS are to be invoked, they are all passed in + * via functional interfaces, so test setups can pass in mock callbacks + * instead. + * + * <i>Warning:</i> this really is private and unstable. Do not use + * outside the org.apache.hadoop.fs.s3a package. + */ [email protected] [email protected] +public class StoreContext { + + /** Filesystem URI. */ + private final URI fsURI; + + /** Bucket name. */ + private final String bucket; + + /** FS configuration after all per-bucket overrides applied. */ + private final Configuration configuration; + + /** Username. */ + private final String username; + + /** Principal who created the FS. */ + private final UserGroupInformation owner; + + /** + * Bounded thread pool for async operations. + */ + private final ListeningExecutorService executor; + + /** + * Capacity of new executors created. + */ + private final int executorCapacity; + + /** Invoker of operations. */ + private final Invoker invoker; + + /** Instrumentation and statistics. */ + private final S3AInstrumentation instrumentation; + private final S3AStorageStatistics storageStatistics; + + /** Seek policy. */ + private final S3AInputPolicy inputPolicy; + + /** How to react to changes in etags and versions. */ + private final ChangeDetectionPolicy changeDetectionPolicy; + + /** Evaluated options. */ + private final boolean multiObjectDeleteEnabled; + + /** List algorithm. */ + private final boolean useListV1; + + /** Is the store versioned? */ + private final boolean versioned; + + /** + * To allow this context to be passed down to the metastore, this field + * wll be null until initialized. + */ + private final MetadataStore metadataStore; + + /** Function to take a key and return a path. */ + private final Function<String, Path> keyToPathQualifier; + + /** Factory for temporary files. */ + private final FunctionsRaisingIOE.BiFunctionRaisingIOE<String, Long, File> + tempFileFactory; + + private final FunctionsRaisingIOE.CallableRaisingIOE<String> + getBucketLocation; + + /** + * Instantiate. + * No attempt to use a builder here as outside tests + * this should only be created in the S3AFileSystem. + */ + public StoreContext( Review comment: No, for the reasons as discussed. 1. if we add more args, we want 100% of uses (production, test cases) to add every param. Doing that in the refactor operations of the IDE is straightforward. 2. I'm thinking that as more FS-level operations are added (path to key, temp file...) I'd just add a new interface "FSLevelOperations" which we'd implement in S3A and for any test suite. This would avoid the need for a new field & constructor arg on every operation, though I'd still require code to call an explicit method for each such operation (i.e. no direct access to FSLevelOperations. No need to do that now precisely because this is all private; we can do that on the next iteration ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
