ArangoDB-Community / pyArango

Python Driver for ArangoDB with built-in validation
https://pyarango.readthedocs.io/en/latest/
Apache License 2.0
238 stars 90 forks source link

More Failover support? #164

Open decay29 opened 4 years ago

decay29 commented 4 years ago

Are there plans for failover support by supporting multiple URLs like the Go driver does? Would the interim solution to be to create multiple connections and switch between them if a 503, "Not a leader" comes back? This is the situation when the leader drops and then comes back as a follower.

Note the driver works fine when the leader goes offline and the follower becomes the leader (requests are handled properly), but when the former leader is brought back, and it becomes a follower, and that is when the 503 shows.

tariqdaouda commented 4 years ago

Thanks for posting this, it could be added in the next updates. in the meantime you could try this simple hack:

connection.arangoURL = [list of new endpoints]
connection.currentURLId = 0

Let me know if that helps

decay29 commented 4 years ago

Thanks for replying:

I get this:

No connection adapters were found for '['http://192.168.1.77:8529', 'http://192.168.1.72:8529']/_db/_system/_api/cursor'

I first construct a Connection object and then swap out the single arangoURL for the list. This is using the latest from github

tariqdaouda commented 4 years ago

Could you copy/past the code you've used?

decay29 commented 4 years ago
       self.urls = ["http://192.168.1.77:8529",
                     "http://192.168.1.72:8529"]
def selectConnection(self, index = 0):
    try:
               self.connection = Connection(arangoURL=self.urls[index],
                                        username="blah",
                                        password="blah",
                                        verify=False)
                self.db = self.connection["_system"]
                self.connection.arangoURL = [self.urls]
                self.connection.currentURLId = 0
                print("connected")
                self.currentURL = self.urls[index]

Anyway, I have it working by just juggling the connections manually by checking for a connection exception, such as whether the url for the db is the leader, whether it is reachable etc.

tariqdaouda commented 4 years ago

Thanks @decay29 I'll keep that in mind for the next version.