Jump to: navigation, search

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

 
(11 intermediate revisions by 2 users not shown)
Line 2: Line 2:
  
 
===Problem ===
 
===Problem ===
Drivers haven’t possibility to store private (consumed by driver) share data
+
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 cases ===
Line 9: Line 9:
  
 
===Concept===
 
===Concept===
Provide share data storage (key-value) for drivers.
+
Provide private data storage (key-value) for drivers:
+
 
Implement simple storage with following interface:
 
 
<source lang="python" >
 
<source lang="python" >
class DriverShareData(object):
 
  def __init__(self, context, db, backend_host):
 
      pass
 
  
  def get(self, share_id, key=None, default_value=None):
 
      pass
 
  
  def update(self, share_id, share_data, delete_existing=False):
+
class StorageDriver(object):
      pass
+
    def __init__(self, backend_host):
 +
        # Backend cannot access data stored by another backend
 +
        self.backend_host = backend_host
  
  def delete(self, share_id, key):
+
    def details_get(self, namespace_name, entity_id, key, default):
      pass
+
        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)
 
</source>
 
</source>
  
Line 35: Line 59:
 
     def __init__(self, share_driver=None, service_name=None, *args, **kwargs):
 
     def __init__(self, share_driver=None, service_name=None, *args, **kwargs):
 
       # …
 
       # …
       self.share_data = DriverShareData(self.context, self.db, self.host)
+
       self.private_driver_storage = PrivateDriverData(
 +
              # …
 +
      )
 
       self.driver = importutils.import_object(
 
       self.driver = importutils.import_object(
 
           share_driver,  
 
           share_driver,  
           self.share_data,
+
           self.private_driver_storage,
 
           #...
 
           #...
 
       )
 
       )
Line 44: Line 70:
 
</source>
 
</source>
  
 +
And use in drivers:
  
This storage will allow to get/update/delete private data of any share 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.
+
<source lang="python">
 +
# 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
  
===This concept vs model updates in Share Manager===
+
# Update
As you can see in  https://github.com/openstack/manila/815e2c95acc402847bb497365ea5caba608fd8cc/master/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.