"""Operational policies independent of the wire format."""fromdataclassesimportdataclass,fieldfromenumimportStrEnumfromsignal_dataset._internal.constantsimport(DEFAULT_ARRAY_RECORD_OPTIONS,DEFAULT_MAX_OPEN_SHARDS,)fromsignal_dataset._internal.policyimportControlPolicy,ResourcePolicyfromsignal_dataset._internal.retryimportRetryPolicy__all__=["AccessMode","AnnotationOptions","CachePolicy","PublicationOptions","RetryPolicy","StorageOptions",]
[docs]@dataclass(frozen=True,slots=True)classStorageOptions:writer_options:str=DEFAULT_ARRAY_RECORD_OPTIONSreader_options:str="readahead_buffer_size:0,max_parallelism:0"file_reader_buffer_size:int|None=Noneresources:ResourcePolicy=field(default_factory=ResourcePolicy)control:ControlPolicy=field(default_factory=ControlPolicy)manifest_cache_pages:int=16records_per_read_batch:int=1_024max_records_per_shard:int|None=Nonemax_encoded_shard_bytes:int|None=None#: How many staged shards to keep open at once, on a backend that stages.#:#: Only `s3://` stages; local and `gs://` hand the URI straight to the#: reader. A staging miss re-downloads a whole object, so under an access#: order that alternates between more shards than are retained, every read#: costs a full shard. One is the right answer for a single sequential#: scan and the wrong one for a shuffled reader, which is the shape a#: training loop usually has -- so this is a choice the caller has to be#: able to make, and until now could not.max_open_shards:int=DEFAULT_MAX_OPEN_SHARDSdef__post_init__(self)->None:size=self.file_reader_buffer_sizeifsizeisnotNoneand(isinstance(size,bool)ornotisinstance(size,int)orsize<0):raiseValueError("file_reader_buffer_size must be a nonnegative integer or None")if(isinstance(self.manifest_cache_pages,bool)ornotisinstance(self.manifest_cache_pages,int)orself.manifest_cache_pages<1):raiseValueError("manifest_cache_pages must be positive")if(isinstance(self.records_per_read_batch,bool)ornotisinstance(self.records_per_read_batch,int)orself.records_per_read_batch<1):raiseValueError("records_per_read_batch must be positive")ifself.max_records_per_shardisnotNoneand(isinstance(self.max_records_per_shard,bool)ornotisinstance(self.max_records_per_shard,int)orself.max_records_per_shard<1):raiseValueError("max_records_per_shard must be positive")if(isinstance(self.max_open_shards,bool)ornotisinstance(self.max_open_shards,int)orself.max_open_shards<1):raiseValueError("max_open_shards must be positive")ifself.max_encoded_shard_bytesisnotNoneand(isinstance(self.max_encoded_shard_bytes,bool)ornotisinstance(self.max_encoded_shard_bytes,int)orself.max_encoded_shard_bytes<1):raiseValueError("max_encoded_shard_bytes must be positive")
[docs]@dataclass(frozen=True,slots=True)classPublicationOptions:"""How a publication is laid out, and how hard it checks its inputs. `verify_record_counts` re-opens every shard a producer reported and counts its records. That is exact, and on object storage it costs a full read of everything being published -- for a terabyte dataset, a terabyte downloaded, twice, for data and metadata. It is off by default. The byte size of each shard is always compared, which costs one HEAD and catches the failure that actually happens: a truncated or half-written upload. """shards_per_manifest:int=10_000verify_record_counts:bool=Falsedef__post_init__(self)->None:if(isinstance(self.shards_per_manifest,bool)ornotisinstance(self.shards_per_manifest,int)orself.shards_per_manifest<1):raiseValueError("shards_per_manifest must be a positive integer")
[docs]@dataclass(frozen=True,slots=True)classAnnotationOptions:records_per_shard:int=10_000catalog_retry_limit:int=8publication_id:str|None=None#: See PublicationOptions.verify_record_counts; same trade, same default.verify_record_counts:bool=Falsedef__post_init__(self)->None:fornamein("records_per_shard","catalog_retry_limit"):value=getattr(self,name)ifisinstance(value,bool)ornotisinstance(value,int)orvalue<1:raiseValueError(f"{name} must be a positive integer")ifself.publication_idisnotNoneandnotself.publication_id:raiseValueError("publication_id must be non-empty or None")