-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update diskmap/diskslice to use directio on linux. Fix filewatcher ex…
…ample
- Loading branch information
John Doak
authored and
John Doak
committed
Dec 12, 2022
1 parent
316e0a2
commit d49b462
Showing
12 changed files
with
287 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//go:build linux | ||
|
||
package diskmap | ||
|
||
import ( | ||
"bufio" | ||
"os" | ||
"sync" | ||
"syscall" | ||
|
||
"github.com/brk0v/directio" | ||
) | ||
|
||
// New returns a new Writer that writes to file "p". | ||
func New(p string) (Writer, error) { | ||
f, err := os.OpenFile(p, os.O_CREATE+os.O_WRONLY+syscall.O_DIRECT, 0666) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
dio, err := directio.New(f) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
w := bufio.NewWriterSize(dio, 67108864) | ||
header := [64]byte{} | ||
_, err = w.Write(header[:]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &writer{ | ||
name: p, | ||
file: f, | ||
dio: dio, | ||
buf: w, | ||
offset: reservedHeader, | ||
index: make(index, 0, 1000), | ||
Mutex: sync.Mutex{}, | ||
}, 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,32 @@ | ||
//go:build !linux | ||
|
||
package diskmap | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"sync" | ||
) | ||
|
||
// New returns a new Writer that writes to file "p". | ||
func New(p string) (Writer, error) { | ||
f, err := os.Create(p) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := f.Chmod(0600); err != nil { | ||
return nil, err | ||
} | ||
|
||
if _, err = f.Seek(reservedHeader, 0); err != nil { | ||
return nil, fmt.Errorf("was unable to seek %d bytes into the file: %q", reservedHeader, err) | ||
} | ||
|
||
return &writer{ | ||
file: f, | ||
offset: reservedHeader, | ||
index: make(index, 0, 1000), | ||
Mutex: sync.Mutex{}, | ||
}, 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
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.