Browse Source

add db replication support in backend and load-balancing in backend

master
anonstudent 7 months ago
parent
commit
60695eb909
  1. 5
      backend-fcgiwrap/cgi-bin/add-client.py
  2. 6
      backend-fcgiwrap/cgi-bin/change-client-money.py
  3. 16
      backend-fcgiwrap/cgi-bin/connect_to_db.py
  4. 5
      backend-fcgiwrap/cgi-bin/delete-client.py
  5. 4
      backend-fcgiwrap/cgi-bin/show-all.py

5
backend-fcgiwrap/cgi-bin/add-client.py

@ -1,11 +1,12 @@ @@ -1,11 +1,12 @@
#!/usr/bin/python3
import tarantool
import cgi
from connect_to_db import tarantool_connect
s = tarantool_connect()
form = cgi.FieldStorage()
connection = tarantool.connect("db-tarantool", 3301)
s = connection.space('maindb')
print("Content-Type: text/html; charset=utf-8") # HTML is following

6
backend-fcgiwrap/cgi-bin/change-client-money.py

@ -1,11 +1,11 @@ @@ -1,11 +1,11 @@
#!/usr/bin/python3
import tarantool
import cgi
from connect_to_db import tarantool_connect
form = cgi.FieldStorage()
s = tarantool_connect()
connection = tarantool.connect("db-tarantool", 3301)
s = connection.space('maindb')
form = cgi.FieldStorage()
print("Content-Type: text/html; charset=utf-8") # HTML is following

16
backend-fcgiwrap/cgi-bin/connect_to_db.py

@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
#!/usr/bin/python3
import tarantool
import random
def tarantool_connect():
availble_db = ["db-tarantool", "db-tarantool2"]
random.shuffle(availble_db) # for load balancing
try:
connection = tarantool.connect(availble_db[0], 3301)
return connection.space('maindb')
except:
connection = tarantool.connect(availble_db[1], 3301)
return connection.space('maindb')

5
backend-fcgiwrap/cgi-bin/delete-client.py

@ -1,11 +1,12 @@ @@ -1,11 +1,12 @@
#!/usr/bin/python3
import tarantool
import cgi
from connect_to_db import tarantool_connect
s = tarantool_connect()
form = cgi.FieldStorage()
connection = tarantool.connect("db-tarantool", 3301)
s = connection.space('maindb')
print("Content-Type: text/html; charset=utf-8") # HTML is following

4
backend-fcgiwrap/cgi-bin/show-all.py

@ -1,8 +1,8 @@ @@ -1,8 +1,8 @@
#!/usr/bin/python3
import tarantool
from connect_to_db import tarantool_connect
connection = tarantool.connect("db-tarantool", 3301)
s = connection.space('maindb')
s = tarantool_connect()
print("Content-Type: text/html; charset=utf-8") # HTML is following

Loading…
Cancel
Save