Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing Sync. #13

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions poc-07.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def update(self, message):
than messages. For now we are putting messages."""

#TODO: we have to later think of its implementation and format.
super(StateDriver, self).update(message)
super(StateDriver, self).update(deepcopy(message))


#TODO: fake real drivers.
Expand Down Expand Up @@ -162,9 +162,13 @@ def update(self, theirMessages):
for theirMessage in theirMessages:
try:
self.driver.update(theirMessage)
self.theirState.update(theirMessage) # Would be async.
except:
raise # Would handle or warn.

#Their state must be populated with the content of our driver.
#FIXME:Later on, update their state with metadata of our Driver messages.
for message in self.driver.search():
self.theirState.update(message)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would harm perfs. We are making a new full read of the other side (twice since from each side)!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicolas if I will go asymptotic way the reading once will have complexity O(n) and reading it twice O(2n) = O(n). So perfomance won't be affected that much. The previous way of upating stage had bug.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trust me. Reading each driver twice will definelty harm perfs.
It's not about algo complexity. It's about I/O.


#FIXME: we are lying around. The real search() should return full
# messages or have parameter to set what we request exactly.
Expand All @@ -178,10 +182,9 @@ def getChanges(self):

#TODO: we have to read both states to know what to sync. The current
# implementation is wrong.
for message in self.theirState.search():
if message not in stateMessages:
stateMessages.append(deepcopy(message))

#FIXED: I think there is no point of comparing this.
#As after the sync the two states must be identical.

for message in messages:
if message not in stateMessages:
# Missing in the other side.
Expand Down Expand Up @@ -264,10 +267,22 @@ def run(self):
engine.run()
engine.debug("# Run of PASS 1: done.")
m2r.markImportant()
engine.debug("# After Run1 but before Run 2")

print("\n# PASS 2")
engine.run()
engine.debug("# Run of PASS 2: done.")

#TODO: PASS 3 with changed messages.
#TODO: PASS 3 without update.
print ("\n# Pass 3")
engine.run()
engine.debug("# Run of PASS 3: done.")

#PASS 4 with update
print ("\n# Pass 4")
m1l.markRead()
engine.run()
engine.debug("# Run of PASS 4: done.")

#PASS 5 without any update
engine.run()
engine.debug("# Run of PASS 5: done.")