Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce transaction manager #836

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Soil-Core-Tests/SoilTransactionTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ SoilTransactionTest >> testConflictingReadVersion [
{ #category : #tests }
SoilTransactionTest >> testEmptyAbort [
| tx |
tx := SoilTransaction new.
tx := soil newTransaction.
tx root: Object new.
tx abort.
self assert: tx isAborted
Expand Down
19 changes: 17 additions & 2 deletions src/Soil-Core/Soil.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ Class {
'control',
'setup',
'fabric',
'metadata'
'metadata',
'transactionManager'
],
#category : #'Soil-Core-Model'
}
Expand Down Expand Up @@ -120,6 +121,9 @@ Soil >> basicOpen [
soil: self;
open;
yourself.
transactionManager := SoilTransactionManager new
soil: self;
yourself.
journal := SoilPersistentDatabaseJournal new
soil: self.
"journal open might checkpoint so we set the journal
Expand Down Expand Up @@ -236,6 +240,9 @@ Soil >> initializeFilesystem [
soil: self;
initializeFilesystem;
yourself.
transactionManager := SoilTransactionManager new
soil: self;
yourself.
journal := SoilPersistentDatabaseJournal new
soil: self;
initializeFilesystem;
Expand Down Expand Up @@ -332,7 +339,9 @@ Soil >> newSerializer [

{ #category : #transactions }
Soil >> newTransaction [
^ self newTransaction: self transactionClass
^ self transactionManager
newTransaction: self transactionClass
readVersion: self control databaseVersion
]

{ #category : #transactions }
Expand Down Expand Up @@ -467,6 +476,12 @@ Soil >> transactionClass [
^ self fabric transactionClass
]

{ #category : #accessing }
Soil >> transactionManager [

^ transactionManager
]

{ #category : #writing }
Soil >> writeEverythingToDisk [
self behaviorRegistry
Expand Down
25 changes: 13 additions & 12 deletions src/Soil-Core/SoilTransaction.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ Class {

{ #category : #aborting }
SoilTransaction >> abort [
soil ifNotNil: [
soil notificationHandler transactionAborted: self ].
self basicAbort.

self transactionManager abortTransaction: self
]

{ #category : #accessing }
Expand Down Expand Up @@ -241,18 +238,12 @@ SoilTransaction >> buildWriteVersion [

{ #category : #accessing }
SoilTransaction >> commit [
self basicCommit.
recordsToCommit ifNotEmpty: [
soil checkpoint ].
self basicAbort.
self transactionManager commitTransaction: self
]

{ #category : #actions }
SoilTransaction >> commitAndContinue [
self basicCommit.
recordsToCommit ifNotEmpty: [
soil checkpoint ].
self continue
self transactionManager commitAndContinueTransaction: self
]

{ #category : #actions }
Expand Down Expand Up @@ -321,6 +312,11 @@ SoilTransaction >> hasModifications [
^ self dirtyObjects notEmpty
]

{ #category : #testing }
SoilTransaction >> hasRecordsToCommit [
^ recordsToCommit notEmpty
]

{ #category : #accessing }
SoilTransaction >> indexes [
^ indexes
Expand Down Expand Up @@ -639,6 +635,11 @@ SoilTransaction >> start [
createdAt := DateAndTime now
]

{ #category : #accessing }
SoilTransaction >> transactionManager [
^ soil transactionManager
]

{ #category : #accessing }
SoilTransaction >> writeVersion [
^ writeVersion
Expand Down
73 changes: 73 additions & 0 deletions src/Soil-Core/SoilTransactionManager.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
Class {
#name : #SoilTransactionManager,
#superclass : #Object,
#instVars : [
'soil',
'transactions',
'semaphore'
],
#category : #'Soil-Core-Model'
}

{ #category : #'as yet unclassified' }
SoilTransactionManager >> abortTransaction: aTransaction [
soil ifNotNil: [
soil notificationHandler transactionAborted: self ].
aTransaction basicAbort.
self removeTransaction: aTransaction

]

{ #category : #adding }
SoilTransactionManager >> addTransaction: aSoilTransaction [
semaphore critical: [
transactions add: aSoilTransaction ]
]

{ #category : #'as yet unclassified' }
SoilTransactionManager >> commitAndContinueTransaction: aTransaction [
aTransaction basicCommit.
aTransaction hasRecordsToCommit ifTrue: [
soil checkpoint ].
aTransaction continue
]

{ #category : #'as yet unclassified' }
SoilTransactionManager >> commitTransaction: aTransaction [
aTransaction basicCommit.
aTransaction hasRecordsToCommit ifTrue: [
soil checkpoint ].
aTransaction basicAbort.
self removeTransaction: aTransaction
]

{ #category : #initialization }
SoilTransactionManager >> initialize [
super initialize.
transactions := OrderedCollection new.
semaphore := Semaphore forMutualExclusion
]

{ #category : #'instance creation' }
SoilTransactionManager >> newTransaction: aClass readVersion: version [
| txn |
txn := aClass new
soil: soil;
readVersion: version;
start;
yourself.
soil notificationHandler transactionCreated: txn.
self addTransaction: txn.
^ txn
]

{ #category : #removing }
SoilTransactionManager >> removeTransaction: aSoilTransaction [
semaphore critical: [
transactions remove: aSoilTransaction ]
]

{ #category : #accessing }
SoilTransactionManager >> soil: aSoil [
soil := aSoil
]
Loading