Revision 49b3fdac lib/confd/client.py

b/lib/confd/client.py
347 347
class ConfdFilterCallback:
348 348
  """Callback that calls another callback, but filters duplicate results.
349 349

  
350
  @ivar consistent: a dictionary indexed by salt; for each salt, if
351
      all responses ware identical, this will be True; this is the
352
      expected state on a healthy cluster; on inconsistent or
353
      partitioned clusters, this might be False, if we see answers
354
      with the same serial but different contents
355

  
350 356
  """
351 357
  def __init__(self, callback, logger=None):
352 358
    """Constructor for ConfdFilterCallback
......
364 370
    self._logger = logger
365 371
    # answers contains a dict of salt -> answer
366 372
    self._answers = {}
373
    self.consistent = {}
367 374

  
368 375
  def _LogFilter(self, salt, new_reply, old_reply):
369 376
    if not self._logger:
......
388 395
    # if we have no answer we have received none, before the expiration.
389 396
    if up.salt in self._answers:
390 397
      del self._answers[up.salt]
398
    if up.salt in self.consistent:
399
      del self.consistent[up.salt]
391 400

  
392 401
  def _HandleReply(self, up):
393 402
    """Handle a single confd reply, and decide whether to filter it.
......
399 408
    """
400 409
    filter_upcall = False
401 410
    salt = up.salt
411
    if salt not in self.consistent:
412
      self.consistent[salt] = True
402 413
    if salt not in self._answers:
403 414
      # first answer for a query (don't filter, and record)
404 415
      self._answers[salt] = up.server_reply
......
413 424
      # else: different content, pass up a second answer
414 425
    else:
415 426
      # older or same-version answer (duplicate or outdated, filter)
427
      if up.server_reply.answer != self._answers[salt].answer:
428
        self.consistent[salt] = False
416 429
      filter_upcall = True
417 430
      self._LogFilter(salt, up.server_reply, self._answers[salt])
418 431

  

Also available in: Unified diff