Skip to content

Commit 3b5b075

Browse files
committed
WIP: New HTTPConn for each obj in file
1 parent f783446 commit 3b5b075

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

h5pyd/_hl/dataset.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,8 +1789,6 @@ def __getitem__(self, args):
17891789
if next_port > high_port:
17901790
next_port = low_port
17911791

1792-
# TODO: Handle the case where some or all datasets share an HTTPConn object
1793-
17941792
with ThreadPoolExecutor(max_workers=self.max_workers) as executor:
17951793
# Unwrap one-selection list
17961794
if (isinstance(args, list) and len(args) == 1):
@@ -1843,8 +1841,6 @@ def __setitem__(self, args, vals):
18431841
self.log.debug(msg)
18441842
num_endpoints = 1
18451843

1846-
# TODO: Handle the case where some or all datasets share an HTTPConn object
1847-
# For now, assume each connection is distinct
18481844
if (num_endpoints > 1):
18491845
next_port = low_port
18501846
port_len = len(ports[0])

h5pyd/_hl/group.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ def create_group(self, h5path):
214214
self.log.debug("create_group - iterate for link: {}".format(link))
215215
create_group = False
216216
req = "/groups/" + parent_uuid + "/links/" + link
217-
218217
try:
219218
rsp_json = self.GET(req)
220219
except IOError as ioe:

h5pyd/_hl/httpconn.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,29 @@ def __init__(
323323
else:
324324
self.log.error("Unknown openid provider: {}".format(provider))
325325

326+
def __copy__(self):
327+
new_conn = HttpConn(
328+
self._domain,
329+
endpoint=self._endpoint,
330+
username=self._username,
331+
password=self._password,
332+
bucket=self._bucket,
333+
api_key=self._api_key,
334+
mode=self._mode,
335+
use_session=self._use_session,
336+
use_cache=True if self._cache is not None else False,
337+
logger=self._logger,
338+
retries=self._retries,
339+
timeout=self._timeout,
340+
)
341+
342+
# Share object cache between connections on the same file/domain
343+
if self._cache is not None:
344+
new_conn._cache = self._cache
345+
new_conn._objdb = self._objdb
346+
347+
return new_conn
348+
326349
def __del__(self):
327350
if self._hsds:
328351
self.log.debug("hsds stop")

h5pyd/_hl/objectid.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
from datetime import datetime
1515
import pytz
1616
import time
17+
from .httpconn import HttpConn
1718
from .h5type import createDataType
19+
from copy import copy
1820

1921

2022
def parse_lastmodified(datestr):
@@ -34,7 +36,7 @@ def parse_lastmodified(datestr):
3436
class ObjectID:
3537

3638
"""
37-
Uniquely identifies an h5serv resource
39+
Uniquely identifies an HSDS resource
3840
"""
3941

4042
@property
@@ -103,9 +105,10 @@ def __init__(self, parent, item, objtype_code=None,
103105
self._obj_json = item
104106

105107
if http_conn is not None:
106-
self._http_conn = http_conn
108+
self._http_conn = copy(http_conn)
107109
elif parent_id is not None and parent_id.http_conn is not None:
108-
self._http_conn = parent_id.http_conn
110+
# Create new connection with same parameters as parent
111+
self._http_conn = copy(parent_id.http_conn)
109112
else:
110113
raise IOError("Expected parent to have http connector")
111114

test/hl/test_file.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,12 @@ def test_create(self):
118118
self.assertEqual(f.mode, 'r+')
119119
self.assertEqual(len(f.keys()), 0)
120120
root_grp = f['/']
121-
# f.create_group("subgrp")
122121
root_grp.create_group("subgrp")
123122
self.assertEqual(len(f.keys()), 1)
124123
f.close()
125124
self.assertEqual(f.id.id, 0)
126125

127-
# rre-open in append mode
126+
# re-open in append mode
128127
f = h5py.File(filename, "a")
129128
f.create_group("foo")
130129
del f["foo"]
@@ -135,6 +134,7 @@ def test_create(self):
135134
wait_time = 90 # change to >90 to test async updates
136135
print("waiting {wait_time:d} seconds for root scan sync".format(wait_time=wait_time))
137136
time.sleep(wait_time) # let async process update obj number
137+
138138
f = h5py.File(filename, 'r')
139139
self.assertEqual(f.filename, filename)
140140
self.assertEqual(f.name, "/")

0 commit comments

Comments
 (0)