Beispiel #1
0
 def __init__(self, myport, service):
     self.service = service
     stores = config_lib.CONFIG["Dataserver.server_list"]
     if not stores:
         logging.error(
             "Dataserver.server_list is empty: no data servers will"
             " be available")
         raise DataMasterError("Dataserver.server_list is empty")
     self.servers = [DataServer(loc, idx) for idx, loc in enumerate(stores)]
     self.registered_count = 0
     # Load server mapping.
     self.mapping = self.service.LoadServerMapping()
     if not self.mapping:
         # Bootstrap mapping.
         # Each server information is linked to its corresponding object.
         # Updating the data server object will reflect immediately on
         # the mapping.
         for server in self.servers:
             server.SetInitialInterval(len(self.servers))
         servers_info = [server.server_info for server in self.servers]
         self.mapping = rdf_data_server.DataServerMapping(
             version=0, num_servers=len(self.servers), servers=servers_info)
         self.service.SaveServerMapping(self.mapping, create_pathing=True)
     else:
         # Check mapping and configuration matching.
         if len(self.mapping.servers) != len(self.servers):
             raise DataMasterError("Server mapping does not correspond "
                                   "to the configuration.")
         for server in self.servers:
             self._EnsureServerInMapping(server)
     # Create locks.
     self.server_lock = threading.Lock()
     # Register the master.
     self.myself = self.servers[0]
     if self.myself.Port() == myport:
         self._DoRegisterServer(self.myself)
     else:
         logging.warning(
             "First server in Dataserver.server_list is not the "
             "master. Found port '%i' but my port is '%i'. If you"
             " really are running master, you may want to specify"
             " flag --port %i.", self.myself.Port(), myport, myport)
         raise DataMasterError(
             "First server in Dataserver.server_list must be "
             "the master.")
     # Start database measuring thread.
     sleep = config_lib.CONFIG["Dataserver.stats_frequency"]
     self.periodic_thread = utils.InterruptableThread(
         target=self._PeriodicThread, sleep_time=sleep)
     self.periodic_thread.start()
     # Holds current rebalance operation.
     self.rebalance = None
     self.rebalance_pool = []
Beispiel #2
0
 def Start(self):
   self._PeriodicThread()
   self.periodic_thread = utils.InterruptableThread(
       target=self._PeriodicThread, sleep_time=10)
   self.periodic_thread.start()
   return True
Beispiel #3
0
 def __init__(self):
     # Start the flusher thread.
     self.flusher_thread = utils.InterruptableThread(
         name="DataStore flusher thread", target=self.Flush, sleep_time=0.5)
     self.flusher_thread.start()
     self.monitor_thread = None