_session.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #
  2. # Copyright 2019 The FATE Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. from fate_arch.storage import StorageSessionBase, StorageEngine, EggRollStoreType
  17. from fate_arch.abc import AddressABC
  18. from fate_arch.common.address import EggRollAddress
  19. from eggroll.core.session import session_init
  20. from eggroll.roll_pair.roll_pair import RollPairContext
  21. class StorageSession(StorageSessionBase):
  22. def __init__(self, session_id, options=None):
  23. super(StorageSession, self).__init__(session_id=session_id, engine=StorageEngine.EGGROLL)
  24. self._options = options if options else {}
  25. self._options['eggroll.session.deploy.mode'] = "cluster"
  26. self._rp_session = session_init(session_id=self._session_id, options=self._options)
  27. self._rpc = RollPairContext(session=self._rp_session)
  28. self._session_id = self._rp_session.get_session_id()
  29. def table(self, name, namespace,
  30. address: AddressABC, partitions,
  31. store_type: EggRollStoreType = EggRollStoreType.ROLLPAIR_LMDB, options=None, **kwargs):
  32. if isinstance(address, EggRollAddress):
  33. from fate_arch.storage.eggroll._table import StorageTable
  34. return StorageTable(context=self._rpc, name=name, namespace=namespace, address=address,
  35. partitions=partitions, store_type=store_type, options=options)
  36. raise NotImplementedError(f"address type {type(address)} not supported with eggroll storage")
  37. def cleanup(self, name, namespace):
  38. self._rpc.cleanup(name=name, namespace=namespace)
  39. def stop(self):
  40. return self._rp_session.stop()
  41. def kill(self):
  42. return self._rp_session.kill()