サービスでのSnowflakeステージボリュームの使用

Snowflake supports various storage volume types for your application containers, including internal stage, local storage, memory storage, and block storage volumes. This section explains how to configure volumes and volume mounts for internal stages. A An internal stage volume is a volume configured to use a Snowflake stage as persistent storage.

With stage volumes your service can access an internal stage's objects as if they are files on your file system, simplifying your service code compared to using a Snowflake driver and GET and PUT SQL commands to access these objects. Stage volumes can also perform better for scenarios with streaming reads or writes of large data files.

If you file system operations can easily be translated to streaming GET and PUT operations, then Stage volumes will work well for your scenario. If your application needs to rename or move files, modify existing files, or perform file system based locking, then stage volume is not a good fit for your workload.

注釈

There are currently two implementations of stage volumes; a generally available version and a deprecated version. Snowflake recommends that you use the generally available version for new services and that you migrate your existing applications from the deprecated version.

The stage volume implementation streams file contents directly to and from cloud storage, ensuring that you always get the latest contents. Consider the following points when you use a stage volume:

  • A stage volume is optimized for large, sequential reads and writes, providing strong performance for these access patterns. For best results, read and write data in large, contiguous chunks.

  • Reads always return the latest data, which lets data sharing occur between services.

  • Random writes or file appends aren't supported. Attempting these operations results in an error. Snowflake recommends that you use block storage volumes for these workloads.

Configure a Snowflake stage as a storage volume in a service specification

To create a service where service containers use a stage volume, you perform two steps to specify the required settings in the service specification:

  • Define a stage volume that identifies the Snowflake stage to use as storage volume.

  • Specify where to mount the stage volume in your application container.

Step 1: Define a stage volume

To define a stage volume, add the spec.volumes field in the service specification as shown in the following example. The example shows only the minimum required fields:

spec:
  containers:
    ..
  volumes:
  - name: <name>
    source: stage
    stageConfig:
       name: <stage_name>
Copy

The following list defines the fields from the example:

  • name: Provides the name of the volume.

  • source: Identifies the type of the volume (stage).

  • stageConfig.name: Identifies the Snowflake internal stage or folder on a stage to mount; for example @my_stage, @my_stage/folder, or @my_db.my_schema.my_stage/folder/nestedfolder. Double quotes must surround this value.

You can include the following optional fields in stageConfig:

  • stageConfig.resources field: The Snowflake component that provides the mounted stage volume requires CPU and memory resources. Use this field to specify these CPU and memory requirements, similar to the resource specifications for your application containers. For more information, see containers.resources フィールド fields. If this field isn't specified, the following default resource settings apply:

    • resources.requests.cpu: 0

    • resources.requests.memory: 0.5Gi

    • resources.limits.cpu: 0.5

    • resources.limits.memory: 1Gi

    For most applications with typical data traffic to stage volumes, you don't need to set this field, because the default resource settings should be sufficient. However, if your application performs a high volume of reads and writes, the default settings might lead to performance constraints or read/write failures. For more information, see ステージ・ボリュームの両方の実装の共通ガイドライン.

    To avoid these problems, check the CPU and memory metrics for the container (stage-mount-v2-sidecar-<stage-volume-name>). Snowflake adds this container to your service that provides the implementation of the stage volume you configured. This lets you to see exactly what resources your stage volume is using and determine if it is constrained by CPU or memory. Use these metrics to update the CPU and memory limits as needed.

  • stageConfig.metadataCache field: If your application frequently retrieves file metadata or lists files on a Snowflake stage in a loop, and you don't expect the data to change often, you can enable metadata caching for the Snowflake stage storage volume to significantly improve performance. The cache stores this metadata for a specified time period, after which it is cleared. If the application then tries to access the metadata, Snowflake refreshes the cache. Use the hours, minutes, and seconds units to specify the metadataCache. For example 90s, 5m, 1h, 1h30m, 1h30m45s. If not specified, there is no caching.

    注釈

    Configure metadata caching only when the data in your Snowflake stage doesn't change for service lifetime; for example, a service that has read-only workloads that need to work on a static set of data in the stage. Don't configure metadata caching for workloads where data in your Snowflake stage is updated while the service is running.

The following spec.volumes field defines a Snowflake stage volume. The field includes the optional stageConfig fields:

spec:
  containers:
    ..
  volumes:
  - name: <name>
    source: stage
    stageConfig:
        name: <stage_name>
        metadataCache: 1h
        resources:
            requests:
                cpu: 0.35
                memory: 0.4Gi
            limits:
                cpu: 2.0
                memory: 1Gi
Copy

Step 2: Specify where to mount the stage volume in the container

After you define a Snowflake stage storage volume by adding the spec.volumes field, use the spec.containers.volumeMounts field to describe where to mount the stage volume in your application containers, as shown in the following example:

spec:
  containers:
  name: ...
  image: ...
  volumeMounts:
  - name: <name>
    mountPath: <absolute_directory_path>
Copy

このフィールドに入力する情報は、サポートされるすべてのストレージボリュームタイプで一貫しており、ステージボリュームの両方の実装に適用されます。

In the example service specification, the app container mounts an internal stage @ai_models_stage:

spec:
  containers:
  - name: app
    image: <image1-name>
    volumeMounts:
    - name: ai-models
      mountPath: /opt/ai-model
  volumes:
  - name: ai-models
    source: stage
    stageConfig:
      name: "@ai_models_stage"
Copy

アクセス制御の要件

サービス所有者ロールは、サービスを作成するために使用されるロールです。また、サービスがSnowflakeとやりとりする際に使用するロールでもあります。所有者ロールは、マウントされたステージへのアクセス向けとしてコンテナーに付与される権限を決定します。サービスの所有者ロールには、ステージ上で READ 権限が必要です。

たとえば、ステージでサービスロールが WRITE 権限を持っていない場合、そのステージのマウントは読み取り専用になります。つまり、コンテナーができるのはステージからファイルを読み取ることのみです。所有者ロールが読み取りと書き込みの両方をサポートするステージ・マウントには、ステージ上で WRITE 権限が必要です。

About the deprecated implementation

The deprecated stage-volume implementation uses a shared cache for reads and writes. Although this works well for some scenarios, you can't control whether data is read from the cache or directly from the stage, which might not be suitable for all applications. Additionally, when you use the cache for reads and writes, this can introduce performance overhead.

Migrating code from the deprecated implementation

The newer implementation replaces the deprecated implementation, with the following behavioral changes:

  • The newer stage-volume implementation streams file contents directly to and from cloud storage, ensuring that you always get the latest contents. This provides predictable behavior and significantly faster throughput. The deprecated stage-volume implementation caches chunks of file data, making it difficult to know if you are reading the latest data.

  • キャッシュの削除により、新しい実装ではランダム読み取りのパフォーマンスが低下する可能性があります。ただし、ローカルディスクキャッシュがないと、ボリューム間の一貫性が向上します。ファイルの変更は、ファイルが閉じられると、ローカルディスクのバッファーなしでバックステージに直接書き込まれます。

  • 読み取りは常に最新のデータを返すため、この構成はサービス間でデータを共有するのに適しています。

  • Random writes or file appends aren't supported. Attempting these operations results in an error. Snowflake recommends that you use block storage volumes for these workloads.

Specify a Snowflake stage volume in a service specification (deprecated)

To create a service where service containers use Snowflake stage volume, specify the required settings in the service specification as shown in the following steps:

  1. To specify the stage volume, use the spec.volumes field as shown in the following example:

    volumes:
    - name: <name>
      source: <stage_name>
    
    Copy

    以下のフィールドは必須です。

    • name: The name of the volume.

    • source: The Snowflake internal stage or folder on the stage to mount; for example @my_stage, @my_stage/folder. Quotes must surround this value.

  2. To describe where to mount the stage volume in your application containers, use the spec.containers.volumeMounts field, as shown in the following example:

    volumeMounts:
    - name: <name>
      mountPath: <absolute_directory_path>
    
    Copy

    このフィールドに入力する情報は、サポートされるすべてのストレージボリュームタイプで一貫しており、ステージボリュームの両方の実装に適用されます。

Example (deprecated)

In the example service specification, the app container mounts an internal stage @model_stage by using the deprecated stage volume implementations:

spec:
  containers:
  - name: app
    image: <image1-name>
    volumeMounts:
    - name: models-legacy
      mountPath: /opt/model-legacy
  volumes:
  - name: models-legacy
    source: "@model_stage"
Copy

The volumeMounts field specifies where inside the container to mount the stage volume. This specification remains the same for both the stage volume implementations.

ステージボリュームを使用する際のガイドライン

This section provides you with guidelines to follow when you implement application code in which a container uses a Snowflake stage as storage volume.

ステージ・ボリュームの両方の実装の共通ガイドライン

  • ステージ・マウントはシーケンシャルな読み書きに最適化されています。

  • ステージ・マウントのI/O操作は、コンテナーのファイル・システムやブロック・ストレージ・ボリュームのI/O操作よりも待機時間が高くなる可能性があります。I/O操作が成功したかどうかを確認するために、常にステータスコードをチェックすべきです。

  • ステージは、アップロードファイルの更新を非同期にマウントします。ステージ・マウント上のファイルへの変更は、ファイル・ディスクリプターが正常にクローズまたはフラッシュされた後にのみ、ステージに永続化されることが保証されます。ステージマウント上のファイルへの変更が他のコンテナーやSnowflakeから見えるようになるまで、多少の遅延が発生する場合があります。

  • マウントされたステージの各ディレクトリに含まれるファイルは、100,000個以下である必要があります。ディレクトリ内のファイル数に応じて readdir 待機時間が長くなることが予想されます。

Guidelines when using the deprecated version of the stage volume implementation

  • ステージ・マウント内で複数のファイルへの同時書き込みを避けます。

  • ステージ・マウントはネットワーク・ファイルシステムではありません。マルチクライアントの調整にステージマウントを使わないでください。

  • 同じファイルへの複数のハンドルを同時に開かないでください。オープンされたファイル・ハンドルは、読み取り操作か書き込み操作のどちらかに使用します。ファイルに書き込んだ後、そのファイルから読み込むには、読み込む前に一旦ファイルを閉じ、再度ファイルを開きます。

Guidelines when using the generally available stage volume implementation

  • 複数のステージマウント(異なるコンテナーにマウントされた同じステージボリューム)から同じファイルへの同時書き込みはサポートされていません。

  • ローカルディスクキャッシュがないため、マウント間の一貫性が向上します。ファイルの変更は、ファイルを閉じると、ローカルディスクのバッファーなしでバックステージに直接フラッシュされます。読み取りは常に最新のデータを返すため、新しいステージ・マウントはサービス間でデータを共有するのに適しています。

  • 最適なパフォーマンスのため、大きな連続したチャンクでデータを読み書きします。 一般に利用可能なステージボリュームの実装と比較して、小規模な読み取りおよび書き込みのパフォーマンスコストは、新しい実装によるパフォーマンス向上を軽減することができます。

ステージボリュームを使用する際の制限事項

このセクションでは、コンテナーがステージボリュームを使用するアプリケーションコードを実装するときに注意すべき制限について説明します。これらの限度額に関する問題が発生した場合は、アカウント担当者にお問い合わせください。

ステージボリュームの両方の実装における共通の制限

  • ステージまたはサブディレクトリをステージでマウントすることができます。例: @my_stage @my_stage/folder.例えば、 @my_stage/folder のように、1つのファイルを1つのステージにマウントすることはできません。

  • 外部ステージはサポートされていません。Snowflake内部ステージのみがサポートされています。

  • 1つのサービスにつき最大5つのステージ・ボリュームを使用できます。詳細については、spec.volumes をご参照ください。

  • コンピューティングプールノードあたり最大8ステージボリュームがサポートされています。Snowflake は、メモリ、 CPU、 GPU を管理する方法と同様に、ノードごとのステージマウントの制限を管理します。新しいサービスインスタンスを起動すると、既存のノードにリクエストされたステージマウントをサポートする容量がない場合に、Snowflakeが新しいノードを起動することがあります。

  • ステージマウントは、 POSIX 互換性のあるファイルシステムではありません。例:

    • ファイル名とディレクトリ名の変更はアトミックではありません。

    • ハードリンクはサポートされていません。

  • ファイルシステムの変更を監視する Linux カーネルサブシステムの inode notify(inotify) は、ステージマウントでは動作しません。

Limitations when using the deprecated version of the stage volume implementation

  • ステージボリュームの機能は、Snowflakeアカウントのクラウドプラットフォームによって異なります:

    • アカウントは、SNOWFLAKE_FULL および SNOWFLAKE_SSE ステージ暗号化の両方に対応する内部ステージを AWS でサポートします。詳細については、内部ステージパラメーター をご参照ください。

    • Azure 上のアカウントは現在、SNOWFLAKE_SSE 暗号化の内部ステージをサポートしています。SNOWFLAKE_SSE を実行する場合は、 :doc:` パラメーターを使用して暗号化タイプを指定します。 CREATE

    • Google Cloud上のアカウントはサポートされていません。

  • 複数のステージマウント(異なるコンテナーにマウントされた同じステージボリューム)から同じファイルへの同時書き込みはサポートされていません。

ステージ・ボリューム実装の一般公開バージョンを使用する場合の制限事項

  • ランダム書き込み、ファイル追加はサポートされていません。

  • マウントされる各ステージには、ステージごとに512 MB メモリが必要です。つまり、インスタンスのサイズに応じて使用できるステージボリュームの数に制限があることを意味します。複数のコンテナにボリュームをマウントしても、メモリ消費が増加することはありません。