identifier.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:raw-data-repository 作者: all-of-us 项目源码 文件源码
def get_id():
  """Reserve a globally unique ID.

  The system will create a random number between MIN_ID and MAX_ID.  It then
  attempts to create a record in datastore reserving that ID.  If the attempt
  succeeds, the ID is handed out.  If it fails, it tries again.
  """
  while True:
    try:
      candidate = random.randint(MIN_ID, MAX_ID)
      # _check_and_create_record will create the record without using a
      # transaction.  Then _reserve_candidate will flip the reserved flag within
      # a transaction.  Unfortunately, it doesn't appear that transactional
      # gurantees don't extend to two threads creating the same entity at the
      # same time.
      if _reserve_candidate(candidate):
        return candidate
    except TransactionFailedError:
      pass
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号