コード例 #1
0
ファイル: navel.py プロジェクト: Cloudxtreme/Trieste
 def addRandomData (self, n):
   i= 0
   while i<n:
     key= random (1000)
     char= chr (ord ('a')+random (3))
     self._data.addValue (key, char)
     i+= 1
コード例 #2
0
ファイル: umbdata.py プロジェクト: Cloudxtreme/Trieste
 def randomKey():
     # the '=' is for when the navel holds the whole key space
     # i.e., it's the only one in the ring
     if self._min >= self._max:
         if random(2):
             n = random(0, self._max)
         else:
             n = random(self._min, consts.maxIno)
     else:
         n = random(self._min, self._max)
     return n
コード例 #3
0
ファイル: umbdata.py プロジェクト: StyXman/Trieste
 def randomKey ():
   # the '=' is for when the navel holds the whole key space
   # i.e., it's the only one in the ring
   if self._min>=self._max:
     if random (2):
       n= random (0, self._max)
     else:
       n= random (self._min, consts.maxIno)
   else:
     n= random (self._min, self._max)
   return n
コード例 #4
0
ファイル: peerlist.py プロジェクト: StyXman/Trieste
 def getRandomVice (self):
   self.acquire ()
   keyList= self._vices.keys ()
   size= len (keyList)
   index= random(size)
   peer= self._vices[keyList[index]]
   self.release ()
   return peer
コード例 #5
0
ファイル: peerlist.py プロジェクト: StyXman/Trieste
 def getRandomNavel (self):
   self.acquire ()
   keyList= self._navels.keys ()
   size= len (keyList)
   index= random(size)
   peer= self._navels[keyList[index]]
   self.release ()
   return peer
コード例 #6
0
ファイル: umbdata.py プロジェクト: Cloudxtreme/Trieste
    def findFree(self):
        def randomKey():
            # the '=' is for when the navel holds the whole key space
            # i.e., it's the only one in the ring
            if self._min >= self._max:
                if random(2):
                    n = random(0, self._max)
                else:
                    n = random(self._min, consts.maxIno)
            else:
                n = random(self._min, self._max)
            return n

        i = self._min
        j = randomKey()
        k = self._max - 1
        self.debug(2, "i: %d, j: %d, k: %d" % (i, j, k))
        while self._hash.has_key(j) and not (i == j or j == k):
            if random(2):
                k = j
                # check this property
                if i > j:
                    # WAS
                    j = ((i + j + consts.maxIno) / 2) % consts.maxIno
                else:
                    j = ((i + j) / 2) % consts.maxIno
            else:
                i = j
                if j > k:
                    # WAS
                    j = ((j + k + consts.maxIno) / 2) % consts.maxIno
                else:
                    j = ((j + k) / 2) % consts.maxIno
            self.debug(2, "i: %d, j: %d, k: %d" % (i, j, k))

        if (i == j or j == k):
            self.debug(2, 'no luck, try linearly')
            j = self._min
            while self._hash.has_key(j) and not j == self._max:
                j = (j + 1) % consts.maxIno
            if j == self._max:
                # sorry, ugly; check again
                if self._hash.has_key(j):
                    # no more no more
                    self._full = True
                    return None

        # mark as used; will need GC for asked but not used free ino's
        # WARNING: very similar to inode w/o a active vice!
        self._hash[j] = []
        return j
コード例 #7
0
ファイル: umbdata.py プロジェクト: StyXman/Trieste
  def findFree (self):
    def randomKey ():
      # the '=' is for when the navel holds the whole key space
      # i.e., it's the only one in the ring
      if self._min>=self._max:
        if random (2):
          n= random (0, self._max)
        else:
          n= random (self._min, consts.maxIno)
      else:
        n= random (self._min, self._max)
      return n

    i= self._min
    j= randomKey ()
    k= self._max-1
    self.debug (2, "i: %d, j: %d, k: %d" % (i, j, k))
    while self._hash.has_key (j) and not (i==j or j==k):
      if random (2):
        k= j
        # check this property
        if i>j:
          # WAS
          j= ((i+j+consts.maxIno)/2) % consts.maxIno
        else:
          j= ((i+j)/2) % consts.maxIno
      else:
        i= j
        if j>k:
          # WAS
          j= ((j+k+consts.maxIno)/2) % consts.maxIno
        else:
          j= ((j+k)/2) % consts.maxIno
      self.debug (2, "i: %d, j: %d, k: %d" % (i, j, k))

    if (i==j or j==k):
      self.debug (2, 'no luck, try linearly')
      j= self._min
      while self._hash.has_key (j) and not j==self._max:
        j= (j+1) % consts.maxIno
      if j==self._max:
        # sorry, ugly; check again
        if self._hash.has_key (j):
          # no more no more
          self._full= True
          return None

    # mark as used; will need GC for asked but not used free ino's
    # WARNING: very similar to inode w/o a active vice!
    self._hash[j]= []
    return j
コード例 #8
0
ファイル: navel.py プロジェクト: Cloudxtreme/Trieste
  def periodic (self):
    self.debug (1, 'periodic')
    Master.periodic (self)
    if not self._terminate:
      # we migh been asked to finish right now.
      self.stabilize ()

      if random (10)==1:
        peer= self._peers.getRandomNavel ()
        # don't gossip w/ myself!
        if not peer==self._self:
          self.gossip (peer)

      self.debug (1, "%s <-- %d --> %s" % (self._pred and self._pred.key () or None, self.key (), self._succ and self._succ.key () or None))
    else:
      self.debug (1, 'you might be pregnant...')
コード例 #9
0
ファイル: policies.py プロジェクト: Cloudxtreme/Trieste
class WeightedUniform(Random):
    """
    The policy that just selects ramdon things
  """
    def vicesForNewFile(self, master):
        """
      returns: a list of sm's where a new file will reside.
    """
        totalFreeBlocks = 0
        index = 0
        statedVices = []

        vices = master.peers().vices()
        for key in vices.keys():
            vice = vices[key]
            try:
                fsstat = vice.statfs()
                blocks = fsstat[0]
                bfree = fsstat[1]

                totalFreeBlocks += bfree

                self.debug(2, 'usage: %f' % ((1.0 * bfree) / blocks))
                statedVices.append((vice, totalFreeBlocks))
            except Exception, e:
                pass

        i = random(totalFreeBlocks)
        index = 0

        # now check where has it fell
        vice = None
        item = next(statedVices)
        if item:
            (vice, index) = item
            self.debug(
                2, 'i: %d; tfb: %d; index: %d' % (i, totalFreeBlocks, index))
        while item is not None and i > index:
            item = next(statedVices)
            if item:
                (vice, index) = item
                self.debug(
                    2,
                    'i: %d; tfb: %d; index: %d' % (i, totalFreeBlocks, index))

        self.debug(1, 'vice: %s' % vice)
        return (vice, [])
コード例 #10
0
ファイル: navel.py プロジェクト: Cloudxtreme/Trieste
  def __init__ (self, url=None, column=0, fileName=None):
    # take care of repeated keys!
    key= random (maxIno)
    Master.__init__ (self, url, key, column, fileName=fileName)
    self._succ= None
    self._pred= None

    # thread support
    # RLock's; just in case
    self._succLock= RLock ()
    self._predLock= RLock ()

    self._serverType= NavelServer
    self._chal= None

    self._self= None
    self._prevSucc= None
    self._prevPred= None
コード例 #11
0
ファイル: master.py プロジェクト: Cloudxtreme/Trieste
 def init (self):
   # do not allow fast update
   self._timeout= random (consts.periodicTimeOut)+5
   self.debug (1, "timeout: %d" % (self._timeout))