Skip to main content

Writing to Multiple File Systems from the Same Deployer

This topic is not new. It comes back regularly, pretty much with every single enterprise client I have implemented. "Why do we need different Deployers for different file systems?". "Why can't just Tridion publish to different file systems?". And so on...

Recently, it came up again, so I setup a small PoC to see how feasible it is to write a Storage Extension (in SDL Tridion 2011SP1) that would perform the typical CRUD operations a Deployer would perform, only on multiple file systems.

The idea behind the storage extension is to have several file systems defined in the cd_storage_conf.xml that would be grouped under one logical name. Then have an item type mapping (e.g. Page) that would point to the group of file system. The goal is to have that item type created, updated, removed, etc on each of the file systems defined in the group.

The cd_storage_conf.xml Storages node would look something like this:

    <Storage Type="filesystem" Class=""
        Id="MultiFS" defaultFilesystem="false">
        <Root Path="not-used" />

    <Storage Type="filesystem" Class=""
        Id="FileRoot1" defaultFilesystem="false">
        <Root Path="C:\Temp\Root1" />

    <Storage Type="filesystem" Class=""
        Id="FileRoot2" defaultFilesystem="false">
        <Root Path="D:\Temp\Root2" />

    <StorageGroup Id="MultiFS">
        <Storage Id="FileRoot1"/>
        <Storage Id="FileRoot2"/>

Item mapping for the Page type would point to the MultiFS id:

    <ItemTypes defaultStorageId="brokerdb" cached="true">
        <Item typeMapping="Page" cached="false" storageId="MultiFS" />

In order to make the setup-above work, I had to create my own DAO (Data Access Object) storage extension. There is a reference to the DAO bundle definition in the cd_storage_conf.xml:

        <Bundle src="multifs_dao_bundle.xml" />

The file multifs_dao_bundle.xml contains the definition of my custom DAO:

    <StorageDAOBundle type="filesystem">
        <StorageDAO typeMapping="Page"
            class="com.tridion.extension.multifs.MultiFSDAO" />

The whole logic lies in the class MultiFSDAO, which acts like a wrapper around an array of objects. A helper configuration class reads the StorageGroup node from cd_storage_conf.xml and then reads the Root/@path (i.e. storage location) value for each referenced Storage node.

public class MultiFSDAO extends FSBaseDAO implements PageDAO {

    private FSPageDAO[] pageDAOs;

    public MultiFSDAO(String storageId, String storageName, File storageLocation) {
        super(storageId, storageName, storageLocation);
        createDAOs(storageId, storageName, null);

    public MultiFSDAO(String storageId, String storageName, File storageLocation, FSEntityManager entityManager) {
        super(storageId, storageName, storageLocation, entityManager);
        createDAOs(storageId, storageName, entityManager);

    private void createDAOs(String storageId, String storageName, FSEntityManager entityManager) {
        MultiFSConfiguration configuration = MultiFSConfiguration.getInstance();
        Map<String, String> storageGroups = configuration.getStorageGroups();
        String groups = storageGroups.get(storageId);
        if (groups == null) {
            groups = storageId;

        String storageIds[] = groups.split(",");
        pageDAOs = new FSPageDAO[storageIds.length];
        Map<String, String> storageLocations = configuration.getStorageLocations();

        for (int i = 0; i < storageIds.length; i++) {
            String id = storageIds[i];
            String location = storageLocations.get(id);

            if (entityManager == null) {
                pageDAOs[i] = new FSPageDAO(id, storageName, new File(location));
            } else {
                pageDAOs[i] = new FSPageDAO(id, storageName, new File(location), entityManager);

Once we have the array of FSPageDAO objects, it's a simple matter of just implementing the CRUD operations on the collection of FSPageDAOs.

public void create(CharacterData page, String relativePath) throws StorageException {
    for (PageDAO pageDAO : pageDAOs) {
        pageDAO.create(page, relativePath);

public Collection<CharacterData> findAll(int publicationId) throws StorageException {
    Collection<CharacterData> result = null;
    for (PageDAO pageDAO : pageDAOs) {
        result = pageDAO.findAll(publicationId);

    return result;

public CharacterData findByPrimaryKey(int publicationId, int pageId) throws StorageException {
    CharacterData result = null;
    for (PageDAO pageDAO : pageDAOs) {
        result = pageDAO.findByPrimaryKey(publicationId, pageId);

    return result;

public void remove(int publicationId, int pageId, String relativePath) throws StorageException {
    for (PageDAO pageDAO : pageDAOs) {
        pageDAO.remove(publicationId, pageId, relativePath);

public void update(CharacterData page, String originalRelativePath, String newRelativePath) throws StorageException {
    for (PageDAO pageDAO : pageDAOs) {
        pageDAO.update(page, originalRelativePath, newRelativePath);

The big disclaimer: the code-above is by no means production ready -- I just used it for a small PoC. I have not tested it thoroughly either. It does deploy pages to multiple file systems, but I did not try any corner cases. I don't even think it works in all scenarios: think about here at transactionality, or what happens (or should happen) if a destination failed. The deploy will not be rolled back. What happens upon unpublish of a previously failed published? And the questions could go on... Use at your own discretion!


Popular posts from this blog

Running sp_updatestats on AWS RDS database

Part of the maintenance tasks that I perform on a MSSQL Content Manager database is to run stored procedure sp_updatestats . exec sp_updatestats However, that is not supported on an AWS RDS instance. The error message below indicates that only the sa  account can perform this: Msg 15247 , Level 16 , State 1 , Procedure sp_updatestats, Line 15 [Batch Start Line 0 ] User does not have permission to perform this action. Instead there are several posts that suggest using UPDATE STATISTICS instead: I stumbled upon the following post from 2008 (!!!), , which describes a way to wrap the call to sp_updatestats and execute it under a different user: create procedure dbo.sp_updstats with execute as 'dbo' as

Content Delivery Monitoring in AWS with CloudWatch

This post describes a way of monitoring a Tridion 9 combined Deployer by sending the health checks into a custom metric in CloudWatch in AWS. The same approach can also be used for other Content Delivery services. Once the metric is available in CloudWatch, we can create alarms in case the service errors out or becomes unresponsive. The overall architecture is as follows: Content Delivery service sends heartbeat (or exposes HTTP endpoint) for monitoring Monitoring Agent checks heartbeat (or HTTP health check) regularly and stores health state AWS lambda function: runs regularly reads the health state from Monitoring Agent pushes custom metrics into CloudWatch I am running the Deployer ( installation docs ) and Monitoring Agent ( installation docs ) on a t2.medium EC2 instance running CentOS on which I also installed the Systems Manager Agent (SSM Agent) ( installation docs ). In my case I have a combined Deployer that I want to monitor. This consists of an Endpoint and a

Debugging a Tridion 2011 Event System

OK, so you wrote your Tridion Event System. Now it's time to debug it. I know this is a hypothetical situtation -- your code never needs any kind of debugging ;) but indulge me... Recently, Alvin Reyes ( @nivlong ) blogged about being difficult to know how exactly to debug a Tridion Event System. More exactly, the question was " What process do I attach to for debugging even system code? ". Unfortunately, there is no simple or generic answer for it. Different events are fired by different Tridion CM modules. These modules run as different programs (or services) or run inside other programs (e.g. IIS). This means that you will need to monitor (or debug) different processes, based on which events your code handles. So the usual suspects are: dllhost.exe (or dllhost3g.exe ) - running as the MTSUser is the SDL Tridion Content Manager COM+ application and it fires events on generic TOM objects (e.g. events based on Tridion.ContentManager.Extensibility.Events.CrudEven