Skip to content

Commit 0678231

Browse files
authored
[filestorage] - Add directory validation for compaction on-rebound (#35114)
**Description:** Currently, we only verify the existence of the compaction directory when `compaction.on_start` is enabled. This check should also be performed when `compaction.on_rebound` is enabled. Otherwise, we encounter continuous error notifications due to the directory not existing, which results in compaction failures. **Testing:** Added
1 parent ede416f commit 0678231

File tree

3 files changed

+92
-1
lines changed

3 files changed

+92
-1
lines changed
+27
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: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: filestorage
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Add directory validation for compaction on-rebound
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: [35114]
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: []

extension/storage/filestorage/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type CompactionConfig struct {
5353

5454
func (cfg *Config) Validate() error {
5555
var dirs []string
56-
if cfg.Compaction.OnStart {
56+
if cfg.Compaction.OnStart || cfg.Compaction.OnRebound {
5757
dirs = []string{cfg.Directory, cfg.Compaction.Directory}
5858
} else {
5959
dirs = []string{cfg.Directory}

extension/storage/filestorage/config_test.go

+64
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,67 @@ func TestHandleProvidingFilePathAsDirWithAnError(t *testing.T) {
9595
require.Error(t, err)
9696
require.EqualError(t, err, file.Name()+" is not a directory")
9797
}
98+
99+
func TestCompactionDirectory(t *testing.T) {
100+
f := NewFactory()
101+
tests := []struct {
102+
name string
103+
config func(*testing.T) *Config
104+
err error
105+
}{
106+
{
107+
name: "directory-must-exists-error",
108+
config: func(t *testing.T) *Config {
109+
cfg := f.CreateDefaultConfig().(*Config)
110+
cfg.Directory = t.TempDir() // actual directory
111+
cfg.Compaction.Directory = "/not/a/dir" // not a directory
112+
cfg.Compaction.OnRebound = true
113+
cfg.Compaction.OnStart = true
114+
return cfg
115+
},
116+
err: os.ErrNotExist,
117+
},
118+
{
119+
name: "directory-must-exists-error-on-start",
120+
config: func(t *testing.T) *Config {
121+
cfg := f.CreateDefaultConfig().(*Config)
122+
cfg.Directory = t.TempDir() // actual directory
123+
cfg.Compaction.Directory = "/not/a/dir" // not a directory
124+
cfg.Compaction.OnRebound = false
125+
cfg.Compaction.OnStart = true
126+
return cfg
127+
},
128+
err: os.ErrNotExist,
129+
},
130+
{
131+
name: "directory-must-exists-error-on-rebound",
132+
config: func(t *testing.T) *Config {
133+
cfg := f.CreateDefaultConfig().(*Config)
134+
cfg.Directory = t.TempDir() // actual directory
135+
cfg.Compaction.Directory = "/not/a/dir" // not a directory
136+
cfg.Compaction.OnRebound = true
137+
cfg.Compaction.OnStart = false
138+
return cfg
139+
},
140+
err: os.ErrNotExist,
141+
},
142+
{
143+
name: "compaction-disabled-no-error",
144+
config: func(t *testing.T) *Config {
145+
cfg := f.CreateDefaultConfig().(*Config)
146+
cfg.Directory = t.TempDir() // actual directory
147+
cfg.Compaction.Directory = "/not/a/dir" // not a directory
148+
cfg.Compaction.OnRebound = false
149+
cfg.Compaction.OnStart = false
150+
return cfg
151+
},
152+
err: nil,
153+
},
154+
}
155+
for _, test := range tests {
156+
t.Run(test.name, func(t *testing.T) {
157+
require.ErrorIs(t, component.ValidateConfig(test.config(t)), test.err)
158+
})
159+
}
160+
161+
}

0 commit comments

Comments
 (0)