What are transactions? Transaction processing systems

In a world where everything is changing so rapidly, one cannot stop for a minute. This also applies to obtaining new information. An unknown term or the latest version of a software product is an occasion to replenish knowledge in a particular area. Today we’ll talk about what transactions are, how it works.

Introduction to Terminology

A variety of software products for automating business processes have firmly established themselves in the market over the past 15 years. This requires the ability to work with software at different levels of interaction: as an operator, programmer, accountant, etc. Therefore, it is so important to understand some of the mechanisms of the program. To begin with, we’ll deal with such a frequently encountered and frightening term as transaction. Most often, behind a beautiful borrowed word lies far from such a complex phenomenon as many imagine, pronouncing a new term, trying it by ear. Let's understand what transactions are.

what is a transaction

Definition of a concept

This designation is used in relation to any product in which work with the database is implemented. Several operations, logically combined into a single unit and performed alternately one after another, is a transaction. In everyday life, a transaction can be considered a chain of procedures like "woke up - washed, dressed, had breakfast, went to work."

Consider this concept on the example of 1C products. A transaction is an indivisible sequence of actions. A good example is a record of a unit of goods: opening the necessary directory, creating a new element, filling in the fields provided. In order for all these actions to lead to the desired result, it is necessary to perform them strictly from the first to the last. Only under this condition will the procedure be considered successful. Otherwise, the transaction is canceled.

The processes under consideration can be either automatic, that is, provided in the system, or manually added by the developer after purchasing the finished product in order to make the latter more convenient for users of a particular enterprise. In addition, from automatic mode, when the behavior of the system is regulated by built-in mechanisms, transactions can be transferred to managed.

unable to complete secure transaction

Transactions in 1C: the intricacies of the embedded language

What transactions are in the general case, we understand. But since each company engaged in software development does this in its own way, there are certain differences between transactions in general and transactions in 1C in particular. For example, nested (transaction within a transaction) in 1C are not supported.

In terms of syntax, the built-in language operators are fairly simple. The beginning of the process is announced using the special procedure Start Transaction (). The Commit transaction () procedure is used to record changes during the execution of actions. If a failure occurs during the execution, there is the option to Cancel the Transaction () to roll back the changes made.

Why is using transactions preferable? Because the code in these procedures runs much faster. This is exactly what any programmer strives for. The difference in speed may not be so noticeable if 1C users in the office have 1-2 employees, but you cannot help but feel it when it comes to entire departments that simultaneously perform different work in the specified program.

Underwater rocks

In addition to the obvious plus, which consists in a serious increase in the speed of reading and writing when working with the database, transactions have their own minus. Let us return to the earlier example from life. What are transactions made not by one person, but by the whole family? Everyone is trying to get into the bathroom to wash earlier, everyone is crowding in the kitchen, because it is time for breakfast. As a result, family members are unhappy with each other. At best, this is just a bad start to the day, at worst it’s being late for work, reprimand from superiors, frustrated plans.

The same thing happens in the program. If all users start simultaneously changing data in the same document, which version should be considered the latest? What data to save before? To prevent such confusion, there is a locking mechanism. This means that while one user is working on a document, the second is standing in a virtual queue and waiting. After the transaction is completed or rolled back successfully, the next user can work on the document.

1s transaction

To be or not to be controlled by locks?

The concept of a transaction cannot be considered fully considered without the question of excessive locks. What is a big evil: the absence of locks, leading to an incorrect reading and writing process with incorrect output results, or too many of them, hampering the work of the whole enterprise?

The best solution - managed locks, which are the golden mean. A competent programmer will be able to customize an existing mechanism to the needs of the organization so that really important documents are processed in order of priority. For the same configuration items that do not need locks, you can enable free editing.

Thus, timely analysis of transactions and the correct attitude to locks allows you to fully use the flexibility of the 1C: Enterprise system and optimize the base, minimizing time losses.

transaction processing systems

What does redundant blocking lead to?

The question is far from rhetorical. If you remove the necessary locks, there will be confusion and chaos. Incorrect data will begin to accumulate in the database due to the simultaneous write-off of balances or, conversely, the accrual of assets. But these consequences are of a kind that will not come to light immediately. At first, the work will go quickly, creating the illusion of the correct choice of rejection of locks. On the other hand, an unreasonably large number of locks immediately causes error messages. “Cannot complete the secure transaction,” the system warns us. What does it mean? Two transactions mutually blocked each other in such a way that neither one can neither complete what has been started nor carry out a cancellation. A vicious circle of "dead" transactions will hang in the database until it is detected, significantly reducing system performance.

Unnecessary undo operations increase the number of entries in the log. In addition, such a system is not viable, because an even greater increase in users will simply bury it under the load of "dead" locks. Downtime will increase steadily. How to avoid such situations?

transaction cancellation

Insulation levels are another way to stay aground.

Speaking of what transactions are, we mentioned pitfalls. Continuing the analogy, it is safe to say that varying the level of locks is a reliable pilot tool for traveling on the sea 1C. There are two levels of isolation: "read only, no write" and "neither write nor read." In automatic mode, the selection is not available. But it’s enough to put the application in a controlled mode, and it will be possible to put “smart” restrictions, choosing not only important documents, but also assigning them an appropriate level of isolation.

However, correctly delivered work is, first of all, the prevention of emergency situations, and not just the timely elimination of failures that have already occurred. Assistant database administrator will serve as a transaction processing system. It is on the basis of data on how any operations in the system went, whether they were successfully completed or canceled, it is possible to predict further system behavior and prevent potential threats.

transaction concept

Summarizing

We figured out the definition of a transaction, examined the algorithm for executing the process from the inside, and familiarized ourselves with the different ways of regulating operations within the same information base.

transaction analysis

As practice has shown, the mechanism is not simple, but it is accessible for understanding and deeper study even for novice programmers and database administrators. Regulatory methods may not yet be brought to perfection, and avoiding problems in a fully automatic mode is also not possible, but, nevertheless, with each new version of the software, the developer’s life becomes easier.

Source: https://habr.com/ru/post/C22669/


All Articles