Remove DB reindex during a read operation (#26601)
The DB should be what is trusted for certain operations. If it is not present when read we should assume the corresponding store is empty, rather than trying a write operation during a read. * Add a unit test * Document what needs to be there in tests
This commit is contained in:
parent
21ce23816e
commit
2386630e10
@ -1024,12 +1024,7 @@ def _write(self, type, value, traceback):
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
def _read(self):
|
def _read(self):
|
||||||
"""Re-read Database from the data in the set location.
|
"""Re-read Database from the data in the set location. This does no locking."""
|
||||||
|
|
||||||
This does no locking, with one exception: it will automatically
|
|
||||||
try to regenerate a missing DB if local. This requires taking a
|
|
||||||
write lock.
|
|
||||||
"""
|
|
||||||
if os.path.isfile(self._index_path):
|
if os.path.isfile(self._index_path):
|
||||||
current_verifier = ''
|
current_verifier = ''
|
||||||
if _use_uuid:
|
if _use_uuid:
|
||||||
@ -1049,12 +1044,6 @@ def _read(self):
|
|||||||
"No database index file is present, and upstream"
|
"No database index file is present, and upstream"
|
||||||
" databases cannot generate an index file")
|
" databases cannot generate an index file")
|
||||||
|
|
||||||
# The file doesn't exist, try to traverse the directory.
|
|
||||||
# reindex() takes its own write lock, so no lock here.
|
|
||||||
with lk.WriteTransaction(self.lock):
|
|
||||||
self._write(None, None, None)
|
|
||||||
self.reindex(spack.store.layout)
|
|
||||||
|
|
||||||
def _add(
|
def _add(
|
||||||
self,
|
self,
|
||||||
spec,
|
spec,
|
||||||
|
@ -894,3 +894,18 @@ def _raise(db, spec):
|
|||||||
with pytest.raises(Exception):
|
with pytest.raises(Exception):
|
||||||
with spack.store.db.prefix_write_lock(s):
|
with spack.store.db.prefix_write_lock(s):
|
||||||
assert False
|
assert False
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.regression('26600')
|
||||||
|
def test_database_works_with_empty_dir(tmpdir):
|
||||||
|
# Create the lockfile and failures directory otherwise
|
||||||
|
# we'll get a permission error on Database creation
|
||||||
|
db_dir = tmpdir.ensure_dir('.spack-db')
|
||||||
|
db_dir.ensure('lock')
|
||||||
|
db_dir.ensure_dir('failures')
|
||||||
|
tmpdir.chmod(mode=0o555, rec=1)
|
||||||
|
db = spack.database.Database(str(tmpdir))
|
||||||
|
with db.read_transaction():
|
||||||
|
db.query()
|
||||||
|
# Check that reading an empty directory didn't create a new index.json
|
||||||
|
assert not os.path.exists(db._index_path)
|
||||||
|
Loading…
Reference in New Issue
Block a user