Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sub-optimal way of creating replicas #135

Open
greg0ire opened this issue Sep 21, 2022 · 4 comments
Open

Sub-optimal way of creating replicas #135

greg0ire opened this issue Sep 21, 2022 · 4 comments

Comments

@greg0ire
Copy link
Contributor

greg0ire commented Sep 21, 2022

During yesterday's troubleshooting I mentioned in #134 with @julienpa and @godelized, they told me changing the primary to add replicas one by one was not the best way to proceed and had significant overhead. They hinting that one should gather the names of all replicas and perform a single set settings call on the primary. I don't have all the details, but they will comment on this issue.

@godelized
Copy link

Algolia is indeed capable of batching settings operations in certain conditions.
Changing the list of virtual replicas of an index might require an update of the primary index that could take some time, especially for a huge index. In this situation it's preferable to update the virtual replica list at once. In case of terraforming new (empty) indices, it's ok to update the replica list incrementally.

@k-yomo
Copy link
Owner

k-yomo commented Sep 27, 2022

Yeah, we used to do the batch update with the replicas field.

"replicas": {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
Optional: true,
Description: "List of replica names.",
},

However, it's difficult to support individual replica index resource for the config update while having the replicas field because it can cause conflicts and unexpected behavior.
(e.g. replica is included in the primary's replicas but the replica index resource is about to be destroyed)
Let me think about if there is a good way.

As a workaround, we can create multiple replicas from the console, and import it to terraform after.

@k-yomo
Copy link
Owner

k-yomo commented Sep 27, 2022

We may want to include replica setting in algolia_index so that we can do batch update while making it possible to update individual replica. (If we do this way, then we should deprecate algolia_virtual_index resource)
The one of the cons of this way would be that it's gonna be a little cluttered and less readable.

resource "algolia_index" "primary_index" {
  ...
  replica {
    name = "replica_index"
  }
  replica {
    ...
  }
  virtual_replica{
    ...
  }
}

@greg0ire
Copy link
Contributor Author

greg0ire commented Sep 27, 2022

Another con that would impact us a lot would be that it would make it hard to avoid repetition between replicas: the replicas we have have very similar settings, so I created a module called products-virtual-replica to account for that and I can call that module several times with the settings that vary. With the syntax above I'm not sure how to avoid that repetition.

resource "algolia_index" "primary_index" {
  ...
  replica {
    name = "replica_index"
    languages_config {
      ignore_plurals_for    = [var.language]
      remove_stop_words_for = [var.language]
      query_languages       = [var.language]

    }
  }

  replica {
    languages_config {
      ignore_plurals_for    = [var.language]
      remove_stop_words_for = [var.language]
      query_languages       = [var.language]
    }
  }
  virtual_replica{
     ...
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants