Return-Path: X-Original-To: apmail-accumulo-dev-archive@www.apache.org Delivered-To: apmail-accumulo-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1FA0819A0E for ; Thu, 21 Apr 2016 14:35:31 +0000 (UTC) Received: (qmail 50021 invoked by uid 500); 21 Apr 2016 14:35:31 -0000 Delivered-To: apmail-accumulo-dev-archive@accumulo.apache.org Received: (qmail 49980 invoked by uid 500); 21 Apr 2016 14:35:31 -0000 Mailing-List: contact dev-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list dev@accumulo.apache.org Received: (qmail 49969 invoked by uid 99); 21 Apr 2016 14:35:30 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Apr 2016 14:35:30 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 955DADFC70; Thu, 21 Apr 2016 14:35:30 +0000 (UTC) From: keith-turner To: dev@accumulo.apache.org Reply-To: dev@accumulo.apache.org References: In-Reply-To: Subject: [GitHub] accumulo pull request: ACCUMULO-4195 Added generalized configurati... Content-Type: text/plain Message-Id: <20160421143530.955DADFC70@git1-us-west.apache.org> Date: Thu, 21 Apr 2016 14:35:30 +0000 (UTC) Github user keith-turner commented on a diff in the pull request: https://github.com/apache/accumulo/pull/95#discussion_r60591210 --- Diff: core/src/main/java/org/apache/accumulo/core/file/FileOperations.java --- @@ -48,38 +48,295 @@ public static FileOperations getInstance() { return new DispatchingFileFactory(); } + // + // Abstract methods (to be implemented by subclasses) + // + + protected abstract long getFileSize(GetFileSizeOperation options) throws IOException; + + protected abstract FileSKVWriter openWriter(OpenWriterOperation options) throws IOException; + + protected abstract FileSKVIterator openIndex(OpenIndexOperation options) throws IOException; + + protected abstract FileSKVIterator openScanReader(OpenScanReaderOperation options) throws IOException; + + protected abstract FileSKVIterator openReader(OpenReaderOperation options) throws IOException; + + // + // File operations + // + /** - * Open a reader that will not be seeked giving an initial seek location. This is useful for file operations that only need to scan data within a range and do - * not need to seek. Therefore file metadata such as indexes does not need to be kept in memory while the file is scanned. Also seek optimizations like bloom - * filters do not need to be loaded. + * Construct an operation object allowing one to query the size of a file.
+ * Syntax: * + *
    +   * long size = fileOperations.getFileSize().ofFile(filename, fileSystem, fsConfiguration).withTableConfiguration(tableConf).execute();
    +   * 
*/ + public GetFileSizeOperation getFileSize() { + return new GetFileSizeOperation(); + } - public abstract FileSKVIterator openReader(String file, Range range, Set columnFamilies, boolean inclusive, FileSystem fs, Configuration conf, - RateLimiter readLimiter, AccumuloConfiguration tableConf) throws IOException; + /** + * Construct an operation object allowing one to create a writer for a file.
+ * Syntax: + * + *
    +   * FileSKVWriter writer = fileOperations.openWriter()
    +   *     .ofFile(...)
    +   *     .withTableConfiguration(...)
    +   *     .withRateLimiter(...) // optional
    +   *     .withCompression(...) // optional
    +   *     .execute();
    +   * 
+ */ + public OpenWriterOperation openWriter() { + return new OpenWriterOperation(); + } + + /** + * Construct an operation object allowing one to create an index iterator for a file.
+ * Syntax: + * + *
    +   * FileSKVIterator iterator = fileOperations.openIndex()
    +   *     .ofFile(...)
    +   *     .withTableConfiguration(...)
    +   *     .withRateLimiter(...) // optional
    +   *     .withBlockCache(...) // optional
    +   *     .execute();
    +   * 
+ */ + public OpenIndexOperation openIndex() { + return new OpenIndexOperation(); + } - public abstract FileSKVIterator openReader(String file, Range range, Set columnFamilies, boolean inclusive, FileSystem fs, Configuration conf, - RateLimiter readLimiter, AccumuloConfiguration tableConf, BlockCache dataCache, BlockCache indexCache) throws IOException; + /** + * Construct an operation object allowing one to create a "scan" reader for a file. Scan readers do not have any optimizations for seeking beyond their + * initial position. This is useful for file operations that only need to scan data within a range and do not need to seek. Therefore file metadata such as + * indexes does not need to be kept in memory while the file is scanned. Also seek optimizations like bloom filters do not need to be loaded.
+ * Syntax: + * + *
    +   * FileSKVIterator scanner = fileOperations.openScanReader()
    +   *     .ofFile(...)
    +   *     .overRange(...)
    +   *     .withTableConfiguration(...)
    +   *     .withRateLimiter(...) // optional
    +   *     .withBlockCache(...) // optional
    +   *     .execute();
    +   * 
+ */ + public OpenScanReaderOperation openScanReader() { + return new OpenScanReaderOperation(); + } /** - * Open a reader that fully support seeking and also enable any optimizations related to seeking, like bloom filters. + * Construct an operation object allowing one to create a reader for a file. A reader constructed in this manner fully supports seeking, and also enables any + * optimizations related to seeking (e.g. Bloom filters).
+ * Syntax: * + *
    +   * FileSKVIterator scanner = fileOperations.openReader()
    +   *     .ofFile(...)
    +   *     .withTableConfiguration(...)
    +   *     .withRateLimiter(...) // optional
    +   *     .withBlockCache(...) // optional
    +   *     .seekToBeginning(...) // optional
    +   *     .execute();
    +   * 
+ */ + public OpenReaderOperation openReader() { + return new OpenReaderOperation(); + } + + // + // Operation objects. + // + + /** + * Options common to all FileOperations. + */ + protected static class FileAccessOperation> { + private AccumuloConfiguration tableConfiguration; + + private String filename; + private FileSystem fs; + private Configuration fsConf; + + /** Specify the table configuration defining access to this file. */ + @SuppressWarnings("unchecked") + public SubclassType withTableConfiguration(AccumuloConfiguration tableConfiguration) { + this.tableConfiguration = tableConfiguration; + return (SubclassType) this; + } + + /** Specify the file this operation should apply to. */ + @SuppressWarnings("unchecked") + public SubclassType ofFile(String filename, FileSystem fs, Configuration fsConf) { + this.filename = filename; + this.fs = fs; + this.fsConf = fsConf; + return (SubclassType) this; + } + + public String getFilename() { + return filename; + } + + public FileSystem getFileSystem() { + return fs; + } + + public Configuration getConfiguration() { + return fsConf; + } + + public AccumuloConfiguration getTableConfiguration() { --- End diff -- Will this return null if withTableConfiguration was not called? It seems like a lot of code uses this w/o checking if its null. Was thinking about the following options * Make execute() check if is null and fail fast if so, not sure if this really any more informative than the NPE (because the NPE would occur in something that execute calls). * return DefaultConfig if its null. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---