Documentation ¶
Overview ¶
Example ¶
bb := make([]byte, testBuffSize) a, err := NewAIO(testFile, os.O_CREATE|os.O_RDWR, 0666) if err != nil { fmt.Println("Failed to create AIO", err) } for i := range bb { bb[i] = 0xab } var requests []RequestId //kick off 16 requests to write to the file //this should generate a file of testBuffSize*16 for i := 0; i < 16; i++ { r, err := a.Write(bb) if err != nil { fmt.Println("Failure to issue write", err) return } requests = append(requests, r) } //wait for the first 8 requests to finish in order for i := 0; i < 8; i++ { if _, err := a.WaitFor(requests[i]); err != nil { fmt.Println("Failed waiting for write request", err) return } } //wait for the next 8 requests to finish in any order //this is a batch wait, several can come back completed := make([]RequestId, 8) toComplete := 8 for toComplete > 0 { n, err := a.WaitAny(completed) if err != nil { fmt.Println("Failed to wait for any write requests", err) return } toComplete -= n } //flush the file handle the AIO for good measure if err := a.Flush(); err != nil { fmt.Println("Failed to sync AIO") } if err := a.Close(); err != nil { fmt.Println("Failed to close AIO") }
Output:
Index ¶
- Variables
- type AIO
- func (a *AIO) Close() error
- func (a *AIO) FD() *os.File
- func (a *AIO) Flush() error
- func (a *AIO) ReadAt(b []byte, offset int64) (RequestId, error)
- func (a *AIO) Ready() bool
- func (a *AIO) Truncate(sz int64) error
- func (a *AIO) Wait() error
- func (a *AIO) WaitAny(completed []RequestId) (int, error)
- func (a *AIO) WaitFor(id RequestId) (int, error)
- func (a *AIO) Write(b []byte) (RequestId, error)
- func (a *AIO) WriteAt(b []byte, offset int64) (RequestId, error)
- type AIOExtConfig
- type RequestId
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrInitFail = errors.New("Failed to initailize AIO context") ErrNotInit = errors.New("Not initialized") ErrDestroy = errors.New("Failed to tear down context") ErrIoSubFail = errors.New("Failed to submit new IO request") ErrInvalidBuffer = errors.New("Invalid buffer") ErrWaitAllFailed = errors.New("Failed to wait for all requests to complete") ErrNilEvent = errors.New("The kernel returned a nil event result. Fatal error") ErrNilCallback = errors.New("The kernel returned a nil callback structure. Fatal error") ErrUntrackedEventKey = errors.New("The kernel returned an event key we weren't tracking") ErrInvalidEventPtr = errors.New("The kernel returned an invalid callback event pointer") ErrCompletion = errors.New("The kernel failed to process all of the request") ErrWhatTheHell = errors.New("A callback event occurred but no buffer was put into the pool") ErrNotFound = errors.New("ID not found") ErrNotDone = errors.New("Request not finished") ErrInvalidQueueDepth = errors.New("Invalid queue depth") )
Functions ¶
This section is empty.
Types ¶
type AIO ¶
type AIO struct {
// contains filtered or unexported fields
}
func New ¶
func New(fio *os.File, cfg AIOExtConfig) (*AIO, error)
New creates a file aio with the given file handle
func NewAIO ¶
NewAIO opens a file with the appropriate flags and permissions and positions the file index at the end of the file
func NewAIOExt ¶
NewAIOExt opens a file with the appropriate flags and permissions and positions the file index at the end of the file with additional configuration options
func (*AIO) FD ¶
FD hands back the underlying *os.File pointer This is NOT A COPY, so do not do close it or do anything crazy with it. This is purely a convienence method, use at your own peril
func (*AIO) Flush ¶
Flush will wait for all submitted jobs to finish and then flush the file descriptor. Because the Linux kernel does not actually support Flush via the AIO interface we just issue a plain old flush via userland. No async here. Flush DOES NOT ack outstanding requests
func (*AIO) Ready ¶
Ready returns whether or not there is a callback buffer ready to go basically a check on whether or not we will block on a read/write attempt
func (*AIO) Truncate ¶
Truncate will wait for all submitted jobs to finish and then trunctate the file to the designated size.
func (*AIO) WaitAny ¶
WaitAny will block until a request finishes and will populate a
buffer of request IDs with the items that finish, returning the completion count and a potential error. If there are no outstanding requests it will return 0, nil
type AIOExtConfig ¶
type AIOExtConfig struct {
QueueDepth int
}