IndexSet default setting
An index set can be marked as `default` in `IndexSetConfig`. This cannot be changed by the user at the moment, but should be. We have to ensure that only one index set is the default!
Since we are using MongoDB, there are no cross-document atomic operations or transactions so we have to take care of that ourselves.
## Idea 1: Use a timestamp
We are currently using a boolean `default` field in the `index_sets` database collection to mark the default index set. Because of the lack of transactions this is not really safe to update for several documents at once. (set `true` on the new default, set `false` on all others)
As an alternative to the boolean flag we could use a timestamp field like `default_since` or similar that will be set to the current time when a "set default index set" request comes in. To determine the default we have to load the index set with the newest timestamp. By using a unique index on the timestamp field, we would avoid duplicate timestamps.
## Idea 2: Coordinate on master
Another idea was to publish an event on the cluster event bus to set the default index set. All nodes subscribe to the event but only the master node will actually handle it. Since only one node **should** be master and the events are not processed in parallel, this should avoid interleaving writes to the index sets collection. It doesn't guarantee any order though.
This is more complicated than the timestamp idea beacuse it involves the cluster event bus and needs an event handler. It also makes the request to set the default index set async so we have to deal with that in the UI. It also fails when there is more than one active master node.
## Other Ideas?
Please let me know if you have different, better ideas. Let's discuss!
Can we simply use a `ClusterConfig` (or similar) setting that contains the id (or name or both) of the current default? That way there's always exactly 0 or 1 default index sets.
@bernd Idea 3:
Store the default index set ID in cluster config. This would make queries for that more expensive, but in how many places do we really have to check if an index set is the default index set?
@joschi @kroepke Good point! That seems to be the simplest idea, I guess. Thank you!
@joschi Right now we only need it for display purposes in the UI and when importing content packs.
This is ready for review now.
I added a migration to create a `DefaultIndexSetConfig` cluster config object and delete the `default` field from the index set documents.
Rebased against master.