Write behind is a technology to write updated records asynchronously to a backend such as a database. The application can 'commit' changes to replicated memory only and then periodically, all updated records are written to the database in a large batch. This eliminates the database from the response time for updates which improves performance and drastically lowers the load on the database by combining lots of small transactions in to a few big ones.
Clearly, once the application updates the data then the writes to the database must succeed. Sometimes, there are problems. Unforeseen interactions with the data or just application bugs. When the write behind logic cannot update a record then it inserts an entry in a special Map associated with the map holding the failed write behind update. The application needs to watch this map and handle these errors. Usually, the application will just log them to disk, it may try to reconcile the problem also. It all depends on whats possible in the application.
I'm attaching sample source code showing how to write such a watcher. The watcher should be added to your objectgrid.xml file like this:
<objectGrid name="Grid">
<bean id="TransactionCallback" className="purequery.loader.PQTxCallback">
<property name="connecturi" type="java.lang.String" value="jdbc:db2://172.16.129.133:50000/SAMPLE"/>
<property name="username" type="java.lang.String" value="db2admin"/>
<property name="password" type="java.lang.String" value="db2admin"/>
</bean>
<bean id="ObjectGridEventListener" className="utils.WriteBehindDumper" />
You can see the ObjectGridEventListener bean thats been added which is the write behind watcher or dumper is what I've called it here.
It basically interacts over the Maps for all primary shards in a JVM looking for ones with write behind enabled. If it finds one then it tries to log up to 100 bad updates. It keeps watching a primary shard until it's moved to a different JVM. All applications using write behind MUST use a watcher similar to this one as otherwise the JVMs will run out of memory as this error map is never evicted.
Comments