Class SnowflakeS3Client

    • Constructor Detail

      • SnowflakeS3Client

        public SnowflakeS3Client​(Map<?,​?> stageCredentials,
                                 com.amazonaws.ClientConfiguration clientConfig,
                                 net.snowflake.common.core.RemoteStoreFileEncryptionMaterial encMat,
                                 Properties proxyProperties,
                                 String stageRegion,
                                 String stageEndPoint,
                                 boolean isClientSideEncrypted,
                                 SFBaseSession session,
                                 boolean useS3RegionalUrl)
                          throws SnowflakeSQLException
        Throws:
        SnowflakeSQLException
    • Method Detail

      • getRetryBackoffMaxExponent

        public int getRetryBackoffMaxExponent()
        Description copied from interface: SnowflakeStorageClient
        Returns the max exponent for multiplying backoff with the power of 2, the value of 4 will give us 16secs as the max number of time to sleep before retry
        Specified by:
        getRetryBackoffMaxExponent in interface SnowflakeStorageClient
        Returns:
        Returns the exponent
      • renew

        public void renew​(Map<?,​?> stageCredentials)
                   throws SnowflakeSQLException
        Renew the S3 client with fresh AWS credentials/access token
        Specified by:
        renew in interface SnowflakeStorageClient
        Parameters:
        stageCredentials - a Map of new AWS credential properties, to refresh the client with (as returned by GS)
        Throws:
        SnowflakeSQLException - if any error occurs
      • download

        public void download​(SFSession session,
                             String command,
                             String localLocation,
                             String destFileName,
                             int parallelism,
                             String remoteStorageLocation,
                             String stageFilePath,
                             String stageRegion,
                             String presignedUrl)
                      throws SnowflakeSQLException
        Download a file from S3.
        Specified by:
        download in interface SnowflakeStorageClient
        Parameters:
        session - session object
        command - command to download file
        localLocation - local file path
        destFileName - destination file name
        parallelism - number of threads for parallel downloading
        remoteStorageLocation - s3 bucket name
        stageFilePath - stage file path
        stageRegion - region name where the stage persists
        presignedUrl - Not used in S3
        Throws:
        SnowflakeSQLException - if download failed without an exception
        SnowflakeSQLException - if failed to decrypt downloaded file
        SnowflakeSQLException - if file metadata is incomplete
      • downloadToStream

        public InputStream downloadToStream​(SFSession session,
                                            String command,
                                            int parallelism,
                                            String remoteStorageLocation,
                                            String stageFilePath,
                                            String stageRegion,
                                            String presignedUrl)
                                     throws SnowflakeSQLException
        Download a file from remote storage
        Specified by:
        downloadToStream in interface SnowflakeStorageClient
        Parameters:
        session - session object
        command - command to download file
        parallelism - number of threads for parallel downloading
        remoteStorageLocation - remote storage location, i.e. bucket for s3
        stageFilePath - stage file path
        stageRegion - region name where the stage persists
        presignedUrl - Not used in S3
        Returns:
        input file stream
        Throws:
        SnowflakeSQLException - when download failure
      • upload

        public void upload​(SFSession session,
                           String command,
                           int parallelism,
                           boolean uploadFromStream,
                           String remoteStorageLocation,
                           File srcFile,
                           String destFileName,
                           InputStream inputStream,
                           FileBackedOutputStream fileBackedOutputStream,
                           StorageObjectMetadata meta,
                           String stageRegion,
                           String presignedUrl)
                    throws SnowflakeSQLException
        Upload a file (-stream) to S3.
        Specified by:
        upload in interface SnowflakeStorageClient
        Parameters:
        session - session object
        command - upload command
        parallelism - number of threads do parallel uploading
        uploadFromStream - true if upload source is stream
        remoteStorageLocation - s3 bucket name
        srcFile - source file if not uploading from a stream
        destFileName - file name on s3 after upload
        inputStream - stream used for uploading if fileBackedOutputStream is null
        fileBackedOutputStream - stream used for uploading if not null
        meta - object meta data
        stageRegion - region name where the stage persists
        presignedUrl - Not used in S3
        Throws:
        SnowflakeSQLException - if upload failed even after retry
      • handleStorageException

        public void handleStorageException​(Exception ex,
                                           int retryCount,
                                           String operation,
                                           SFSession session,
                                           String command)
                                    throws SnowflakeSQLException
        Description copied from interface: SnowflakeStorageClient
        Handles exceptions thrown by the remote storage provider
        Specified by:
        handleStorageException in interface SnowflakeStorageClient
        Parameters:
        ex - the exception to handle
        retryCount - current number of retries, incremented by the caller before each call
        operation - string that indicates the function/operation that was taking place, when the exception was raised, for example "upload"
        session - the current SFSession object used by the client
        command - the command attempted at the time of the exception
        Throws:
        SnowflakeSQLException - exceptions that were not handled, or retried past what the retry policy allows, are propagated
      • isClientException400Or404

        public boolean isClientException400Or404​(Exception ex)
        Checks the status code of the exception to see if it's a 400 or 404
      • addEncryptionMetadata

        public void addEncryptionMetadata​(StorageObjectMetadata meta,
                                          MatDesc matDesc,
                                          byte[] ivData,
                                          byte[] encKeK,
                                          long contentLength)
        Adds encryption metadata to the StorageObjectMetadata object
        Specified by:
        addEncryptionMetadata in interface SnowflakeStorageClient
        Parameters:
        meta - the storage metadata object to add the encryption info to
        matDesc - the material descriptor
        ivData - the initialization vector
        encKeK - the key encryption key
        contentLength - the length of the encrypted content
      • addDigestMetadata

        public void addDigestMetadata​(StorageObjectMetadata meta,
                                      String digest)
        Adds digest metadata to the StorageObjectMetadata object
        Specified by:
        addDigestMetadata in interface SnowflakeStorageClient
        Parameters:
        meta - the storage metadata object to add the digest to
        digest - the digest metadata to add
      • addStreamingIngestMetadata

        public void addStreamingIngestMetadata​(StorageObjectMetadata meta,
                                               String clientName,
                                               String clientKey)
        Adds streaming ingest metadata to the StorageObjectMetadata object, used for streaming ingest per client billing calculation
        Specified by:
        addStreamingIngestMetadata in interface SnowflakeStorageClient
        Parameters:
        meta - the storage metadata object to add the digest to
        clientName - streaming ingest client name
        clientKey - streaming ingest client key, provided by Snowflake