PhoenixKit.Modules.Storage.Locations (phoenix_kit v2.41.0)

Copy Markdown View Source

Where a stored object is: its phoenix_kit_file_locations rows (V204).

An object is named by its key (FileInstance.file_name). Several instances may share one key (a cross-user copy, a tile written twice), and each instance has one location row per bucket that holds the object (phoenix_kit_file_locations_instance_bucket_index).

PhoenixKit.Modules.Storage.Manager reads, serves and checks objects through this: the buckets the rows name come first, then the other enabled buckets, and when one of those turns out to hold the object, a row is recorded for it (record/2). That fallback is what keeps files stored before every writer recorded its locations working while Storage.Workers.LocationBackfillJob has not reached them yet.

Summary

Functions

The buckets the profile of file_uuid's library marks backup: never served for that file, not even probed when its location rows name no bucket that has the object. Never raises.

The uuids of the buckets the active location rows of key name.

Whether key is known to be in no bucket: every instance stored under it was checked and found nowhere, and nothing has recorded it since. A read then answers "not found" without asking every bucket again.

Marks instances checked against every bucket, found in found_in of them. Never raises.

How many instances have not been checked against every bucket yet.

The buckets the active location rows of key name, each with the role and serve order its file's storage profile gives it (V205), best first: primaries, then replicas, then buckets the profile no longer lists, then backups; each group by serve_order. role is nil for a bucket not in the profile. Never raises: a failed lookup is [], as for bucket_uuids/1.

Records that bucket_uuid holds the object at key: an active location row for every instance stored under that key that has none on that bucket. Returns how many rows were added. Never raises.

Records every bucket in bucket_uuids for key (record/2 each) and marks the key's instances checked: what a writer calls once its instance row exists, with the buckets the manager stored the object in (a writer knows every bucket it wrote).

The instances not checked against every bucket yet: what LocationBackfillJob walks. Not "has no location row": a read that finds a key records one bucket, and a missing object never gets a row.

Functions

backup_buckets(file_uuid)

@spec backup_buckets(term()) :: [String.t()]

The buckets the profile of file_uuid's library marks backup: never served for that file, not even probed when its location rows name no bucket that has the object. Never raises.

bucket_uuids(key)

@spec bucket_uuids(String.t()) :: [String.t()]

The uuids of the buckets the active location rows of key name.

known_missing?(key)

@spec known_missing?(String.t()) :: boolean()

Whether key is known to be in no bucket: every instance stored under it was checked and found nowhere, and nothing has recorded it since. A read then answers "not found" without asking every bucket again.

mark_checked(instance_uuids, found_in)

@spec mark_checked([term()], non_neg_integer()) :: :ok

Marks instances checked against every bucket, found in found_in of them. Never raises.

missing_count()

@spec missing_count() :: non_neg_integer()

How many instances have not been checked against every bucket yet.

ranked(key, file_uuid \\ nil)

@spec ranked(String.t(), term()) :: [
  %{bucket_uuid: String.t(), role: String.t() | nil}
]

The buckets the active location rows of key name, each with the role and serve order its file's storage profile gives it (V205), best first: primaries, then replicas, then buckets the profile no longer lists, then backups; each group by serve_order. role is nil for a bucket not in the profile. Never raises: a failed lookup is [], as for bucket_uuids/1.

record(key, bucket_uuid)

@spec record(String.t(), term()) :: non_neg_integer()

Records that bucket_uuid holds the object at key: an active location row for every instance stored under that key that has none on that bucket. Returns how many rows were added. Never raises.

record_all(key, bucket_uuids)

@spec record_all(String.t(), [term()]) :: non_neg_integer()

Records every bucket in bucket_uuids for key (record/2 each) and marks the key's instances checked: what a writer calls once its instance row exists, with the buckets the manager stored the object in (a writer knows every bucket it wrote).

unchecked_query()

@spec unchecked_query() :: Ecto.Query.t()

The instances not checked against every bucket yet: what LocationBackfillJob walks. Not "has no location row": a read that finds a key records one bucket, and a missing object never gets a row.