From 7f3a2027e84913eadbaa87d433566be621b8f1d1 Mon Sep 17 00:00:00 2001 From: Erik Weathers Date: Tue, 16 Jan 2024 13:45:13 -0800 Subject: [PATCH] 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 --- pkg/ldbwriter/ldb_callback_writer.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/pkg/ldbwriter/ldb_callback_writer.go b/pkg/ldbwriter/ldb_callback_writer.go index 45236a6..ce4464a 100644 --- a/pkg/ldbwriter/ldb_callback_writer.go +++ b/pkg/ldbwriter/ldb_callback_writer.go @@ -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 @@ -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)