Publication Technical Review

There are several tricks described in this topic that help you optimize and understand your publication process.

One Important Technique for Tracking Items to Publish

During normal operation, Data Hub inspects the pool to find items valid for publication. Data Hub queries the database by page for canonical items, ordered by the canonical item id. An in-memory id tracker retains information about the first item available for publication. Don't retrieve earlier items from the database again. An item qualifies for publication and prevents the advancement of the id tracker in the following circumstances. It has not been published to the target system before. It has failed less than the configured number of attempts. In the best case scenario of no errors, Data Hub still needs to load all items included in the previous publication from the database. The load confirms that the id tracker can be safely moved forwards. After moving it forward, subsequent publications no longer load these items.

After a restart, the in-memory id tracker is reset to zero. So, check all items in the database as potential candidates for publication. All current (nonarchived) items that have not yet been removed by the cleanup extension and all systemic errors load from the database, page by page. For this reason, a publication after a restart can take a long time to complete. The cause may be a large volume of systemic errors and/or a large volume of items that have not passed the cleanup time threshold.

Trapping Performance Issues

The following description depends upon the publications.xml (shown in the following codeblock). It was created using the Data Hub publications REST API GET request /pools/{poolName}/publications.

Using the publications.xml file, you can find the single current publication by searching for the publication whose actionId is 4043 (shown in the following code block). This publication already has a startTime assigned, which means it is currently in progress for the pool. Remember, only one publication can be running at a time for a given pool. All other publications that have a status of IN_PROGRESS are either pending or are never processed. We can see that this particular publication started at 15:52:19. You can safely assume that any data received or composed after this startTime is still pending and not picked up for publication yet. Also note that the canonicalItemCount field has already been populated for the targetSystemPublication. Populated TargetItems have already been created (internal to the Data Hub). Data Hub is either waiting for a response from SAP Commerce Cloud, or it is in the process of completing the publication by setting all statuses appropriately. The canonicalItemCount indicates the number of canonical items that were valid for attempting to send to the target system. The count is the number of items in the pool that have not been published successfully and have less than the maximum number of retry attempts. If they fail individually during target item creation, some of these items might not be sent to the target system (for example MISSING_REFERENCE). If this count equals the configured max publication action size, then there are more items in the pool for publishing in the next publication. If not, then all canonical items that were available in the pool at the startTime publish to SAP Commerce Cloud with this publication.
<publicationActionData>
    <actionId>4043</actionId>
    <type>PUBLICATION</type>
    <startTime>2017-02-21T15:52:19Z</startTime>
    <status>IN_PROGRESS</status>
    <poolName>SAPCUSTOMER_INBOUND_POOL</poolName>
    <targetSystemPublications>
        <publicationId>11229</publicationId>
        <status>IN_PROGRESS</status>
        <targetSystemName>HybrisCore</targetSystemName>
        <actionId>4043</actionId>
        <poolName>SAPCUSTOMER_INBOUND_POOL</poolName>
        <numberOfErrors>0</numberOfErrors>
        <canonicalItemCount>34163</canonicalItemCount>
    </targetSystemPublications>
</publicationActionData>
We then look at the previous publication for an example of a completed one (see publication 4041 that follows). Here, we see that the publication took ~4:45 for 1039 items. ~4:45 is slow and should be investigated. The status of FAILURE indicates that the publication did not complete cleanly. We should see something in the Data Hub logs or the SAP Commerce Cloud logs to indicate why it happened. In this example, the following log statement was found in the log file:
INFO | jvm 1 | main | 2017/02/21 15:52:19.351 | [m[0;32mINFO [TaskExecutor-master-32871-Task [8883518210998]] [ImpexDataImportClient]
Returning ERROR(Error writing media file (mediaId: 8815818932254, file:/NFS_DATA/hybris-media/sys_master/impex/hfe/h29/8815818932254.bin, dir:/NFS_DATA/hybris-media/sys_master/impex/hfe/h29)) to http://192.168.0.10:29991/datahub-webapp/v1/core-publications/11635
As you can see, the publication failed due to the inability of SAP Commerce Cloud to write the ImpEx file.
<publicationActionData>
    <actionId>4041</actionId>
    <type>PUBLICATION</type>
    <startTime>2017-02-21T11:08:13Z</startTime>
    <endTime>2017-02-21T15:52:19Z</endTime>
    <status>FAILURE</status>
    <poolName>SAPCUSTOMER_INBOUND_POOL</poolName>
    <targetSystemPublications>
        <publicationId>11227</publicationId>
        <startTime>2017-02-21T11:08:15Z</startTime>
        <endTime>2017-02-21T15:52:19Z</endTime>
        <status>FAILURE</status>
        <targetSystemName>HybrisCore</targetSystemName>
        <actionId>4041</actionId>
        <poolName>SAPCUSTOMER_INBOUND_POOL</poolName>
        <numberOfErrors>1</numberOfErrors>
        <canonicalItemCount>1039</canonicalItemCount>
    </targetSystemPublications>
</publicationActionData>
The previous publication was successful but still took ~4:30 for 57 items. Something is still very inefficient here and bears further investigation.
<publicationActionData>
    <actionId>4037</actionId>
    <type>PUBLICATION</type>
    <startTime>2017-02-21T06:27:57Z</startTime>
    <endTime>2017-02-21T11:08:09Z</endTime>
    <status>SUCCESS</status>
    <poolName>SAPCUSTOMER_INBOUND_POOL</poolName>
    <targetSystemPublications>
        <publicationId>11207</publicationId>
        <startTime>2017-02-21T06:27:59Z</startTime>
        <endTime>2017-02-21T11:08:09Z</endTime>
        <status>SUCCESS</status>
        <targetSystemName>HybrisCore</targetSystemName>
        <actionId>4037</actionId>
        <poolName>SAPCUSTOMER_INBOUND_POOL</poolName>
        <numberOfErrors>0</numberOfErrors>
        <canonicalItemCount>57</canonicalItemCount>
    </targetSystemPublications>
</publicationActionData>

Note that MISSING_REFERENCE errors are considered internal errors and do not count in the numberOfErrors field for a given publication. Later versions (6.x) of the Data Hub display this count as well, and also provide a PENDING status for disambiguation.

Looking back further in the publications.xml file, you can see IN_PROGRESS publications (both with and without startTime). These publications are never going to be processed and are the result of Data Hub restarts. If there are more recent publications that completed successfully (just search for a higher actionId), you can safely ignore these publications. This behavior has been changed in the later Data Hub versions (6.x). Later versions contain a process to clean up the old, unused data on server startup. The pending actions would actually be available for processing again. See the following examples for IN_PROGRESS actions, which are never processed:

Example #1

<publicationActionData>
    <actionId>3778</actionId>
    <type>PUBLICATION</type>
    <status>IN_PROGRESS</status>
    <poolName>SAPCUSTOMER_INBOUND_POOL</poolName>
    <targetSystemPublications>
        <publicationId>10756</publicationId>
        <status>IN_PROGRESS</status>
        <targetSystemName>HybrisCore</targetSystemName>
        <actionId>3778</actionId>
        <poolName>SAPCUSTOMER_INBOUND_POOL</poolName>
        <numberOfErrors>0</numberOfErrors>
    </targetSystemPublications>
</publicationActionData>

Example #2

<publicationActionData>
    <actionId>2580</actionId>
    <type>PUBLICATION</type>
    <startTime>2017-02-20T18:22:25Z</startTime>
    <status>IN_PROGRESS</status>
    <poolName>SAPCUSTOMER_INBOUND_POOL</poolName>
    <targetSystemPublications>
        <publicationId>7538</publicationId>
        <status>IN_PROGRESS</status>
        <targetSystemName>HybrisCore</targetSystemName>
        <actionId>2580</actionId>
        <poolName>SAPCUSTOMER_INBOUND_POOL</poolName>
        <numberOfErrors>0</numberOfErrors>
    </targetSystemPublications>
</publicationActionData>