Skip to content

Commit

Permalink
oio-meta2-mover, Python API: Delete meta2 index entries from old peer
Browse files Browse the repository at this point in the history
  • Loading branch information
aneutron authored and fvennetier committed Nov 26, 2018
1 parent 8334ef2 commit 9d54b16
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
3 changes: 2 additions & 1 deletion bin/oio-meta2-mover 100644 → 100755
Expand Up @@ -54,7 +54,8 @@ if __name__ == '__main__':
mapping = Meta1RefMapping(args.namespace)
moved = mapping.move(args.src_service, args.dest_service, args.base,
'meta2')
moved_ok = mapping.apply(moved)
kwargs = {'src_service': args.src_service}
moved_ok = mapping.apply(moved, **kwargs)
except Exception as exc:
print("ERROR: " + str(exc))
if not moved_ok:
Expand Down
10 changes: 9 additions & 1 deletion oio/directory/meta.py
Expand Up @@ -16,6 +16,7 @@
from collections import defaultdict

from oio.directory.admin import AdminClient
from oio.rdir.client import RdirClient
from oio.conscience.client import ConscienceClient
from oio.common.exceptions import OioException, ServiceBusy
from oio.common.logger import get_logger
Expand All @@ -26,10 +27,11 @@ class MetaMapping(object):

def __init__(self, conf, service_types,
admin_client=None, conscience_client=None, logger=None,
**kwargs):
rdir_client=None, **kwargs):
self.conf = conf
self._admin = admin_client
self._conscience = conscience_client
self._rdir = rdir_client
self.logger = logger or get_logger(self.conf)
self.raw_services_by_base = defaultdict(list)
self.services_by_base = dict()
Expand All @@ -50,6 +52,12 @@ def conscience(self):
self._conscience = ConscienceClient(self.conf)
return self._conscience

@property
def rdir(self):
if not self._rdir:
self._rdir = RdirClient(self.conf)
return self._rdir

def reset(self):
"""
Reset the base allocations and reload the services from Conscience.
Expand Down
13 changes: 13 additions & 0 deletions oio/directory/meta1.py
Expand Up @@ -53,6 +53,19 @@ def _apply_link_services(self, moved_ok, **kwargs):
service_type=service_type, cid=cid, replace=True,
services=dict(host=','.join(peers), type=service_type,
args=args, seq=seq))
"""
FIXME(ABO): This part can be removed when, either:
- meta1 sends the removed services bundled with the
account.services events.
- meta2 sends a storage.container.deleted event when the
sqliterepo layer is the one that notifies the deletion of
the databases.
"""
if service_type == 'meta2' and kwargs.get('src_service'):
self.rdir.meta2_index_delete(
volume_id=kwargs.get('src_service'),
container_id=cid
)
except OioException as exc:
self.logger.warn(
"Failed to link services for base %s (seq=%d): %s",
Expand Down
6 changes: 3 additions & 3 deletions oio/rdir/client.py
Expand Up @@ -484,8 +484,8 @@ def _resolve_cid_to_path(self, cid):
resp['name']
)

def meta2_index_delete(self, volume_id, container_id=None, container_path=None,
**kwargs):
def meta2_index_delete(self, volume_id, container_path=None,
container_id=None, **kwargs):
"""
Remove a meta2 record from the volume's index. Either the container ID
or the container path have to be given.
Expand All @@ -499,7 +499,7 @@ def meta2_index_delete(self, volume_id, container_id=None, container_path=None,
elif container_path and not container_id:
_tmp = container_path.rsplit("/")
container_id = cid_from_name(_tmp[1], _tmp[3])
else:
elif not container_path and not container_id:
raise ValueError("At least the container ID or the container path "
"should be given.")

Expand Down

0 comments on commit 9d54b16

Please sign in to comment.