Skip to content

Commit

Permalink
make API for ending transaction more clear and less subtle (remove po…
Browse files Browse the repository at this point in the history
…ssibly premature optimization of updating passed-in slice; also remove metric for ldb_changes_accumulated in favor of just using the ldb_changes_written one
  • Loading branch information
erikdw committed Jan 16, 2024
1 parent a616e62 commit 7f3a202
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions pkg/ldbwriter/ldb_callback_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,19 @@ func (w *CallbackWriter) beginTransaction(ledgerSequence schema.DMLSequence) {
len(w.transactionChanges), ledgerSequence)
}
w.transactionChanges = make([]sqlite.SQLiteWatchChange, 0)
// TODO: Figure out if we wanna use a gauge or a counter here
stats.Set("ldb_changes_accumulated", 0)
}

// Transaction done! Return the accumulated changes including the latest ones
func (w *CallbackWriter) endTransaction(changes *[]sqlite.SQLiteWatchChange) {
*changes = append(w.transactionChanges, *changes...)
// TODO: Figure out if we wanna use a gauge or a counter here
stats.Set("ldb_changes_accumulated", len(*changes))
func (w *CallbackWriter) endTransaction(changes []sqlite.SQLiteWatchChange) (transactionChanges []sqlite.SQLiteWatchChange) {
w.accumulateChanges(changes)
transactionChanges = w.transactionChanges
w.transactionChanges = nil
return
}

// Transaction isn't over yet, save the latest changes
func (w *CallbackWriter) accumulateChanges(changes []sqlite.SQLiteWatchChange) {
w.transactionChanges = append(w.transactionChanges, changes...)
// TODO: Figure out if we wanna use a gauge or a counter here
stats.Set("ldb_changes_accumulated", len(w.transactionChanges))
}

// ApplyDMLStatement
Expand Down Expand Up @@ -86,7 +82,7 @@ func (w *CallbackWriter) ApplyDMLStatement(ctx context.Context, statement schema
transaction = true
if statement.Statement == schema.DMLTxEndKey {
// Transaction done, let's send what we have accumulated
w.endTransaction(&changes)
changes = w.endTransaction(changes)
} else {
// Transaction not over, continue accumulating
w.accumulateChanges(changes)
Expand Down

0 comments on commit 7f3a202

Please sign in to comment.