Jump to: navigation, search

Difference between revisions of "Manila/Provide private data storage API for drivers"

(Concept)
 
(5 intermediate revisions by the same user not shown)
Line 12: Line 12:
  
 
<source lang="python" >
 
<source lang="python" >
 +
  
 
class StorageDriver(object):
 
class StorageDriver(object):
Line 30: Line 31:
  
 
class SqlStorageDriver(StorageDriver):
 
class SqlStorageDriver(StorageDriver):
     pass # TBD
+
     pass
 +
 
  
class NoSqlStorageDriver(StorageDriver):
+
class PrivateDriverData(object):
    pass  # TBD
 
  
class DataNamespace(object):
+
     def __init__(self, context, storage):
     def __init__(self, name, storage):
 
        self.name = name
 
 
         self.storage = storage
 
         self.storage = storage
 +
        self.context = context
  
 
     def details_get(self, entity_id, key=None, default=None):
 
     def details_get(self, entity_id, key=None, default=None):
         return self.storage.details_get(self.name, entity_id, key, default)
+
         return self.storage.details_get(entity_id, key, default)
  
 
     def details_update(self, entity_id, details, delete_existing=False):
 
     def details_update(self, entity_id, details, delete_existing=False):
 
         return self.storage.details_update(
 
         return self.storage.details_update(
             self.name, entity_id, details, delete_existing)
+
             entity_id, details, delete_existing)
  
 
     def details_delete(self, entity_id, key=None):
 
     def details_delete(self, entity_id, key=None):
         return self.storage.details_delete(self.name, entity_id, key)
+
         return self.storage.details_delete(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]
 
 
</source>
 
</source>
  
Line 89: Line 70:
 
</source>
 
</source>
  
 +
And use in drivers:
  
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:
 
 
<source lang="python">
 
<source lang="python">
# TBD
+
# Get data
</source>
+
share_data = self.data_storage.details_get(share_id)  # Get all data
 +
volume_id = self.data_storage.details_get(share_id, 'volume_id')  # Get single key
  
===This concept vs model updates in Share Manager===
+
# Update
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:
+
self.data_storage.details_update(share_id, {'foo': 'bar'})
<source lang="python">
 
        # ...
 
        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,
+
# Delete
                                                  export_locations)
+
self.data_storage.details_delete(share_id, 'foo') # Delete single key
      # ...
+
self.data_storage.details_delete(share_id)  # Delete all
 
</source>
 
</source>
  
  
We could follow this rule and simply replace return value by dictionary with optional keys:
 
  
<source lang="python">
+
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.
        # ...
 
        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,
+
Default implementation will store data in separate table in Manila database:
                                                  data['export_locations'])
+
<source lang="sql">
            # New code
+
CREATE TABLE private_drivers_data
            private_share_data = data.get('private_share_data')
+
(
            if private_share_data:
+
    created_at DATETIME,
              self.db.private_share_data_update(context, share_id, private_share_data)
+
    updated_at DATETIME,
      # ...
+
    deleted_at DATETIME,
 +
    deleted INT,
 +
    host VARCHAR(255) NOT NULL,  # Backend name
 +
    entity_id VARCHAR(36) NOT NULL, # Entity UUID
 +
    `key` VARCHAR(255) NOT NULL,
 +
    value VARCHAR(1023) NOT NULL,
 +
    PRIMARY KEY(host, entity_id, key)
 +
);
 
</source>
 
</source>
 
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===
 
===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.
 
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.

Latest revision as of 10:23, 21 April 2015

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


class PrivateDriverData(object):

    def __init__(self, context, storage):
        self.storage = storage
        self.context = context

    def details_get(self, entity_id, key=None, default=None):
        return self.storage.details_get(entity_id, key, default)

    def details_update(self, entity_id, details, delete_existing=False):
        return self.storage.details_update(
            entity_id, details, delete_existing)

    def details_delete(self, entity_id, key=None):
        return self.storage.details_delete(entity_id, key)


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,
           #...
       )
       # ...

And use in drivers:

# Get data
share_data = self.data_storage.details_get(share_id)  # Get all data
volume_id = self.data_storage.details_get(share_id, 'volume_id')  # Get single key

# Update
self.data_storage.details_update(share_id, {'foo': 'bar'})

# Delete
self.data_storage.details_delete(share_id, 'foo')  # Delete single key
self.data_storage.details_delete(share_id)  # Delete all


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:

CREATE TABLE private_drivers_data
(
    created_at DATETIME,
    updated_at DATETIME,
    deleted_at DATETIME,
    deleted INT,
    host VARCHAR(255) NOT NULL,  # Backend name
    entity_id VARCHAR(36) NOT NULL, # Entity UUID
    `key` VARCHAR(255) NOT NULL, 
    value VARCHAR(1023) NOT NULL,
    PRIMARY KEY(host, entity_id, key)
);

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.