Reputation: 36395
I am developing an application which uses Git as a database. My current approach is to call out to the git
shell command to construct a new commit whenever the application changes something. This is very simple, but a big disadvantage is that it does not allow any concurrent writes to the database: two threads cannot construct a commit simultaneously, because there is a single HEAD
, a single index
, and a single working copy.
However, since commits, trees, and blobs are all content-addressed, I think it should be possible to construct all of these concurrently. What would be the recommended approach for this? Perhaps:
git add
, git commit
, etc., which explicitly specify a different HEAD
and index
file to use. As far as I can see, such things do not exist.git clone
to get an entirely new working copy for each concurrent user. This is inordinately expensive.Upvotes: 2
Views: 890
Reputation: 1323483
Since 2014, there have been several initiatives to propose a "Git-like" database:
The most recent is liquidata-inc/dolt: "Git for data"
Dolt is a relational database, i.e. it has tables, and you can execute SQL queries against those tables.
It also has version control primitives that operate at the level of table cell. Thus Dolt is a database that supports fine grained value-wise version control, where all changes to data and schema are stored in commit log.
Before, with a different approach: SOM-Research/Gitana (2017).
See "A conceptual and database schema for Git via Gitana" by Valerio Cosentino (Twitter)
Closer to what you are looking for is src-d/gitbase
SQL interface to git repositories, written in G
It can be used to perform SQL queries about the Git history and about the Universal AST of the code itself.
All three projects can include ideas about how to use Git for this kind of database usage.
Note also that recent version of Git (including the upcoming Q2 2020 Git 2.27) have improved the git push --atomic
.
The same Git 2.27 is in the process of implementing two-phase commit-style atomic ref-updates across multiple repositories: see "Is it possible to manage multiple repositories coherently?".
Upvotes: 3
Reputation: 393771
Another possible option is for each concurrent user to create (and checkout) a new branch and commit to that branch, and then to merge the branches to the master branch periodically.
That might have some problems though :
Upvotes: 0