[PR #810] [CLOSED] New versioning strategy for optimistic lock: next version value managed by App #8737

Open
opened 2026-01-22 16:01:28 +01:00 by admin · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/doctrine/orm/pull/810
Author: @diego-mazzaro
Created: 10/1/2013
Status: Closed

Base: masterHead: AppManagedVersions


📝 Commits (1)

  • e465001 Added versioning strategy for optimistic lock with next version value managed at the app level

📊 Changes

6 files changed (+131 additions, -45 deletions)

View changed files

📝 lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php (+2 -0)
📝 lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php (+59 -8)
📝 lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php (+3 -0)
📝 lib/Doctrine/ORM/Persisters/BasicEntityPersister.php (+59 -31)
📝 lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php (+6 -4)
📝 lib/Doctrine/ORM/UnitOfWork.php (+2 -2)

📄 Description

With this improvment the next value for the version field used for the optimisic lock strategy can be managed by the application.

When can be useful?
Obviously it is useful if we whant different values than the standard and for example:

  • using also negative numbers
  • using a combination of datetime and progressive number
  • mark with the same version all the records touched in a single updating session
  • anything that I want to do with my app and can be meaningful for me

And really can be done something different from standard ways?
The base property that a version column next value must have in order to accomplish his own task is this:
be different from any value that any other concurrently running client/process/thread/session may have read as current version value for the same record.
The opposite may sound more clear: if I write the same value that anyone concurrently working with me has read as current version he will find the same version when writing and will think that all is ok.

That told the standard implementations are:

  • next version = version + 1: prerfect
  • next version = TIMESTAMP: not so perfect but someone can live with

This two obviously respects the base property but the point is that they are not the only ones. Some examples:

  • increment by two: not so strange but different
  • increment up to 1000 and then restart from 0
    • if I'm sure that every session will end before other 1000 session has occourred it can work
  • use a GUID as version so I will "never" finish the possible values
  • use strings
    • wisely: knowing the "base property"
  • use values from an autogenerated ID of other table (generated for each updating session)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/doctrine/orm/pull/810 **Author:** [@diego-mazzaro](https://github.com/diego-mazzaro) **Created:** 10/1/2013 **Status:** ❌ Closed **Base:** `master` ← **Head:** `AppManagedVersions` --- ### 📝 Commits (1) - [`e465001`](https://github.com/doctrine/orm/commit/e465001bfab18fc25a3b7a41aec2c8eb4497499e) Added versioning strategy for optimistic lock with next version value managed at the app level ### 📊 Changes **6 files changed** (+131 additions, -45 deletions) <details> <summary>View changed files</summary> 📝 `lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php` (+2 -0) 📝 `lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php` (+59 -8) 📝 `lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php` (+3 -0) 📝 `lib/Doctrine/ORM/Persisters/BasicEntityPersister.php` (+59 -31) 📝 `lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php` (+6 -4) 📝 `lib/Doctrine/ORM/UnitOfWork.php` (+2 -2) </details> ### 📄 Description With this improvment the next value for the version field used for the optimisic lock strategy can be managed by the application. **When can be useful?** Obviously it is useful if we whant different values than the standard and for example: - using also negative numbers - using a combination of datetime and progressive number - mark with the same version all the records touched in a single updating session - anything that I want to do with my app and can be meaningful for me **And really can be done something different from standard ways?** The **base property** that a version column next value must have in order to accomplish his own task is this: _be different from any value that any other concurrently running client/process/thread/session may have read as current version value for the same record._ The opposite may sound more clear: if I write the same value that anyone concurrently working with me has read as current version he will find the same version when writing and will think that all is ok. That told the standard implementations are: - next version = version + 1: prerfect - next version = TIMESTAMP: not so perfect but someone can live with This two obviously respects the **base property** but the point is that they are not the only ones. Some examples: - increment by two: not so strange but different - increment up to 1000 and then restart from 0 - if I'm sure that every session will end before other 1000 session has occourred it can work - use a GUID as version so I will "never" finish the possible values - use strings - wisely: knowing the "base property" - use values from an autogenerated ID of other table (generated for each updating session) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
admin added the pull-request label 2026-01-22 16:01:28 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#8737