Repository: polarsignals/frostdb (go)

Issue:
`Test_Table_ReadIsolation` flaky
Running

```
go test -run Test_Table_ReadIsolation -count=1000
```

For me reliably produces several occurrences of:

```
--- FAIL: Test_Table_ReadIsolation (0.00s)
    table_test.go:361:
                Error Trace:    /Users/brancz/src/github.com/polarsignals/frostdb/table_test.go:361
                                                        /Users/brancz/src/github.com/polarsignals/frostdb/table.go:751
                                                        /Users/brancz/src/github.com/polarsignals/frostdb/table_test.go:348
                Error:          Not equal:
                                expected: 3
                                actual  : 4
                Test:           Test_Table_ReadIsolation
```


Discussion:

Patch:
diff --git a/db.go b/db.go
--- a/db.go
+++ b/db.go
@@ -1266,6 +1266,7 @@ func (db *DB) begin() (uint64, uint64, func()) {
 		if mark := db.highWatermark.Load(); mark+1 == txn {
 			// This is the next consecutive transaction; increase the watermark.
 			db.highWatermark.Store(txn)
+			return
 		}
 
 		// place completed transaction in the waiting pool


Test patch:
diff --git a/table_test.go b/table_test.go
--- a/table_test.go
+++ b/table_test.go
@@ -272,43 +272,7 @@ func Test_Table_ReadIsolation(t *testing.T) {
 	c, table := basicTable(t)
 	defer c.Close()
 
-	samples := dynparquet.Samples{{
-		Labels: map[string]string{
-			"label1": "value1",
-			"label2": "value2",
-		},
-		Stacktrace: []uuid.UUID{
-			{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1},
-			{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2},
-		},
-		Timestamp: 1,
-		Value:     1,
-	}, {
-		Labels: map[string]string{
-			"label1": "value2",
-			"label2": "value2",
-			"label3": "value3",
-		},
-		Stacktrace: []uuid.UUID{
-			{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1},
-			{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2},
-		},
-		Timestamp: 2,
-		Value:     2,
-	}, {
-		Labels: map[string]string{
-			"label1": "value3",
-			"label2": "value2",
-			"label4": "value4",
-		},
-		Stacktrace: []uuid.UUID{
-			{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1},
-			{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2},
-		},
-		Timestamp: 3,
-		Value:     3,
-	}}
-
+	samples := dynparquet.GenerateTestSamples(3)
 	r, err := samples.ToRecord()
 	require.NoError(t, err)
 
@@ -318,18 +282,7 @@ func Test_Table_ReadIsolation(t *testing.T) {
 	require.NoError(t, err)
 
 	// Perform a new insert that will have a higher tx id
-	samples = dynparquet.Samples{{
-		Labels: map[string]string{
-			"blarg": "blarg",
-			"blah":  "blah",
-		},
-		Stacktrace: []uuid.UUID{
-			{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1},
-			{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2},
-		},
-		Timestamp: 1,
-		Value:     1,
-	}}
+	samples = dynparquet.GenerateTestSamples(1)
 
 	r, err = samples.ToRecord()
 	require.NoError(t, err)
@@ -339,12 +292,10 @@ func Test_Table_ReadIsolation(t *testing.T) {
 
 	table.db.Wait(tx)
 
-	// Now we cheat and reset our tx and watermark
-	table.db.tx.Store(2)
-	table.db.highWatermark.Store(2)
+	// Reset the database to the previous tx
+	table.db.resetToTxn(tx-1, nil)
 
 	pool := memory.NewGoAllocator()
-
 	err = table.View(ctx, func(ctx context.Context, tx uint64) error {
 		rows := int64(0)
 		err = table.Iterator(
@@ -353,7 +304,6 @@ func Test_Table_ReadIsolation(t *testing.T) {
 			pool,
 			[]logicalplan.Callback{func(ctx context.Context, ar arrow.Record) error {
 				rows += ar.NumRows()
-
 				return nil
 			}},
 		)