Skip to content

Commit 52cdf9e

Browse files
remoteobjcat: sync directory before marker move in createNewCatalogFileLocked
Without a directory sync before the marker move, a crash could leave the marker pointing to a non-existent catalog file on filesystems with unordered metadata updates. Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
1 parent 1438bc9 commit 52cdf9e

11 files changed

Lines changed: 33 additions & 1 deletion

File tree

objstorage/objstorageprovider/remoteobjcat/catalog.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,15 @@ func (c *Catalog) createNewCatalogFileLocked() (outErr error) {
351351
if err := writeRecord(&ve, file, recWriter); err != nil {
352352
return err
353353
}
354-
354+
// Sync the directory to ensure the catalog file is durable before creating
355+
// the marker that references it. This prevents a crash from leaving the
356+
// marker pointing to a non-existent catalog file. Without this sync, both
357+
// the catalog and marker files would be unsynced until Move() completes,
358+
// creating a race where a crash could include the marker but not the
359+
// catalog on filesystems with unordered metadata updates.
360+
if err := c.mu.marker.SyncDir(); err != nil {
361+
return err
362+
}
355363
// Move the marker to the new filename. Move handles syncing the data
356364
// directory as well.
357365
if err := c.mu.marker.Move(filename); err != nil {

objstorage/objstorageprovider/remoteobjcat/testdata/catalog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ add 1 10 100
99
----
1010
create: test/REMOTE-OBJ-CATALOG-000001
1111
sync: test/REMOTE-OBJ-CATALOG-000001
12+
sync: test
1213
create: test/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
1314
sync: test/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
1415
close: test/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
@@ -80,6 +81,7 @@ add 8 80 80
8081
----
8182
create: test/REMOTE-OBJ-CATALOG-000002
8283
sync: test/REMOTE-OBJ-CATALOG-000002
84+
sync: test
8385
create: test/marker.remote-obj-catalog.000002.REMOTE-OBJ-CATALOG-000002
8486
sync: test/marker.remote-obj-catalog.000002.REMOTE-OBJ-CATALOG-000002
8587
close: test/marker.remote-obj-catalog.000002.REMOTE-OBJ-CATALOG-000002
@@ -117,6 +119,7 @@ add 5 50 500
117119
----
118120
create: other-path/REMOTE-OBJ-CATALOG-000001
119121
sync: other-path/REMOTE-OBJ-CATALOG-000001
122+
sync: other-path
120123
create: other-path/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
121124
sync: other-path/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
122125
close: other-path/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
@@ -163,6 +166,7 @@ random-batches n=20 size=2000
163166
----
164167
create: test/REMOTE-OBJ-CATALOG-000003
165168
sync: test/REMOTE-OBJ-CATALOG-000003
169+
sync: test
166170
create: test/marker.remote-obj-catalog.000003.REMOTE-OBJ-CATALOG-000003
167171
sync: test/marker.remote-obj-catalog.000003.REMOTE-OBJ-CATALOG-000003
168172
close: test/marker.remote-obj-catalog.000003.REMOTE-OBJ-CATALOG-000003
@@ -189,6 +193,7 @@ sync: test/REMOTE-OBJ-CATALOG-000003
189193
close: test/REMOTE-OBJ-CATALOG-000003
190194
create: test/REMOTE-OBJ-CATALOG-000004
191195
sync: test/REMOTE-OBJ-CATALOG-000004
196+
sync: test
192197
create: test/marker.remote-obj-catalog.000004.REMOTE-OBJ-CATALOG-000004
193198
sync: test/marker.remote-obj-catalog.000004.REMOTE-OBJ-CATALOG-000004
194199
close: test/marker.remote-obj-catalog.000004.REMOTE-OBJ-CATALOG-000004
@@ -223,6 +228,7 @@ sync: test/REMOTE-OBJ-CATALOG-000004
223228
close: test/REMOTE-OBJ-CATALOG-000004
224229
create: test/REMOTE-OBJ-CATALOG-000005
225230
sync: test/REMOTE-OBJ-CATALOG-000005
231+
sync: test
226232
create: test/marker.remote-obj-catalog.000005.REMOTE-OBJ-CATALOG-000005
227233
sync: test/marker.remote-obj-catalog.000005.REMOTE-OBJ-CATALOG-000005
228234
close: test/marker.remote-obj-catalog.000005.REMOTE-OBJ-CATALOG-000005
@@ -248,6 +254,7 @@ sync: test/REMOTE-OBJ-CATALOG-000005
248254
close: test/REMOTE-OBJ-CATALOG-000005
249255
create: test/REMOTE-OBJ-CATALOG-000006
250256
sync: test/REMOTE-OBJ-CATALOG-000006
257+
sync: test
251258
create: test/marker.remote-obj-catalog.000006.REMOTE-OBJ-CATALOG-000006
252259
sync: test/marker.remote-obj-catalog.000006.REMOTE-OBJ-CATALOG-000006
253260
close: test/marker.remote-obj-catalog.000006.REMOTE-OBJ-CATALOG-000006
@@ -259,6 +266,7 @@ sync: test/REMOTE-OBJ-CATALOG-000006
259266
close: test/REMOTE-OBJ-CATALOG-000006
260267
create: test/REMOTE-OBJ-CATALOG-000007
261268
sync: test/REMOTE-OBJ-CATALOG-000007
269+
sync: test
262270
create: test/marker.remote-obj-catalog.000007.REMOTE-OBJ-CATALOG-000007
263271
sync: test/marker.remote-obj-catalog.000007.REMOTE-OBJ-CATALOG-000007
264272
close: test/marker.remote-obj-catalog.000007.REMOTE-OBJ-CATALOG-000007
@@ -272,6 +280,7 @@ sync: test/REMOTE-OBJ-CATALOG-000007
272280
close: test/REMOTE-OBJ-CATALOG-000007
273281
create: test/REMOTE-OBJ-CATALOG-000008
274282
sync: test/REMOTE-OBJ-CATALOG-000008
283+
sync: test
275284
create: test/marker.remote-obj-catalog.000008.REMOTE-OBJ-CATALOG-000008
276285
sync: test/marker.remote-obj-catalog.000008.REMOTE-OBJ-CATALOG-000008
277286
close: test/marker.remote-obj-catalog.000008.REMOTE-OBJ-CATALOG-000008

objstorage/objstorageprovider/testdata/provider/local_readahead

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ open dir=p1 creator-id=1
55
<local fs> open-dir: p1
66
<local fs> create: p1/REMOTE-OBJ-CATALOG-000001
77
<local fs> sync: p1/REMOTE-OBJ-CATALOG-000001
8+
<local fs> sync: p1
89
<local fs> create: p1/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
910
<local fs> sync: p1/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
1011
<local fs> close: p1/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001

objstorage/objstorageprovider/testdata/provider/shared_attach

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ open dir=p1 creator-id=1
88
<local fs> open-dir: p1
99
<local fs> create: p1/REMOTE-OBJ-CATALOG-000001
1010
<local fs> sync: p1/REMOTE-OBJ-CATALOG-000001
11+
<local fs> sync: p1
1112
<local fs> create: p1/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
1213
<local fs> sync: p1/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
1314
<local fs> close: p1/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
@@ -77,6 +78,7 @@ open dir=p2 creator-id=2
7778
<local fs> open-dir: p2
7879
<local fs> create: p2/REMOTE-OBJ-CATALOG-000001
7980
<local fs> sync: p2/REMOTE-OBJ-CATALOG-000001
81+
<local fs> sync: p2
8082
<local fs> create: p2/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
8183
<local fs> sync: p2/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
8284
<local fs> close: p2/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001

objstorage/objstorageprovider/testdata/provider/shared_attach_after_unref

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ open dir=p5 creator-id=5
77
<local fs> open-dir: p5
88
<local fs> create: p5/REMOTE-OBJ-CATALOG-000001
99
<local fs> sync: p5/REMOTE-OBJ-CATALOG-000001
10+
<local fs> sync: p5
1011
<local fs> create: p5/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
1112
<local fs> sync: p5/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
1213
<local fs> close: p5/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
@@ -34,6 +35,7 @@ open dir=p6 creator-id=6
3435
<local fs> open-dir: p6
3536
<local fs> create: p6/REMOTE-OBJ-CATALOG-000001
3637
<local fs> sync: p6/REMOTE-OBJ-CATALOG-000001
38+
<local fs> sync: p6
3739
<local fs> create: p6/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
3840
<local fs> sync: p6/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
3941
<local fs> close: p6/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001

objstorage/objstorageprovider/testdata/provider/shared_attach_multi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ open dir=p1 creator-id=1
77
<local fs> open-dir: p1
88
<local fs> create: p1/REMOTE-OBJ-CATALOG-000001
99
<local fs> sync: p1/REMOTE-OBJ-CATALOG-000001
10+
<local fs> sync: p1
1011
<local fs> create: p1/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
1112
<local fs> sync: p1/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
1213
<local fs> close: p1/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
@@ -30,6 +31,7 @@ open dir=p2 creator-id=2
3031
<local fs> open-dir: p2
3132
<local fs> create: p2/REMOTE-OBJ-CATALOG-000001
3233
<local fs> sync: p2/REMOTE-OBJ-CATALOG-000001
34+
<local fs> sync: p2
3335
<local fs> create: p2/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
3436
<local fs> sync: p2/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
3537
<local fs> close: p2/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001

objstorage/objstorageprovider/testdata/provider/shared_basic

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ open dir=p1 creator-id=1
77
<local fs> open-dir: p1
88
<local fs> create: p1/REMOTE-OBJ-CATALOG-000001
99
<local fs> sync: p1/REMOTE-OBJ-CATALOG-000001
10+
<local fs> sync: p1
1011
<local fs> create: p1/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
1112
<local fs> sync: p1/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
1213
<local fs> close: p1/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
@@ -123,6 +124,7 @@ close
123124
<local fs> sync: p1
124125
<local fs> create: p1/REMOTE-OBJ-CATALOG-000002
125126
<local fs> sync: p1/REMOTE-OBJ-CATALOG-000002
127+
<local fs> sync: p1
126128
<local fs> create: p1/marker.remote-obj-catalog.000002.REMOTE-OBJ-CATALOG-000002
127129
<local fs> sync: p1/marker.remote-obj-catalog.000002.REMOTE-OBJ-CATALOG-000002
128130
<local fs> close: p1/marker.remote-obj-catalog.000002.REMOTE-OBJ-CATALOG-000002

objstorage/objstorageprovider/testdata/provider/shared_no_ref

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ open dir=p1 creator-id=1
77
<local fs> open-dir: p1
88
<local fs> create: p1/REMOTE-OBJ-CATALOG-000001
99
<local fs> sync: p1/REMOTE-OBJ-CATALOG-000001
10+
<local fs> sync: p1
1011
<local fs> create: p1/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
1112
<local fs> sync: p1/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
1213
<local fs> close: p1/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
@@ -134,6 +135,7 @@ open dir=p2 creator-id=2
134135
<local fs> open-dir: p2
135136
<local fs> create: p2/REMOTE-OBJ-CATALOG-000001
136137
<local fs> sync: p2/REMOTE-OBJ-CATALOG-000001
138+
<local fs> sync: p2
137139
<local fs> create: p2/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
138140
<local fs> sync: p2/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
139141
<local fs> close: p2/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001

objstorage/objstorageprovider/testdata/provider/shared_readahead

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ open dir=p1 creator-id=1
55
<local fs> open-dir: p1
66
<local fs> create: p1/REMOTE-OBJ-CATALOG-000001
77
<local fs> sync: p1/REMOTE-OBJ-CATALOG-000001
8+
<local fs> sync: p1
89
<local fs> create: p1/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
910
<local fs> sync: p1/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
1011
<local fs> close: p1/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001

objstorage/objstorageprovider/testdata/provider/shared_remove

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ open dir=p1 creator-id=1
55
<local fs> open-dir: p1
66
<local fs> create: p1/REMOTE-OBJ-CATALOG-000001
77
<local fs> sync: p1/REMOTE-OBJ-CATALOG-000001
8+
<local fs> sync: p1
89
<local fs> create: p1/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
910
<local fs> sync: p1/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
1011
<local fs> close: p1/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
@@ -45,6 +46,7 @@ open dir=p2 creator-id=2
4546
<local fs> open-dir: p2
4647
<local fs> create: p2/REMOTE-OBJ-CATALOG-000001
4748
<local fs> sync: p2/REMOTE-OBJ-CATALOG-000001
49+
<local fs> sync: p2
4850
<local fs> create: p2/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
4951
<local fs> sync: p2/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001
5052
<local fs> close: p2/marker.remote-obj-catalog.000001.REMOTE-OBJ-CATALOG-000001

0 commit comments

Comments
 (0)