Skip to content

Commit 9edd7c9

Browse files
committed
Add noop ExcludePathPatterns option
1 parent e32d5c3 commit 9edd7c9

File tree

8 files changed

+102
-15
lines changed

8 files changed

+102
-15
lines changed

master/medasync/syncer.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type Config struct {
4949
TemporaryDirectory string
5050
GlobalWorkDirectory string
5151
NodeList []string
52+
ExcludePathPatterns []string
5253

5354
// Invocation dependent params
5455

@@ -164,7 +165,7 @@ func (s *Syncer) prepareDatabase(ctx context.Context) error {
164165
}
165166

166167
func (s *Syncer) applyPolicy() (*filelist.CloseParser, error) {
167-
options := []options.PolicyOptioner{
168+
policyOpts := []options.PolicyOptioner{
168169
scaleadpt.PolicyOpt.SnapshotName(s.Config.SnapshotName),
169170
scaleadpt.PolicyOpt.Subpath(s.Config.Subpath),
170171
scaleadpt.PolicyOpt.TempDir(s.Config.TemporaryDirectory),
@@ -180,16 +181,24 @@ func (s *Syncer) applyPolicy() (*filelist.CloseParser, error) {
180181
fields["global_work_directory"] = s.Config.GlobalWorkDirectory
181182
fields["node_list"] = s.Config.NodeList
182183

183-
options = append(
184-
options,
184+
policyOpts = append(
185+
policyOpts,
185186
scaleadpt.PolicyOpt.GlobalWorkDirectory(s.Config.GlobalWorkDirectory),
186187
scaleadpt.PolicyOpt.NodeList(s.Config.NodeList),
187188
)
188189
}
189190

191+
opts := []options.FilelistPolicyOptioner{
192+
filelist.Opt.PolicyOpts(policyOpts...),
193+
}
194+
195+
if len(s.Config.ExcludePathPatterns) > 0 {
196+
opts = append(opts, filelist.Opt.ExcludePathPatterns(s.Config.ExcludePathPatterns))
197+
}
198+
190199
s.fieldLogger.WithFields(fields).Info("Starting applying list policy")
191200

192-
parser, err := filelist.ApplyPolicy(s.Config.FileSystem, options...)
201+
parser, err := filelist.ApplyPolicy(s.Config.FileSystem, opts...)
193202
if err != nil {
194203
return nil, errors.Wrap(err, "(*Syncer).applyPolicy: apply policy on file system")
195204
}

master/medasync/syncer_config_methods.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ func (c *Config) CopyFrom(other *Config) {
44
c.SynchronisationChunkSize = other.SynchronisationChunkSize
55
c.Inserter.CopyFrom(&other.Inserter)
66

7+
c.Subpath = other.Subpath
78
c.TemporaryDirectory = other.TemporaryDirectory
89
c.GlobalWorkDirectory = other.GlobalWorkDirectory
910
c.NodeList = other.NodeList
10-
c.Subpath = other.Subpath
11+
c.ExcludePathPatterns = other.ExcludePathPatterns
1112

1213
c.SnapshotName = other.SnapshotName
1314
c.RunID = other.RunID
@@ -24,6 +25,9 @@ func (c *Config) Merge(other *Config) *Config {
2425
}
2526
c.Inserter.Merge(&other.Inserter)
2627

28+
if len(other.Subpath) > 0 {
29+
c.Subpath = other.Subpath
30+
}
2731
if len(other.TemporaryDirectory) > 0 {
2832
c.TemporaryDirectory = other.TemporaryDirectory
2933
}
@@ -33,8 +37,8 @@ func (c *Config) Merge(other *Config) *Config {
3337
if len(other.NodeList) > 0 {
3438
c.NodeList = other.NodeList
3539
}
36-
if len(other.Subpath) > 0 {
37-
c.Subpath = other.Subpath
40+
if len(other.ExcludePathPatterns) > 0 {
41+
c.ExcludePathPatterns = other.ExcludePathPatterns
3842
}
3943

4044
if len(other.SnapshotName) > 0 {

scaleadpt/filelist/policy.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,22 @@ func (p *CloseParser) Close() error {
5353
}
5454
}
5555

56+
// Opt provides simple access to FilelistPolicyOptioners methods.
57+
var Opt = options.FilelistPolicyOptioners{}
58+
5659
// ApplyPolicy applies the FileListPolicy and returns a CloseParser to read the
5760
// matching files.
5861
// The CloseParser should be closed in all cases (after processing is finished
5962
// or if an error occurs).
60-
func ApplyPolicy(fs *scaleadpt.FileSystem, opts ...options.PolicyOptioner) (*CloseParser, error) {
61-
// Extract TempDir from opts
62-
tempDir := (&options.PolicyOptions{}).Apply(opts).TempDir
63+
func ApplyPolicy(fs *scaleadpt.FileSystem, opts ...options.FilelistPolicyOptioner) (*CloseParser, error) {
64+
optsAggregate := (&options.FilelistPolicyOptions{}).Apply(opts)
65+
66+
// Extract TempDir from PolicyOptions
67+
tempDir := optsAggregate.PolicyOptions.TempDir
6368

6469
listPath := osutils.TouchNonExistingTempFile("scaleadpt-filelist-", ".list.files", tempDir)
6570

66-
err := fs.ApplyListPolicy(FileListPolicy, listPath, opts...)
71+
err := fs.ApplyListPolicy(FileListPolicy, listPath, &optsAggregate.PolicyOptions)
6772
if err != nil {
6873
return nil, err
6974
}

scaleadpt/options/filelist_policy.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package options
2+
3+
// FilelistPolicyOptions is the option aggregate structure for options for
4+
// policy apply operations in the filelist package.
5+
type FilelistPolicyOptions struct {
6+
PolicyOptions PolicyOptions
7+
ExcludePathPatterns []string
8+
}
9+
10+
func (f *FilelistPolicyOptions) Apply(opts []FilelistPolicyOptioner) *FilelistPolicyOptions {
11+
for _, opt := range opts {
12+
opt.apply(f)
13+
}
14+
15+
return f
16+
}
17+
18+
func (f *FilelistPolicyOptions) apply(options *FilelistPolicyOptions) {
19+
*options = *f
20+
}
21+
22+
type FilelistPolicyOptioner interface {
23+
apply(*FilelistPolicyOptions)
24+
}
25+
26+
type filelistPolicyOptionerFunc func(*FilelistPolicyOptions)
27+
28+
func (f filelistPolicyOptionerFunc) apply(options *FilelistPolicyOptions) {
29+
f(options)
30+
}
31+
32+
type FilelistPolicyOptioners struct{}
33+
34+
func (_ FilelistPolicyOptioners) PolicyOpts(opts ...PolicyOptioner) FilelistPolicyOptioner {
35+
return filelistPolicyOptionerFunc(func(options *FilelistPolicyOptions) {
36+
options.PolicyOptions = PolicyOptions{}
37+
options.PolicyOptions.Apply(opts)
38+
})
39+
}
40+
41+
func (_ FilelistPolicyOptioners) ExcludePathPatterns(patterns []string) FilelistPolicyOptioner {
42+
return filelistPolicyOptionerFunc(func(options *FilelistPolicyOptions) {
43+
options.ExcludePathPatterns = patterns
44+
})
45+
}

scaleadpt/options/policy.go

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ func (p *PolicyOptions) Apply(opts []PolicyOptioner) *PolicyOptions {
2727
return p
2828
}
2929

30+
func (p *PolicyOptions) apply(options *PolicyOptions) {
31+
*options = *p
32+
}
33+
3034
type PolicyOptioner interface {
3135
apply(*PolicyOptions)
3236
}

scaleadpt/options/snapshot.go

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ func (s *SnapshotOptions) Apply(opts []SnapshotOptioner) *SnapshotOptions {
1414
return s
1515
}
1616

17+
func (s *SnapshotOptions) apply(options *SnapshotOptions) {
18+
*options = *s
19+
}
20+
1721
type SnapshotOptioner interface {
1822
apply(*SnapshotOptions)
1923
}

tools/scaleadpt-tester/main.go

+16-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"git.scc.kit.edu/sdm/lsdf-checksum/scaleadpt"
1414
"git.scc.kit.edu/sdm/lsdf-checksum/scaleadpt/filelist"
15+
"git.scc.kit.edu/sdm/lsdf-checksum/scaleadpt/options"
1516
)
1617

1718
type Spec struct {
@@ -35,9 +36,10 @@ type SpecSnapshotDirsInfo struct {
3536
}
3637

3738
type SpecListPolicy struct {
38-
Subpath string `yaml:"subpath"`
39-
Files []SpecListPolicyFile `yaml:"files"`
40-
FilesComplete bool `yaml:"files_complete"`
39+
Subpath string `yaml:"subpath"`
40+
Files []SpecListPolicyFile `yaml:"files"`
41+
FilesComplete bool `yaml:"files_complete"`
42+
ExcludePathPatterns []string `yaml:"exclude_path_patterns"`
4143
}
4244

4345
type SpecListPolicyFile struct {
@@ -404,7 +406,17 @@ func (c *Checker) checkListPolicy() {
404406
specFiles[file.Path] = file
405407
}
406408

407-
parser, err := filelist.ApplyPolicy(c.fs, scaleadpt.PolicyOpt.Subpath(c.spec.ListPolicy.Subpath))
409+
options := []options.FilelistPolicyOptioner{
410+
filelist.Opt.PolicyOpts(scaleadpt.PolicyOpt.Subpath(c.spec.ListPolicy.Subpath)),
411+
}
412+
413+
if len(c.spec.ListPolicy.ExcludePathPatterns) > 0 {
414+
options = append(options,
415+
filelist.Opt.ExcludePathPatterns(c.spec.ListPolicy.ExcludePathPatterns),
416+
)
417+
}
418+
419+
parser, err := filelist.ApplyPolicy(c.fs, options...)
408420
if err != nil {
409421
f.AddRuntimeErr(err)
410422
return

tools/scaleadpt-tester/spec.example.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ filesystems:
2323
list_policy:
2424
# Subpath in the filesystem for which to execute the list policy.
2525
subpath: /test-dir
26+
# Optional list of SQL patterns on the filepath with matching files
27+
# excluded from the output.
28+
exclude_path_patterns:
29+
- '%.csv'
2630
# Is the list of files below "complete", i.e. does it describe all files
2731
# in the tree?
2832
files_complete: false

0 commit comments

Comments
 (0)