def post_args(self, last_known_generation, last_known_trans_id=None, sync_id=None, ensure=False): """ Handle the initial arguments for the sync POST request from client. :param last_known_generation: The last server replica generation the client knows about. :type last_known_generation: int :param last_known_trans_id: The last server replica transaction_id the client knows about. :type last_known_trans_id: str :param sync_id: The id of the current sync session. :type sync_id: str :param ensure: Whether the server replica should be created if it does not already exist. :type ensure: bool """ # create or open the database cache = get_cache_for('db-' + sync_id + self.dbname, expire=120) if ensure: db, self.replica_uid = self.state.ensure_database(self.dbname) else: db = self.state.open_database(self.dbname) db.init_caching(cache) # validate the information the client has about server replica db.validate_gen_and_trans_id( last_known_generation, last_known_trans_id) # get a sync exchange object self.sync_exch = self.sync_exchange_class( db, self.source_replica_uid, last_known_generation, sync_id) self._sync_id = sync_id self._staging = [] self._staging_size = 0
def __init__(self, source_replica_uid, sync_id): """ Initialize the sync state object. :param sync_id: The id of current sync :type sync_id: str :param source_replica_uid: The source replica uid :type source_replica_uid: str """ self._source_replica_uid = source_replica_uid self._sync_id = sync_id caching_key = source_replica_uid + sync_id self._storage = caching.get_cache_for(caching_key)