Read the code carefully
class Node:
def __init__(self, name, mode):
self.name = name
self.mode = mode # "CP" or "AP"
self.partitioned = False
self.state = {}
def write(self, key, value):
if self.partitioned and self.mode == "CP":
return "refuse" # would risk inconsistency
self.state[key] = value
return "ok"
def read(self, key):
if self.partitioned and self.mode == "CP":
return "refuse" # better to fail than serve stale
return self.state.get(key, "missing")
trading = Node("trading", mode="CP")
feed = Node("feed", mode="AP")
trading.partitioned = True
feed.partitioned = True
trading.state = {"price": 100}
feed.state = {"feed_count": 42}
print(trading.write("price", 101)) # CP partitioned → refuse
print(feed.write("feed_count", 43)) # AP partitioned → ok (local)
print(trading.read("price")) # CP partitioned read → refuse
print(feed.read("feed_count")) # AP partitioned read → 43 (fresh local)
# What does this print? Type your prediction.What will the program print? Write here: