Skip to content

Commit

Permalink
[filestorage] - Add directory validation for compaction on-rebound (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
VihasMakwana authored Sep 10, 2024
1 parent ede416f commit 0678231
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 1 deletion.
27 changes: 27 additions & 0 deletions .chloggen/add-validation-for-rebound.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: filestorage

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add directory validation for compaction on-rebound

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [35114]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
2 changes: 1 addition & 1 deletion extension/storage/filestorage/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type CompactionConfig struct {

func (cfg *Config) Validate() error {
var dirs []string
if cfg.Compaction.OnStart {
if cfg.Compaction.OnStart || cfg.Compaction.OnRebound {
dirs = []string{cfg.Directory, cfg.Compaction.Directory}
} else {
dirs = []string{cfg.Directory}
Expand Down
64 changes: 64 additions & 0 deletions extension/storage/filestorage/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,67 @@ func TestHandleProvidingFilePathAsDirWithAnError(t *testing.T) {
require.Error(t, err)
require.EqualError(t, err, file.Name()+" is not a directory")
}

func TestCompactionDirectory(t *testing.T) {
f := NewFactory()
tests := []struct {
name string
config func(*testing.T) *Config
err error
}{
{
name: "directory-must-exists-error",
config: func(t *testing.T) *Config {
cfg := f.CreateDefaultConfig().(*Config)
cfg.Directory = t.TempDir() // actual directory
cfg.Compaction.Directory = "/not/a/dir" // not a directory
cfg.Compaction.OnRebound = true
cfg.Compaction.OnStart = true
return cfg
},
err: os.ErrNotExist,
},
{
name: "directory-must-exists-error-on-start",
config: func(t *testing.T) *Config {
cfg := f.CreateDefaultConfig().(*Config)
cfg.Directory = t.TempDir() // actual directory
cfg.Compaction.Directory = "/not/a/dir" // not a directory
cfg.Compaction.OnRebound = false
cfg.Compaction.OnStart = true
return cfg
},
err: os.ErrNotExist,
},
{
name: "directory-must-exists-error-on-rebound",
config: func(t *testing.T) *Config {
cfg := f.CreateDefaultConfig().(*Config)
cfg.Directory = t.TempDir() // actual directory
cfg.Compaction.Directory = "/not/a/dir" // not a directory
cfg.Compaction.OnRebound = true
cfg.Compaction.OnStart = false
return cfg
},
err: os.ErrNotExist,
},
{
name: "compaction-disabled-no-error",
config: func(t *testing.T) *Config {
cfg := f.CreateDefaultConfig().(*Config)
cfg.Directory = t.TempDir() // actual directory
cfg.Compaction.Directory = "/not/a/dir" // not a directory
cfg.Compaction.OnRebound = false
cfg.Compaction.OnStart = false
return cfg
},
err: nil,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
require.ErrorIs(t, component.ValidateConfig(test.config(t)), test.err)
})
}

}

0 comments on commit 0678231

Please sign in to comment.