次の方法で共有


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

Comments

  • Anonymous
    October 20, 2010
    First, thanks for this article. Pardeep, is there any possibilty that we have more than one collection ids against one blobstoreid? And how how can we fetch the collectionid for a blobstore id?

  • Anonymous
    October 20, 2010
    Hi Malik, Collections and blob stores do not have a direct relationship in the sense that a collection can have its blobs stored in multiple blob stores and a blob store can have blobs from multiple collections. The relationship you may be talking about is that of the default blob store for a collection. Yes, it is possible to have multiple collections with the same default blob store. You can see the default blob stores for each collection in the view mssqlrbs.rbs_collections as mentioned in the post above.

  • Anonymous
    October 21, 2010
    Pardeep, I am writing a sharepoint timer job to migrate all blobs from database to rbs blob store. If there are already some blobs in rbs blob store, following sql gives me all details regarding that blobstore. "select blob_store_id, store_pool_id, collection_id, can_store_new_blobs from mssqlrbs.rbs_pools where blob_store_id = (select blob_store_id from mssqlrbs.rbs_blob_stores where blob_store_name= @BlobStoreName)&quot; this query returns me collectionid which is later required for migrating blobs. But if there are no blobs already in the blobstore, lets say there is no storepool so far then it becomes difficult to get the right collectionid for my database. I need this collection id so that i can pass it to "[mssqlrbs].[rbs_sp_find_blob_destination]" to get the storepoolid and other information. How can i get collectionid? I can see a column "owning_application" in view "rbs_collections". Is it safe to say that I always need collectionid that has owning application value "Microsoft SharePoint"? Please let me know if I am taking a wrong path.

  • Anonymous
    January 11, 2011
    SharePoint will have its prescribed way of migrating blobs; they do not support customers/apps directly accessing their database. One possibility is to do a SharePoint site level backup and restore to a ContentDB that has a default RBS destination for blobs.