Skip to content

Commit e0ac249

Browse files
committed
Rework refresh_vgrid_map in order to init all vgrid entries in VGRIDS early
and to never skip init of the individual fields in those vgrid dicts, even if the source file for the corresponding field (like `owners` or `members`) is older than the map timestamp of the current vgrid map file. That should address a potential race when vgrids are modified during long-running refresh calls and any other causes for those fields missing in the existing map. Remove an unused leftover variable in check_vgrid_access.
1 parent 2a0f803 commit e0ac249

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

mig/shared/vgridaccess.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,18 +401,18 @@ def refresh_vgrid_map(configuration, clean=False):
401401
optional_conf = [SETTINGS, ]
402402

403403
for vgrid in all_vgrids:
404+
# Make sure vgrid dict exists before filling it
405+
vgrid_map[VGRIDS][vgrid] = vgrid_map[VGRIDS].get(vgrid, {})
404406
for (field, name, list_call) in conf_read:
405407
conf_path = os.path.join(configuration.vgrid_home, vgrid, name)
406408
if not os.path.isfile(conf_path):
407-
# Make sure vgrid dict exists before filling it
408-
vgrid_map[VGRIDS][vgrid] = vgrid_map[VGRIDS].get(vgrid, {})
409409
vgrid_map[VGRIDS][vgrid][field] = []
410410
if vgrid != default_vgrid and field not in optional_conf:
411411
_logger.warning('missing file: %s' %
412412
conf_path)
413413
dirty[VGRIDS] = dirty.get(VGRIDS, []) + [vgrid]
414414

415-
elif vgrid not in vgrid_map[VGRIDS] or \
415+
elif field not in vgrid_map[VGRIDS][vgrid] or \
416416
os.path.getmtime(conf_path) >= map_stamp:
417417
(status, entries) = list_call(vgrid, configuration,
418418
recursive=False)
@@ -425,6 +425,8 @@ def refresh_vgrid_map(configuration, clean=False):
425425
vgrid_map[VGRIDS][vgrid] = map_entry
426426
vgrid_map[VGRIDS][vgrid][field] = entries
427427
dirty[VGRIDS] = dirty.get(VGRIDS, []) + [vgrid]
428+
else:
429+
_logger.debug("caching %s for %s in vgrid map" % (name, vgrid))
428430
# Remove any missing vgrids from map
429431
missing_vgrids = [vgrid for vgrid in vgrid_map[VGRIDS]
430432
if not vgrid in all_vgrids]
@@ -853,7 +855,6 @@ def check_vgrid_access(configuration, client_id, vgrid_name, recursive=True,
853855
the vgrid module and should replace that one everywhere that only vgrid map
854856
(cached) lookups are needed.
855857
"""
856-
vgrid_access = [default_vgrid]
857858
vgrid_map = get_vgrid_map(configuration, recursive, caching)
858859
vgrid_entry = vgrid_map.get(VGRIDS, {}).get(
859860
vgrid_name, {OWNERS: [], MEMBERS: []})

0 commit comments

Comments
 (0)