View Source Snap.Cluster.Namespace (Snap v0.9.0)
Manages the namespacing of a cluster, so a cluster can be scoped to only operate on indexes with a specific prefix.
This is useful for a few purposes:
Running multiple instances of
Snap
, across completely different applications, against a single cluster. You might not want do this in production, but it's useful to only run one copy of ElasticSearch/OpenSearch locally when working on multiple applications.Running multiple environments of the same application. You don't want your tests to blow away all your development data each time they run.
Running tests in parallel, so each test process cannot see or act upon indexes that another test is operating on. This gives you the benefits of
Ecto
style sandboxing, meaning your tests can run withasync: true
even though ElasticSearch/OpenSearch doesn't support isolated transactions.
All of the convenience modules respect namespacing:
The low level HTTP API on Snap
does not.
There are two types of namespace:
Config namespace
You can namespace the entire Snap.Cluster
in the config. This is used to
achive isolation at a per application and environment level.
For example, to isolate your development and test environments, set
index_namespace: "dev"
in your dev config, and index_namespace: "test"
in
your test config.
You might even want to isolate multiple applications on a per environment
basis, with index_namespace: "app1-dev"
, for example.
Process namespace
The process namespace is used to achive isolation between parallel running tests. It's not likely you'll want to use this in other situations.
For more information, see Snap.Test
.
Summary
Functions
Given an index, adds the namespace to the supplied index for the
Snap.Cluster
in the currently running process.
Returns a specification to start this module under a supervisor.
Clears the previously set process namespace, if any.
Returns the previously set process namespace, if any.
Given an index, returns the index namespace for the Snap.Cluster
in the
currently running process.
Same as set_process_namespace/3
, but for the running process.
Set the index namespace of the provided pid
. Subsequent operations through
convenience APIs are performed on namespaced indexes.
Functions
Given an index, adds the namespace to the supplied index for the
Snap.Cluster
in the currently running process.
Returns a specification to start this module under a supervisor.
See Supervisor
.
Clears the previously set process namespace, if any.
Returns the previously set process namespace, if any.
Given an index, returns the index namespace for the Snap.Cluster
in the
currently running process.
Same as set_process_namespace/3
, but for the running process.
Set the index namespace of the provided pid
. Subsequent operations through
convenience APIs are performed on namespaced indexes.