Loading

interfaces.py

  1. #!/usr/bin/env python
  2. from zope.interface import Interface, Attribute
  3.  
  4.  
  5. class IPeerSelector(Interface):
  6.     """
  7.    I select peers for an upload, maximizing some measure of health.
  8.  
  9.    I keep track of the state of a grid relative to a file. This means
  10.    that I know about all of the peers that parts of that file could be
  11.    placed on, and about shares that have been placed on those peers.
  12.    Given this, I assign shares to peers in a way that maximizes the
  13.    file's health according to whichever definition of health I am
  14.    programmed with. I tell the uploader whether or not my assignment is
  15.    healthy. I keep track of failures during the process and update my
  16.    conclusions appropriately.
  17.    """
  18.     def add_peer_with_share(peerid, shnum):
  19.         """
  20.        Update my internal state to reflect the fact that peer peerid
  21.        holds share shnum. Called for shares that are detected before
  22.        peer selection begins.
  23.        """
  24.  
  25.     def confirm_share_allocation(peerid, shnum):
  26.         """
  27.        Confirm that an allocated peer=>share pairing has been
  28.        successfully established.
  29.        """
  30.  
  31.     def add_peers(peerids=set):
  32.         """
  33.        Update my internal state to include the peers in peerids as
  34.        potential candidates for storing a file.
  35.        """
  36.  
  37.     def mark_readonly_peer(peerid):
  38.         """
  39.        Mark the peer peerid as full. This means that any
  40.        peer-with-share relationships I know about for peerid remain
  41.        valid, but that peerid will not be assigned any new shares.
  42.        """
  43.  
  44.     def mark_bad_peer(peerid):
  45.         """
  46.        Mark the peer peerid as bad. This is typically called when an
  47.        error is encountered when communicating with a peer. I will
  48.        disregard any existing peer => share relationships associated
  49.        with peerid, and will not attempt to assign it any more shares.
  50.        """
  51.  
  52.     def get_share_placements():
  53.         """
  54.        Return the share-placement map (a dict) which maps shares to
  55.        server-ids
  56.        """
  57.  
  58.  
  59. class IPeerSelector2Factory(Interface):
  60.     """
  61.    Creates IPeerSelector2 instance.
  62.    """
  63.     def __call__(total_shares, potential_peers=(), preferred_peers=()):
  64.         """
  65.        Initialize PeerSelector instance
  66.        """
  67.  
  68.  
  69. class IPeerSelector2(Interface):
  70.     """
  71.    I select peers for an upload, maximizing some measure of health.
  72.  
  73.    I keep track of the state of a grid relative to a file.
  74.    This means that I know about all of the peers that parts of that file could
  75.    be placed on, and about shares that have been placed on those peers.
  76.    Given this, I assign shares to peers in a way that maximizes the file's
  77.    health according to whichever definition of health I am programmed with.
  78.    I also understandand relative preferences between peers for shares to be
  79.    placed on.
  80.    I tell the uploader whether or not my assignment is healthy.
  81.    I keep track of failures during the process and update my conclusions
  82.    appropriately.
  83.    """
  84.     def iterate_peers():
  85.         """
  86.        Iterates peers in order of preference.
  87.  
  88.        Yields (IServer, bool is_readonly, bool is_preferred) triples.
  89.        Preferred peers go first, then non-preferred, in order they were listed
  90.        in potential_peers sequence.
  91.        """
  92.  
  93.     # TODO: We don't need following two methods given initialization is done
  94.     # via IPeerSelector2Factory
  95.  
  96.     # def set_potential_peers(potential_peers):
  97.     #     """
  98.     #     Set the ordered list of potential peers.
  99.     #     """
  100.  
  101.     # def mark_preferred_peer(peerid):
  102.     #     """
  103.     #     Mark peerid as a preferred peer.
  104.  
  105.     #     Preferred peers get one share allocation each (up to number of shares)
  106.     #     regardless of whether those shares already exist elsewhere.
  107.     #     """
  108.  
  109.     def add_peer_with_share(peerid, shnum):
  110.         """
  111.        Update my internal state to reflect the fact that peer peerid
  112.        holds share shnum. Called for shares that are detected before
  113.        peer selection begins.
  114.        """
  115.  
  116.     def confirm_share_allocation(peerid, shnum):
  117.         """
  118.        Confirm that an allocated peer=>share pairing has been
  119.        successfully established.
  120.        """
  121.  
  122.     def mark_readonly_peer(peerid):
  123.         """
  124.        Mark the peer peerid as full. This means that any
  125.        peer-with-share relationships I know about for peerid remain
  126.        valid, but that peerid will not be assigned any new shares.
  127.        """
  128.  
  129.     def mark_bad_peer(peerid):
  130.         """
  131.        Mark the peer peerid as bad. This is typically called when an
  132.        error is encountered when communicating with a peer. I will
  133.        disregard any existing peer => share relationships associated
  134.        with peerid, and will not attempt to assign it any more shares.
  135.        """
  136.  
  137.     def get_share_placements():
  138.         """
  139.        Return the share-placement map (a dict) which maps shares to
  140.        server-ids
  141.        """
  142.  
  143.     def get_sharemap_of_preexisting_shares():
  144.         """
  145.        Return mapping of shares to sets of servers.
  146.        """

Version history

Revision # Author Created at
p2xdzehwj Anonymous 25 Jan 2020, 00:18:18 UTC Diff