ephraimbuddy commented on code in PR #75498: URL: https://github.com/apache/airflow/pull/75498#discussion_r4585363852
########## airflow-core/src/airflow/dag_processing/bundles/filesystem_artifact_store.py: ########## @@ -0,0 +1,519 @@ +# 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. +"""Shared-filesystem artifact store for manifest-backed Dag bundles.""" + +from __future__ import annotations + +import logging +import os +import shutil +import stat +import tempfile +import time +from contextlib import contextmanager, suppress +from fcntl import LOCK_EX, LOCK_NB, LOCK_UN, flock +from pathlib import Path +from typing import TYPE_CHECKING, Any + +from airflow.dag_processing.bundles._filesystem import ( + ensure_destination_is_within_root, + fsync_directory, + fsync_file, + fsync_tree_directories, + get_path_mode, + get_temp_snapshot_prefix, + raise_walk_error, + read_json_file, + remove_bundle_tree_forcefully, + remove_orphaned_temp_snapshots, +) +from airflow.dag_processing.bundles.artifact_store import ( + ArtifactStore, + BundleManifestNotFoundError, + BundleManifestRefDurabilityError, + PublishedSnapshot, +) +from airflow.dag_processing.bundles.manifest import ( + MANIFEST_FILE_NAME, + BundleManifestError, + BundleManifestSourceChangedError, + _raise_source_access_error, + compute_file_sha256, + serialize_bundle_version_manifest, + validate_bundle_relative_path, +) + +if TYPE_CHECKING: + from collections.abc import Callable, Iterator + +log = logging.getLogger(__name__) + +DEFAULT_PUBLICATION_LOCK_TIMEOUT = 600.0 +_LOCK_POLL_INTERVAL = 1.0 +_LOCK_WAIT_LOG_INTERVAL = 30.0 + + +class FilesystemArtifactStore(ArtifactStore): + """ + Artifact store for a ``published_root`` on a filesystem shared by publishers and Airflow. + + Layout under ``published_root``: ``refs/<bundle>/latest.json`` (release reference), + ``versions/<bundle>/<version>/`` (snapshots) and ``_locks/<bundle>.lock`` (publication lock). + ``published_root`` must already exist; the store creates only the directories below it. + Provision it as a dedicated directory inside the shared filesystem so that a missing + mount also makes it disappear. An existing root, including the mount point itself, + does not prove the filesystem is mounted; deployments must ensure mount availability. + + Publishers need write access to the publication directories and read/write access to + the lock file. For different OS users, give ``published_root`` a shared publisher group + with group write and the setgid bit: new directories use those bits from ``published_root``. + + Publishers on different hosts serialize through ``flock`` on the lock file, so the + filesystem must enforce ``flock`` across hosts: NFSv4 does, NFSv3 only with the lock + manager (lockd) running, and FUSE or object-store mounts often accept ``flock`` without + enforcing it, which leaves concurrent publishers unserialized. + + Airflow never deletes published snapshots: a Dag run can request any version it pinned, + for example on a retry, rerun or callback. Snapshots are read-only and may be owned by + the publisher's OS user, so to prune one that no run can still request, remove it as + that user after adding the owner write bit (``chmod -R u+w``). Review Comment: I will address this in a later PR. Let's keep this one thin -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
