Skip to main content

Informix row level locking - Breaking the process boundary

During the time of my previous post, the version of Informix on the Amdahl mainframe was upgraded to a new version that included row level locking.  Common now, at the time, database vendors were busy figuring out the best ways to perform row level locking.

The method that Informix chose had an interesting unexpected feature.  If you had a unique index on a table and you inserted a row, the database implemented a row level lock on the yet to be committed index row by locking the next row in the table.  If there was no index key larger than that, it would lock to the end of the index.

This meant that inserting sequential values at the end of the table, a very common occurrence for our system, would in effect behave like a full table lock.   A clean solution to this problem would have been to apply the CQRS pattern so that the inserts into the database could be queued without affecting the user.  But that would have required a complete refactoring of the linkages between the database interface and the custom screen processing library in an age where C code didn't have unit tests.

The solution/hack was to assign the index numbers non-sequentially.  I created an RPC program that would hand out index values based on a tree based representation of the key numbers.  For example, let's say you had 8 buckets (2^3) of numbers:

If you started with 8 already inserted rows as a preset base case, then an insert would lock only up to the end of the bucket, allowing 8 concurrent inserts at a time.  If you need more concurrency, then you could increase the number of buckets.

Now for 8 of those inserts, regardless of the size of the buckets, we need to not insert the pre-inserted values.  Instead we need to insert into the next set of bucket dividers.  The simple way I decided to do that was to make the size of the buckets 2^8.  That way I could use bit manipulation as follows:


By arraigning the counter this way, I could use a normal counter with simple math to generate the resulting index when it wasn't a special case.  I could also get exponential back-off behavior by decrementing the counter and doing the inserts into the next range when the counter ended in all 1's (the first insert would happen right away, the second would be 1/2 of the way through the counter, etc.).  The remaining "fix" was map the 8 overlapping counter values to the missed inserts into the last bucket (which would always be 111 when inserting into the next set of ranges).

The major boundary change in this solution, assigning sequence or identity values outside of a transaction, is behavior that many (most?) database systems now do: Oracle sequences, SQL Server identity columns, PostgresSQL sequences, etc.

Looking outside of your boundaries expands the solution space available to you. 

Comments

Popular posts from this blog

Spring Boot native builds when internet downloads are blocked made simple

 No direct access to the internet If you work at a company that controls their software bill of materials, it's quite common to be blocked from directly downloading from: Maven Central Docker hub GitHub (the public parts) Getting the bits Maven Maven is first, because without it, you won't be able to compile your Spring Boot application, let alone move on to turning it into a native docker image. I will be showing changes need to work with artifactory, but you should be able to adapt it to other mirror solutions.  repositories {   maven {     name = "central"     url = "https://artifactory.example.com/central"     credentials {       username = "${project.ext.properties.artifactory_username}"       password = "${project.ext.properties.artifactory_apikey}"     }   } } With this configuration change, you should be able to download your plugins and dependencies, allowing you to compile and ...

Kotlin Notebook when you're blocked from Maven Central

 TLDR; If you are blocked getting to maven central when first using Kotlin Notebooks because of company firewalls, you can use a tool like Fiddler Tool to redirect to a different network location. Kotlin Notebooks Kotlin Notebooks are a JDK based environment that brings the Python based Jupyter Notebooks  expressiveness to IntelliJ. From the blog post announcing the plugin, it looks like this: At home, the installation of jar files looked like this: I played around with it at home, but I couldn't use it at work.  Many companies, mine included, do not allow software components to be used when downloaded directly from the internet. In my companies case, we use a product called Artifactory, which allows you to mirror the content from Maven Central while still applying policies like CVE scanning, tracking, etc. The way it should work IntelliJ, as one of the leading IDE's, generally supports this quite well.  In fact, there is a whole setting page dedicated to dealing wi...

Active vs. Passive Log4jShell remediation

 Log4jShell  All computer professionals should be aware of the Log4jShell ( CVE-2021-44228 ) and it follow on defects.  There is no shortage of opinions and lessons to be be learned: The difficulty of performing safe interpretation The problems when assumptions are not clearly documented.  I, for one, was completely shocked to find out that a logging system would actually attempt to do variable substitution in an actual message. The difficulty of finding and resolving issues with such a common library that is not provided by an OS package manager. IT'S A LOG4J CHRISTMAS One of my favorite podcasts, Security Now - episode 850 , discussed an analysis by Google regarding the depth of log4j dependencies.  From the show notes : One contributing reason is because Log4j is, more often than not, an indirect dependency. Java libraries are built by writing some code which uses functions from other Java libraries, which are built by writing some code which uses functions f...