Skip to content

Commit ace719f

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

File tree

8 files changed

+60
-37
lines changed

8 files changed

+60
-37
lines changed

internal/api/syncapi/syncclient.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,17 @@ func NewSyncClient(mgr *SyncManager, localInstanceID string, peer *v1.Multihost_
6262
peer.GetInstanceUrl(),
6363
)
6464

65-
return &SyncClient{
65+
c := &SyncClient{
6666
mgr: mgr,
6767
localInstanceID: localInstanceID,
6868
peer: peer,
6969
reconnectDelay: mgr.syncClientRetryDelay,
7070
client: client,
7171
oplog: oplog,
7272
l: zap.L().Named(fmt.Sprintf("syncclient for %q", peer.GetInstanceId())),
73-
}, nil
73+
}
74+
c.setConnectionState(v1.SyncConnectionState_CONNECTION_STATE_DISCONNECTED, "starting up")
75+
return c, nil
7476
}
7577

7678
func (c *SyncClient) setConnectionState(state v1.SyncConnectionState, message string) {
@@ -116,6 +118,7 @@ func (c *SyncClient) runSyncInternal(ctx context.Context) error {
116118
stream := c.client.Sync(ctx)
117119

118120
ctx, cancelWithError := context.WithCancelCause(ctx)
121+
defer cancelWithError(nil)
119122

120123
receiveError := make(chan error, 1)
121124
receive := make(chan *v1.SyncStreamItem, 1)

internal/api/syncapi/syncmanager.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,16 @@ func (m *SyncManager) runSyncWithPeerInternal(ctx context.Context, config *v1.Co
121121
if err != nil {
122122
return fmt.Errorf("creating sync client: %w", err)
123123
}
124+
m.mu.Lock()
124125
m.syncClients[knownHostPeer.InstanceId] = newClient
126+
m.mu.Unlock()
125127

126-
go newClient.RunSync(ctx)
128+
go func() {
129+
newClient.RunSync(ctx)
130+
m.mu.Lock()
131+
delete(m.syncClients, knownHostPeer.InstanceId)
132+
m.mu.Unlock()
133+
}()
127134

128135
return nil
129136
}

internal/oplog/oplog.go

+4
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,14 @@ func (o *OpLog) QueryMetadata(q Query, f func(OpMetadata) error) error {
7979
}
8080

8181
func (o *OpLog) Subscribe(q Query, f *Subscription) {
82+
o.subscribersMu.Lock()
83+
defer o.subscribersMu.Unlock()
8284
o.subscribers = append(o.subscribers, subAndQuery{f: f, q: q})
8385
}
8486

8587
func (o *OpLog) Unsubscribe(f *Subscription) error {
88+
o.subscribersMu.Lock()
89+
defer o.subscribersMu.Unlock()
8690
for i, sub := range o.subscribers {
8791
if sub.f == f {
8892
o.subscribers = append(o.subscribers[:i], o.subscribers[i+1:]...)

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+
}

scripts/testing/ramdisk-mount.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ fi
1515

1616
# Check if MacOS
1717
if [ "$(uname)" = "Darwin" ]; then
18-
if [ -d "/Volumes/RAM_Disk_512MB" ]; then
19-
echo "RAM disk /Volumes/RAM_Disk_512MB already exists."
18+
if [ -d "/Volumes/RAM_Disk_1GB" ]; then
19+
echo "RAM disk /Volumes/RAM_Disk_1GB already exists."
2020
else
21-
sudo diskutil erasevolume HFS+ RAM_Disk_512MB $(hdiutil attach -nomount ram://1048576)
21+
sudo diskutil erasevolume HFS+ RAM_Disk_1GB $(hdiutil attach -nomount ram://2048000)
2222
fi
23-
export TMPDIR="/Volumes/RAM_Disk_512MB"
23+
export TMPDIR="/Volumes/RAM_Disk_1GB"
2424
export RESTIC_CACHE_DIR="$TMPDIR/.cache"
25-
echo "Created 512MB RAM disk at /Volumes/RAM_Disk_512MB"
25+
echo "Created 512MB RAM disk at /Volumes/RAM_Disk_1GB"
2626
echo "TMPDIR=$TMPDIR"
2727
echo "RESTIC_CACHE_DIR=$RESTIC_CACHE_DIR"
2828
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
2929
# Create ramdisk
3030
sudo mkdir -p /mnt/ramdisk
31-
sudo mount -t tmpfs -o size=512M tmpfs /mnt/ramdisk
31+
sudo mount -t tmpfs -o size=1024M tmpfs /mnt/ramdisk
3232
export TMPDIR="/mnt/ramdisk"
3333
export RESTIC_CACHE_DIR="$TMPDIR/.cache"
3434
fi

scripts/testing/ramdisk-unmount.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ fi
1515

1616
# Check if MacOS
1717
if [ "$(uname)" = "Darwin" ]; then
18-
sudo diskutil unmount /Volumes/RAM_Disk_512MB
19-
hdiutil detach /Volumes/RAM_Disk_512MB
18+
sudo diskutil unmount /Volumes/RAM_Disk_1GB
19+
hdiutil detach /Volumes/RAM_Disk_1GB
2020
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
2121
sudo umount /mnt/ramdisk
2222
fi
2323

2424
unset TMPDIR
25-
unset XDG_CACHE_HOME
25+
unset XDG_CACHE_HOME

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)