Added conservative locking to the spack commands that access the database at _index
This commit is contained in:
parent
c3246ee8ba
commit
9c8e46dc22
@ -28,6 +28,7 @@
|
||||
|
||||
import llnl.util.tty as tty
|
||||
from llnl.util.lang import attr_setdefault
|
||||
from llnl.util.lock import *
|
||||
|
||||
import spack
|
||||
import spack.spec
|
||||
@ -124,6 +125,7 @@ def elide_list(line_list, max_num=10):
|
||||
|
||||
|
||||
def disambiguate_spec(spec):
|
||||
with Read_Lock_Instance(spack.installed_db.lock,1800):
|
||||
matching_specs = spack.installed_db.get_installed(spec)
|
||||
if not matching_specs:
|
||||
tty.die("Spec '%s' matches no installed packages." % spec)
|
||||
|
@ -24,6 +24,7 @@
|
||||
##############################################################################
|
||||
from external import argparse
|
||||
import llnl.util.tty as tty
|
||||
from llnl.util.lock import *
|
||||
|
||||
import spack
|
||||
import spack.cmd
|
||||
@ -54,6 +55,7 @@ def deactivate(parser, args):
|
||||
if args.all:
|
||||
if pkg.extendable:
|
||||
tty.msg("Deactivating all extensions of %s" % pkg.spec.short_spec)
|
||||
with Read_Lock_Instance(spack.installed_db.lock,1800):
|
||||
ext_pkgs = spack.installed_db.installed_extensions_for(spec)
|
||||
|
||||
for ext_pkg in ext_pkgs:
|
||||
|
@ -27,6 +27,7 @@
|
||||
from external import argparse
|
||||
|
||||
import llnl.util.tty as tty
|
||||
from llnl.util.lock import *
|
||||
|
||||
import spack
|
||||
import spack.cmd
|
||||
@ -54,6 +55,7 @@ def diy(self, args):
|
||||
if not args.spec:
|
||||
tty.die("spack diy requires a package spec argument.")
|
||||
|
||||
with Write_Lock_Instance(spack.installed_db.lock,1800):
|
||||
specs = spack.cmd.parse_specs(args.spec)
|
||||
if len(specs) > 1:
|
||||
tty.die("spack diy only takes one spec.")
|
||||
|
@ -27,6 +27,7 @@
|
||||
|
||||
import llnl.util.tty as tty
|
||||
from llnl.util.tty.colify import colify
|
||||
from llnl.util.lock import *
|
||||
|
||||
import spack
|
||||
import spack.cmd
|
||||
@ -80,6 +81,7 @@ def extensions(parser, args):
|
||||
colify(ext.name for ext in extensions)
|
||||
|
||||
# List specs of installed extensions.
|
||||
with Read_Lock_Instance(spack.installed_db.lock,1800):
|
||||
installed = [s.spec for s in spack.installed_db.installed_extensions_for(spec)]
|
||||
print
|
||||
if not installed:
|
||||
|
@ -32,6 +32,7 @@
|
||||
from llnl.util.tty.colify import *
|
||||
from llnl.util.tty.color import *
|
||||
from llnl.util.lang import *
|
||||
from llnl.util.lock import *
|
||||
|
||||
import spack
|
||||
import spack.spec
|
||||
@ -138,8 +139,10 @@ def find(parser, args):
|
||||
|
||||
# Get all the specs the user asked for
|
||||
if not query_specs:
|
||||
with Read_Lock_Instance(spack.installed_db.lock,1800):
|
||||
specs = set(spack.installed_db.installed_package_specs())
|
||||
else:
|
||||
with Read_Lock_Instance(spack.installed_db.lock,1800):
|
||||
results = [set(spack.installed_db.get_installed(qs)) for qs in query_specs]
|
||||
specs = set.union(*results)
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
from external import argparse
|
||||
|
||||
import llnl.util.tty as tty
|
||||
from llnl.util.lock import *
|
||||
|
||||
import spack
|
||||
import spack.cmd
|
||||
@ -68,6 +69,7 @@ def install(parser, args):
|
||||
if args.no_checksum:
|
||||
spack.do_checksum = False # TODO: remove this global.
|
||||
|
||||
with Write_Lock_Instance(spack.installed_db.lock,1800):
|
||||
specs = spack.cmd.parse_specs(args.packages, concretize=True)
|
||||
for spec in specs:
|
||||
package = spack.db.get(spec)
|
||||
|
@ -27,6 +27,7 @@
|
||||
|
||||
import llnl.util.tty as tty
|
||||
from llnl.util.tty.colify import colify
|
||||
from llnl.util.lock import *
|
||||
|
||||
import spack
|
||||
import spack.cmd
|
||||
@ -53,6 +54,7 @@ def uninstall(parser, args):
|
||||
if not args.packages:
|
||||
tty.die("uninstall requires at least one package argument.")
|
||||
|
||||
with Write_Lock_Instance(spack.installed_db.lock,1800):
|
||||
specs = spack.cmd.parse_specs(args.packages)
|
||||
|
||||
# For each spec provided, make sure it refers to only one package.
|
||||
|
@ -158,12 +158,12 @@ def write(self):
|
||||
within the same lock, so there is no need to refresh
|
||||
the database within write()
|
||||
"""
|
||||
temp_name = os.getpid() + socket.getfqdn() + ".temp"
|
||||
temp_file = path.join(self._root,temp_name)
|
||||
with open(self.temp_path,'w') as f:
|
||||
temp_name = str(os.getpid()) + socket.getfqdn() + ".temp"
|
||||
temp_file = join_path(self._root,temp_name)
|
||||
with open(temp_file,'w') as f:
|
||||
self._last_write_time = int(time.time())
|
||||
self._write_database_to_yaml(f)
|
||||
os.rename(temp_name,self._file_path)
|
||||
os.rename(temp_file,self._file_path)
|
||||
|
||||
def is_dirty(self):
|
||||
"""
|
||||
@ -184,6 +184,7 @@ def add(self, spec, path):
|
||||
sph['path']=path
|
||||
sph['hash']=spec.dag_hash()
|
||||
|
||||
#Should always already be locked
|
||||
with Write_Lock_Instance(self.lock,60):
|
||||
self.read_database()
|
||||
self._data.append(sph)
|
||||
@ -197,6 +198,7 @@ def remove(self, spec):
|
||||
Searches for and removes the specified spec
|
||||
Writes the database back to memory
|
||||
"""
|
||||
#Should always already be locked
|
||||
with Write_Lock_Instance(self.lock,60):
|
||||
self.read_database()
|
||||
|
||||
@ -237,6 +239,7 @@ def installed_package_specs(self):
|
||||
Read installed package names from the database
|
||||
and return their specs
|
||||
"""
|
||||
#Should always already be locked
|
||||
with Read_Lock_Instance(self.lock,60):
|
||||
self.read_database()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user