Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow single process access to multiple repos. #20

Merged
merged 2 commits into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/hangar/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,10 @@ def abort_reader_txn(self, lmdbenv: lmdb.Environment) -> bool:
class EnvironmentsSingleton(type):
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(EnvironmentsSingleton, cls).__call__(*args, **kwargs)
return cls._instances[cls]
repo_path = kwargs['repo_path']
rlizzo marked this conversation as resolved.
Show resolved Hide resolved
if repo_path not in cls._instances:
cls._instances[repo_path] = super(EnvironmentsSingleton, cls).__call__(*args, **kwargs)
return cls._instances[repo_path]


class Environments(metaclass=EnvironmentsSingleton):
Expand Down
5 changes: 3 additions & 2 deletions src/hangar/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(self,
self._index_expr_factory.maketuple = False
self._schema_dtype_num = varDtypeNum
self._mode = mode
self._fs = FileHandles()
self._fs = FileHandles(repo_path=repo_pth)
self._Query = RecordQuery(self._dataenv)
self._TxnRegister = TxnRegister()

Expand Down Expand Up @@ -925,7 +925,8 @@ def init_dataset(self, name: str, shape=None, dtype=None, prototype=None, *,
STAGE_DATA_DIR = config.get('hangar.repository.stage_data_dir')
stage_dir = os.path.join(self._repo_pth, STAGE_DATA_DIR, f'hdf_{schema_hash}')
if not os.path.isdir(stage_dir):
f_handle = FileHandles().create_schema(self._repo_pth, schema_hash, prototype)
f_handle = FileHandles(repo_path=self._repo_pth).create_schema(
self._repo_pth, schema_hash, prototype)
f_handle.close()

# -------- set vals in lmdb only after schema is sure to exist --------
Expand Down
11 changes: 6 additions & 5 deletions src/hangar/hdf5_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

class FileHandlesSingleton(type):
_instances = {}

def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(FileHandlesSingleton, cls).__call__(*args, **kwargs)
return cls._instances[cls]
repo_pth = kwargs['repo_path']
if repo_pth not in cls._instances:
cls._instances[repo_pth] = super(FileHandlesSingleton, cls).__call__(*args, **kwargs)
return cls._instances[repo_pth]


'''
Expand All @@ -37,7 +37,8 @@ class FileHandles(metaclass=FileHandlesSingleton):
write to the same dataset schema.
'''

def __init__(self):
def __init__(self, repo_path):
self.repo_path = repo_path
self.rHands = {}
self.wHands = {}
self.hMaxSize = {}
Expand Down
2 changes: 1 addition & 1 deletion src/hangar/remote/hangar_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self,
auth_username: str = '', auth_password: str = ''):

self.env = envs
self.fs = FileHandles()
self.fs = FileHandles(repo_path=self.env.repo_path)
self.fs.open(self.env.repo_path, 'r')

self.header_adder_int = header_adder_interceptor(auth_username, auth_password)
Expand Down