Repository navigation
refactor(storage): introduce transaction runner, move restart workunit logic out of the spanner storage - #950
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the RestartWorkUnitExecutions logic out of the Spanner repository layer and into the server package as a private method on WorkUnitHandler. It introduces a TransactionRunner interface and context-propagated read-write transactions to decouple the storage layer from business logic. Multiple new storage methods are added to handle saving and updating executions, status history, and experiment statuses within these transactions. Feedback is provided regarding a potential nil pointer dereference panic in restartWorkUnitExecutions when calling wu.GetExecutable() if the executable is not configured.
2ddc0b9 to
787cd2f
Compare
…ner storage Move RestartWorkUnitExecutions orchestration logic from internal/storage/spanner/workunit to cmd/experiment_state_server/server to decouple domain orchestration from Spanner. Introduce TransactionRunner in storage.Storage and granular persistence write methods requiring an active ambient read-write transaction. TAG=agy CONV=915fe59e-48a0-43ba-b44f-367b95338b58
Replace ambient context transaction propagation with explicit repository-scoped Transaction struct (tx.WorkUnits, tx.Experiments, tx.StatusMessages, tx.StatusHistory) constructed via repository WithTx methods. TAG=agy CONV=915fe59e-48a0-43ba-b44f-367b95338b58
…mentStatus Merge SaveExperimentStatus and UpdateExperimentStatus into a single UpdateExperimentStatus method using r.tx, and document ExperimentTxStore removal TODO. TAG=agy CONV=915fe59e-48a0-43ba-b44f-367b95338b58
90f62a4 to
0a3622b
Compare
0a3622b to
ac9d39d
Compare
AntonTyb
left a comment
There was a problem hiding this comment.
- there is a Todo left - is it still valid?
- logs? debug/info pleeeeeease.
- Remove in-place proto defaulting from SaveWorkUnitExecution and UpdateCurrentWorkUnitExecution - Document TransactionRunner retry invariants - Convert restartWorkUnitExecutions to a package-level function accepting TransactionRunner - Guard against nil current executions returning status.ErrInternal - Clean up unused MockStorage error fields and clone protos in mock queries - Add TestRestartWorkUnitExecutions_RetryIsIdempotent test
aad9208 to
b3dcecc
Compare
…ner transactions - Add dedicated TxRepository wrappers embedding *Repository and non-nil tx across workunit, experiment, statusmessage, and statushistory - Hang transactional write methods on *TxRepository to convert runtime r.tx == nil guards into compile-time type guarantees - Override FetchWorkUnit and FetchExperiment on *TxRepository to ensure transactional reads are served from r.tx - Remove obsolete runtime precondition checks and their unit tests - Export TxRepository aliases on spanner package and wire WithTx symmetrically in RunInTransaction
b3dcecc to
e415db4
Compare
|
@VLukiantsev
|
VLukiantsev
left a comment
There was a problem hiding this comment.
LGTM — all review threads verified against e415db4 (fixes applied or deferrals agreed as out of Step-1 scope). TxRepository wrapper design looks solid for the follow-up PRs. One optional non-blocking nit left on spanner.go:42.
AntonTyb
left a comment
There was a problem hiding this comment.
- repeated definition of TxRepository
- can you add some docs about the new setup?
…aliases - Add internal/storage/README.md detailing storage architecture, TransactionRunner, *storage.Transaction, Repository vs TxRepository, retry guidelines, and hermetic testing. - Update cmd/experiment_state_server/README.md with high-level storage overview and link to internal/storage documentation. - Drop unused *TxRepository type aliases in internal/storage/spanner/spanner.go. TAG=agy CONV=915fe59e-48a0-43ba-b44f-367b95338b58
|
This PR is one step towards a storage refactor. There are a couple of other methods that need to be refactored in a similar way. For now I just want to show the direction in which I want to go and the rest of the PRs will follow.
Current problem with existing storage split:
We have storage methods that orchestrate a lot of business logic. For example, if we would now want to add support for another database, the new repository class would need to replicate all the business logic (validation, processing data, orchestrating multiple db operations) within its restartWorkUnitExecutions implementation.
Goal of this and the follow-up PRs:
The end goal of this and few follow up PRs is to refactor the most complex and most business-logic-heavy methods out of the storage and move it to the service/business-logic layer. This will make it easier to provide another database repository implementations and e.g. in case of changes in the restart logic it won't require cascade changes in all the other repositories.
To achieve this, I introduce abstraction over transactions so the service layer can own its boundaries without leaking db details. That allows to move problematic function out of storage and make repository functions thinner and more reusable.
What is not the goal at this moment:
Main decisions being made in this PR:
Next steps:
TAG=agy
CONV=915fe59e-48a0-43ba-b44f-367b95338b58