Manila/Provide private data storage API for drivers
Contents
Provide limited data API for drivers
Problem
Drivers haven’t possibility to store key/value pairs in the database for shares/snapshots/etc. These values are not visible to the tenants, they're just for the drivers.
Use cases
Use case #1: Generic driver should store volume id instead of renaming volume (current behaviour)
Use case #2: Some backends that can't create 32-character share names and need to maintain a mapping from the 128-bit UUID to something smaller.
Concept
Provide private data storage (key-value) for drivers:
class StorageDriver(object):
def __init__(self, backend_host):
# Backend cannot access data stored by another backend
self.backend_host = backend_host
def details_get(self, namespace_name, entity_id, key, default):
raise NotImplementedError()
def details_update(self, namespace_name, entity_id, details,
delete_existing):
raise NotImplementedError()
def details_delete(self, namespace_name, entity_id, key):
raise NotImplementedError()
class SqlStorageDriver(StorageDriver):
pass # TBD
class NoSqlStorageDriver(StorageDriver):
pass # TBD
class DataNamespace(object):
def __init__(self, name, storage):
self.name = name
self.storage = storage
def details_get(self, entity_id, key=None, default=None):
return self.storage.details_get(self.name, entity_id, key, default)
def details_update(self, entity_id, details, delete_existing=False):
return self.storage.details_update(
self.name, entity_id, details, delete_existing)
def details_delete(self, entity_id, key=None):
return self.storage.details_delete(self.name, entity_id, key)
class PrivateDriverData(object):
registered_namespaces = ["share", "snapshot", "share_server"]
def __init__(self, context, storage):
self.storage = storage
self.context = context
self._namespaces = self._init_namespaces(self.registered_namespaces)
def _init_namespaces(self, namespaces):
return [DataNamespace(ns, self.storage) for ns in namespaces]
def __getattr__(self, item):
if item not in self._namespaces:
raise AttributeError("Namespace %s is not registered." % item)
return self._namespaces[item]
Provide this storage in the manager to all drivers:
class ShareManager(manager.SchedulerDependentManager):
# …
def __init__(self, share_driver=None, service_name=None, *args, **kwargs):
# …
self.private_driver_storage = PrivateDriverData(
# …
)
self.driver = importutils.import_object(
share_driver,
self.private_driver_storage,
#...
)
# ...
This storage will allow to get/update/delete private data of any entity managed by the driver. Drivers will be able to create mappings between data in manila (Share) and backends (NAS). Also, drivers could use this storage for caching purposes - to minimize an amount of requests to the backend.
Default implementation will store data in separate table in Manila database:
# TBD
As you can see in https://github.com/openstack/manila/blob/815e2c95acc402847bb497365ea5caba608fd8cc/manila/share/manager.py Share Manager is responsible to update information in DB. For example:
# ...
try:
if snapshot_ref:
export_locations = self.driver.create_share_from_snapshot(
context, share_ref, snapshot_ref,
share_server=share_server)
else:
export_locations = self.driver.create_share(
context, share_ref, share_server=share_server)
self.db.share_export_locations_update(context, share_id,
export_locations)
# ...
We could follow this rule and simply replace return value by dictionary with optional keys:
# ...
try:
if snapshot_ref:
data = self.driver.create_share_from_snapshot(
context, share_ref, snapshot_ref,
share_server=share_server)
else:
data = self.driver.create_share(
context, share_ref, share_server=share_server)
self.db.share_export_locations_update(context, share_id,
data['export_locations'])
# New code
private_share_data = data.get('private_share_data')
if private_share_data:
self.db.private_share_data_update(context, share_id, private_share_data)
# ...
But in this case we will be forced to do so in each method where drivers require private share data. Furthermore, we will be forced to retrieve and pass private share data to drivers through argument even if they don't require this data. This will cause performance penalty and code will look like a mess :)
That's why my (u_glide) proposal is: Leave current model updates in Share manager as is and provide DriverShareData interface to all drivers in the manager.
DB scaling risks
By default, all private share data will be stored in manila SQL DB and we have a risk that DB becomes a bottleneck in large deployments. This risk (in a scope of this feature) can be addressed by implementation of different storage backends for this interface. As we can see backends don’t share data, so storage can be easily horizontally scaled. We can move private share data to any distributed key-value storage.