Commit cc841dca authored by Vincent Pelletier's avatar Vincent Pelletier

Factorise replicator connection checks.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2205 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent f3d2b3a3
...@@ -21,6 +21,16 @@ from neo import logging ...@@ -21,6 +21,16 @@ from neo import logging
from neo.handler import EventHandler from neo.handler import EventHandler
from neo.protocol import Packets from neo.protocol import Packets
def checkConnectionIsReplicatorConnection(func):
def decorator(self, conn, *args, **kw):
if self.app.replicator.current_connection is conn:
result = func(self, conn, *args, **kw)
else:
# Should probably raise & close connection...
result = None
return result
return decorator
class ReplicationHandler(EventHandler): class ReplicationHandler(EventHandler):
"""This class handles events for replications.""" """This class handles events for replications."""
...@@ -41,11 +51,9 @@ class ReplicationHandler(EventHandler): ...@@ -41,11 +51,9 @@ class ReplicationHandler(EventHandler):
# set the UUID on the connection # set the UUID on the connection
conn.setUUID(uuid) conn.setUUID(uuid)
@checkConnectionIsReplicatorConnection
def answerTIDs(self, conn, tid_list): def answerTIDs(self, conn, tid_list):
app = self.app app = self.app
if app.replicator.current_connection is not conn:
return
if tid_list: if tid_list:
# If I have pending TIDs, check which TIDs I don't have, and # If I have pending TIDs, check which TIDs I don't have, and
# request the data. # request the data.
...@@ -68,21 +76,17 @@ class ReplicationHandler(EventHandler): ...@@ -68,21 +76,17 @@ class ReplicationHandler(EventHandler):
conn.ask(p, timeout=300) conn.ask(p, timeout=300)
app.replicator.oid_offset = 0 app.replicator.oid_offset = 0
@checkConnectionIsReplicatorConnection
def answerTransactionInformation(self, conn, tid, def answerTransactionInformation(self, conn, tid,
user, desc, ext, packed, oid_list): user, desc, ext, packed, oid_list):
app = self.app app = self.app
if app.replicator.current_connection is not conn:
return
# Directly store the transaction. # Directly store the transaction.
app.dm.storeTransaction(tid, (), (oid_list, user, desc, ext, packed), app.dm.storeTransaction(tid, (), (oid_list, user, desc, ext, packed),
False) False)
@checkConnectionIsReplicatorConnection
def answerOIDs(self, conn, oid_list): def answerOIDs(self, conn, oid_list):
app = self.app app = self.app
if app.replicator.current_connection is not conn:
return
if oid_list: if oid_list:
# Pick one up, and ask the history. # Pick one up, and ask the history.
oid = oid_list.pop() oid = oid_list.pop()
...@@ -94,11 +98,9 @@ class ReplicationHandler(EventHandler): ...@@ -94,11 +98,9 @@ class ReplicationHandler(EventHandler):
# finished. # finished.
app.replicator.replication_done = True app.replicator.replication_done = True
@checkConnectionIsReplicatorConnection
def answerObjectHistory(self, conn, oid, history_list): def answerObjectHistory(self, conn, oid, history_list):
app = self.app app = self.app
if app.replicator.current_connection is not conn:
return
if history_list: if history_list:
# Check if I have objects, request those which I don't have. # Check if I have objects, request those which I don't have.
serial_list = [t[0] for t in history_list] serial_list = [t[0] for t in history_list]
...@@ -128,12 +130,10 @@ class ReplicationHandler(EventHandler): ...@@ -128,12 +130,10 @@ class ReplicationHandler(EventHandler):
app.replicator.current_partition.getRID()) app.replicator.current_partition.getRID())
conn.ask(p, timeout=300) conn.ask(p, timeout=300)
@checkConnectionIsReplicatorConnection
def answerObject(self, conn, oid, serial_start, def answerObject(self, conn, oid, serial_start,
serial_end, compression, checksum, data, data_serial): serial_end, compression, checksum, data, data_serial):
app = self.app app = self.app
if app.replicator.current_connection is not conn:
return
# Directly store the transaction. # Directly store the transaction.
obj = (oid, compression, checksum, data, data_serial) obj = (oid, compression, checksum, data, data_serial)
app.dm.storeTransaction(serial_start, [obj], None, False) app.dm.storeTransaction(serial_start, [obj], None, False)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment