Skip to content

Commit 7f3a202

Browse files
committed
make API for ending transaction more clear and less subtle (remove possibly premature optimization of updating passed-in slice; also remove metric for ldb_changes_accumulated in favor of just using the ldb_changes_written one
1 parent a616e62 commit 7f3a202

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

pkg/ldbwriter/ldb_callback_writer.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,19 @@ func (w *CallbackWriter) beginTransaction(ledgerSequence schema.DMLSequence) {
3333
len(w.transactionChanges), ledgerSequence)
3434
}
3535
w.transactionChanges = make([]sqlite.SQLiteWatchChange, 0)
36-
// TODO: Figure out if we wanna use a gauge or a counter here
37-
stats.Set("ldb_changes_accumulated", 0)
3836
}
3937

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

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

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

0 commit comments

Comments
 (0)