Διάβασε τον κώδικα προσεκτικά
class Replica:
def __init__(self):
self.state = {}
def replicate(self, primary_state):
# Sync up to the primary's current state.
self.state = dict(primary_state)
class Primary:
def __init__(self):
self.state = {"profile": "Alice"} # initial
primary = Primary()
replica = Replica()
replica.replicate(primary.state) # initial sync
# User updates profile on the primary.
primary.state["profile"] = "Alicia"
# Read 1 — went to the lagging replica BEFORE it caught up.
print(replica.state.get("profile"))
# Read 2 — routed to primary (read-your-own-writes pattern).
print(primary.state.get("profile"))
# Replica eventually catches up.
replica.replicate(primary.state)
# Read 3 — same replica, now post-sync.
print(replica.state.get("profile"))
# What does this print? Type your prediction.Τι θα εμφανίσει το πρόγραμμα; Γράψε εδώ: