yorkie-team / yorkie

Yorkie is a document store for collaborative applications.
https://yorkie.dev
Apache License 2.0
788 stars 146 forks source link

Handle housekeeping with sharded cluster #505

Open hackerwins opened 1 year ago

hackerwins commented 1 year ago

What would you like to be added:

We recently introduced cluster mode based on the shard key. This shard key is used to assign APIs requested by clients to servers in the cluster based on project or document.

Housekeeping operations should also apply this sharded cluster structure. We can think of two options:

  1. Only the master server executes housekeeping in the cluster
  2. Split housekeeping tasks per project and execute them on servers mapped by project

Why is this needed:

krapie commented 1 year ago

The options that you've suggested look good to me. I have listed some of the considerations for these options below.

  1. Only the master server executes housekeeping in the cluster.
  2. Split housekeeping tasks per project and execute them on servers mapped by project.

These options seem like opposite options to me, but I think they both can be implemented by using etcd. I'll keep searching for more information on these options.

krapie commented 1 year ago

I have implemented leader election with K8s lease object, but this will make yorkie k8s dependent.

Therefore, I will change this implementation with MongoDB, where yorkie already have dependency on.

To be specific about the implementation, I will use the way of nodes try to update on the same document(same _id) by checking lease_expire_at field.

Also, to ensure that only one node becomes the leader when a lease has expired, I will use TTL indexes to remove document on expiry, preventing nodes to update the same document simultaneously.

krapie commented 4 months ago

@hackerwins Are we proceeding this issue?

hackerwins commented 4 months ago

No, it's still on hold. During housekeeping, it seems that Client Deactivation competing across nodes doesn't cause significant issues, so we haven't proceeded with this.