Skip to content

Commit d33efba

Browse files
authored
[extension/storage/filestorage] Ensure fsync is turned on after compaction (#31185)
**Description:** Fsync was added to filestorage, but during compaction the database is re-opened which doesn't carry over the fsync configuration but always sets it to false(!) **Link to tracking Issue:** #20266 **Testing:** - **Documentation:** -
1 parent 2d8ba25 commit d33efba

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

.chloggen/ensure-fsync.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: extension/storage
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Ensure fsync is turned on after compaction
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [20266]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

extension/storage/filestorage/client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ type fileStorageClient struct {
3737
closed bool
3838
}
3939

40-
func bboltOptions(timeout time.Duration, fSync bool) *bbolt.Options {
40+
func bboltOptions(timeout time.Duration, noSync bool) *bbolt.Options {
4141
return &bbolt.Options{
4242
Timeout: timeout,
43-
NoSync: !fSync,
43+
NoSync: noSync,
4444
NoFreelistSync: true,
4545
FreelistType: bbolt.FreelistMapType,
4646
}
4747
}
4848

49-
func newClient(logger *zap.Logger, filePath string, timeout time.Duration, compactionCfg *CompactionConfig, fSync bool) (*fileStorageClient, error) {
50-
options := bboltOptions(timeout, fSync)
49+
func newClient(logger *zap.Logger, filePath string, timeout time.Duration, compactionCfg *CompactionConfig, noSync bool) (*fileStorageClient, error) {
50+
options := bboltOptions(timeout, noSync)
5151
db, err := bbolt.Open(filePath, 0600, options)
5252
if err != nil {
5353
return nil, err
@@ -172,7 +172,7 @@ func (c *fileStorageClient) Compact(compactionDirectory string, timeout time.Dur
172172
}()
173173

174174
// use temporary file as compaction target
175-
options := bboltOptions(timeout, false)
175+
options := bboltOptions(timeout, c.db.NoSync)
176176

177177
c.compactionMutex.Lock()
178178
defer c.compactionMutex.Unlock()

extension/storage/filestorage/extension.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (lfs *localFileStorage) GetClient(_ context.Context, kind component.Kind, e
6464
rawName = sanitize(rawName)
6565
}
6666
absoluteName := filepath.Join(lfs.cfg.Directory, rawName)
67-
client, err := newClient(lfs.logger, absoluteName, lfs.cfg.Timeout, lfs.cfg.Compaction, lfs.cfg.FSync)
67+
client, err := newClient(lfs.logger, absoluteName, lfs.cfg.Timeout, lfs.cfg.Compaction, !lfs.cfg.FSync)
6868

6969
if err != nil {
7070
return nil, err

0 commit comments

Comments
 (0)