Documentation ¶
Index ¶
- Constants
- Variables
- func IsDirectIOAvailable() (available bool, err error)
- func NewCompressorForType(compType int) (compressor.CompressionI, error)
- func SkipNextV1(r *FileReader) error
- func SkipNextV2(r *FileReader) error
- type BufferedIOFactory
- type ByteReaderReset
- type ByteReaderResetCount
- type CloseableI
- type CountingBufferedReader
- type DirectIOFactory
- type FileReader
- type FileWriter
- type FileWriterOption
- type FileWriterOptions
- type Header
- type MMapReader
- type OpenClosableI
- type OpenableI
- type ReadAtI
- type Reader
- type ReaderI
- type ReaderWriterCloserFactory
- type Reset
- type SizeI
- type WriteCloserFlusher
- type Writer
- type WriterI
Constants ¶
const ( CompressionTypeNone = iota CompressionTypeGZIP = iota CompressionTypeSnappy = iota CompressionTypeLzw = iota )
never reorder, always append
const CurrentVersion = Version3
const DefaultBufferSize = 1024 * 1024 * 4
DefaultBufferSize is four mebibyte and can be customized using the option BufferSizeBytes.
const FileHeaderSizeBytes = 8
FileHeaderSizeBytes has a 4 byte version number, 4 byte compression code = 8 bytes
const MagicNumberSeparator uint32 = 0x130691
const MagicNumberSeparatorLong uint64 = 0x130691
const RecordHeaderSizeBytesV1V2 = 20
const RecordHeaderV3MaxSizeBytes = binary.MaxVarintLen64 + binary.MaxVarintLen64 + binary.MaxVarintLen64 + 1
RecordHeaderV3MaxSizeBytes is the max buffer sizes to prevent PutUvarint to panic: 10 byte magic number, 10 byte uncompressed size, 10 bytes for compressed size, 1 byte for nil = 31 bytes
const Version1 uint32 = 0x01
const Version2 uint32 = 0x02
const Version3 uint32 = 0x03
Variables ¶
var DirectIOSyncWriteErr = errors.New("currently not supporting directIO with sync writing")
var MagicNumberMismatchErr = fmt.Errorf("magic number mismatch")
Functions ¶
func IsDirectIOAvailable ¶ added in v1.4.0
IsDirectIOAvailable tests whether DirectIO is available (on the OS / filesystem). It will return (true, nil) if that's the case, if it's not available it will be (false, nil). Any other error will be indicated by the error (either true/false).
func NewCompressorForType ¶
func NewCompressorForType(compType int) (compressor.CompressionI, error)
NewCompressorForType returns an instance of the desired compressor defined by its identifier. An error is returned if the desired compressor is not implemented. Only CompressionTypeNone, CompressionTypeSnappy and CompressionTypeGZIP are available currently.
func SkipNextV1 ¶ added in v1.1.0
func SkipNextV1(r *FileReader) error
SkipNextV1 is legacy support path for non-vint compressed V1
func SkipNextV2 ¶ added in v1.6.0
func SkipNextV2(r *FileReader) error
Types ¶
type BufferedIOFactory ¶ added in v1.4.0
type BufferedIOFactory struct { }
func (BufferedIOFactory) CreateNewReader ¶ added in v1.4.0
func (d BufferedIOFactory) CreateNewReader(filePath string, bufSize int) (*os.File, ByteReaderResetCount, error)
func (BufferedIOFactory) CreateNewWriter ¶ added in v1.4.0
func (d BufferedIOFactory) CreateNewWriter(filePath string, bufSize int) (*os.File, WriteCloserFlusher, error)
type ByteReaderReset ¶ added in v1.4.0
type ByteReaderResetCount ¶ added in v1.4.0
type ByteReaderResetCount interface { ByteReaderReset Count() uint64 }
func NewCountingByteReader ¶ added in v1.1.0
func NewCountingByteReader(reader ByteReaderReset) ByteReaderResetCount
type CloseableI ¶ added in v1.1.0
type CloseableI interface { // Close closes the given file. Errors can happen when: // File was already closed before or is not yet open. // File could not be closed on the filesystem (eg when flushes fail) Close() error }
type CountingBufferedReader ¶ added in v1.1.0
type CountingBufferedReader struct {
// contains filtered or unexported fields
}
func (*CountingBufferedReader) Count ¶ added in v1.3.0
func (c *CountingBufferedReader) Count() uint64
func (*CountingBufferedReader) Read ¶ added in v1.1.0
func (c *CountingBufferedReader) Read(p []byte) (n int, err error)
Read reads data into p. It returns the number of bytes read into p. The bytes are taken from at most one Read on the underlying Reader, hence n may be less than len(p). To read exactly len(p) bytes, use io.ReadFull(b, p). At EOF, the count will be zero and err will be io.EOF.
func (*CountingBufferedReader) ReadByte ¶ added in v1.1.0
func (c *CountingBufferedReader) ReadByte() (byte, error)
ReadByte reads and returns a single byte. If no byte is available, returns an error.
func (*CountingBufferedReader) Reset ¶ added in v1.1.0
func (c *CountingBufferedReader) Reset(r io.Reader)
Reset discards any buffered data, resets all state, and switches the buffered reader to read from r.
func (*CountingBufferedReader) Size ¶ added in v1.4.0
func (c *CountingBufferedReader) Size() int
type DirectIOFactory ¶ added in v1.4.0
type DirectIOFactory struct { }
func (DirectIOFactory) CreateNewReader ¶ added in v1.4.0
func (d DirectIOFactory) CreateNewReader(filePath string, bufSize int) (*os.File, ByteReaderResetCount, error)
func (DirectIOFactory) CreateNewWriter ¶ added in v1.4.0
func (d DirectIOFactory) CreateNewWriter(filePath string, bufSize int) (*os.File, WriteCloserFlusher, error)
type FileReader ¶
type FileReader struct {
// contains filtered or unexported fields
}
func (*FileReader) Close ¶
func (r *FileReader) Close() error
func (*FileReader) Open ¶
func (r *FileReader) Open() error
func (*FileReader) ReadNext ¶
func (r *FileReader) ReadNext() ([]byte, error)
func (*FileReader) SkipNext ¶
func (r *FileReader) SkipNext() error
type FileWriter ¶
type FileWriter struct {
// contains filtered or unexported fields
}
FileWriter defines a binary file format (little endian). The file header has a 32 bit version number and a 32 bit compression type enum according to the table above. Each record written in the file follows the following format (sequentially): - MagicNumber (encoding/binary/Uvarint) to separate records from each other. - single byte set to 1 if the record is supposed to be nil. Otherwise, 0. - Uncompressed data payload size (encoding/binary/Uvarint). - Compressed data payload size (encoding/binary/Uvarint), or 0 if the data is not compressed. - Payload as plain bytes, possibly compressed
func (*FileWriter) Close ¶
func (w *FileWriter) Close() error
func (*FileWriter) Open ¶
func (w *FileWriter) Open() error
func (*FileWriter) Size ¶ added in v1.1.0
func (w *FileWriter) Size() uint64
func (*FileWriter) Write ¶
func (w *FileWriter) Write(record []byte) (uint64, error)
Write appends a record of bytes, returns the current offset this item was written to
func (*FileWriter) WriteSync ¶
func (w *FileWriter) WriteSync(record []byte) (uint64, error)
WriteSync appends a record of bytes and forces a disk sync, returns the current offset this item was written to. When directIO is enabled however, we can't write misaligned blocks and immediately returns DirectIOSyncWriteErr
type FileWriterOption ¶ added in v1.2.0
type FileWriterOption func(*FileWriterOptions)
func BufferSizeBytes ¶ added in v1.3.0
func BufferSizeBytes(p int) FileWriterOption
BufferSizeBytes sets the write buffer size, by default it uses DefaultBufferSize. This is the internal memory buffer before it's written to disk.
func CompressionType ¶ added in v1.2.0
func CompressionType(p int) FileWriterOption
CompressionType sets the record compression for the given file, the types are all prefixed with CompressionType*. Valid values for example are CompressionTypeNone, CompressionTypeSnappy, CompressionTypeGZIP.
func DirectIO ¶ added in v1.3.0
func DirectIO() FileWriterOption
DirectIO is experimental: this flag enables DirectIO while writing. This has some limitation when writing headers and disables the ability to use WriteSync.
func File ¶ added in v1.2.0
func File(p *os.File) FileWriterOption
File uses the given os.File as the sink to write into. The code manages the given file lifecycle (ie closing). Either this or Path must be supplied
func Path ¶ added in v1.2.0
func Path(p string) FileWriterOption
Path defines the file path where to write the recordio file into. Path will create a new file if it doesn't exist yet, it will not create any parent directories. Either this or File must be supplied.
type FileWriterOptions ¶ added in v1.2.0
type FileWriterOptions struct {
// contains filtered or unexported fields
}
type MMapReader ¶
type MMapReader struct {
// contains filtered or unexported fields
}
func (*MMapReader) Close ¶
func (r *MMapReader) Close() error
func (*MMapReader) Open ¶
func (r *MMapReader) Open() error
func (*MMapReader) ReadNextAt ¶
func (r *MMapReader) ReadNextAt(offset uint64) ([]byte, error)
type OpenClosableI ¶
type OpenClosableI interface { CloseableI OpenableI }
type OpenableI ¶ added in v1.1.0
type OpenableI interface { // Open opens the given file for reading or writing. Errors can happen in multiple circumstances: // File or directory doesn't exist or are not accessible. // File was already opened or closed before. // File is corrupt, header wasn't readable or versions are incompatible. Open() error }
type ReadAtI ¶
type ReadAtI interface { OpenClosableI // ReadNextAt reads the next record at the given offset, EOF error when it reaches the end signalled by (nil, io.EOF). // It can be wrapped however, so always check using errors.Is(err, io.EOF). Implementation must be thread-safe. ReadNextAt(offset uint64) ([]byte, error) }
ReadAtI implementors must make their implementation thread-safe
func NewMemoryMappedReaderWithPath ¶
NewMemoryMappedReaderWithPath creates a new mmap reader at the given path.
type Reader ¶ added in v1.4.0
type Reader struct {
// contains filtered or unexported fields
}
Reader implements buffering for an io.Reader object. This is the same writer as bufio.Reader, but it allows us to supply the buffer from the outside. Namely, it only has a new constructor in NewReaderBuf and implements Close()
func (*Reader) Buffered ¶ added in v1.4.0
Buffered returns the number of bytes that can be read from the current buffer.
func (*Reader) Read ¶ added in v1.4.0
Read reads data into p. It returns the number of bytes read into p. The bytes are taken from at most one Read on the underlying Reader, hence n may be less than len(p). To read exactly len(p) bytes, use io.ReadFull(b, p). At EOF, the count will be zero and err will be io.EOF.
func (*Reader) ReadByte ¶ added in v1.4.0
ReadByte reads and returns a single byte. If no byte is available, returns an error.
type ReaderI ¶
type ReaderI interface { OpenClosableI // ReadNext reads the next record, EOF error when it reaches the end signalled by (nil, io.EOF). It can be wrapped however, so always check using errors.Is(err, io.EOF). ReadNext() ([]byte, error) // SkipNext skips the next record, EOF error when it reaches the end signalled by io.EOF as the error. It can be wrapped however, so always check using errors.Is(err, io.EOF). SkipNext() error }
func NewFileReaderWithFile ¶
NewFileReaderWithFile creates a new recordio file reader that can read RecordIO files with the given file. The file will be managed from here on out (ie closing).
func NewFileReaderWithPath ¶
NewFileReaderWithPath creates a new recordio file reader that can read RecordIO files at the given path.
type ReaderWriterCloserFactory ¶ added in v1.4.0
type SizeI ¶ added in v1.1.0
type SizeI interface { // Size returns the current size of the file in bytes Size() uint64 }
type WriteCloserFlusher ¶ added in v1.4.0
type WriteCloserFlusher interface { io.WriteCloser Flush() error Size() int }
func NewAlignedWriterBuf ¶ added in v1.4.0
func NewAlignedWriterBuf(w io.WriteCloser, buf []byte) WriteCloserFlusher
func NewWriterBuf ¶ added in v1.4.0
func NewWriterBuf(w io.WriteCloser, buf []byte) WriteCloserFlusher
type Writer ¶ added in v1.4.0
type Writer struct {
// contains filtered or unexported fields
}
Writer implements buffering for an io.Writer object. If an error occurs writing to a Writer, no more data will be accepted and all subsequent writes, and Flush, will return the error. After all data has been written, the client should call the Flush method to guarantee all data has been forwarded to the underlying io.Writer. This is the same writer as bufio.Writer, but it allows us to supply the buffer from the outside. Namely, it has a new constructor in NewWriterBuf & NewAlignedWriterBuf, implements Close() and supports block aligned flushes. Additionally, several methods that were not needed are removed to reduce the test surface of the original.
func (*Writer) Available ¶ added in v1.4.0
Available returns how many bytes are unused in the buffer.
type WriterI ¶
type WriterI interface { OpenClosableI SizeI // Write appends a record of bytes, returns the current offset this item was written to Write(record []byte) (uint64, error) // WriteSync appends a record of bytes and forces a disk sync, returns the current offset this item was written to WriteSync(record []byte) (uint64, error) }
func NewFileWriter ¶ added in v1.2.0
func NewFileWriter(writerOptions ...FileWriterOption) (WriterI, error)
NewFileWriter creates a new writer with the given options, either Path or File must be supplied, compression is optional.