Multiple Blob Stores in RBS – Defaults and Explicit Store Selection

Recently I got a question on how a blob store is chosen for storing new blobs when multiple blob stores are present, and how to influence that choice. This might be of interest to many others and so I am writing this blog post. Please feel free to ask questions (using the contact features on this blog site or by posting comments) and we will be happy to answer them.

 

A blob store can be identified using Blob Store Name or Blob Store ID; there is a 1:1 correspondence between these and there is a different name/ID for each instance of blob store registered with the DB. Blob Store Name is different from Blob Store Type. Blob Store Type indicates a class of blob stores, e.g. “Filestream”, “File” or “Centera” – this is fixed by the provider developer and cannot be changed by the admin or application writer. Blob Store Name is associated with an instance of a blob store, usually by the admin who deploys RBS. The list of blob stores registered with a DB can be found using the view mssqlrbs.rbs_blob_stores.

 

Here is the logic (in priority order) that determines which blob store is used to store a new blob.

 

1. If the application specifies a blob store name in CreateNewBlob() call, that blob store is used. This has the highest priority and all defaults are ignored. The blob store name needs to be specified inside the config parameter.

· SqlRemoteBlobContext.CreateNewBlob(int collectionId, ConfigItemList config): set the BlobStoreName parameter in config.

2. Otherwise, if there is a default blob store associated with the collection to which the new blob belongs, that blob store is used. The default blob store for a collection can be specified while creating a collection and can also be modified later. [Note: If the CreateNewBlob() call doesn’t specify a collectionId, the default collection with collectionId 0 is used. A default blob store can be associated with that collection as well.]

· SqlRemoteBlobContext.CreateNewCollection(ConfigItemList config): set the DefaultBlobStoreName parameter in config.

· SqlRemoteBlobCollectionManager.ModifyConfig(ConfigItemList config): set the DefaultBlobStoreName parameter in config.

· To clear/remove default blob store for a collection, call ModifyConfig above with an empty string ("") as the DefaultBlobStoreName. Note that not specifying an item in the config structure means retaining the old value, so you need to explicitly pass in some value to change the default blob store. The value that indicates removal/clearing is the empty string.

· You can see the current default blob store for a collection from the view mssqlrbs.rbs_collections: select blob_store_name from mssqlrbs.rbs_blob_stores as b join mssqlrbs.rbs_collections as c on c.default_blob_store_id = b.blob_store_id where c.collection_id = <Collection you are interested in>.

3. Otherwise, if there is a default blob store for the DB, that blob store is used.

· To set a default blob store for the DB, call Stored Procedure: mssqlrbs.rbs_sp_set_config_value (@config_key sysname, @config_value nvarchar(max)) with @config_key = N'default_blob_store_name' and @config_value = <name of the blob store you want to set as default>. Repeated calls to this SP will overwrite the default blob store and only the latest setting will be retained.

· To clear/remove default blob store for the DB, call SP: mssqlrbs.rbs_sp_delete_config_value (N'default_blob_store_name') .

· You can see the current default blob store for the DB from the view mssqlrbs.rbs_config: select * from mssqlrbs.rbs_config where config_key = N'default_blob_store_name' .

4. Otherwise, an error is returned that no blob store has been specified.

 

- Pradeep