Skip to content

Commit 67bf8e1

Browse files
committed
add more debug log messages
1 parent 5ee8b3e commit 67bf8e1

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

src/h5json/hdf5db.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,14 +381,17 @@ def open(self):
381381
else:
382382
# open reader first and get root id
383383
reader_root_id = self.reader.open()
384+
self.log.debug(f"got reader root_id: {reader_root_id}")
385+
384386
if self._root_id:
385387
if reader_root_id != self._root_id:
386388
raise IOError("reader root id does not match reader root id")
387389
else:
388390
self._root_id = reader_root_id
389-
391+
self.log.debug("open writer")
390392
# now open writer
391393
writer_root_id = self.writer.open()
394+
self.log.debug(f"got writer root_id: {writer_root_id}")
392395
if writer_root_id != self._root_id:
393396
raise IOError("writer root id does not match reader root id")
394397

src/h5json/hsdsstore/hsds_writer.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def __init__(
110110
self._root_id = None
111111
self._append = append
112112
self._track_order = track_order
113+
self._owner = owner
113114
self._linked_domain = linked_domain
114115
self._last_flush_time = 0
115116
self._stats = {"created": 0, "lastModified": 0, "owner": ""}
@@ -120,17 +121,24 @@ def open(self):
120121
# no db set yet
121122
raise IOError("DB not set")
122123

123-
if self._http_conn:
124-
http_conn = self._http_conn
125-
else:
124+
if self._http_conn and not self._http_conn.isClosed():
125+
return self._root_id
126+
127+
if not self._http_conn:
126128
kwargs = self._http_kwargs
127129
kwargs["retries"] = 1 # tbd: test setting
128130
http_conn = HttpConn(self.filepath, **kwargs)
129131
if self._append:
130132
http_conn._mode = "a"
133+
self.log.debug("hsdswriter - set http_conn mode to a")
131134
self._http_conn = http_conn
132-
hsds_info = http_conn.serverInfo()
133-
self.log.debug(f"got hsds info: {hsds_info}")
135+
136+
http_conn = self._http_conn
137+
self.log.debug("hsdswriter - open http conn")
138+
http_conn.open()
139+
140+
hsds_info = self._http_conn.serverInfo()
141+
self.log.debug(f"got hsds info: {hsds_info}")
134142

135143
# fetch the domain json
136144

@@ -148,6 +156,7 @@ def open(self):
148156

149157
domain_json = None
150158
rsp = http_conn.GET(req, params=params)
159+
self.log.debug(f"hsdswriter initial get status_code: {rsp.status_code}")
151160

152161
if rsp.status_code not in (200, 404, 410):
153162
msg = f"Got status code: {rsp.status_code} on initial domain get"
@@ -165,6 +174,7 @@ def open(self):
165174
raise IOError(404, "Location is a folder, not a file")
166175
else:
167176
# not append - delete existing domain
177+
self.log.info("hsds_writer - delete domain")
168178
self.log.info(f"sending delete request for {self.filepath}")
169179
delete_rsp = http_conn.DELETE(req, params=params)
170180
if delete_rsp.status_code not in (200, 410):
@@ -174,6 +184,7 @@ def open(self):
174184

175185
if not domain_json:
176186
# domain doesn't exist, create it
187+
self.log.debug("hsds_writer create domain")
177188
body = {}
178189
if self.db.root_id:
179190
# initialize domain using the db's root_id
@@ -203,6 +214,7 @@ def open(self):
203214
raise IOError(404, "Location is a folder, not a file")
204215

205216
root_id = domain_json["root"]
217+
self.log.debug("hsds_writer got root_id:", root_id)
206218

207219
self._root_id = root_id
208220

src/h5json/hsdsstore/httpconn.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ def add_external_ref(self, fid):
682682
self._external_refs.append(fid)
683683

684684
def open(self):
685+
self.log.debug("http_conn.open")
685686
if self._s:
686687
return # already open
687688

@@ -705,10 +706,12 @@ def open(self):
705706
kwargs = {"max_retries": retry, "pool_connections": 16, "pool_maxsize": 16}
706707
s.mount("http://", HTTPAdapter(**kwargs))
707708
s.mount("https://", HTTPAdapter(**kwargs))
708-
self._s = s
709+
self.log.debug("Httpconn set self._s")
710+
self._s = s
709711

710712
def close(self):
711713
if self._s:
714+
self.log.debug("http_conn.close")
712715
self._s.close()
713716
self._s = None
714717

test/unit/hsds_writer_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def testSimple(self):
4949
for k in ("created", "lastModified", "owner"):
5050
self.assertTrue(k in stats)
5151
http_conn = HttpConn(domain_path, mode='r', retries=1)
52+
http_conn.open()
5253

5354
db.createAttribute(root_id, "attr1", value=[1, 2, 3, 4])
5455
db.createAttribute(root_id, "attr2", 42)
@@ -186,6 +187,14 @@ def testReaderWriter(self):
186187
self.assertTrue(root_id)
187188
db.reader = HSDSReader(domain_path, app_logger=self.log)
188189
db.close()
190+
"""
191+
db.writer = HSDSWriter(domain, **kwargs)
192+
root_id = db.open()
193+
db.close()
194+
# now set the reader
195+
db.reader = HSDSReader(domain, **kwargs)
196+
db.open()
197+
"""
189198
root_id2 = db.open()
190199
self.assertEqual(root_id, root_id2)
191200
root_json = db.getObjectById(root_id)
@@ -209,6 +218,7 @@ def testH5PyToHS(self):
209218

210219
# validate - get the root group and see if counts are correct
211220
http_conn = HttpConn(domain_path, mode='r', retries=1)
221+
http_conn.open()
212222
http_rsp = http_conn.GET(f"/groups/{root_id}")
213223
self.assertEqual(http_rsp.status_code, 200)
214224
root_json = http_rsp.json()

0 commit comments

Comments
 (0)