I have a working Flask application, and am working through the desired production configuration and architecture design.
The desired design.
2 WAMP Servers 1 Apache reverse proxy load balancer.
Users will hit the load balancer, and be served by one of the WAMP servers.
The 2 MYSQL Databases will be congiured in Master - Slave Data Replication.
Data provider will only update the Master, and the web server will also only update the master, fetching all queries from Slave.
So even though the load balancer may connect you to the web server on the master, it is still reading from slave.
My Issue is, if a new record is created to the database, Flask - Admin will only update the model if the user is viewing the admin page on the master.
The master and slave databases both show proper data. but master and slave admin models do not. In order to get the admin model to update, I am forced to reboot the slave server.
Thanks for reading. Please let me know if there are any required information and I will pass it along.
I am using Windows WAMP Server 2.5. Python 3.4. Flask Project
Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
<Proxy balancer://mycluster>
BalancerMember http://100.100.100.1:8080 route=route1
BalancerMember http://100.100.100.2:8080 route=route2
ProxySet stickysession=ROUTEID
</Proxy>
ProxyPass / balancer://mycluster/
<Location /balancer-manager>
SetHandler balancer-manager
Order Deny,Allow
Allow from all
</Location>
class RoutingSession(Session):
def get_bind(self, mapper=None, clause=None):
if self._flushing:
return engines['edit_leader']
else:
return engines['edit_follower']
session_factory = sessionmaker(class_=RoutingSession, autocommit=False)
Session = scoped_session(session_factory)
@contextmanager
def session_scope():
"""Provide a transactional scope around a series of operations."""
session = Session()
try:
yield session
session.commit()
except:
session.rollback()
raise
finally:
Session.remove()
with session_scope() as temp_session:
admin.add_view(my_admin.ComputerAdmin(Computer, temp_session))
admin.add_view(my_admin.DriveAdmin(Drive, temp_session))
admin.add_view(my_admin.RoomAdmin(Room, temp_session))
admin.add_view(my_admin.WorkgroupAdmin(Workgroup, temp_session))
admin.add_view(my_admin.UserAdmin(User, temp_session))
admin.add_view(my_admin.PhoneCategoryAdmin(PhoneCategory, temp_session))
admin.add_view(my_admin.RoomExtensionAdmin(RoomPhoneNumber, temp_session))
admin.add_view(my_admin.PhoneNumberAdmin(PhoneNumber, temp_session))
admin.add_view(my_admin.RoomIntercomAdmin(RoomIntercomNumber, temp_session))
admin.add_view(my_admin.StationTypeAdmin(StationType, temp_session))
The problem was an isolation level
being set to default of repeatable read
setting it to read commited
did the trick