-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wal): move wal file to a temporary file when WAL replay failed (#…
…508) * feat(wal): move corrupted wal files to a temporary file
- Loading branch information
Showing
10 changed files
with
201 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package wal | ||
|
||
import ( | ||
"fmt" | ||
"io/fs" | ||
"path/filepath" | ||
|
||
"github.com/alpacahq/marketstore/v4/utils/log" | ||
) | ||
|
||
type Finder struct { | ||
dirRead func(dir string) ([]fs.FileInfo, error) | ||
} | ||
|
||
func NewFinder(dirRead func(dir string) ([]fs.FileInfo, error)) *Finder { | ||
return &Finder{dirRead: dirRead} | ||
} | ||
|
||
// Find returns all absolute paths to "*.walfile" files directly under the directory. | ||
func (f *Finder) Find(dir string) ([]string, error) { | ||
var ret []string | ||
//files, err := ioutil.ReadDir(rootDir) | ||
files, err := f.dirRead(dir) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to read the directory %s: %w", dir, err) | ||
} | ||
for _, file := range files { | ||
// ignore directories | ||
if file.IsDir() { | ||
// ignore | ||
continue | ||
} | ||
|
||
// ignore files except wal | ||
filename := file.Name() | ||
if filepath.Ext(filename) != ".walfile" { | ||
continue | ||
} | ||
|
||
log.Debug("found a WALFILE: %s", filename) | ||
ret = append(ret, filepath.Join(dir, filename)) | ||
} | ||
return ret, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package wal | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/alpacahq/marketstore/v4/utils/log" | ||
) | ||
|
||
func Move(oldFP, newFP string) error { | ||
err := os.Rename(oldFP, newFP) | ||
if err != nil { | ||
return fmt.Errorf("failed to move %s to %s:%w", oldFP, newFP, err) | ||
} | ||
log.Debug(fmt.Sprintf("moved %s to %s", oldFP, newFP)) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.