CounterLocalService is used to generate the surrogate keys for Liferay's entities. Some use the generic counter, others specify their class name as the counter name.
Can anyone provide a list of which table uses which for Liferay 6.1?
The use case for this question is explained at
primary key clash with records inserted to DB outside of service layer?I'm working my way through the code to find how CounterLocalService instance are injected into the various persistant layer classes. Its a bit slow going but I will return here when I have discovered anything that helps answer my own question.
[edit date="2012-09-11"]
Warning! Warning, Will Robinson!We have a sharded database running in mySQL. Each shard has its own Counter table. None of them are used!
I searched and searched and discovered that in this configuration the counter data is stored in
data/hsql/lportal.log. The counters are run as an in-memory database table which is occasionally saved to this file. This file is a critical part of your database and must be included in system back ups and synchronised with your database. If it is lost or gets out of synch you may have serious problems with your system because of clashing primary keys.
[edit date="2012-09-12"]
If you do not want to have the counters stored in HSQL when using shards then you must still define jdbc.default in your portal-ext.properties. If you do not want to call your default shard "default" you may still name it as you wish and have jdbc.default point to the same data source.
In the
shard documentation it seems as though the use of jdbc.default is arbitrary, since there is a property called shard.default.name. If, as I did, you define a default shard as something like jdbc.shard00, with shard.default.name=shard00 and do not define jdbc.default, then everything works just as you would expect with the one exception to do with the counter records.
So here are the snippets for my final set up
1
2jdbc.default.driverClassName=com.mysql.jdbc.Driver
3jdbc.default.url=jdbc:mysql://localhost/db00?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
4jdbc.default.username= ****
5jdbc.default.password= ****
6
7jdbc.shard00.driverClassName=com.mysql.jdbc.Driver
8jdbc.shard00.url=jdbc:mysql://localhost/db00?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
9jdbc.shard00.username= ****
10jdbc.shard00.password= ****
11
12jdbc.shard01.driverClassName=com.mysql.jdbc.Driver
13jdbc.shard01.url=jdbc:mysql://localhost/db01?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
14jdbc.shard01.username= ****
15jdbc.shard01.password= ****
16
17..etc to shard79
1
2shard.available.names=shard00,shard01, ..etc to shard79
3shard.default.name=shard00
4shard.selector=com.liferay.portal.dao.shard.ManualShardSelector
I beleive shard.available.names is no longer needed. However I have kept it anyway. Note that default does not appear in this list.
Please sign in to flag this as inappropriate.