proxystore.connectors.multi¶
Multi-connector implementation.
ConnectorPolicyConfig
module-attribute
¶
Type of the configuration for a connector and policy pair.
Element zero is the fully qualified path of the connector type, element one is the connector's configuration dictionary, and element two is the policy in dictionary form.
Policy
dataclass
¶
Policy(
priority: int = 0,
host_pattern: Iterable[str] | str | None = None,
min_size_bytes: int = 0,
max_size_bytes: int = sys.maxsize,
subset_tags: list[str] = list(),
superset_tags: list[str] = list(),
)
Policy that allows validating a set of constraints.
Attributes:
-
priority
(int
) –Priority for breaking ties between policies (higher is preferred).
-
host_pattern
(Iterable[str] | str | None
) –Pattern or iterable of patterns of valid hostnames. The hostname returned by
hostname()
is matched againsthost_pattern
usingre.fullmatch()
. Ifhost_pattern
is an iterable, at least one of the patterns must match the hostname. -
min_size_bytes
(int
) –Minimum size in bytes allowed.
-
max_size_bytes
(int
) –Maximum size in bytes allowed.
-
subset_tags
(list[str]
) –Subset tags. See
is_valid()
for more details. -
superset_tags
(list[str]
) –Superset tags. See
is_valid()
for more details.
is_valid
¶
is_valid(
*,
size_bytes: int | None = None,
subset_tags: Iterable[str] | None = None,
superset_tags: Iterable[str] | None = None
) -> bool
Check if set of constraints is valid for this policy.
Note
All arguments are optional keyword arguments that default to
None
. If left as the default, that constraint will not be
checked against the policy.
Parameters:
-
size_bytes
(int | None
, default:None
) –Object size in bytes.
-
subset_tags
(Iterable[str] | None
, default:None
) –Set of tags that must be a subset of the Policy's
subset_tags
to be valid. -
superset_tags
(Iterable[str] | None
, default:None
) –Set of tags that must be a superset of the Policy's
superset_tags
to be valid.
Returns:
-
bool
–If the provided constraints are valid for the policy.
Source code in proxystore/connectors/multi.py
is_valid_on_host
¶
is_valid_on_host() -> bool
Check if this policy is valid on the current host.
Source code in proxystore/connectors/multi.py
as_dict
¶
as_dict() -> PolicyDict
Convert the Policy to a JSON compatible dict.
Example
Source code in proxystore/connectors/multi.py
MultiConnectorError
¶
Bases: Exception
Exceptions raised by the MultiConnector
.
MultiKey
¶
Bases: NamedTuple
Key to objects in MultiConnector
.
Attributes:
-
connector_name
(str
) –Name of connector that the associated object is stored in.
-
connector_key
(Any
) –Key associated with the object.
MultiConnector
¶
MultiConnector(
connectors: dict[str, tuple[Connector[Any], Policy]],
dormant_connectors: (
dict[str, ConnectorPolicyConfig] | None
) = None,
)
Policy based manager for a Connector
collection.
Example
from proxystore.connectors.file import FileConnector
from proxystore.connectors.multi import Policy
from proxystore.connectors.multi import MultiConnector
from proxystore.connectors.redis import RedisConnector
file_connector = FileConnector(...)
redis_connector = RedisConnector(...)
connectors = {
'small': (file_connector, Policy(max_size_bytes=1000000)),
'large': (redis_connector, Policy(min_size_bytes=1000000)),
}
connector = MultiConnector(connector)
Note
Methods of this class will raise
MultiConnectorError
if they are passed an invalid key where a key could be invalid
because the connector which created the key is not known by this class
instance or because the corresponding connector is dormant.
Parameters:
-
connectors
(dict[str, tuple[Connector[Any], Policy]]
) – -
dormant_connectors
(dict[str, ConnectorPolicyConfig] | None
, default:None
) –Mapping of names to tuples containing the configuration of a dormant connector. A dormant connector is a connector that is unused in this process, but could potentially be initialized and used on another process. For example, because the
host_pattern
of the policy does not match the current host. It is not recommended to create dormant connector configurations yourself. Rather, create your connectors and use thehost_pattern
of the policy to determine when a connector should be dormant.
Source code in proxystore/connectors/multi.py
close
¶
Close the connector and clean up.
Warning
This will call close()
on all managed connectors.
config
¶
config() -> dict[str, ConnectorPolicyConfig]
Get the connector configuration.
The configuration contains all the information needed to reconstruct the connector object.
Source code in proxystore/connectors/multi.py
from_config
classmethod
¶
from_config(
config: dict[str, ConnectorPolicyConfig]
) -> MultiConnector
Create a new connector instance from a configuration.
Parameters:
-
config
(dict[str, ConnectorPolicyConfig]
) –Configuration returned by
.config()
.
Source code in proxystore/connectors/multi.py
evict
¶
evict(key: MultiKey) -> None
Evict the object associated with the key.
Parameters:
-
key
(MultiKey
) –Key associated with object to evict.
exists
¶
get
¶
Get the serialized object associated with the key.
Parameters:
-
key
(MultiKey
) –Key associated with the object to retrieve.
Returns:
-
bytes | None
–Serialized object or
None
if the object does not exist.
Source code in proxystore/connectors/multi.py
get_batch
¶
Get a batch of serialized objects associated with the keys.
Parameters:
Returns:
-
list[bytes | None]
–List with same order as
keys
with the serialized objects orNone
if the corresponding key does not have an associated object.
Source code in proxystore/connectors/multi.py
put
¶
Put a serialized object in the store.
Parameters:
-
obj
(bytes
) –Serialized object to put in the store.
-
subset_tags
(Iterable[str]
, default:()
) –Iterable of tags that must be a subset of a connector's policy
subset_tags
to match. -
superset_tags
(Iterable[str]
, default:()
) –Iterable of tags that must be a superset of a connectors's policy
superset_tags
to match.
Returns:
-
MultiKey
–Key which can be used to retrieve the object.
Raises:
-
MultiConnectorError
–If no connector policy matches the arguments.
Source code in proxystore/connectors/multi.py
put_batch
¶
put_batch(
objs: Sequence[bytes],
subset_tags: Iterable[str] = (),
superset_tags: Iterable[str] = (),
) -> list[MultiKey]
Put a batch of serialized objects in the store.
Warning
This method calls
put()
individually
for each item in the batch so items in the batch can potentially
be placed in different connectors.
Parameters:
-
objs
(Sequence[bytes]
) –Sequence of serialized objects to put in the store.
-
subset_tags
(Iterable[str]
, default:()
) –Iterable of tags that must be a subset of a connector's policy
subset_tags
to match. -
superset_tags
(Iterable[str]
, default:()
) –Iterable of tags that must be a superset of a connectors's policy
superset_tags
to match.
Returns:
-
list[MultiKey]
–List of keys with the same order as
objs
which can be used to retrieve the objects.
Raises:
-
MultiConnectorError
–If no connector policy matches the arguments.