Skip to content

Commit e3620f6

Browse files
committed
chore: misc prerelease fixes
1 parent b8acc12 commit e3620f6

File tree

3 files changed

+34
-25
lines changed

3 files changed

+34
-25
lines changed

internal/oplog/sqlitestore/sqlitestore.go

+4-21
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ type SqliteStore struct {
3030
dbpool *sqlitex.Pool
3131
lastIDVal atomic.Int64
3232
dblock *flock.Flock
33-
querymu sync.RWMutex
3433

3534
ogidCache *lru.TwoQueueCache[opGroupInfo, int64]
3635

@@ -222,8 +221,6 @@ func (m *SqliteStore) buildQueryWhereClause(q oplog.Query, includeSelectClauses
222221
}
223222

224223
func (m *SqliteStore) Query(q oplog.Query, f func(*v1.Operation) error) error {
225-
m.querymu.RLock()
226-
defer m.querymu.RUnlock()
227224
conn, err := m.dbpool.Take(context.Background())
228225
if err != nil {
229226
return fmt.Errorf("query: %v", err)
@@ -251,8 +248,6 @@ func (m *SqliteStore) Query(q oplog.Query, f func(*v1.Operation) error) error {
251248
}
252249

253250
func (m *SqliteStore) QueryMetadata(q oplog.Query, f func(oplog.OpMetadata) error) error {
254-
m.querymu.RLock()
255-
defer m.querymu.RUnlock()
256251
conn, err := m.dbpool.Take(context.Background())
257252
if err != nil {
258253
return fmt.Errorf("query metadata: %v", err)
@@ -323,16 +318,14 @@ func (m *SqliteStore) findOrCreateGroup(conn *sqlite.Conn, op *v1.Operation) (og
323318
}
324319

325320
func (m *SqliteStore) Transform(q oplog.Query, f func(*v1.Operation) (*v1.Operation, error)) error {
326-
m.querymu.Lock()
327-
defer m.querymu.Unlock()
328321
conn, err := m.dbpool.Take(context.Background())
329322
if err != nil {
330323
return fmt.Errorf("transform: %v", err)
331324
}
332325
defer m.dbpool.Put(conn)
333326

334327
where, args := m.buildQueryWhereClause(q, true)
335-
return withSqliteTransaction(conn, func() error {
328+
return withImmediateSqliteTransaction(conn, func() error {
336329
return sqlitex.ExecuteTransient(conn, "SELECT operations.operation FROM operations JOIN operation_groups ON operations.ogid = operation_groups.ogid WHERE "+where, &sqlitex.ExecOptions{
337330
Args: args,
338331
ResultFunc: func(stmt *sqlite.Stmt) error {
@@ -391,15 +384,13 @@ func (m *SqliteStore) addInternal(conn *sqlite.Conn, op ...*v1.Operation) error
391384
}
392385

393386
func (m *SqliteStore) Add(op ...*v1.Operation) error {
394-
m.querymu.Lock()
395-
defer m.querymu.Unlock()
396387
conn, err := m.dbpool.Take(context.Background())
397388
if err != nil {
398389
return fmt.Errorf("add operation: %v", err)
399390
}
400391
defer m.dbpool.Put(conn)
401392

402-
return withSqliteTransaction(conn, func() error {
393+
return withImmediateSqliteTransaction(conn, func() error {
403394
for _, o := range op {
404395
o.Id = m.lastIDVal.Add(1)
405396
if o.FlowId == 0 {
@@ -415,15 +406,13 @@ func (m *SqliteStore) Add(op ...*v1.Operation) error {
415406
}
416407

417408
func (m *SqliteStore) Update(op ...*v1.Operation) error {
418-
m.querymu.Lock()
419-
defer m.querymu.Unlock()
420409
conn, err := m.dbpool.Take(context.Background())
421410
if err != nil {
422411
return fmt.Errorf("update operation: %v", err)
423412
}
424413
defer m.dbpool.Put(conn)
425414

426-
return withSqliteTransaction(conn, func() error {
415+
return withImmediateSqliteTransaction(conn, func() error {
427416
return m.updateInternal(conn, op...)
428417
})
429418
}
@@ -456,8 +445,6 @@ func (m *SqliteStore) updateInternal(conn *sqlite.Conn, op ...*v1.Operation) err
456445
}
457446

458447
func (m *SqliteStore) Get(opID int64) (*v1.Operation, error) {
459-
m.querymu.RLock()
460-
defer m.querymu.RUnlock()
461448
conn, err := m.dbpool.Take(context.Background())
462449
if err != nil {
463450
return nil, fmt.Errorf("get operation: %v", err)
@@ -491,16 +478,14 @@ func (m *SqliteStore) Get(opID int64) (*v1.Operation, error) {
491478
}
492479

493480
func (m *SqliteStore) Delete(opID ...int64) ([]*v1.Operation, error) {
494-
m.querymu.Lock()
495-
defer m.querymu.Unlock()
496481
conn, err := m.dbpool.Take(context.Background())
497482
if err != nil {
498483
return nil, fmt.Errorf("delete operation: %v", err)
499484
}
500485
defer m.dbpool.Put(conn)
501486

502487
ops := make([]*v1.Operation, 0, len(opID))
503-
return ops, withSqliteTransaction(conn, func() error {
488+
return ops, withImmediateSqliteTransaction(conn, func() error {
504489
// fetch all the operations we're about to delete
505490
predicate := []string{"operations.id IN ("}
506491
args := []any{}
@@ -548,8 +533,6 @@ func (m *SqliteStore) Delete(opID ...int64) ([]*v1.Operation, error) {
548533
}
549534

550535
func (m *SqliteStore) ResetForTest(t *testing.T) error {
551-
m.querymu.Lock()
552-
defer m.querymu.Unlock()
553536
conn, err := m.dbpool.Take(context.Background())
554537
if err != nil {
555538
return fmt.Errorf("reset for test: %v", err)

internal/oplog/sqlitestore/sqlutil.go

+23
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,33 @@ import (
55
"zombiezen.com/go/sqlite/sqlitex"
66
)
77

8+
// withSqliteTransaction should be used when the function only executes reads
89
func withSqliteTransaction(conn *sqlite.Conn, f func() error) error {
910
var err error
1011
endFunc := sqlitex.Transaction(conn)
1112
err = f()
1213
endFunc(&err)
1314
return err
1415
}
16+
17+
func withImmediateSqliteTransaction(conn *sqlite.Conn, f func() error) error {
18+
var err error
19+
endFunc, err := sqlitex.ImmediateTransaction(conn)
20+
if err != nil {
21+
return err
22+
}
23+
err = f()
24+
endFunc(&err)
25+
return err
26+
}
27+
28+
func withExclusiveSqliteTransaction(conn *sqlite.Conn, f func() error) error {
29+
var err error
30+
endFunc, err := sqlitex.ExclusiveTransaction(conn)
31+
if err != nil {
32+
return err
33+
}
34+
err = f()
35+
endFunc(&err)
36+
return err
37+
}

webui/src/components/OperationTreeView.tsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,15 @@ export const OperationTreeView = ({
126126
const otherTrees: React.ReactNode[] = [];
127127

128128
for (const instance of Object.keys(backupsByInstance)) {
129-
const instanceOps = backupsByInstance[instance];
129+
const instanceBackups = backupsByInstance[instance];
130130
const instTree = (
131131
<DisplayOperationTree
132-
operations={backups}
132+
operations={instanceBackups}
133133
isPlanView={isPlanView}
134134
onSelect={(flow) => {
135135
setSelectedBackupId(flow ? flow.flowID : null);
136136
}}
137+
expand={instance === config!.instance}
137138
/>
138139
);
139140

@@ -205,10 +206,12 @@ const DisplayOperationTree = ({
205206
operations,
206207
isPlanView,
207208
onSelect,
209+
expand,
208210
}: {
209211
operations: FlowDisplayInfo[];
210212
isPlanView?: boolean;
211213
onSelect?: (flow: FlowDisplayInfo | null) => any;
214+
expand?: boolean;
212215
}) => {
213216
const [treeData, setTreeData] = useState<{
214217
tree: OpTreeNode[];
@@ -237,7 +240,7 @@ const DisplayOperationTree = ({
237240
<Tree<OpTreeNode>
238241
treeData={treeData.tree}
239242
showIcon
240-
defaultExpandedKeys={treeData.expanded}
243+
defaultExpandedKeys={expand ? treeData.expanded : []}
241244
onSelect={(keys, info) => {
242245
if (info.selectedNodes.length === 0) return;
243246
const backup = info.selectedNodes[0].backup;
@@ -433,7 +436,7 @@ const buildTree = (
433436
expanded = expandTree(tree, 5, 0, 2);
434437
} else {
435438
tree = buildTreePlan(operations);
436-
expanded = expandTree(tree, 5, 2, 4);
439+
expanded = expandTree(tree, 5, 1, 3);
437440
}
438441
return { tree, expanded };
439442
};

0 commit comments

Comments
 (0)