class_docstr: Legacy protocol, store all experiments and trials inside the Database()
  
  Parameters
  ----------
  config: Dict
      configuration definition passed from experiment_builder
      to storage factory to legacy constructor.
      See `~orion.io.database.Database` for more details
  setup: bool
      Setup the database (create indexes)
class_docstr_tok: ["Legacy","protocol",",","store","all","experiments","and","trials","inside","the","Database","(",")","Parameters","--","--","--","--","--","config",":","Dict","configuration","definition","passed","from","experiment_builder","to","storage","factory","to","legacy","constructor",".","See","`","~orion.io.database.Database","`","for","more","details","setup",":","bool","Setup","the","database","(","create","indexes",")"]
docstr: See :func:`orion.storage.base.BaseStorageProtocol.reserve_trial`
docstr_tok: ["See",":","func",":","`","orion.storage.base.BaseStorageProtocol.reserve_trial","`"]
code: def reserve_trial(self, experiment):
      """See :func:`orion.storage.base.BaseStorageProtocol.reserve_trial`"""
      query = dict(
          experiment=experiment._id,
          status={"$in": ["interrupted", "new", "suspended"]},
      )
      # read and write works on a single document
      now = datetime.datetime.utcnow()
      trial = self._db.read_and_write(
          "trials",
          query=query,
          data=dict(status="reserved", start_time=now, heartbeat=now),
      )
  
      if trial is None:
          return None
  
      return Trial(**trial)
  
imports: import contextlib
  import datetime
  import logging
  import pickle
  import time
  import orion.core
  import orion.core.utils.backward
  from orion.core.io.database import Database, OutdatedDatabaseError, database_factory
  from orion.core.worker.trial import Trial, validate_status
  from orion.storage.base import BaseStorageProtocol, FailedUpdate, LockAcquisitionTimeout, LockedAlgorithmState, get_trial_uid_and_exp, get_uid
label_desc: Use image node_id 22 for calling the Legacy obj's underlying member method code with example usage: obj.reserve_trial(experiment) and returns: Trial, None