@@ -14,6 +14,8 @@ import (
14
14
"github.com/hashicorp/nomad/nomad/structs"
15
15
)
16
16
17
+ // Txn is a transaction against a state store.
18
+ // This can be a read or write transaction.
17
19
type Txn = * memdb.Txn
18
20
19
21
const (
@@ -925,6 +927,8 @@ func (s *StateStore) UpsertJob(index uint64, job *structs.Job) error {
925
927
return nil
926
928
}
927
929
930
+ // UpsertJobTxn is used to register a job or update a job definition, like UpsertJob,
931
+ // but in a transcation. Useful for when making multiple modifications atomically
928
932
func (s * StateStore ) UpsertJobTxn (index uint64 , job * structs.Job , txn Txn ) error {
929
933
return s .upsertJobImpl (index , job , false , txn )
930
934
}
@@ -1019,6 +1023,8 @@ func (s *StateStore) DeleteJob(index uint64, namespace, jobID string) error {
1019
1023
return err
1020
1024
}
1021
1025
1026
+ // DeleteJobTxn is used to deregister a job, like DeleteJob,
1027
+ // but in a transcation. Useful for when making multiple modifications atomically
1022
1028
func (s * StateStore ) DeleteJobTxn (index uint64 , namespace , jobID string , txn Txn ) error {
1023
1029
// COMPAT 0.7: Upgrade old objects that do not have namespaces
1024
1030
if namespace == "" {
@@ -1206,6 +1212,8 @@ func (s *StateStore) JobByID(ws memdb.WatchSet, namespace, id string) (*structs.
1206
1212
return s .JobByIDTxn (ws , namespace , id , txn )
1207
1213
}
1208
1214
1215
+ // JobByIDTxn is used to lookup a job by its ID, like JobByID. JobByID returns the job version
1216
+ // accessable through in the transaction
1209
1217
func (s * StateStore ) JobByIDTxn (ws memdb.WatchSet , namespace , id string , txn Txn ) (* structs.Job , error ) {
1210
1218
// COMPAT 0.7: Upgrade old objects that do not have namespaces
1211
1219
if namespace == "" {
@@ -1534,6 +1542,8 @@ func (s *StateStore) DeletePeriodicLaunch(index uint64, namespace, jobID string)
1534
1542
return err
1535
1543
}
1536
1544
1545
+ // DeletePeriodicLaunchTxn is used to delete the periodic launch, like DeletePeriodicLaunch
1546
+ // but in a transcation. Useful for when making multiple modifications atomically
1537
1547
func (s * StateStore ) DeletePeriodicLaunchTxn (index uint64 , namespace , jobID string , txn Txn ) error {
1538
1548
// COMPAT 0.7: Upgrade old objects that do not have namespaces
1539
1549
if namespace == "" {
@@ -1610,6 +1620,8 @@ func (s *StateStore) UpsertEvals(index uint64, evals []*structs.Evaluation) erro
1610
1620
return err
1611
1621
}
1612
1622
1623
+ // UpsertEvals is used to upsert a set of evaluations, like UpsertEvals
1624
+ // but in a transcation. Useful for when making multiple modifications atomically
1613
1625
func (s * StateStore ) UpsertEvalsTxn (index uint64 , evals []* structs.Evaluation , txn Txn ) error {
1614
1626
// Do a nested upsert
1615
1627
jobs := make (map [structs.NamespacedID ]string , len (evals ))
@@ -3919,6 +3931,9 @@ func (s *StateStore) SchedulerSetConfig(idx uint64, config *structs.SchedulerCon
3919
3931
return nil
3920
3932
}
3921
3933
3934
+ // WithWriteTransaction executes the passed function within a write transaction,
3935
+ // and returns its result. If the invocation returns no error, the transaction
3936
+ // is committed; otherwise, it's aborted.
3922
3937
func (s * StateStore ) WithWriteTransaction (fn func (Txn ) error ) error {
3923
3938
tx := s .db .Txn (true )
3924
3939
defer tx .Abort ()
0 commit comments