Periodically force queries of servers that are refreshing themselves, to

keep metadata up to date.

Subversion-branch: /master
Subversion-revision: 2205
This commit is contained in:
Simon Howard 2010-12-10 18:21:50 +00:00
parent 073864be95
commit 5432fd9b0f

View file

@ -36,6 +36,10 @@ LOG_FILE = "chocolate-master.log"
SERVER_TIMEOUT = 2 * 60 * 60 # 2 hours
# How long is metadata valid before we force another query to refresh it?
METADATA_REFRESH_TIME = 6 * 60 * 60 # 6 hours
# Maximum length of a query response.
MAX_RESPONSE_LEN = 1000
@ -87,8 +91,12 @@ class Server:
self.add_time = time()
def set_metadata(self, metadata):
self.metadata_time = time()
self.metadata = metadata
def metadata_age(self):
return time() - self.metadata_time
def timed_out(self):
return time() - self.add_time > SERVER_TIMEOUT
@ -221,6 +229,13 @@ class MasterServer:
server = Server(addr)
self.servers[addr] = server
# If the metadata for this server is old, un-verify it
# to force a query to refresh it.
if server.verified and server.metadata_age() > METADATA_REFRESH_TIME:
self.log_output(addr, "Metadata is old, forcing query")
server.verified = False
# If the server has already been verified, we can send a
# reply immediately. Otherwise, query the server via a
# different socket first to verify it.