Class SnowflakeGCSClient
- java.lang.Object
-
- net.snowflake.client.jdbc.cloud.storage.SnowflakeGCSClient
-
- All Implemented Interfaces:
SnowflakeStorageClient
public class SnowflakeGCSClient extends Object implements SnowflakeStorageClient
Encapsulates the GCS Storage client and all GCS operations and logic- Author:
- ppaulus
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDigestMetadata(StorageObjectMetadata meta, String digest)Adds digest metadata to the StorageObjectMetadata objectvoidaddEncryptionMetadata(StorageObjectMetadata meta, MatDesc matDesc, byte[] ivData, byte[] encKeK, long contentLength)Adds encryption metadata to the StorageObjectMetadata objectvoidaddStreamingIngestMetadata(StorageObjectMetadata meta, String clientName, String clientKey)Adds streaming ingest metadata to the StorageObjectMetadata object, used for streaming ingest per client billing calculationstatic SnowflakeGCSClientcreateSnowflakeGCSClient(StageInfo stage, net.snowflake.common.core.RemoteStoreFileEncryptionMaterial encMat, SFSession session)voiddownload(SFSession session, String command, String localLocation, String destFileName, int parallelism, String remoteStorageLocation, String stageFilePath, String stageRegion, String presignedUrl)Download a file from remote storage.InputStreamdownloadToStream(SFSession session, String command, int parallelism, String remoteStorageLocation, String stageFilePath, String stageRegion, String presignedUrl)Download a file from remote storageStringgetDigestMetadata(StorageObjectMetadata meta)Gets digest metadata to the StorageObjectMetadata objectintgetEncryptionKeySize()StringgetMatdescKey()Returns the material descriptor keyintgetMaxRetries()StorageObjectMetadatagetObjectMetadata(String remoteStorageLocation, String prefix)Returns the metadata properties for a remote storage objectintgetRetryBackoffMaxExponent()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 retryintgetRetryBackoffMin()StringgetStreamingIngestClientKey(StorageObjectMetadata meta)Gets streaming ingest client key to the StorageObjectMetadata objectStringgetStreamingIngestClientName(StorageObjectMetadata meta)Gets streaming ingest client name to the StorageObjectMetadata objectvoidhandleStorageException(Exception ex, int retryCount, String operation, SFSession session, String command)Handles exceptions thrown by the remote storage providerbooleanisEncrypting()StorageObjectSummaryCollectionlistObjects(String remoteStorageLocation, String prefix)listObjects gets all the objects in a pathvoidrenew(Map<?,?> stageCredentials)Re-creates the encapsulated storage client with a fresh access tokenbooleanrequirePresignedUrl()voidshutdown()shuts down the clientvoidupload(SFSession session, String command, int parallelism, boolean uploadFromStream, String remoteStorageLocation, File srcFile, String destFileName, InputStream inputStream, FileBackedOutputStream fileBackedOutputStream, StorageObjectMetadata meta, String stageRegion, String presignedUrl)Upload a file/stream to remote storagevoiduploadWithPresignedUrlWithoutConnection(int networkTimeoutInMilli, HttpClientSettingsKey ocspModeAndProxyKey, int parallelism, boolean uploadFromStream, String remoteStorageLocation, File srcFile, String destFileName, InputStream inputStream, FileBackedOutputStream fileBackedOutputStream, StorageObjectMetadata meta, String stageRegion, String presignedUrl)Upload a file (-stream) to remote storage with Pre-signed URL without JDBC session.
-
-
-
Method Detail
-
createSnowflakeGCSClient
public static SnowflakeGCSClient createSnowflakeGCSClient(StageInfo stage, net.snowflake.common.core.RemoteStoreFileEncryptionMaterial encMat, SFSession session) throws SnowflakeSQLException
- Throws:
SnowflakeSQLException
-
getMaxRetries
public int getMaxRetries()
- Specified by:
getMaxRetriesin interfaceSnowflakeStorageClient- Returns:
- Returns the Max number of retry attempts
-
getRetryBackoffMaxExponent
public int getRetryBackoffMaxExponent()
Description copied from interface:SnowflakeStorageClientReturns 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:
getRetryBackoffMaxExponentin interfaceSnowflakeStorageClient- Returns:
- Returns the exponent
-
getRetryBackoffMin
public int getRetryBackoffMin()
- Specified by:
getRetryBackoffMinin interfaceSnowflakeStorageClient- Returns:
- Returns the min number of milliseconds to sleep before retry
-
isEncrypting
public boolean isEncrypting()
- Specified by:
isEncryptingin interfaceSnowflakeStorageClient- Returns:
- Returns true if encryption is enabled
-
getEncryptionKeySize
public int getEncryptionKeySize()
- Specified by:
getEncryptionKeySizein interfaceSnowflakeStorageClient- Returns:
- Returns the size of the encryption key
-
requirePresignedUrl
public boolean requirePresignedUrl()
- Specified by:
requirePresignedUrlin interfaceSnowflakeStorageClient- Returns:
- Whether this client requires the use of presigned URLs for upload and download instead of credentials that work for all files uploaded/ downloaded to a stage path. True for GCS.
-
renew
public void renew(Map<?,?> stageCredentials) throws SnowflakeSQLException
Description copied from interface:SnowflakeStorageClientRe-creates the encapsulated storage client with a fresh access token- Specified by:
renewin interfaceSnowflakeStorageClient- Parameters:
stageCredentials- a Map (as returned by GS) which contains the new credential properties- Throws:
SnowflakeSQLException- failure to renew the storage client
-
shutdown
public void shutdown()
Description copied from interface:SnowflakeStorageClientshuts down the client- Specified by:
shutdownin interfaceSnowflakeStorageClient
-
listObjects
public StorageObjectSummaryCollection listObjects(String remoteStorageLocation, String prefix) throws StorageProviderException
listObjects gets all the objects in a path- Specified by:
listObjectsin interfaceSnowflakeStorageClient- Parameters:
remoteStorageLocation- bucket nameprefix- Path- Returns:
- Throws:
StorageProviderException
-
getObjectMetadata
public StorageObjectMetadata getObjectMetadata(String remoteStorageLocation, String prefix) throws StorageProviderException
Description copied from interface:SnowflakeStorageClientReturns the metadata properties for a remote storage object- Specified by:
getObjectMetadatain interfaceSnowflakeStorageClient- Parameters:
remoteStorageLocation- location, i.e. bucket for S3prefix- the prefix/path of the object to retrieve- Returns:
- storage metadata object
- Throws:
StorageProviderException- cloud storage provider error
-
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 remote storage.- Specified by:
downloadin interfaceSnowflakeStorageClient- Parameters:
session- session objectcommand- command to download filelocalLocation- local file pathdestFileName- destination file nameparallelism- [ not used by the GCP implementation ]remoteStorageLocation- remote storage location, i.e. bucket for S3stageFilePath- stage file pathstageRegion- region name where the stage persistspresignedUrl- Credential to use for download- Throws:
SnowflakeSQLException- download failure
-
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:
downloadToStreamin interfaceSnowflakeStorageClient- Parameters:
session- session objectcommand- command to download fileparallelism- number of threads for parallel downloadingremoteStorageLocation- remote storage location, i.e. bucket for s3stageFilePath- stage file pathstageRegion- region name where the stage persistspresignedUrl- Signed credential for download- Returns:
- input file stream
- Throws:
SnowflakeSQLException- when download failure
-
uploadWithPresignedUrlWithoutConnection
public void uploadWithPresignedUrlWithoutConnection(int networkTimeoutInMilli, HttpClientSettingsKey ocspModeAndProxyKey, int parallelism, boolean uploadFromStream, String remoteStorageLocation, File srcFile, String destFileName, InputStream inputStream, FileBackedOutputStream fileBackedOutputStream, StorageObjectMetadata meta, String stageRegion, String presignedUrl) throws SnowflakeSQLExceptionUpload a file (-stream) to remote storage with Pre-signed URL without JDBC session.- Specified by:
uploadWithPresignedUrlWithoutConnectionin interfaceSnowflakeStorageClient- Parameters:
networkTimeoutInMilli- Network timeout for the uploadocspModeAndProxyKey- OCSP mode and proxy settings for the upload.parallelism- number of threads do parallel uploadinguploadFromStream- true if upload source is streamremoteStorageLocation- s3 bucket namesrcFile- source file if not uploading from a streamdestFileName- file name on remote storage after uploadinputStream- stream used for uploading if fileBackedOutputStream is nullfileBackedOutputStream- stream used for uploading if not nullmeta- object meta datastageRegion- region name where the stage persistspresignedUrl- presigned URL for upload. Used by GCP.- Throws:
SnowflakeSQLException- if upload failed
-
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 remote storage- Specified by:
uploadin interfaceSnowflakeStorageClient- Parameters:
session- session objectcommand- upload commandparallelism- [ not used by the GCP implementation ]uploadFromStream- true if upload source is streamremoteStorageLocation- storage container namesrcFile- source file if not uploading from a streamdestFileName- file name on remote storage after uploadinputStream- stream used for uploading if fileBackedOutputStream is nullfileBackedOutputStream- stream used for uploading if not nullmeta- object meta datastageRegion- region name where the stage persistspresignedUrl- Credential used for upload of a file- 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:SnowflakeStorageClientHandles exceptions thrown by the remote storage provider- Specified by:
handleStorageExceptionin interfaceSnowflakeStorageClient- Parameters:
ex- the exception to handleretryCount- current number of retries, incremented by the caller before each calloperation- 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 clientcommand- 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
-
getMatdescKey
public String getMatdescKey()
Returns the material descriptor key- Specified by:
getMatdescKeyin interfaceSnowflakeStorageClient- Returns:
- the material descriptor key
-
addEncryptionMetadata
public void addEncryptionMetadata(StorageObjectMetadata meta, MatDesc matDesc, byte[] ivData, byte[] encKeK, long contentLength)
Adds encryption metadata to the StorageObjectMetadata object- Specified by:
addEncryptionMetadatain interfaceSnowflakeStorageClient- Parameters:
meta- the storage metadata object to add the encryption info tomatDesc- the material descriptorivData- the initialization vectorencKeK- the key encryption keycontentLength- the length of the encrypted content
-
addDigestMetadata
public void addDigestMetadata(StorageObjectMetadata meta, String digest)
Adds digest metadata to the StorageObjectMetadata object- Specified by:
addDigestMetadatain interfaceSnowflakeStorageClient- Parameters:
meta- the storage metadata object to add the digest todigest- the digest metadata to add
-
getDigestMetadata
public String getDigestMetadata(StorageObjectMetadata meta)
Gets digest metadata to the StorageObjectMetadata object- Specified by:
getDigestMetadatain interfaceSnowflakeStorageClient- Parameters:
meta- the metadata object to extract the digest metadata from- Returns:
- the digest metadata value
-
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:
addStreamingIngestMetadatain interfaceSnowflakeStorageClient- Parameters:
meta- the storage metadata object to add the digest toclientName- streaming ingest client nameclientKey- streaming ingest client key, provided by Snowflake
-
getStreamingIngestClientName
public String getStreamingIngestClientName(StorageObjectMetadata meta)
Gets streaming ingest client name to the StorageObjectMetadata object- Specified by:
getStreamingIngestClientNamein interfaceSnowflakeStorageClient
-
getStreamingIngestClientKey
public String getStreamingIngestClientKey(StorageObjectMetadata meta)
Gets streaming ingest client key to the StorageObjectMetadata object- Specified by:
getStreamingIngestClientKeyin interfaceSnowflakeStorageClient
-
-