Logo

dev-resources.site

for different kinds of informations.

SAP Commerce Cloud and Read-Only Replica

Published at
6/4/2023
Categories
sap
commerce
performance
database
Author
mikolayek
Categories
4 categories in total
sap
open
commerce
open
performance
open
database
open
Author
9 person written this
mikolayek
open
SAP Commerce Cloud and Read-Only Replica

Introduction

SAP Commerce Cloud introduced Read-Only Replicas as a standard feature for all production environments.
Aim for Read-only data source is to offload batch queries or expensive ones from master data.
That data-source gives copy of same sized like master. When production runs on Premium P11 master, RO replica will be same, Premium P11 instance running side-by-side with master.
Read-Only replica is available for all Premium DBs in CCv2. That is a standard functionality provided by Azure.

Product Availability

Feature is available from SAP Commerce Cloud version 1905+.
With patches onward: 1905.37, 2005.21, 2011.16, and 2105.6. (You need to run update (aka 'Migrate Data') operation during deployment). CronJob and Job models have been extended and usage of replica has been simplified to a flag.

This patch introduces the support for a read-only replica. The feature includes additional configuration options for the Backoffice search, task engine, Job/CronJob configuration, catalog synchronization, and Solr indexing, access to the database metrics in the Administration Console, and an option to select a data source to run FlexibleSearch queries on.

From: https://help.sap.com/docs/SAP_COMMERCE/eed845124da0491e875df8139c4e6e8c/f18f6a711d07462b80137df6ed533eee.html?version=2005#patch-2005.21

Added Features

HAC Hybris Administration Console

Administration Console has been enriched by metrics review and possibility to query particular datasource explicitly.

Tab Monitoring > Database right now lists all data sources information:

Image description

Tab Azure SQL > Usage is located DB monitoring and DTU usage. Now it is possible to find two tabs: Main data source and Read only data source, where additionally it is possible to see other metrics:

  • DTU Usage
  • Number of DB connections
  • Read Only Data Source Redo Queue Size
  • Read Only Data Source Secondary Replica Lag

Image description

Backoffice

There have been added features for all CronJobs and Jobs to easily set which datasource cronjob should use.
Using navigation go System > Background Processes > CronJobs or Jobs. Field called useReadOnlyDatasource is a Boolean flag which enables alternative datasource.

Image description

Backoffice Search

When Read Replica is enabled it is also possible to use it in backoffice for all DB querying. Property flag which drive that feature by default is set to true.



backoffice.search.read-replica.enabled=true


Enter fullscreen mode Exit fullscreen mode

It is possible to disable Read Replica for particular item types by property too.



backoffice.search.read-replica.type.codes.exclude=Address


Enter fullscreen mode Exit fullscreen mode

Setting that property to Address causes that all queries for given type will be fetched from main database.

SAP Commerce Cloud SDK

It is also possible to use RO replica in code. There is important to keep in mind that update to RO replica is done asynchronously. Updates are visible usually up to XX milliseconds. There is no SLA available and Microsoft assures that most changes are done in one-digit ms time, up to two-digit ms delay.

There are two ways of running query on RO replica.

Local Session Context

It is possible to create local session context in code and after execution, remove it. Below code shows the way how it should be executed. That way generates a bit of boiler-plate, especially if you have to add it in multiple places.



final SessionContext ctx;
try
{
    ctx = JaloSession.getCurrentSession().createLocalSessionContext();
    ctx.setAttribute("ctx.enable.fs.on.read-replica", "true");

    final SearchResult<PK> search = flexibleSearchService.search("SELECT {PK} FROM {Product}");

    // TODO process the query result
}
finally
{
    JaloSession.getCurrentSession().removeLocalSessionContext();
}


Enter fullscreen mode Exit fullscreen mode

Query Hints Categorisation

Another way is to use hints to flexible search creation. That way requires configuration beforehand. It is required to prepare application configuration e.g. in local.properties:



flexiblesearch.categorizedQuery.MyCategory1.useReadOnlyDataSource=true
flexiblesearch.categorizedQuery.MyCategory2.useReadOnlyDataSource=false


Enter fullscreen mode Exit fullscreen mode

where MyCategory1 is your own name. Then it is required to set suffix useReadOnlyDataSource and value for that data-source usage.

Then in code it is straightforward and requires just one additional line:



query1 = new FlexibleSearchQuery("select {PK} from {Product}");
query1.addHints(FlexibleSearchHints.categorizedQuery("MyCategory1"));

query2 = new FlexibleSearchQuery("select {PK} from {Product}");
query2.addHints(FlexibleSearchHints.categorizedQuery("MyCategory2"));


Enter fullscreen mode Exit fullscreen mode

That is it. Rest is handled by core.

Task Engine Support

Task engine can also generate traffic on master data-source. That is why it also has been selected to be configured to use RO replica.

There is new property added, which in platform by default is set to false. By setting it in e.g. local.properties you can enable it.



task.polling.queryTaskProvider.read-replica.enabled=true

Enter fullscreen mode Exit fullscreen mode




What if

It is possible that in the runtime RO replica will not be available, or for given patch that functionality will be disabled (it happened in the past, that RO replica has been disabled in few patches due to found issues). There is a fail-over, which causes that all queries, will be silently rerouted to master data-source. Application will run normally.

Can I disable that?

If for some reason you would like to disable that function on hac and stop using RO replica, you can set in properties that value to '' (empty) value.



flexiblesearch.readOnly.datasource=

Enter fullscreen mode Exit fullscreen mode




Documentation Links

SAP Help Read-Only Replica: https://help.sap.com/docs/SAP_COMMERCE_CLOUD_PUBLIC_CLOUD/0fa6bcf4736c46f78c248512391eb467/1c7d5dde153a45fc9af868244741c32c.html?locale=en-US
SAP Help CronJobs Replica: https://help.sap.com/docs/SAP_COMMERCE_CLOUD_PUBLIC_CLOUD/aa417173fe4a4ba5a473c93eb730a417/d5aabf6700f249a2b433b956fa0620e2.html?version=v2105&locale=en-US
Microsoft Documentation: https://docs.microsoft.com/en-us/azure/azure-sql/database/read-scale-out?view=azuresql
Read-Only Replica SDK: https://help.sap.com/docs/SAP_COMMERCE_CLOUD_PUBLIC_CLOUD/aa417173fe4a4ba5a473c93eb730a417/51204da1b55d468484ba73222eaea5ce.html

commerce Article's
30 articles in total
Favicon
Top 10 M.Com Project Topics & Ideas For Students
Favicon
Key Benefits of Choosing Headless Commerce
Favicon
Enhance Retail with Composable Commerce for B2C
Favicon
Reducing Delivery Times and Costs: How Machine Learning Optimizes Delivery Routes Efficiently
Favicon
Advance Features and Deploying the Project (Nerd Streetwear Online Store) Part III
Favicon
Combine proxies to boost e-commerce results
Favicon
Next-Generation No-Code E-commerce Website Builder
Favicon
Coinbase Commerce: A Complete Guide to Seamless Cryptocurrency Payments
Favicon
The Dynamics of Composable Commerce: The Path to Agile and Scalable Business Solutions
Favicon
Marketplace vs. Own E-commerce Website: Where Should You Sell?
Favicon
Commerce Cloud logs in OpenSearch locally
Favicon
Testing and Quality Assurance for E-Commerce Websites
Favicon
SAP Commerce Cloud and Broken Smart Edit
Favicon
SAP Commerce Cloud and Read-Only Replica
Favicon
The 5 Best Importance of B2B Ecommerce for Your Business
Favicon
Commerce Cloud Exporting Integration Object using Delta Detection
Favicon
Medusa Vs Woocommerce: Comparing Two Open source Online Commerce Platforms
Favicon
Getting started with Shoket
Favicon
SAP Commerce Cloud: 10 Things You Should Know
Favicon
What Are The World-Class Features of Adobe Commerce Development?
Favicon
Principles and Practice of Accounting By CA/CMA Santosh Kumar
Favicon
Deploy Sylius to Heroku
Favicon
What Makes a Great Checkout Experience?
Favicon
Build your next commerce store with SvelteKit
Favicon
How to add new users to the Magento Cloud panel?
Favicon
Working with the Commerce Engine & Docker in Sitecore Experience Commerce 10.1
Favicon
Why go Headless?
Favicon
can i build ecommerce by react and node ? U have suggest for me ? Thank for share
Favicon
Headless eCommerce vs Traditional eCommerce
Favicon
Update all items that share the same catalog entity when the item is saved

Featured ones: