tinode / chat

Instant messaging platform. Backend in Go. Clients: Swift iOS, Java Android, JS webapp, scriptable command line; chatbots
GNU General Public License v3.0
12.08k stars 1.88k forks source link

Is it possible to make mongodb replica_set configurable? #330

Closed beanhacker closed 4 years ago

beanhacker commented 4 years ago

Hello author, the MONOGODB I use here does not do a replication set. If I do a replication set at this time, many other services will also be forced to add the replication set option when connecting. Need to modify the system a lot. replica_set made configurable? thank!

aforge commented 4 years ago

You mean you are running a standalone mongodb deployment?

or-else commented 4 years ago

Hey @Googlom,

Please take a look at this request. Making replica set optional looks like a reasonable idea to me.

Googlom commented 4 years ago

Transactions don't work without replicaset configured on MongoDB. I'll have to remove transaction support to be able to run on standalone MongoDB instance. Or duplicate query logic to support both transaction and non-transaction queries - then it'll be possible to do replica set optional.

or-else commented 4 years ago

I think it's a tradeoff which the user should be able to make. We just need to make it clear to the user. Maybe even write it to the log when initalizing the adapter.

It's a actually quite easy to make transactions optional. Define something like

func (a *adapter) maybeStartTransaction(sess mdb.Session) error {
  if a.useTransactions {
    return sess.StartTransaction()
  }
  return nil
}

func (a *adapter) maybeCommitTransaction(sess mdb.Session) error {
  ... same as above but with sess.CommitTransaction ...
}

And then use these calls everywhere instead of sess.StartTransaction/sess.CommitTransaction.

or-else commented 4 years ago

@Googlom would you make the changes or should I?

Googlom commented 4 years ago

I will make the changes tomorrow

or-else commented 4 years ago

Thanks!

or-else commented 4 years ago

Done in #333