From d57e333534e61fcb7b2b009447a9583c9e96060e Mon Sep 17 00:00:00 2001 From: Charlie Voiselle <464492+angrycub@users.noreply.github.com> Date: Thu, 27 Oct 2022 14:03:43 -0400 Subject: [PATCH] Update architecture-state-store.md (#15049) --- contributing/architecture-state-store.md | 46 ++++++++++++------------ 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/contributing/architecture-state-store.md b/contributing/architecture-state-store.md index 96a8b39e4..b0b32e543 100644 --- a/contributing/architecture-state-store.md +++ b/contributing/architecture-state-store.md @@ -13,37 +13,37 @@ This architecture has a few implications: the state store. These values must be provided as parameters from the RPC handler. - ```go - # Incorrect: generating a timestamp in the state store is not deterministic. - func (s *StateStore) UpsertObject(...) { - # ... - obj.CreateTime = time.Now() - # ... - } + ```go + # Incorrect: generating a timestamp in the state store is not deterministic. + func (s *StateStore) UpsertObject(...) { + # ... + obj.CreateTime = time.Now() + # ... + } - # Correct: non-deterministic values should be passed as inputs: - func (s *StateStore) UpsertObject(..., timestamp time.Time) { - # ... - obj.CreateTime = timestamp - # ... - } - ``` + # Correct: non-deterministic values should be passed as inputs: + func (s *StateStore) UpsertObject(..., timestamp time.Time) { + # ... + obj.CreateTime = timestamp + # ... + } + ``` * Every object you read from the state store must be copied before it can be mutated, because mutating the object modifies it outside the raft workflow. The result can be servers having inconsistent state, transactions breaking, or even server panics. - ```go - # Incorrect: job is mutated without copying. - job, err := state.JobByID(ws, namespace, id) - job.Status = structs.JobStatusRunning + ```go + # Incorrect: job is mutated without copying. + job, err := state.JobByID(ws, namespace, id) + job.Status = structs.JobStatusRunning - # Correct: only the job copy is mutated. - job, err := state.JobByID(ws, namespace, id) - updateJob := job.Copy() - updateJob.Status = structs.JobStatusRunning - ``` + # Correct: only the job copy is mutated. + job, err := state.JobByID(ws, namespace, id) + updateJob := job.Copy() + updateJob.Status = structs.JobStatusRunning + ``` Adding new objects to the state store should be done as part of adding new RPC endpoints. See the [RPC Endpoint Checklist][].