repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
nats-io/nats-streaming-server
stores/filestore.go
FileDescriptorsLimit
func FileDescriptorsLimit(limit int64) FileStoreOption { return func(o *FileStoreOptions) error { if limit < 0 { return fmt.Errorf("file descriptor limit must be a positive number") } o.FileDescriptorsLimit = limit return nil } }
go
func FileDescriptorsLimit(limit int64) FileStoreOption { return func(o *FileStoreOptions) error { if limit < 0 { return fmt.Errorf("file descriptor limit must be a positive number") } o.FileDescriptorsLimit = limit return nil } }
[ "func", "FileDescriptorsLimit", "(", "limit", "int64", ")", "FileStoreOption", "{", "return", "func", "(", "o", "*", "FileStoreOptions", ")", "error", "{", "if", "limit", "<", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "...
// FileDescriptorsLimit is a soft limit hinting at FileStore to try to // limit the number of concurrent opened files to that limit.
[ "FileDescriptorsLimit", "is", "a", "soft", "limit", "hinting", "at", "FileStore", "to", "try", "to", "limit", "the", "number", "of", "concurrent", "opened", "files", "to", "that", "limit", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L316-L324
train
nats-io/nats-streaming-server
stores/filestore.go
ParallelRecovery
func ParallelRecovery(count int) FileStoreOption { return func(o *FileStoreOptions) error { if count <= 0 { return fmt.Errorf("parallel recovery value must be at least 1") } o.ParallelRecovery = count return nil } }
go
func ParallelRecovery(count int) FileStoreOption { return func(o *FileStoreOptions) error { if count <= 0 { return fmt.Errorf("parallel recovery value must be at least 1") } o.ParallelRecovery = count return nil } }
[ "func", "ParallelRecovery", "(", "count", "int", ")", "FileStoreOption", "{", "return", "func", "(", "o", "*", "FileStoreOptions", ")", "error", "{", "if", "count", "<=", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", ...
// ParallelRecovery is a FileStore option that allows the parallel // recovery of channels. When running with SSDs, try to use a higher // value than the default number of 1. When running with HDDs, // performance may be better if it stays at 1.
[ "ParallelRecovery", "is", "a", "FileStore", "option", "that", "allows", "the", "parallel", "recovery", "of", "channels", ".", "When", "running", "with", "SSDs", "try", "to", "use", "a", "higher", "value", "than", "the", "default", "number", "of", "1", ".", ...
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L330-L338
train
nats-io/nats-streaming-server
stores/filestore.go
AllOptions
func AllOptions(opts *FileStoreOptions) FileStoreOption { return func(o *FileStoreOptions) error { if err := BufferSize(opts.BufferSize)(o); err != nil { return err } if err := CompactInterval(opts.CompactInterval)(o); err != nil { return err } if err := CompactFragmentation(opts.CompactFragmentation)(...
go
func AllOptions(opts *FileStoreOptions) FileStoreOption { return func(o *FileStoreOptions) error { if err := BufferSize(opts.BufferSize)(o); err != nil { return err } if err := CompactInterval(opts.CompactInterval)(o); err != nil { return err } if err := CompactFragmentation(opts.CompactFragmentation)(...
[ "func", "AllOptions", "(", "opts", "*", "FileStoreOptions", ")", "FileStoreOption", "{", "return", "func", "(", "o", "*", "FileStoreOptions", ")", "error", "{", "if", "err", ":=", "BufferSize", "(", "opts", ".", "BufferSize", ")", "(", "o", ")", ";", "er...
// AllOptions is a convenient option to pass all options from a FileStoreOptions // structure to the constructor.
[ "AllOptions", "is", "a", "convenient", "option", "to", "pass", "all", "options", "from", "a", "FileStoreOptions", "structure", "to", "the", "constructor", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L354-L386
train
nats-io/nats-streaming-server
stores/filestore.go
checkFileVersion
func checkFileVersion(r io.Reader) error { fv, err := util.ReadInt(r) if err != nil { return fmt.Errorf("unable to verify file version: %v", err) } if fv == 0 || fv > fileVersion { return fmt.Errorf("unsupported file version: %v (supports [1..%v])", fv, fileVersion) } return nil }
go
func checkFileVersion(r io.Reader) error { fv, err := util.ReadInt(r) if err != nil { return fmt.Errorf("unable to verify file version: %v", err) } if fv == 0 || fv > fileVersion { return fmt.Errorf("unsupported file version: %v (supports [1..%v])", fv, fileVersion) } return nil }
[ "func", "checkFileVersion", "(", "r", "io", ".", "Reader", ")", "error", "{", "fv", ",", "err", ":=", "util", ".", "ReadInt", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", ...
// check that the version of the file is understood by this interface
[ "check", "that", "the", "version", "of", "the", "file", "is", "understood", "by", "this", "interface" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L660-L669
train
nats-io/nats-streaming-server
stores/filestore.go
createNewWriter
func (w *bufferedWriter) createNewWriter(file *os.File) io.Writer { w.buf = bufio.NewWriterSize(file, w.bufSize) return w.buf }
go
func (w *bufferedWriter) createNewWriter(file *os.File) io.Writer { w.buf = bufio.NewWriterSize(file, w.bufSize) return w.buf }
[ "func", "(", "w", "*", "bufferedWriter", ")", "createNewWriter", "(", "file", "*", "os", ".", "File", ")", "io", ".", "Writer", "{", "w", ".", "buf", "=", "bufio", ".", "NewWriterSize", "(", "file", ",", "w", ".", "bufSize", ")", "\n", "return", "w...
// createNewWriter creates a new buffer writer for `file` with // the bufferedWriter's current buffer size.
[ "createNewWriter", "creates", "a", "new", "buffer", "writer", "for", "file", "with", "the", "bufferedWriter", "s", "current", "buffer", "size", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L781-L784
train
nats-io/nats-streaming-server
stores/filestore.go
tryShrinkBuffer
func (w *bufferedWriter) tryShrinkBuffer(file *os.File) (io.Writer, error) { // Nothing to do if we are already at the lowest // or file not set/opened. if w.bufSize == w.minShrinkSize || file == nil { return w.buf, nil } if !w.shrinkReq { percentFilled := w.buf.Buffered() * 100 / w.bufSize if percentFilled...
go
func (w *bufferedWriter) tryShrinkBuffer(file *os.File) (io.Writer, error) { // Nothing to do if we are already at the lowest // or file not set/opened. if w.bufSize == w.minShrinkSize || file == nil { return w.buf, nil } if !w.shrinkReq { percentFilled := w.buf.Buffered() * 100 / w.bufSize if percentFilled...
[ "func", "(", "w", "*", "bufferedWriter", ")", "tryShrinkBuffer", "(", "file", "*", "os", ".", "File", ")", "(", "io", ".", "Writer", ",", "error", ")", "{", "// Nothing to do if we are already at the lowest", "// or file not set/opened.", "if", "w", ".", "bufSiz...
// tryShrinkBuffer checks and possibly shrinks the buffer
[ "tryShrinkBuffer", "checks", "and", "possibly", "shrinks", "the", "buffer" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L811-L840
train
nats-io/nats-streaming-server
stores/filestore.go
checkShrinkRequest
func (w *bufferedWriter) checkShrinkRequest() { percentFilled := w.buf.Buffered() * 100 / w.bufSize // If above the threshold, cancel the request. if percentFilled > bufShrinkThreshold { w.shrinkReq = false } }
go
func (w *bufferedWriter) checkShrinkRequest() { percentFilled := w.buf.Buffered() * 100 / w.bufSize // If above the threshold, cancel the request. if percentFilled > bufShrinkThreshold { w.shrinkReq = false } }
[ "func", "(", "w", "*", "bufferedWriter", ")", "checkShrinkRequest", "(", ")", "{", "percentFilled", ":=", "w", ".", "buf", ".", "Buffered", "(", ")", "*", "100", "/", "w", ".", "bufSize", "\n", "// If above the threshold, cancel the request.", "if", "percentFi...
// checkShrinkRequest checks how full the buffer is, and if is above a certain // threshold, cancels the shrink request
[ "checkShrinkRequest", "checks", "how", "full", "the", "buffer", "is", "and", "if", "is", "above", "a", "certain", "threshold", "cancels", "the", "shrink", "request" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L844-L850
train
nats-io/nats-streaming-server
stores/filestore.go
openFile
func (fm *filesManager) openFile(file *file) error { fm.Lock() if fm.isClosed { fm.Unlock() return fmt.Errorf("unable to open file %q, store is being closed", file.name) } curState := atomic.LoadInt32(&file.state) if curState == fileRemoved { fm.Unlock() return fmt.Errorf("unable to open file %q, it has be...
go
func (fm *filesManager) openFile(file *file) error { fm.Lock() if fm.isClosed { fm.Unlock() return fmt.Errorf("unable to open file %q, store is being closed", file.name) } curState := atomic.LoadInt32(&file.state) if curState == fileRemoved { fm.Unlock() return fmt.Errorf("unable to open file %q, it has be...
[ "func", "(", "fm", "*", "filesManager", ")", "openFile", "(", "file", "*", "file", ")", "error", "{", "fm", ".", "Lock", "(", ")", "\n", "if", "fm", ".", "isClosed", "{", "fm", ".", "Unlock", "(", ")", "\n", "return", "fmt", ".", "Errorf", "(", ...
// openFile opens the given file and sets its state to `fileInUse`. // If the file manager has been closed or the file removed, this call // returns an error. // Otherwise, if the file's state is not `fileClosed` this call will panic. // This call will possibly cause opened but unused files to be closed if the // numbe...
[ "openFile", "opens", "the", "given", "file", "and", "sets", "its", "state", "to", "fileInUse", ".", "If", "the", "file", "manager", "has", "been", "closed", "or", "the", "file", "removed", "this", "call", "returns", "an", "error", ".", "Otherwise", "if", ...
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L926-L952
train
nats-io/nats-streaming-server
stores/filestore.go
closeLockedFile
func (fm *filesManager) closeLockedFile(file *file) error { if !atomic.CompareAndSwapInt32(&file.state, fileInUse, fileClosing) { panic(fmt.Errorf("file %q is requested to be closed but was not locked by caller", file.name)) } fm.Lock() err := fm.doClose(file) fm.Unlock() return err }
go
func (fm *filesManager) closeLockedFile(file *file) error { if !atomic.CompareAndSwapInt32(&file.state, fileInUse, fileClosing) { panic(fmt.Errorf("file %q is requested to be closed but was not locked by caller", file.name)) } fm.Lock() err := fm.doClose(file) fm.Unlock() return err }
[ "func", "(", "fm", "*", "filesManager", ")", "closeLockedFile", "(", "file", "*", "file", ")", "error", "{", "if", "!", "atomic", ".", "CompareAndSwapInt32", "(", "&", "file", ".", "state", ",", "fileInUse", ",", "fileClosing", ")", "{", "panic", "(", ...
// closeLockedFile closes the handle of the given file, but only if the caller // has locked the file. Will panic otherwise. // If the file's beforeClose callback is not nil, this callback is invoked // before the file handle is closed.
[ "closeLockedFile", "closes", "the", "handle", "of", "the", "given", "file", "but", "only", "if", "the", "caller", "has", "locked", "the", "file", ".", "Will", "panic", "otherwise", ".", "If", "the", "file", "s", "beforeClose", "callback", "is", "not", "nil...
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L958-L966
train
nats-io/nats-streaming-server
stores/filestore.go
closeFileIfOpened
func (fm *filesManager) closeFileIfOpened(file *file) error { if !atomic.CompareAndSwapInt32(&file.state, fileOpened, fileClosing) { return nil } fm.Lock() err := fm.doClose(file) fm.Unlock() return err }
go
func (fm *filesManager) closeFileIfOpened(file *file) error { if !atomic.CompareAndSwapInt32(&file.state, fileOpened, fileClosing) { return nil } fm.Lock() err := fm.doClose(file) fm.Unlock() return err }
[ "func", "(", "fm", "*", "filesManager", ")", "closeFileIfOpened", "(", "file", "*", "file", ")", "error", "{", "if", "!", "atomic", ".", "CompareAndSwapInt32", "(", "&", "file", ".", "state", ",", "fileOpened", ",", "fileClosing", ")", "{", "return", "ni...
// closeFileIfOpened closes the handle of the given file, but only if the // file is opened and not currently locked. Does not return any error or panic // if file is in any other state. // If the file's beforeClose callback is not nil, this callback is invoked // before the file handle is closed.
[ "closeFileIfOpened", "closes", "the", "handle", "of", "the", "given", "file", "but", "only", "if", "the", "file", "is", "opened", "and", "not", "currently", "locked", ".", "Does", "not", "return", "any", "error", "or", "panic", "if", "file", "is", "in", ...
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L973-L981
train
nats-io/nats-streaming-server
stores/filestore.go
doClose
func (fm *filesManager) doClose(file *file) error { var err error if file.beforeClose != nil { err = file.beforeClose() } util.CloseFile(err, file.handle) // Regardless of error, we need to change the state to closed. file.handle = nil atomic.StoreInt32(&file.state, fileClosed) fm.openedFDs-- return err }
go
func (fm *filesManager) doClose(file *file) error { var err error if file.beforeClose != nil { err = file.beforeClose() } util.CloseFile(err, file.handle) // Regardless of error, we need to change the state to closed. file.handle = nil atomic.StoreInt32(&file.state, fileClosed) fm.openedFDs-- return err }
[ "func", "(", "fm", "*", "filesManager", ")", "doClose", "(", "file", "*", "file", ")", "error", "{", "var", "err", "error", "\n", "if", "file", ".", "beforeClose", "!=", "nil", "{", "err", "=", "file", ".", "beforeClose", "(", ")", "\n", "}", "\n",...
// doClose closes the file handle, setting it to nil and switching state to `fileClosed`. // If a `beforeClose` callback was registered on file creation, it is invoked // before the file handler is actually closed. // Lock is required on entry.
[ "doClose", "closes", "the", "file", "handle", "setting", "it", "to", "nil", "and", "switching", "state", "to", "fileClosed", ".", "If", "a", "beforeClose", "callback", "was", "registered", "on", "file", "creation", "it", "is", "invoked", "before", "the", "fi...
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L1006-L1017
train
nats-io/nats-streaming-server
stores/filestore.go
lockFile
func (fm *filesManager) lockFile(file *file) (bool, error) { if atomic.CompareAndSwapInt32(&file.state, fileOpened, fileInUse) { return true, nil } return false, fm.openFile(file) }
go
func (fm *filesManager) lockFile(file *file) (bool, error) { if atomic.CompareAndSwapInt32(&file.state, fileOpened, fileInUse) { return true, nil } return false, fm.openFile(file) }
[ "func", "(", "fm", "*", "filesManager", ")", "lockFile", "(", "file", "*", "file", ")", "(", "bool", ",", "error", ")", "{", "if", "atomic", ".", "CompareAndSwapInt32", "(", "&", "file", ".", "state", ",", "fileOpened", ",", "fileInUse", ")", "{", "r...
// lockFile locks the given file. // If the file was already opened, the boolean returned is true, // otherwise, the file is opened and the call returns false.
[ "lockFile", "locks", "the", "given", "file", ".", "If", "the", "file", "was", "already", "opened", "the", "boolean", "returned", "is", "true", "otherwise", "the", "file", "is", "opened", "and", "the", "call", "returns", "false", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L1022-L1027
train
nats-io/nats-streaming-server
stores/filestore.go
unlockFile
func (fm *filesManager) unlockFile(file *file) { if !atomic.CompareAndSwapInt32(&file.state, fileInUse, fileOpened) { panic(fmt.Errorf("failed to switch state from fileInUse to fileOpened for file %q, state=%v", file.name, file.state)) } }
go
func (fm *filesManager) unlockFile(file *file) { if !atomic.CompareAndSwapInt32(&file.state, fileInUse, fileOpened) { panic(fmt.Errorf("failed to switch state from fileInUse to fileOpened for file %q, state=%v", file.name, file.state)) } }
[ "func", "(", "fm", "*", "filesManager", ")", "unlockFile", "(", "file", "*", "file", ")", "{", "if", "!", "atomic", ".", "CompareAndSwapInt32", "(", "&", "file", ".", "state", ",", "fileInUse", ",", "fileOpened", ")", "{", "panic", "(", "fmt", ".", "...
// unlockFile unlocks the file if currently locked, otherwise panic.
[ "unlockFile", "unlocks", "the", "file", "if", "currently", "locked", "otherwise", "panic", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L1036-L1041
train
nats-io/nats-streaming-server
stores/filestore.go
trySwitchState
func (fm *filesManager) trySwitchState(file *file, newState int32) (bool, error) { wasOpened := false wasClosed := false for i := 0; i < 10000; i++ { if atomic.CompareAndSwapInt32(&file.state, fileOpened, newState) { wasOpened = true break } if atomic.CompareAndSwapInt32(&file.state, fileClosed, newState...
go
func (fm *filesManager) trySwitchState(file *file, newState int32) (bool, error) { wasOpened := false wasClosed := false for i := 0; i < 10000; i++ { if atomic.CompareAndSwapInt32(&file.state, fileOpened, newState) { wasOpened = true break } if atomic.CompareAndSwapInt32(&file.state, fileClosed, newState...
[ "func", "(", "fm", "*", "filesManager", ")", "trySwitchState", "(", "file", "*", "file", ",", "newState", "int32", ")", "(", "bool", ",", "error", ")", "{", "wasOpened", ":=", "false", "\n", "wasClosed", ":=", "false", "\n", "for", "i", ":=", "0", ";...
// trySwitchState attempts to switch an initial state of `fileOpened` // or `fileClosed` to the given newState. If it can't it will return an // error, otherwise, returned a boolean to indicate if the initial state // was `fileOpened`.
[ "trySwitchState", "attempts", "to", "switch", "an", "initial", "state", "of", "fileOpened", "or", "fileClosed", "to", "the", "given", "newState", ".", "If", "it", "can", "t", "it", "will", "return", "an", "error", "otherwise", "returned", "a", "boolean", "to...
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L1047-L1067
train
nats-io/nats-streaming-server
stores/filestore.go
close
func (fm *filesManager) close() error { fm.Lock() if fm.isClosed { fm.Unlock() return nil } fm.isClosed = true files := make([]*file, 0, len(fm.files)) for _, file := range fm.files { files = append(files, file) } fm.files = nil fm.Unlock() var err error for _, file := range files { wasOpened, sser...
go
func (fm *filesManager) close() error { fm.Lock() if fm.isClosed { fm.Unlock() return nil } fm.isClosed = true files := make([]*file, 0, len(fm.files)) for _, file := range fm.files { files = append(files, file) } fm.files = nil fm.Unlock() var err error for _, file := range files { wasOpened, sser...
[ "func", "(", "fm", "*", "filesManager", ")", "close", "(", ")", "error", "{", "fm", ".", "Lock", "(", ")", "\n", "if", "fm", ".", "isClosed", "{", "fm", ".", "Unlock", "(", ")", "\n", "return", "nil", "\n", "}", "\n", "fm", ".", "isClosed", "="...
// close the files manager, including all files currently opened. // Returns the first error encountered when closing the files.
[ "close", "the", "files", "manager", "including", "all", "files", "currently", "opened", ".", "Returns", "the", "first", "error", "encountered", "when", "closing", "the", "files", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L1147-L1178
train
nats-io/nats-streaming-server
stores/filestore.go
Init
func (fs *FileStore) Init(info *spb.ServerInfo) error { fs.Lock() defer fs.Unlock() if fs.serverFile == nil { var err error // Open/Create the server file (note that this file must not be opened, // in APPEND mode to allow truncate to work). fs.serverFile, err = fs.fm.createFile(serverFileName, os.O_RDWR|os...
go
func (fs *FileStore) Init(info *spb.ServerInfo) error { fs.Lock() defer fs.Unlock() if fs.serverFile == nil { var err error // Open/Create the server file (note that this file must not be opened, // in APPEND mode to allow truncate to work). fs.serverFile, err = fs.fm.createFile(serverFileName, os.O_RDWR|os...
[ "func", "(", "fs", "*", "FileStore", ")", "Init", "(", "info", "*", "spb", ".", "ServerInfo", ")", "error", "{", "fs", ".", "Lock", "(", ")", "\n", "defer", "fs", ".", "Unlock", "(", ")", "\n\n", "if", "fs", ".", "serverFile", "==", "nil", "{", ...
// Init is used to persist server's information after the first start
[ "Init", "is", "used", "to", "persist", "server", "s", "information", "after", "the", "first", "start" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L1461-L1495
train
nats-io/nats-streaming-server
stores/filestore.go
recoverClients
func (fs *FileStore) recoverClients() ([]*Client, error) { var err error var recType recordType var recSize int _buf := [256]byte{} buf := _buf[:] offset := int64(4) // Create a buffered reader to speed-up recovery br := bufio.NewReaderSize(fs.clientsFile.handle, defaultBufSize) for { buf, recSize, recTyp...
go
func (fs *FileStore) recoverClients() ([]*Client, error) { var err error var recType recordType var recSize int _buf := [256]byte{} buf := _buf[:] offset := int64(4) // Create a buffered reader to speed-up recovery br := bufio.NewReaderSize(fs.clientsFile.handle, defaultBufSize) for { buf, recSize, recTyp...
[ "func", "(", "fs", "*", "FileStore", ")", "recoverClients", "(", ")", "(", "[", "]", "*", "Client", ",", "error", ")", "{", "var", "err", "error", "\n", "var", "recType", "recordType", "\n", "var", "recSize", "int", "\n\n", "_buf", ":=", "[", "256", ...
// recoverClients reads the client files and returns an array of RecoveredClient
[ "recoverClients", "reads", "the", "client", "files", "and", "returns", "an", "array", "of", "RecoveredClient" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L1498-L1557
train
nats-io/nats-streaming-server
stores/filestore.go
recoverServerInfo
func (fs *FileStore) recoverServerInfo() (*spb.ServerInfo, error) { info := &spb.ServerInfo{} buf, size, _, err := readRecord(fs.serverFile.handle, nil, false, fs.crcTable, fs.opts.DoCRC) if err != nil { if err == io.EOF { // We are done, no state recovered return nil, nil } fs.log.Errorf("Server file %q...
go
func (fs *FileStore) recoverServerInfo() (*spb.ServerInfo, error) { info := &spb.ServerInfo{} buf, size, _, err := readRecord(fs.serverFile.handle, nil, false, fs.crcTable, fs.opts.DoCRC) if err != nil { if err == io.EOF { // We are done, no state recovered return nil, nil } fs.log.Errorf("Server file %q...
[ "func", "(", "fs", "*", "FileStore", ")", "recoverServerInfo", "(", ")", "(", "*", "spb", ".", "ServerInfo", ",", "error", ")", "{", "info", ":=", "&", "spb", ".", "ServerInfo", "{", "}", "\n", "buf", ",", "size", ",", "_", ",", "err", ":=", "rea...
// recoverServerInfo reads the server file and returns a ServerInfo structure
[ "recoverServerInfo", "reads", "the", "server", "file", "and", "returns", "a", "ServerInfo", "structure" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L1560-L1590
train
nats-io/nats-streaming-server
stores/filestore.go
shouldCompactClientFile
func (fs *FileStore) shouldCompactClientFile() bool { // Global switch if !fs.opts.CompactEnabled { return false } // Check that if minimum file size is set, the client file // is at least at the minimum. if fs.opts.CompactMinFileSize > 0 && fs.cliFileSize < fs.opts.CompactMinFileSize { return false } // Ch...
go
func (fs *FileStore) shouldCompactClientFile() bool { // Global switch if !fs.opts.CompactEnabled { return false } // Check that if minimum file size is set, the client file // is at least at the minimum. if fs.opts.CompactMinFileSize > 0 && fs.cliFileSize < fs.opts.CompactMinFileSize { return false } // Ch...
[ "func", "(", "fs", "*", "FileStore", ")", "shouldCompactClientFile", "(", ")", "bool", "{", "// Global switch", "if", "!", "fs", ".", "opts", ".", "CompactEnabled", "{", "return", "false", "\n", "}", "\n", "// Check that if minimum file size is set, the client file"...
// shouldCompactClientFile returns true if the client file should be compacted // Lock is held by caller
[ "shouldCompactClientFile", "returns", "true", "if", "the", "client", "file", "should", "be", "compacted", "Lock", "is", "held", "by", "caller" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L1704-L1724
train
nats-io/nats-streaming-server
stores/filestore.go
compactClientFile
func (fs *FileStore) compactClientFile(orgFileName string) error { // Open a temporary file tmpFile, err := getTempFile(fs.fm.rootDir, clientsFileName) if err != nil { return err } defer func() { if tmpFile != nil { tmpFile.Close() os.Remove(tmpFile.Name()) } }() bw := bufio.NewWriterSize(tmpFile, de...
go
func (fs *FileStore) compactClientFile(orgFileName string) error { // Open a temporary file tmpFile, err := getTempFile(fs.fm.rootDir, clientsFileName) if err != nil { return err } defer func() { if tmpFile != nil { tmpFile.Close() os.Remove(tmpFile.Name()) } }() bw := bufio.NewWriterSize(tmpFile, de...
[ "func", "(", "fs", "*", "FileStore", ")", "compactClientFile", "(", "orgFileName", "string", ")", "error", "{", "// Open a temporary file", "tmpFile", ",", "err", ":=", "getTempFile", "(", "fs", ".", "fm", ".", "rootDir", ",", "clientsFileName", ")", "\n", "...
// Rewrite the content of the clients map into a temporary file, // then swap back to active file. // Store lock held on entry
[ "Rewrite", "the", "content", "of", "the", "clients", "map", "into", "a", "temporary", "file", "then", "swap", "back", "to", "active", "file", ".", "Store", "lock", "held", "on", "entry" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L1729-L1773
train
nats-io/nats-streaming-server
stores/filestore.go
Close
func (fs *FileStore) Close() error { fs.Lock() if fs.closed { fs.Unlock() return nil } fs.closed = true err := fs.genericStore.close() fm := fs.fm lockFile := fs.lockFile fs.Unlock() if fm != nil { if fmerr := fm.close(); fmerr != nil && err == nil { err = fmerr } } if lockFile != nil { err =...
go
func (fs *FileStore) Close() error { fs.Lock() if fs.closed { fs.Unlock() return nil } fs.closed = true err := fs.genericStore.close() fm := fs.fm lockFile := fs.lockFile fs.Unlock() if fm != nil { if fmerr := fm.close(); fmerr != nil && err == nil { err = fmerr } } if lockFile != nil { err =...
[ "func", "(", "fs", "*", "FileStore", ")", "Close", "(", ")", "error", "{", "fs", ".", "Lock", "(", ")", "\n", "if", "fs", ".", "closed", "{", "fs", ".", "Unlock", "(", ")", "\n", "return", "nil", "\n", "}", "\n", "fs", ".", "closed", "=", "tr...
// Close closes all stores.
[ "Close", "closes", "all", "stores", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L1788-L1811
train
nats-io/nats-streaming-server
stores/filestore.go
beforeDataFileCloseCb
func (ms *FileMsgStore) beforeDataFileCloseCb(fslice *fileSlice) beforeFileClose { return func() error { if fslice != ms.writeSlice { return nil } if ms.bw != nil && ms.bw.buf != nil && ms.bw.buf.Buffered() > 0 { if err := ms.bw.buf.Flush(); err != nil { return err } } if ms.fstore.opts.DoSync {...
go
func (ms *FileMsgStore) beforeDataFileCloseCb(fslice *fileSlice) beforeFileClose { return func() error { if fslice != ms.writeSlice { return nil } if ms.bw != nil && ms.bw.buf != nil && ms.bw.buf.Buffered() > 0 { if err := ms.bw.buf.Flush(); err != nil { return err } } if ms.fstore.opts.DoSync {...
[ "func", "(", "ms", "*", "FileMsgStore", ")", "beforeDataFileCloseCb", "(", "fslice", "*", "fileSlice", ")", "beforeFileClose", "{", "return", "func", "(", ")", "error", "{", "if", "fslice", "!=", "ms", ".", "writeSlice", "{", "return", "nil", "\n", "}", ...
// beforeDataFileCloseCb returns a beforeFileClose callback to be used // by FileMsgStore's files when a data file for that slice is being closed. // This is invoked asynchronously and should not acquire the store's lock. // That being said, we have the guarantee that this will be not be invoked // concurrently for a g...
[ "beforeDataFileCloseCb", "returns", "a", "beforeFileClose", "callback", "to", "be", "used", "by", "FileMsgStore", "s", "files", "when", "a", "data", "file", "for", "that", "slice", "is", "being", "closed", ".", "This", "is", "invoked", "asynchronously", "and", ...
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L2069-L2087
train
nats-io/nats-streaming-server
stores/filestore.go
beforeIndexFileCloseCb
func (ms *FileMsgStore) beforeIndexFileCloseCb(fslice *fileSlice) beforeFileClose { return func() error { if fslice != ms.writeSlice { return nil } if len(ms.bufferedMsgs) > 0 { if err := ms.processBufferedMsgs(fslice); err != nil { return err } } if ms.fstore.opts.DoSync { if err := fslice.i...
go
func (ms *FileMsgStore) beforeIndexFileCloseCb(fslice *fileSlice) beforeFileClose { return func() error { if fslice != ms.writeSlice { return nil } if len(ms.bufferedMsgs) > 0 { if err := ms.processBufferedMsgs(fslice); err != nil { return err } } if ms.fstore.opts.DoSync { if err := fslice.i...
[ "func", "(", "ms", "*", "FileMsgStore", ")", "beforeIndexFileCloseCb", "(", "fslice", "*", "fileSlice", ")", "beforeFileClose", "{", "return", "func", "(", ")", "error", "{", "if", "fslice", "!=", "ms", ".", "writeSlice", "{", "return", "nil", "\n", "}", ...
// beforeIndexFileCloseCb returns a beforeFileClose callback to be used // by FileMsgStore's files when an index file for that slice is being closed. // This is invoked asynchronously and should not acquire the store's lock. // That being said, we have the guarantee that this will be not be invoked // concurrently for ...
[ "beforeIndexFileCloseCb", "returns", "a", "beforeFileClose", "callback", "to", "be", "used", "by", "FileMsgStore", "s", "files", "when", "an", "index", "file", "for", "that", "slice", "is", "being", "closed", ".", "This", "is", "invoked", "asynchronously", "and"...
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L2094-L2111
train
nats-io/nats-streaming-server
stores/filestore.go
setFile
func (ms *FileMsgStore) setFile(fslice *fileSlice, offset int64) error { var err error file := fslice.file.handle ms.writer = file if file != nil && ms.bw != nil { ms.writer = ms.bw.createNewWriter(file) } if offset == -1 { ms.wOffset, err = file.Seek(0, io.SeekEnd) } else { ms.wOffset = offset } return ...
go
func (ms *FileMsgStore) setFile(fslice *fileSlice, offset int64) error { var err error file := fslice.file.handle ms.writer = file if file != nil && ms.bw != nil { ms.writer = ms.bw.createNewWriter(file) } if offset == -1 { ms.wOffset, err = file.Seek(0, io.SeekEnd) } else { ms.wOffset = offset } return ...
[ "func", "(", "ms", "*", "FileMsgStore", ")", "setFile", "(", "fslice", "*", "fileSlice", ",", "offset", "int64", ")", "error", "{", "var", "err", "error", "\n", "file", ":=", "fslice", ".", "file", ".", "handle", "\n", "ms", ".", "writer", "=", "file...
// setFile sets the current data and index file. // The buffered writer is recreated.
[ "setFile", "sets", "the", "current", "data", "and", "index", "file", ".", "The", "buffered", "writer", "is", "recreated", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L2115-L2128
train
nats-io/nats-streaming-server
stores/filestore.go
lockFiles
func (ms *FileMsgStore) lockFiles(fslice *fileSlice) error { return ms.doLockFiles(fslice, false) }
go
func (ms *FileMsgStore) lockFiles(fslice *fileSlice) error { return ms.doLockFiles(fslice, false) }
[ "func", "(", "ms", "*", "FileMsgStore", ")", "lockFiles", "(", "fslice", "*", "fileSlice", ")", "error", "{", "return", "ms", ".", "doLockFiles", "(", "fslice", ",", "false", ")", "\n", "}" ]
// lockFiles locks the data and index files of the given file slice. // If files were closed they are opened in this call, and if so, // and if this slice is the write slice, the writer and offset are reset.
[ "lockFiles", "locks", "the", "data", "and", "index", "files", "of", "the", "given", "file", "slice", ".", "If", "files", "were", "closed", "they", "are", "opened", "in", "this", "call", "and", "if", "so", "and", "if", "this", "slice", "is", "the", "wri...
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L2174-L2176
train
nats-io/nats-streaming-server
stores/filestore.go
lockIndexFile
func (ms *FileMsgStore) lockIndexFile(fslice *fileSlice) error { return ms.doLockFiles(fslice, true) }
go
func (ms *FileMsgStore) lockIndexFile(fslice *fileSlice) error { return ms.doLockFiles(fslice, true) }
[ "func", "(", "ms", "*", "FileMsgStore", ")", "lockIndexFile", "(", "fslice", "*", "fileSlice", ")", "error", "{", "return", "ms", ".", "doLockFiles", "(", "fslice", ",", "true", ")", "\n", "}" ]
// lockIndexFile locks the index file of the given file slice. // If the file was closed it is opened in this call.
[ "lockIndexFile", "locks", "the", "index", "file", "of", "the", "given", "file", "slice", ".", "If", "the", "file", "was", "closed", "it", "is", "opened", "in", "this", "call", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L2180-L2182
train
nats-io/nats-streaming-server
stores/filestore.go
unlockIndexFile
func (ms *FileMsgStore) unlockIndexFile(fslice *fileSlice) { ms.fm.unlockFile(fslice.idxFile) }
go
func (ms *FileMsgStore) unlockIndexFile(fslice *fileSlice) { ms.fm.unlockFile(fslice.idxFile) }
[ "func", "(", "ms", "*", "FileMsgStore", ")", "unlockIndexFile", "(", "fslice", "*", "fileSlice", ")", "{", "ms", ".", "fm", ".", "unlockFile", "(", "fslice", ".", "idxFile", ")", "\n", "}" ]
// unlockIndexFile unlocks the already locked index file of the given file slice.
[ "unlockIndexFile", "unlocks", "the", "already", "locked", "index", "file", "of", "the", "given", "file", "slice", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L2185-L2187
train
nats-io/nats-streaming-server
stores/filestore.go
unlockFiles
func (ms *FileMsgStore) unlockFiles(fslice *fileSlice) { ms.fm.unlockFile(fslice.file) ms.fm.unlockFile(fslice.idxFile) }
go
func (ms *FileMsgStore) unlockFiles(fslice *fileSlice) { ms.fm.unlockFile(fslice.file) ms.fm.unlockFile(fslice.idxFile) }
[ "func", "(", "ms", "*", "FileMsgStore", ")", "unlockFiles", "(", "fslice", "*", "fileSlice", ")", "{", "ms", ".", "fm", ".", "unlockFile", "(", "fslice", ".", "file", ")", "\n", "ms", ".", "fm", ".", "unlockFile", "(", "fslice", ".", "idxFile", ")", ...
// unlockFiles unlocks both data and index files of the given file slice.
[ "unlockFiles", "unlocks", "both", "data", "and", "index", "files", "of", "the", "given", "file", "slice", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L2190-L2193
train
nats-io/nats-streaming-server
stores/filestore.go
writeIndex
func (ms *FileMsgStore) writeIndex(w io.Writer, seq uint64, offset, timestamp int64, msgSize int) error { _buf := [msgIndexRecSize]byte{} buf := _buf[:] ms.addIndex(buf, seq, offset, timestamp, msgSize) _, err := w.Write(buf[:msgIndexRecSize]) return err }
go
func (ms *FileMsgStore) writeIndex(w io.Writer, seq uint64, offset, timestamp int64, msgSize int) error { _buf := [msgIndexRecSize]byte{} buf := _buf[:] ms.addIndex(buf, seq, offset, timestamp, msgSize) _, err := w.Write(buf[:msgIndexRecSize]) return err }
[ "func", "(", "ms", "*", "FileMsgStore", ")", "writeIndex", "(", "w", "io", ".", "Writer", ",", "seq", "uint64", ",", "offset", ",", "timestamp", "int64", ",", "msgSize", "int", ")", "error", "{", "_buf", ":=", "[", "msgIndexRecSize", "]", "byte", "{", ...
// writeIndex writes a message index record to the writer `w`
[ "writeIndex", "writes", "a", "message", "index", "record", "to", "the", "writer", "w" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L2480-L2486
train
nats-io/nats-streaming-server
stores/filestore.go
addIndex
func (ms *FileMsgStore) addIndex(buf []byte, seq uint64, offset, timestamp int64, msgSize int) { util.ByteOrder.PutUint64(buf, seq) util.ByteOrder.PutUint64(buf[8:], uint64(offset)) util.ByteOrder.PutUint64(buf[16:], uint64(timestamp)) util.ByteOrder.PutUint32(buf[24:], uint32(msgSize)) crc := crc32.Checksum(buf[:...
go
func (ms *FileMsgStore) addIndex(buf []byte, seq uint64, offset, timestamp int64, msgSize int) { util.ByteOrder.PutUint64(buf, seq) util.ByteOrder.PutUint64(buf[8:], uint64(offset)) util.ByteOrder.PutUint64(buf[16:], uint64(timestamp)) util.ByteOrder.PutUint32(buf[24:], uint32(msgSize)) crc := crc32.Checksum(buf[:...
[ "func", "(", "ms", "*", "FileMsgStore", ")", "addIndex", "(", "buf", "[", "]", "byte", ",", "seq", "uint64", ",", "offset", ",", "timestamp", "int64", ",", "msgSize", "int", ")", "{", "util", ".", "ByteOrder", ".", "PutUint64", "(", "buf", ",", "seq"...
// addIndex adds a message index record in the given buffer
[ "addIndex", "adds", "a", "message", "index", "record", "in", "the", "given", "buffer" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L2489-L2496
train
nats-io/nats-streaming-server
stores/filestore.go
readIndex
func (ms *FileMsgStore) readIndex(r io.Reader) (uint64, *msgIndex, error) { _buf := [msgIndexRecSize]byte{} buf := _buf[:] if _, err := io.ReadFull(r, buf); err != nil { return 0, nil, err } mindex := &msgIndex{} seq := util.ByteOrder.Uint64(buf) mindex.offset = int64(util.ByteOrder.Uint64(buf[8:])) mindex.ti...
go
func (ms *FileMsgStore) readIndex(r io.Reader) (uint64, *msgIndex, error) { _buf := [msgIndexRecSize]byte{} buf := _buf[:] if _, err := io.ReadFull(r, buf); err != nil { return 0, nil, err } mindex := &msgIndex{} seq := util.ByteOrder.Uint64(buf) mindex.offset = int64(util.ByteOrder.Uint64(buf[8:])) mindex.ti...
[ "func", "(", "ms", "*", "FileMsgStore", ")", "readIndex", "(", "r", "io", ".", "Reader", ")", "(", "uint64", ",", "*", "msgIndex", ",", "error", ")", "{", "_buf", ":=", "[", "msgIndexRecSize", "]", "byte", "{", "}", "\n", "buf", ":=", "_buf", "[", ...
// readIndex reads a message index record from the given reader // and returns an allocated msgIndex object.
[ "readIndex", "reads", "a", "message", "index", "record", "from", "the", "given", "reader", "and", "returns", "an", "allocated", "msgIndex", "object", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L2500-L2526
train
nats-io/nats-streaming-server
stores/filestore.go
processBufferedMsgs
func (ms *FileMsgStore) processBufferedMsgs(fslice *fileSlice) error { idxBufferSize := len(ms.bufferedMsgs) * msgIndexRecSize ms.tmpMsgBuf = util.EnsureBufBigEnough(ms.tmpMsgBuf, idxBufferSize) bufOffset := 0 for _, pseq := range ms.bufferedSeqs { bm := ms.bufferedMsgs[pseq] if bm != nil { mindex := bm.inde...
go
func (ms *FileMsgStore) processBufferedMsgs(fslice *fileSlice) error { idxBufferSize := len(ms.bufferedMsgs) * msgIndexRecSize ms.tmpMsgBuf = util.EnsureBufBigEnough(ms.tmpMsgBuf, idxBufferSize) bufOffset := 0 for _, pseq := range ms.bufferedSeqs { bm := ms.bufferedMsgs[pseq] if bm != nil { mindex := bm.inde...
[ "func", "(", "ms", "*", "FileMsgStore", ")", "processBufferedMsgs", "(", "fslice", "*", "fileSlice", ")", "error", "{", "idxBufferSize", ":=", "len", "(", "ms", ".", "bufferedMsgs", ")", "*", "msgIndexRecSize", "\n", "ms", ".", "tmpMsgBuf", "=", "util", "....
// processBufferedMsgs adds message index records in the given buffer // for every pending buffered messages.
[ "processBufferedMsgs", "adds", "message", "index", "records", "in", "the", "given", "buffer", "for", "every", "pending", "buffered", "messages", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L2767-L2789
train
nats-io/nats-streaming-server
stores/filestore.go
readMsgIndex
func (ms *FileMsgStore) readMsgIndex(slice *fileSlice, seq uint64) (*msgIndex, error) { // Compute the offset in the index file itself. idxFileOffset := 4 + (int64(seq-slice.firstSeq)+int64(slice.rmCount))*msgIndexRecSize // Then position the file pointer of the index file. if _, err := slice.idxFile.handle.Seek(id...
go
func (ms *FileMsgStore) readMsgIndex(slice *fileSlice, seq uint64) (*msgIndex, error) { // Compute the offset in the index file itself. idxFileOffset := 4 + (int64(seq-slice.firstSeq)+int64(slice.rmCount))*msgIndexRecSize // Then position the file pointer of the index file. if _, err := slice.idxFile.handle.Seek(id...
[ "func", "(", "ms", "*", "FileMsgStore", ")", "readMsgIndex", "(", "slice", "*", "fileSlice", ",", "seq", "uint64", ")", "(", "*", "msgIndex", ",", "error", ")", "{", "// Compute the offset in the index file itself.", "idxFileOffset", ":=", "4", "+", "(", "int6...
// readMsgIndex reads a message index record from disk and returns a msgIndex // object. Same than getMsgIndex but without checking for message in // ms.bufferedMsgs first.
[ "readMsgIndex", "reads", "a", "message", "index", "record", "from", "disk", "and", "returns", "a", "msgIndex", "object", ".", "Same", "than", "getMsgIndex", "but", "without", "checking", "for", "message", "in", "ms", ".", "bufferedMsgs", "first", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L2912-L2928
train
nats-io/nats-streaming-server
stores/filestore.go
removeFirstMsg
func (ms *FileMsgStore) removeFirstMsg(mindex *msgIndex, lockFile bool) error { // Work with the first slice slice := ms.files[ms.firstFSlSeq] // Get the message index for the first valid message in this slice if mindex == nil { if lockFile || slice != ms.writeSlice { ms.lockIndexFile(slice) } var err erro...
go
func (ms *FileMsgStore) removeFirstMsg(mindex *msgIndex, lockFile bool) error { // Work with the first slice slice := ms.files[ms.firstFSlSeq] // Get the message index for the first valid message in this slice if mindex == nil { if lockFile || slice != ms.writeSlice { ms.lockIndexFile(slice) } var err erro...
[ "func", "(", "ms", "*", "FileMsgStore", ")", "removeFirstMsg", "(", "mindex", "*", "msgIndex", ",", "lockFile", "bool", ")", "error", "{", "// Work with the first slice", "slice", ":=", "ms", ".", "files", "[", "ms", ".", "firstFSlSeq", "]", "\n", "// Get th...
// removeFirstMsg "removes" the first message of the first slice. // If the slice is "empty" the file slice is removed.
[ "removeFirstMsg", "removes", "the", "first", "message", "of", "the", "first", "slice", ".", "If", "the", "slice", "is", "empty", "the", "file", "slice", "is", "removed", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L2932-L2975
train
nats-io/nats-streaming-server
stores/filestore.go
removeFirstSlice
func (ms *FileMsgStore) removeFirstSlice() { sl := ms.files[ms.firstFSlSeq] // We may or may not have the first slice locked, so need to close // the file knowing that files can be in either state. ms.fm.closeLockedOrOpenedFile(sl.file) ms.fm.remove(sl.file) // Close index file too. ms.fm.closeLockedOrOpenedFile...
go
func (ms *FileMsgStore) removeFirstSlice() { sl := ms.files[ms.firstFSlSeq] // We may or may not have the first slice locked, so need to close // the file knowing that files can be in either state. ms.fm.closeLockedOrOpenedFile(sl.file) ms.fm.remove(sl.file) // Close index file too. ms.fm.closeLockedOrOpenedFile...
[ "func", "(", "ms", "*", "FileMsgStore", ")", "removeFirstSlice", "(", ")", "{", "sl", ":=", "ms", ".", "files", "[", "ms", ".", "firstFSlSeq", "]", "\n", "// We may or may not have the first slice locked, so need to close", "// the file knowing that files can be in either...
// removeFirstSlice removes the first file slice. // Should not be called if first slice is also last!
[ "removeFirstSlice", "removes", "the", "first", "file", "slice", ".", "Should", "not", "be", "called", "if", "first", "slice", "is", "also", "last!" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L2979-L3043
train
nats-io/nats-streaming-server
stores/filestore.go
getFileSliceForSeq
func (ms *FileMsgStore) getFileSliceForSeq(seq uint64) *fileSlice { if len(ms.files) == 0 { return nil } // Start with write slice slice := ms.writeSlice if (slice.firstSeq <= seq) && (seq <= slice.lastSeq) { return slice } // We want to support possible gaps in file slice sequence, so // no dichotomy, but ...
go
func (ms *FileMsgStore) getFileSliceForSeq(seq uint64) *fileSlice { if len(ms.files) == 0 { return nil } // Start with write slice slice := ms.writeSlice if (slice.firstSeq <= seq) && (seq <= slice.lastSeq) { return slice } // We want to support possible gaps in file slice sequence, so // no dichotomy, but ...
[ "func", "(", "ms", "*", "FileMsgStore", ")", "getFileSliceForSeq", "(", "seq", "uint64", ")", "*", "fileSlice", "{", "if", "len", "(", "ms", ".", "files", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "// Start with write slice", "slice", ":=", ...
// getFileSliceForSeq returns the file slice where the message of the // given sequence is stored, or nil if the message is not found in any // of the file slices.
[ "getFileSliceForSeq", "returns", "the", "file", "slice", "where", "the", "message", "of", "the", "given", "sequence", "is", "stored", "or", "nil", "if", "the", "message", "is", "not", "found", "in", "any", "of", "the", "file", "slices", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L3048-L3066
train
nats-io/nats-streaming-server
stores/filestore.go
backgroundTasks
func (ms *FileMsgStore) backgroundTasks() { defer ms.allDone.Done() ms.RLock() hasBuffer := ms.bw != nil maxAge := int64(ms.limits.MaxAge) nextExpiration := ms.expiration lastCacheCheck := ms.timeTick lastBufShrink := ms.timeTick ms.RUnlock() for { // Update time timeTick := time.Now().UnixNano() atomi...
go
func (ms *FileMsgStore) backgroundTasks() { defer ms.allDone.Done() ms.RLock() hasBuffer := ms.bw != nil maxAge := int64(ms.limits.MaxAge) nextExpiration := ms.expiration lastCacheCheck := ms.timeTick lastBufShrink := ms.timeTick ms.RUnlock() for { // Update time timeTick := time.Now().UnixNano() atomi...
[ "func", "(", "ms", "*", "FileMsgStore", ")", "backgroundTasks", "(", ")", "{", "defer", "ms", ".", "allDone", ".", "Done", "(", ")", "\n\n", "ms", ".", "RLock", "(", ")", "\n", "hasBuffer", ":=", "ms", ".", "bw", "!=", "nil", "\n", "maxAge", ":=", ...
// backgroundTasks performs some background tasks related to this // messages store.
[ "backgroundTasks", "performs", "some", "background", "tasks", "related", "to", "this", "messages", "store", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L3070-L3157
train
nats-io/nats-streaming-server
stores/filestore.go
lookup
func (ms *FileMsgStore) lookup(seq uint64) (*pb.MsgProto, error) { // Reject message for sequence outside valid range if seq < ms.first || seq > ms.last { return nil, nil } // Check first if it's in the cache. msg := ms.cache.get(seq) if msg == nil && ms.bufferedMsgs != nil { // Possibly in bufferedMsgs bm ...
go
func (ms *FileMsgStore) lookup(seq uint64) (*pb.MsgProto, error) { // Reject message for sequence outside valid range if seq < ms.first || seq > ms.last { return nil, nil } // Check first if it's in the cache. msg := ms.cache.get(seq) if msg == nil && ms.bufferedMsgs != nil { // Possibly in bufferedMsgs bm ...
[ "func", "(", "ms", "*", "FileMsgStore", ")", "lookup", "(", "seq", "uint64", ")", "(", "*", "pb", ".", "MsgProto", ",", "error", ")", "{", "// Reject message for sequence outside valid range", "if", "seq", "<", "ms", ".", "first", "||", "seq", ">", "ms", ...
// lookup returns the message for the given sequence number, possibly // reading the message from disk. // Store write lock is assumed to be held on entry
[ "lookup", "returns", "the", "message", "for", "the", "given", "sequence", "number", "possibly", "reading", "the", "message", "from", "disk", ".", "Store", "write", "lock", "is", "assumed", "to", "be", "held", "on", "entry" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L3162-L3209
train
nats-io/nats-streaming-server
stores/filestore.go
initCache
func (ms *FileMsgStore) initCache() { ms.cache = &msgsCache{ seqMaps: make(map[uint64]*cachedMsg), } }
go
func (ms *FileMsgStore) initCache() { ms.cache = &msgsCache{ seqMaps: make(map[uint64]*cachedMsg), } }
[ "func", "(", "ms", "*", "FileMsgStore", ")", "initCache", "(", ")", "{", "ms", ".", "cache", "=", "&", "msgsCache", "{", "seqMaps", ":", "make", "(", "map", "[", "uint64", "]", "*", "cachedMsg", ")", ",", "}", "\n", "}" ]
// initCache initializes the message cache
[ "initCache", "initializes", "the", "message", "cache" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L3326-L3330
train
nats-io/nats-streaming-server
stores/filestore.go
add
func (c *msgsCache) add(seq uint64, msg *pb.MsgProto, isNew bool) { exp := cacheTTL if isNew { exp += msg.Timestamp } else { exp += time.Now().UnixNano() } cMsg := &cachedMsg{ expiration: exp, msg: msg, } if c.tail == nil { c.head = cMsg } else { c.tail.next = cMsg // Ensure last expiration...
go
func (c *msgsCache) add(seq uint64, msg *pb.MsgProto, isNew bool) { exp := cacheTTL if isNew { exp += msg.Timestamp } else { exp += time.Now().UnixNano() } cMsg := &cachedMsg{ expiration: exp, msg: msg, } if c.tail == nil { c.head = cMsg } else { c.tail.next = cMsg // Ensure last expiration...
[ "func", "(", "c", "*", "msgsCache", ")", "add", "(", "seq", "uint64", ",", "msg", "*", "pb", ".", "MsgProto", ",", "isNew", "bool", ")", "{", "exp", ":=", "cacheTTL", "\n", "if", "isNew", "{", "exp", "+=", "msg", ".", "Timestamp", "\n", "}", "els...
// add adds a message to the cache. // Store write lock is assumed held on entry
[ "add", "adds", "a", "message", "to", "the", "cache", ".", "Store", "write", "lock", "is", "assumed", "held", "on", "entry" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L3334-L3360
train
nats-io/nats-streaming-server
stores/filestore.go
get
func (c *msgsCache) get(seq uint64) *pb.MsgProto { cMsg := c.seqMaps[seq] if cMsg == nil { return nil } // Bump the expiration cMsg.expiration = time.Now().UnixNano() + cacheTTL // If not already at the tail of the list, move it there if cMsg != c.tail { if cMsg.prev != nil { cMsg.prev.next = cMsg.next ...
go
func (c *msgsCache) get(seq uint64) *pb.MsgProto { cMsg := c.seqMaps[seq] if cMsg == nil { return nil } // Bump the expiration cMsg.expiration = time.Now().UnixNano() + cacheTTL // If not already at the tail of the list, move it there if cMsg != c.tail { if cMsg.prev != nil { cMsg.prev.next = cMsg.next ...
[ "func", "(", "c", "*", "msgsCache", ")", "get", "(", "seq", "uint64", ")", "*", "pb", ".", "MsgProto", "{", "cMsg", ":=", "c", ".", "seqMaps", "[", "seq", "]", "\n", "if", "cMsg", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "// Bump the e...
// get returns a message if available in the cache. // Store write lock is assumed held on entry
[ "get", "returns", "a", "message", "if", "available", "in", "the", "cache", ".", "Store", "write", "lock", "is", "assumed", "held", "on", "entry" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L3364-L3392
train
nats-io/nats-streaming-server
stores/filestore.go
evict
func (c *msgsCache) evict(now int64) { if c.head == nil { return } if now >= c.tail.expiration { // Bulk remove c.seqMaps = make(map[uint64]*cachedMsg) c.head, c.tail, c.tryEvict = nil, nil, 0 return } cMsg := c.head for cMsg != nil && cMsg.expiration <= now { delete(c.seqMaps, cMsg.msg.Sequence) cM...
go
func (c *msgsCache) evict(now int64) { if c.head == nil { return } if now >= c.tail.expiration { // Bulk remove c.seqMaps = make(map[uint64]*cachedMsg) c.head, c.tail, c.tryEvict = nil, nil, 0 return } cMsg := c.head for cMsg != nil && cMsg.expiration <= now { delete(c.seqMaps, cMsg.msg.Sequence) cM...
[ "func", "(", "c", "*", "msgsCache", ")", "evict", "(", "now", "int64", ")", "{", "if", "c", ".", "head", "==", "nil", "{", "return", "\n", "}", "\n", "if", "now", ">=", "c", ".", "tail", ".", "expiration", "{", "// Bulk remove", "c", ".", "seqMap...
// evict move down the cache maps, evicting the last one. // Store write lock is assumed held on entry
[ "evict", "move", "down", "the", "cache", "maps", "evicting", "the", "last", "one", ".", "Store", "write", "lock", "is", "assumed", "held", "on", "entry" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L3396-L3417
train
nats-io/nats-streaming-server
stores/filestore.go
empty
func (c *msgsCache) empty() { atomic.StoreInt32(&c.tryEvict, 0) c.head, c.tail = nil, nil c.seqMaps = make(map[uint64]*cachedMsg) }
go
func (c *msgsCache) empty() { atomic.StoreInt32(&c.tryEvict, 0) c.head, c.tail = nil, nil c.seqMaps = make(map[uint64]*cachedMsg) }
[ "func", "(", "c", "*", "msgsCache", ")", "empty", "(", ")", "{", "atomic", ".", "StoreInt32", "(", "&", "c", ".", "tryEvict", ",", "0", ")", "\n", "c", ".", "head", ",", "c", ".", "tail", "=", "nil", ",", "nil", "\n", "c", ".", "seqMaps", "="...
// empty empties the cache
[ "empty", "empties", "the", "cache" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L3420-L3424
train
nats-io/nats-streaming-server
stores/filestore.go
Flush
func (ms *FileMsgStore) Flush() error { ms.Lock() var err error if ms.writeSlice != nil { err = ms.lockFiles(ms.writeSlice) if err == nil { err = ms.flush(ms.writeSlice) ms.unlockFiles(ms.writeSlice) } } ms.Unlock() return err }
go
func (ms *FileMsgStore) Flush() error { ms.Lock() var err error if ms.writeSlice != nil { err = ms.lockFiles(ms.writeSlice) if err == nil { err = ms.flush(ms.writeSlice) ms.unlockFiles(ms.writeSlice) } } ms.Unlock() return err }
[ "func", "(", "ms", "*", "FileMsgStore", ")", "Flush", "(", ")", "error", "{", "ms", ".", "Lock", "(", ")", "\n", "var", "err", "error", "\n", "if", "ms", ".", "writeSlice", "!=", "nil", "{", "err", "=", "ms", ".", "lockFiles", "(", "ms", ".", "...
// Flush flushes outstanding data into the store.
[ "Flush", "flushes", "outstanding", "data", "into", "the", "store", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L3495-L3507
train
nats-io/nats-streaming-server
stores/filestore.go
CreateSub
func (ss *FileSubStore) CreateSub(sub *spb.SubState) error { // Check if we can create the subscription (check limits and update // subscription count) ss.Lock() defer ss.Unlock() if err := ss.createSub(sub); err != nil { return err } if err := ss.writeRecord(nil, subRecNew, sub); err != nil { delete(ss.subs...
go
func (ss *FileSubStore) CreateSub(sub *spb.SubState) error { // Check if we can create the subscription (check limits and update // subscription count) ss.Lock() defer ss.Unlock() if err := ss.createSub(sub); err != nil { return err } if err := ss.writeRecord(nil, subRecNew, sub); err != nil { delete(ss.subs...
[ "func", "(", "ss", "*", "FileSubStore", ")", "CreateSub", "(", "sub", "*", "spb", ".", "SubState", ")", "error", "{", "// Check if we can create the subscription (check limits and update", "// subscription count)", "ss", ".", "Lock", "(", ")", "\n", "defer", "ss", ...
// CreateSub records a new subscription represented by SubState. On success, // it returns an id that is used by the other methods.
[ "CreateSub", "records", "a", "new", "subscription", "represented", "by", "SubState", ".", "On", "success", "it", "returns", "an", "id", "that", "is", "used", "by", "the", "other", "methods", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L3787-L3805
train
nats-io/nats-streaming-server
stores/filestore.go
UpdateSub
func (ss *FileSubStore) UpdateSub(sub *spb.SubState) error { ss.Lock() defer ss.Unlock() if err := ss.writeRecord(nil, subRecUpdate, sub); err != nil { return err } // We need to get a copy of the passed sub, we can't hold a reference // to it. csub := *sub si := ss.subs[sub.ID] if si != nil { s := si.(*su...
go
func (ss *FileSubStore) UpdateSub(sub *spb.SubState) error { ss.Lock() defer ss.Unlock() if err := ss.writeRecord(nil, subRecUpdate, sub); err != nil { return err } // We need to get a copy of the passed sub, we can't hold a reference // to it. csub := *sub si := ss.subs[sub.ID] if si != nil { s := si.(*su...
[ "func", "(", "ss", "*", "FileSubStore", ")", "UpdateSub", "(", "sub", "*", "spb", ".", "SubState", ")", "error", "{", "ss", ".", "Lock", "(", ")", "\n", "defer", "ss", ".", "Unlock", "(", ")", "\n", "if", "err", ":=", "ss", ".", "writeRecord", "(...
// UpdateSub updates a given subscription represented by SubState.
[ "UpdateSub", "updates", "a", "given", "subscription", "represented", "by", "SubState", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L3808-L3826
train
nats-io/nats-streaming-server
stores/filestore.go
shouldCompact
func (ss *FileSubStore) shouldCompact() bool { // Gobal switch if !ss.opts.CompactEnabled { return false } // Check that if minimum file size is set, the client file // is at least at the minimum. if ss.opts.CompactMinFileSize > 0 && ss.fileSize < ss.opts.CompactMinFileSize { return false } // Check fragmen...
go
func (ss *FileSubStore) shouldCompact() bool { // Gobal switch if !ss.opts.CompactEnabled { return false } // Check that if minimum file size is set, the client file // is at least at the minimum. if ss.opts.CompactMinFileSize > 0 && ss.fileSize < ss.opts.CompactMinFileSize { return false } // Check fragmen...
[ "func", "(", "ss", "*", "FileSubStore", ")", "shouldCompact", "(", ")", "bool", "{", "// Gobal switch", "if", "!", "ss", ".", "opts", ".", "CompactEnabled", "{", "return", "false", "\n", "}", "\n", "// Check that if minimum file size is set, the client file", "// ...
// shouldCompact returns a boolean indicating if we should compact // Lock is held by caller
[ "shouldCompact", "returns", "a", "boolean", "indicating", "if", "we", "should", "compact", "Lock", "is", "held", "by", "caller" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L3853-L3878
train
nats-io/nats-streaming-server
stores/filestore.go
AddSeqPending
func (ss *FileSubStore) AddSeqPending(subid, seqno uint64) error { ss.Lock() ss.updateSub.ID, ss.updateSub.Seqno = subid, seqno if err := ss.writeRecord(nil, subRecMsg, &ss.updateSub); err != nil { ss.Unlock() return err } si := ss.subs[subid] if si != nil { s := si.(*subscription) if seqno > s.sub.LastSe...
go
func (ss *FileSubStore) AddSeqPending(subid, seqno uint64) error { ss.Lock() ss.updateSub.ID, ss.updateSub.Seqno = subid, seqno if err := ss.writeRecord(nil, subRecMsg, &ss.updateSub); err != nil { ss.Unlock() return err } si := ss.subs[subid] if si != nil { s := si.(*subscription) if seqno > s.sub.LastSe...
[ "func", "(", "ss", "*", "FileSubStore", ")", "AddSeqPending", "(", "subid", ",", "seqno", "uint64", ")", "error", "{", "ss", ".", "Lock", "(", ")", "\n", "ss", ".", "updateSub", ".", "ID", ",", "ss", ".", "updateSub", ".", "Seqno", "=", "subid", ",...
// AddSeqPending adds the given message seqno to the given subscription.
[ "AddSeqPending", "adds", "the", "given", "message", "seqno", "to", "the", "given", "subscription", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L3881-L3898
train
nats-io/nats-streaming-server
stores/filestore.go
AckSeqPending
func (ss *FileSubStore) AckSeqPending(subid, seqno uint64) error { ss.Lock() ss.updateSub.ID, ss.updateSub.Seqno = subid, seqno if err := ss.writeRecord(nil, subRecAck, &ss.updateSub); err != nil { ss.Unlock() return err } si := ss.subs[subid] if si != nil { s := si.(*subscription) delete(s.seqnos, seqno)...
go
func (ss *FileSubStore) AckSeqPending(subid, seqno uint64) error { ss.Lock() ss.updateSub.ID, ss.updateSub.Seqno = subid, seqno if err := ss.writeRecord(nil, subRecAck, &ss.updateSub); err != nil { ss.Unlock() return err } si := ss.subs[subid] if si != nil { s := si.(*subscription) delete(s.seqnos, seqno)...
[ "func", "(", "ss", "*", "FileSubStore", ")", "AckSeqPending", "(", "subid", ",", "seqno", "uint64", ")", "error", "{", "ss", ".", "Lock", "(", ")", "\n", "ss", ".", "updateSub", ".", "ID", ",", "ss", ".", "updateSub", ".", "Seqno", "=", "subid", ",...
// AckSeqPending records that the given message seqno has been acknowledged // by the given subscription.
[ "AckSeqPending", "records", "that", "the", "given", "message", "seqno", "has", "been", "acknowledged", "by", "the", "given", "subscription", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L3902-L3921
train
nats-io/nats-streaming-server
stores/filestore.go
compact
func (ss *FileSubStore) compact(orgFileName string) error { tmpFile, err := getTempFile(ss.fm.rootDir, "subs") if err != nil { return err } tmpBW := bufio.NewWriterSize(tmpFile, defaultBufSize) // Save values in case of failed compaction savedNumRecs := ss.numRecs savedDelRecs := ss.delRecs savedFileSize := s...
go
func (ss *FileSubStore) compact(orgFileName string) error { tmpFile, err := getTempFile(ss.fm.rootDir, "subs") if err != nil { return err } tmpBW := bufio.NewWriterSize(tmpFile, defaultBufSize) // Save values in case of failed compaction savedNumRecs := ss.numRecs savedDelRecs := ss.delRecs savedFileSize := s...
[ "func", "(", "ss", "*", "FileSubStore", ")", "compact", "(", "orgFileName", "string", ")", "error", "{", "tmpFile", ",", "err", ":=", "getTempFile", "(", "ss", ".", "fm", ".", "rootDir", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "r...
// compact rewrites all subscriptions on a temporary file, reducing the size // since we get rid of deleted subscriptions and message sequences that have // been acknowledged. On success, the subscriptions file is replaced by this // temporary file. // Lock is held by caller
[ "compact", "rewrites", "all", "subscriptions", "on", "a", "temporary", "file", "reducing", "the", "size", "since", "we", "get", "rid", "of", "deleted", "subscriptions", "and", "message", "sequences", "that", "have", "been", "acknowledged", ".", "On", "success", ...
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L3928-L3990
train
nats-io/nats-streaming-server
stores/filestore.go
writeRecord
func (ss *FileSubStore) writeRecord(w io.Writer, recType recordType, rec record) error { var err error totalSize := 0 recSize := rec.Size() var bwBuf *bufio.Writer needsUnlock := false if w == nil { if err := ss.lockFile(); err != nil { return err } needsUnlock = true if ss.bw != nil { bwBuf = ss....
go
func (ss *FileSubStore) writeRecord(w io.Writer, recType recordType, rec record) error { var err error totalSize := 0 recSize := rec.Size() var bwBuf *bufio.Writer needsUnlock := false if w == nil { if err := ss.lockFile(); err != nil { return err } needsUnlock = true if ss.bw != nil { bwBuf = ss....
[ "func", "(", "ss", "*", "FileSubStore", ")", "writeRecord", "(", "w", "io", ".", "Writer", ",", "recType", "recordType", ",", "rec", "record", ")", "error", "{", "var", "err", "error", "\n", "totalSize", ":=", "0", "\n", "recSize", ":=", "rec", ".", ...
// writes a record in the subscriptions file. // store's lock is held on entry.
[ "writes", "a", "record", "in", "the", "subscriptions", "file", ".", "store", "s", "lock", "is", "held", "on", "entry", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L3994-L4060
train
nats-io/nats-streaming-server
stores/filestore.go
Flush
func (ss *FileSubStore) Flush() error { ss.Lock() err := ss.lockFile() if err == nil { err = ss.flush() ss.fm.unlockFile(ss.file) } ss.Unlock() return err }
go
func (ss *FileSubStore) Flush() error { ss.Lock() err := ss.lockFile() if err == nil { err = ss.flush() ss.fm.unlockFile(ss.file) } ss.Unlock() return err }
[ "func", "(", "ss", "*", "FileSubStore", ")", "Flush", "(", ")", "error", "{", "ss", ".", "Lock", "(", ")", "\n", "err", ":=", "ss", ".", "lockFile", "(", ")", "\n", "if", "err", "==", "nil", "{", "err", "=", "ss", ".", "flush", "(", ")", "\n"...
// Flush persists buffered operations to disk.
[ "Flush", "persists", "buffered", "operations", "to", "disk", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L4081-L4090
train
nats-io/nats-streaming-server
stores/filestore.go
Close
func (ss *FileSubStore) Close() error { ss.Lock() if ss.closed { ss.Unlock() return nil } ss.closed = true if ss.shrinkTimer != nil { if ss.shrinkTimer.Stop() { // If we can stop, timer callback won't fire, // so we need to decrement the wait group. ss.allDone.Done() } } ss.Unlock() // Wait ...
go
func (ss *FileSubStore) Close() error { ss.Lock() if ss.closed { ss.Unlock() return nil } ss.closed = true if ss.shrinkTimer != nil { if ss.shrinkTimer.Stop() { // If we can stop, timer callback won't fire, // so we need to decrement the wait group. ss.allDone.Done() } } ss.Unlock() // Wait ...
[ "func", "(", "ss", "*", "FileSubStore", ")", "Close", "(", ")", "error", "{", "ss", ".", "Lock", "(", ")", "\n", "if", "ss", ".", "closed", "{", "ss", ".", "Unlock", "(", ")", "\n", "return", "nil", "\n", "}", "\n\n", "ss", ".", "closed", "=", ...
// Close closes this store
[ "Close", "closes", "this", "store" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L4093-L4125
train
nats-io/nats-streaming-server
server/raft_transport.go
Dial
func (n *natsStreamLayer) Dial(address raft.ServerAddress, timeout time.Duration) (net.Conn, error) { if !n.conn.IsConnected() { return nil, errors.New("raft-nats: dial failed, not connected") } // QUESTION: The Raft NetTransport does connection pooling, which is useful // for TCP sockets. The NATS transport sim...
go
func (n *natsStreamLayer) Dial(address raft.ServerAddress, timeout time.Duration) (net.Conn, error) { if !n.conn.IsConnected() { return nil, errors.New("raft-nats: dial failed, not connected") } // QUESTION: The Raft NetTransport does connection pooling, which is useful // for TCP sockets. The NATS transport sim...
[ "func", "(", "n", "*", "natsStreamLayer", ")", "Dial", "(", "address", "raft", ".", "ServerAddress", ",", "timeout", "time", ".", "Duration", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "if", "!", "n", ".", "conn", ".", "IsConnected", "(", ...
// Dial creates a new net.Conn with the remote address. This is implemented by // performing a handshake over NATS which establishes unique inboxes at each // endpoint for streaming data.
[ "Dial", "creates", "a", "new", "net", ".", "Conn", "with", "the", "remote", "address", ".", "This", "is", "implemented", "by", "performing", "a", "handshake", "over", "NATS", "which", "establishes", "unique", "inboxes", "at", "each", "endpoint", "for", "stre...
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/raft_transport.go#L225-L276
train
nats-io/nats-streaming-server
server/raft_transport.go
newNATSTransport
func newNATSTransport(id string, conn *nats.Conn, timeout time.Duration, logOutput io.Writer) (*raft.NetworkTransport, error) { if logOutput == nil { logOutput = os.Stderr } return newNATSTransportWithLogger(id, conn, timeout, log.New(logOutput, "", log.LstdFlags)) }
go
func newNATSTransport(id string, conn *nats.Conn, timeout time.Duration, logOutput io.Writer) (*raft.NetworkTransport, error) { if logOutput == nil { logOutput = os.Stderr } return newNATSTransportWithLogger(id, conn, timeout, log.New(logOutput, "", log.LstdFlags)) }
[ "func", "newNATSTransport", "(", "id", "string", ",", "conn", "*", "nats", ".", "Conn", ",", "timeout", "time", ".", "Duration", ",", "logOutput", "io", ".", "Writer", ")", "(", "*", "raft", ".", "NetworkTransport", ",", "error", ")", "{", "if", "logOu...
// newNATSTransport creates a new raft.NetworkTransport implemented with NATS // as the transport layer.
[ "newNATSTransport", "creates", "a", "new", "raft", ".", "NetworkTransport", "implemented", "with", "NATS", "as", "the", "transport", "layer", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/raft_transport.go#L350-L355
train
nats-io/nats-streaming-server
server/raft_transport.go
newNATSTransportWithLogger
func newNATSTransportWithLogger(id string, conn *nats.Conn, timeout time.Duration, logger *log.Logger) (*raft.NetworkTransport, error) { return createNATSTransport(id, conn, logger, timeout, func(stream raft.StreamLayer) *raft.NetworkTransport { return raft.NewNetworkTransportWithLogger(stream, 3, timeout, logger) ...
go
func newNATSTransportWithLogger(id string, conn *nats.Conn, timeout time.Duration, logger *log.Logger) (*raft.NetworkTransport, error) { return createNATSTransport(id, conn, logger, timeout, func(stream raft.StreamLayer) *raft.NetworkTransport { return raft.NewNetworkTransportWithLogger(stream, 3, timeout, logger) ...
[ "func", "newNATSTransportWithLogger", "(", "id", "string", ",", "conn", "*", "nats", ".", "Conn", ",", "timeout", "time", ".", "Duration", ",", "logger", "*", "log", ".", "Logger", ")", "(", "*", "raft", ".", "NetworkTransport", ",", "error", ")", "{", ...
// newNATSTransportWithLogger creates a new raft.NetworkTransport implemented // with NATS as the transport layer using the provided Logger.
[ "newNATSTransportWithLogger", "creates", "a", "new", "raft", ".", "NetworkTransport", "implemented", "with", "NATS", "as", "the", "transport", "layer", "using", "the", "provided", "Logger", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/raft_transport.go#L359-L363
train
nats-io/nats-streaming-server
server/raft_transport.go
newNATSTransportWithConfig
func newNATSTransportWithConfig(id string, conn *nats.Conn, config *raft.NetworkTransportConfig) (*raft.NetworkTransport, error) { if config.Timeout == 0 { config.Timeout = 2 * time.Second } return createNATSTransport(id, conn, config.Logger, config.Timeout, func(stream raft.StreamLayer) *raft.NetworkTransport { ...
go
func newNATSTransportWithConfig(id string, conn *nats.Conn, config *raft.NetworkTransportConfig) (*raft.NetworkTransport, error) { if config.Timeout == 0 { config.Timeout = 2 * time.Second } return createNATSTransport(id, conn, config.Logger, config.Timeout, func(stream raft.StreamLayer) *raft.NetworkTransport { ...
[ "func", "newNATSTransportWithConfig", "(", "id", "string", ",", "conn", "*", "nats", ".", "Conn", ",", "config", "*", "raft", ".", "NetworkTransportConfig", ")", "(", "*", "raft", ".", "NetworkTransport", ",", "error", ")", "{", "if", "config", ".", "Timeo...
// newNATSTransportWithConfig returns a raft.NetworkTransport implemented // with NATS as the transport layer, using the given config struct.
[ "newNATSTransportWithConfig", "returns", "a", "raft", ".", "NetworkTransport", "implemented", "with", "NATS", "as", "the", "transport", "layer", "using", "the", "given", "config", "struct", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/raft_transport.go#L367-L375
train
nats-io/nats-streaming-server
stores/memstore.go
expireMsgs
func (ms *MemoryMsgStore) expireMsgs() { ms.Lock() defer ms.Unlock() if ms.closed { ms.wg.Done() return } now := time.Now().UnixNano() maxAge := int64(ms.limits.MaxAge) for { m, ok := ms.msgs[ms.first] if !ok { if ms.first < ms.last { ms.first++ continue } ms.ageTimer = nil ms.wg.Don...
go
func (ms *MemoryMsgStore) expireMsgs() { ms.Lock() defer ms.Unlock() if ms.closed { ms.wg.Done() return } now := time.Now().UnixNano() maxAge := int64(ms.limits.MaxAge) for { m, ok := ms.msgs[ms.first] if !ok { if ms.first < ms.last { ms.first++ continue } ms.ageTimer = nil ms.wg.Don...
[ "func", "(", "ms", "*", "MemoryMsgStore", ")", "expireMsgs", "(", ")", "{", "ms", ".", "Lock", "(", ")", "\n", "defer", "ms", ".", "Unlock", "(", ")", "\n", "if", "ms", ".", "closed", "{", "ms", ".", "wg", ".", "Done", "(", ")", "\n", "return",...
// expireMsgs ensures that messages don't stay in the log longer than the // limit's MaxAge.
[ "expireMsgs", "ensures", "that", "messages", "don", "t", "stay", "in", "the", "log", "longer", "than", "the", "limit", "s", "MaxAge", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/memstore.go#L189-L222
train
nats-io/nats-streaming-server
stores/memstore.go
removeFirstMsg
func (ms *MemoryMsgStore) removeFirstMsg() { firstMsg := ms.msgs[ms.first] ms.totalBytes -= uint64(firstMsg.Size()) ms.totalCount-- delete(ms.msgs, ms.first) ms.first++ }
go
func (ms *MemoryMsgStore) removeFirstMsg() { firstMsg := ms.msgs[ms.first] ms.totalBytes -= uint64(firstMsg.Size()) ms.totalCount-- delete(ms.msgs, ms.first) ms.first++ }
[ "func", "(", "ms", "*", "MemoryMsgStore", ")", "removeFirstMsg", "(", ")", "{", "firstMsg", ":=", "ms", ".", "msgs", "[", "ms", ".", "first", "]", "\n", "ms", ".", "totalBytes", "-=", "uint64", "(", "firstMsg", ".", "Size", "(", ")", ")", "\n", "ms...
// removeFirstMsg removes the first message and updates totals.
[ "removeFirstMsg", "removes", "the", "first", "message", "and", "updates", "totals", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/memstore.go#L225-L231
train
nats-io/nats-streaming-server
stores/sqlstore.go
SQLNoCaching
func SQLNoCaching(noCaching bool) SQLStoreOption { return func(o *SQLStoreOptions) error { o.NoCaching = noCaching return nil } }
go
func SQLNoCaching(noCaching bool) SQLStoreOption { return func(o *SQLStoreOptions) error { o.NoCaching = noCaching return nil } }
[ "func", "SQLNoCaching", "(", "noCaching", "bool", ")", "SQLStoreOption", "{", "return", "func", "(", "o", "*", "SQLStoreOptions", ")", "error", "{", "o", ".", "NoCaching", "=", "noCaching", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// SQLNoCaching sets the NoCaching option
[ "SQLNoCaching", "sets", "the", "NoCaching", "option" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/sqlstore.go#L231-L236
train
nats-io/nats-streaming-server
stores/sqlstore.go
SQLMaxOpenConns
func SQLMaxOpenConns(max int) SQLStoreOption { return func(o *SQLStoreOptions) error { o.MaxOpenConns = max return nil } }
go
func SQLMaxOpenConns(max int) SQLStoreOption { return func(o *SQLStoreOptions) error { o.MaxOpenConns = max return nil } }
[ "func", "SQLMaxOpenConns", "(", "max", "int", ")", "SQLStoreOption", "{", "return", "func", "(", "o", "*", "SQLStoreOptions", ")", "error", "{", "o", ".", "MaxOpenConns", "=", "max", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// SQLMaxOpenConns sets the MaxOpenConns option
[ "SQLMaxOpenConns", "sets", "the", "MaxOpenConns", "option" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/sqlstore.go#L239-L244
train
nats-io/nats-streaming-server
stores/sqlstore.go
SQLAllOptions
func SQLAllOptions(opts *SQLStoreOptions) SQLStoreOption { return func(o *SQLStoreOptions) error { o.NoCaching = opts.NoCaching o.MaxOpenConns = opts.MaxOpenConns return nil } }
go
func SQLAllOptions(opts *SQLStoreOptions) SQLStoreOption { return func(o *SQLStoreOptions) error { o.NoCaching = opts.NoCaching o.MaxOpenConns = opts.MaxOpenConns return nil } }
[ "func", "SQLAllOptions", "(", "opts", "*", "SQLStoreOptions", ")", "SQLStoreOption", "{", "return", "func", "(", "o", "*", "SQLStoreOptions", ")", "error", "{", "o", ".", "NoCaching", "=", "opts", ".", "NoCaching", "\n", "o", ".", "MaxOpenConns", "=", "opt...
// SQLAllOptions is a convenient option to pass all options from a SQLStoreOptions // structure to the constructor.
[ "SQLAllOptions", "is", "a", "convenient", "option", "to", "pass", "all", "options", "from", "a", "SQLStoreOptions", "structure", "to", "the", "constructor", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/sqlstore.go#L248-L254
train
nats-io/nats-streaming-server
stores/sqlstore.go
sqlStmtError
func sqlStmtError(code int, err error) error { return fmt.Errorf("sql: error executing %q: %v", sqlStmts[code], err) }
go
func sqlStmtError(code int, err error) error { return fmt.Errorf("sql: error executing %q: %v", sqlStmts[code], err) }
[ "func", "sqlStmtError", "(", "code", "int", ",", "err", "error", ")", "error", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "sqlStmts", "[", "code", "]", ",", "err", ")", "\n", "}" ]
// sqlStmtError returns an error including the text of the offending SQL statement.
[ "sqlStmtError", "returns", "an", "error", "including", "the", "text", "of", "the", "offending", "SQL", "statement", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/sqlstore.go#L353-L355
train
nats-io/nats-streaming-server
stores/sqlstore.go
updateDBLock
func (s *SQLStore) updateDBLock() { defer s.wg.Done() var ( ticker = time.NewTicker(sqlLockUpdateInterval) hasLock = true err error failed int ) for { select { case <-ticker.C: hasLock, _, _, err = s.acquireDBLock(false) if !hasLock || err != nil { // If there is no error but we did not...
go
func (s *SQLStore) updateDBLock() { defer s.wg.Done() var ( ticker = time.NewTicker(sqlLockUpdateInterval) hasLock = true err error failed int ) for { select { case <-ticker.C: hasLock, _, _, err = s.acquireDBLock(false) if !hasLock || err != nil { // If there is no error but we did not...
[ "func", "(", "s", "*", "SQLStore", ")", "updateDBLock", "(", ")", "{", "defer", "s", ".", "wg", ".", "Done", "(", ")", "\n\n", "var", "(", "ticker", "=", "time", ".", "NewTicker", "(", "sqlLockUpdateInterval", ")", "\n", "hasLock", "=", "true", "\n",...
// This go-routine updates the DB store lock at regular intervals.
[ "This", "go", "-", "routine", "updates", "the", "DB", "store", "lock", "at", "regular", "intervals", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/sqlstore.go#L478-L514
train
nats-io/nats-streaming-server
stores/sqlstore.go
acquireDBLock
func (s *SQLStore) acquireDBLock(steal bool) (bool, string, uint64, error) { s.dbLock.Lock() defer s.dbLock.Unlock() var ( lockID string tick uint64 hasLock bool ) tx, err := s.dbLock.db.Begin() if err != nil { return false, "", 0, err } defer func() { if tx != nil { tx.Rollback() } }() r :...
go
func (s *SQLStore) acquireDBLock(steal bool) (bool, string, uint64, error) { s.dbLock.Lock() defer s.dbLock.Unlock() var ( lockID string tick uint64 hasLock bool ) tx, err := s.dbLock.db.Begin() if err != nil { return false, "", 0, err } defer func() { if tx != nil { tx.Rollback() } }() r :...
[ "func", "(", "s", "*", "SQLStore", ")", "acquireDBLock", "(", "steal", "bool", ")", "(", "bool", ",", "string", ",", "uint64", ",", "error", ")", "{", "s", ".", "dbLock", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "dbLock", ".", "Unlock", "(...
// Returns if lock is acquired, the owner and tick value of the lock record.
[ "Returns", "if", "lock", "is", "acquired", "the", "owner", "and", "tick", "value", "of", "the", "lock", "record", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/sqlstore.go#L517-L558
train
nats-io/nats-streaming-server
stores/sqlstore.go
releaseDBLockIfOwner
func (s *SQLStore) releaseDBLockIfOwner() { s.dbLock.Lock() defer s.dbLock.Unlock() if s.dbLock.isOwner { s.dbLock.db.Exec(sqlStmts[sqlDBLockUpdate], "", 0) } }
go
func (s *SQLStore) releaseDBLockIfOwner() { s.dbLock.Lock() defer s.dbLock.Unlock() if s.dbLock.isOwner { s.dbLock.db.Exec(sqlStmts[sqlDBLockUpdate], "", 0) } }
[ "func", "(", "s", "*", "SQLStore", ")", "releaseDBLockIfOwner", "(", ")", "{", "s", ".", "dbLock", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "dbLock", ".", "Unlock", "(", ")", "\n", "if", "s", ".", "dbLock", ".", "isOwner", "{", "s", ".", ...
// Release the store lock if this store was the owner of the lock
[ "Release", "the", "store", "lock", "if", "this", "store", "was", "the", "owner", "of", "the", "lock" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/sqlstore.go#L561-L567
train
nats-io/nats-streaming-server
stores/sqlstore.go
scheduleSubStoreFlush
func (s *SQLStore) scheduleSubStoreFlush(ss *SQLSubStore) { needSignal := false f := s.ssFlusher f.Lock() f.stores[ss] = struct{}{} if !f.signaled { f.signaled = true needSignal = true } f.Unlock() if needSignal { select { case f.signalCh <- struct{}{}: default: } } }
go
func (s *SQLStore) scheduleSubStoreFlush(ss *SQLSubStore) { needSignal := false f := s.ssFlusher f.Lock() f.stores[ss] = struct{}{} if !f.signaled { f.signaled = true needSignal = true } f.Unlock() if needSignal { select { case f.signalCh <- struct{}{}: default: } } }
[ "func", "(", "s", "*", "SQLStore", ")", "scheduleSubStoreFlush", "(", "ss", "*", "SQLSubStore", ")", "{", "needSignal", ":=", "false", "\n", "f", ":=", "s", ".", "ssFlusher", "\n", "f", ".", "Lock", "(", ")", "\n", "f", ".", "stores", "[", "ss", "]...
// Add this store to the list of SubStore needing flushing // and signal the go-routine responsible for flushing if // need be.
[ "Add", "this", "store", "to", "the", "list", "of", "SubStore", "needing", "flushing", "and", "signal", "the", "go", "-", "routine", "responsible", "for", "flushing", "if", "need", "be", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/sqlstore.go#L617-L633
train
nats-io/nats-streaming-server
stores/sqlstore.go
newSQLMsgStore
func (s *SQLStore) newSQLMsgStore(channel string, channelID int64, limits *MsgStoreLimits) *SQLMsgStore { msgStore := &SQLMsgStore{ sqlStore: s, channelID: channelID, } msgStore.init(channel, s.log, limits) if !s.opts.NoCaching { msgStore.writeCache = &sqlMsgsCache{msgs: make(map[uint64]*sqlCachedMsg)} } r...
go
func (s *SQLStore) newSQLMsgStore(channel string, channelID int64, limits *MsgStoreLimits) *SQLMsgStore { msgStore := &SQLMsgStore{ sqlStore: s, channelID: channelID, } msgStore.init(channel, s.log, limits) if !s.opts.NoCaching { msgStore.writeCache = &sqlMsgsCache{msgs: make(map[uint64]*sqlCachedMsg)} } r...
[ "func", "(", "s", "*", "SQLStore", ")", "newSQLMsgStore", "(", "channel", "string", ",", "channelID", "int64", ",", "limits", "*", "MsgStoreLimits", ")", "*", "SQLMsgStore", "{", "msgStore", ":=", "&", "SQLMsgStore", "{", "sqlStore", ":", "s", ",", "channe...
// creates an instance of a SQLMsgStore
[ "creates", "an", "instance", "of", "a", "SQLMsgStore" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/sqlstore.go#L636-L646
train
nats-io/nats-streaming-server
stores/sqlstore.go
newSQLSubStore
func (s *SQLStore) newSQLSubStore(channelID int64, limits *SubStoreLimits) *SQLSubStore { subStore := &SQLSubStore{ sqlStore: s, channelID: channelID, maxSubID: &s.maxSubID, limits: *limits, } subStore.log = s.log if s.opts.NoCaching { subStore.subLastSent = make(map[uint64]uint64) } else { subSto...
go
func (s *SQLStore) newSQLSubStore(channelID int64, limits *SubStoreLimits) *SQLSubStore { subStore := &SQLSubStore{ sqlStore: s, channelID: channelID, maxSubID: &s.maxSubID, limits: *limits, } subStore.log = s.log if s.opts.NoCaching { subStore.subLastSent = make(map[uint64]uint64) } else { subSto...
[ "func", "(", "s", "*", "SQLStore", ")", "newSQLSubStore", "(", "channelID", "int64", ",", "limits", "*", "SubStoreLimits", ")", "*", "SQLSubStore", "{", "subStore", ":=", "&", "SQLSubStore", "{", "sqlStore", ":", "s", ",", "channelID", ":", "channelID", ",...
// creates an instance of SQLSubStore
[ "creates", "an", "instance", "of", "SQLSubStore" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/sqlstore.go#L649-L665
train
nats-io/nats-streaming-server
stores/sqlstore.go
initSQLStmtsTable
func initSQLStmtsTable(driver string) { // The sqlStmts table is initialized with MySQL statements. // Update the statements for the selected driver. switch driver { case driverPostgres: // Replace ? with $1, $2, etc... for i, stmt := range sqlStmts { n := 0 for strings.IndexByte(stmt, '?') != -1 { n+...
go
func initSQLStmtsTable(driver string) { // The sqlStmts table is initialized with MySQL statements. // Update the statements for the selected driver. switch driver { case driverPostgres: // Replace ? with $1, $2, etc... for i, stmt := range sqlStmts { n := 0 for strings.IndexByte(stmt, '?') != -1 { n+...
[ "func", "initSQLStmtsTable", "(", "driver", "string", ")", "{", "// The sqlStmts table is initialized with MySQL statements.", "// Update the statements for the selected driver.", "switch", "driver", "{", "case", "driverPostgres", ":", "// Replace ? with $1, $2, etc...", "for", "i"...
// initialize the global sqlStmts table to driver's one.
[ "initialize", "the", "global", "sqlStmts", "table", "to", "driver", "s", "one", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/sqlstore.go#L680-L705
train
nats-io/nats-streaming-server
stores/sqlstore.go
Init
func (s *SQLStore) Init(info *spb.ServerInfo) error { s.Lock() defer s.Unlock() count := 0 r := s.db.QueryRow(sqlStmts[sqlHasServerInfoRow]) if err := r.Scan(&count); err != nil && err != sql.ErrNoRows { return sqlStmtError(sqlHasServerInfoRow, err) } infoBytes, _ := info.Marshal() if count == 0 { if _, err...
go
func (s *SQLStore) Init(info *spb.ServerInfo) error { s.Lock() defer s.Unlock() count := 0 r := s.db.QueryRow(sqlStmts[sqlHasServerInfoRow]) if err := r.Scan(&count); err != nil && err != sql.ErrNoRows { return sqlStmtError(sqlHasServerInfoRow, err) } infoBytes, _ := info.Marshal() if count == 0 { if _, err...
[ "func", "(", "s", "*", "SQLStore", ")", "Init", "(", "info", "*", "spb", ".", "ServerInfo", ")", "error", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n", "count", ":=", "0", "\n", "r", ":=", "s", ".", "db",...
// Init implements the Store interface
[ "Init", "implements", "the", "Store", "interface" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/sqlstore.go#L708-L727
train
nats-io/nats-streaming-server
stores/sqlstore.go
Close
func (s *SQLStore) Close() error { s.Lock() if s.closed { s.Unlock() return nil } s.closed = true // This will cause MsgStore's and SubStore's to be closed. err := s.close() db := s.db wg := &s.wg // Signal background go-routines to quit if s.doneCh != nil { close(s.doneCh) } s.Unlock() // Wait for ...
go
func (s *SQLStore) Close() error { s.Lock() if s.closed { s.Unlock() return nil } s.closed = true // This will cause MsgStore's and SubStore's to be closed. err := s.close() db := s.db wg := &s.wg // Signal background go-routines to quit if s.doneCh != nil { close(s.doneCh) } s.Unlock() // Wait for ...
[ "func", "(", "s", "*", "SQLStore", ")", "Close", "(", ")", "error", "{", "s", ".", "Lock", "(", ")", "\n", "if", "s", ".", "closed", "{", "s", ".", "Unlock", "(", ")", "\n", "return", "nil", "\n", "}", "\n", "s", ".", "closed", "=", "true", ...
// Close implements the Store interface
[ "Close", "implements", "the", "Store", "interface" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/sqlstore.go#L1272-L1308
train
nats-io/nats-streaming-server
stores/sqlstore.go
GetSequenceFromTimestamp
func (ms *SQLMsgStore) GetSequenceFromTimestamp(timestamp int64) (uint64, error) { ms.Lock() defer ms.Unlock() // No message ever stored if ms.first == 0 { return 0, nil } // All messages have expired if ms.first > ms.last { return ms.last + 1, nil } r := ms.sqlStore.preparedStmts[sqlGetSequenceFromTimesta...
go
func (ms *SQLMsgStore) GetSequenceFromTimestamp(timestamp int64) (uint64, error) { ms.Lock() defer ms.Unlock() // No message ever stored if ms.first == 0 { return 0, nil } // All messages have expired if ms.first > ms.last { return ms.last + 1, nil } r := ms.sqlStore.preparedStmts[sqlGetSequenceFromTimesta...
[ "func", "(", "ms", "*", "SQLMsgStore", ")", "GetSequenceFromTimestamp", "(", "timestamp", "int64", ")", "(", "uint64", ",", "error", ")", "{", "ms", ".", "Lock", "(", ")", "\n", "defer", "ms", ".", "Unlock", "(", ")", "\n", "// No message ever stored", "...
// GetSequenceFromTimestamp implements the MsgStore interface
[ "GetSequenceFromTimestamp", "implements", "the", "MsgStore", "interface" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/sqlstore.go#L1481-L1502
train
nats-io/nats-streaming-server
stores/sqlstore.go
LastMsg
func (ms *SQLMsgStore) LastMsg() (*pb.MsgProto, error) { ms.Lock() msg, err := ms.lookup(ms.last) ms.Unlock() return msg, err }
go
func (ms *SQLMsgStore) LastMsg() (*pb.MsgProto, error) { ms.Lock() msg, err := ms.lookup(ms.last) ms.Unlock() return msg, err }
[ "func", "(", "ms", "*", "SQLMsgStore", ")", "LastMsg", "(", ")", "(", "*", "pb", ".", "MsgProto", ",", "error", ")", "{", "ms", ".", "Lock", "(", ")", "\n", "msg", ",", "err", ":=", "ms", ".", "lookup", "(", "ms", ".", "last", ")", "\n", "ms"...
// LastMsg implements the MsgStore interface
[ "LastMsg", "implements", "the", "MsgStore", "interface" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/sqlstore.go#L1513-L1518
train
nats-io/nats-streaming-server
stores/sqlstore.go
expireMsgs
func (ms *SQLMsgStore) expireMsgs() { ms.Lock() defer ms.Unlock() if ms.closed { ms.wg.Done() return } var ( count int maxSeq uint64 totalSize uint64 timestamp int64 ) processErr := func(errCode int, err error) { ms.log.Errorf("Unable to perform expiration for channel %q: %v", ms.subject, ...
go
func (ms *SQLMsgStore) expireMsgs() { ms.Lock() defer ms.Unlock() if ms.closed { ms.wg.Done() return } var ( count int maxSeq uint64 totalSize uint64 timestamp int64 ) processErr := func(errCode int, err error) { ms.log.Errorf("Unable to perform expiration for channel %q: %v", ms.subject, ...
[ "func", "(", "ms", "*", "SQLMsgStore", ")", "expireMsgs", "(", ")", "{", "ms", ".", "Lock", "(", ")", "\n", "defer", "ms", ".", "Unlock", "(", ")", "\n\n", "if", "ms", ".", "closed", "{", "ms", ".", "wg", ".", "Done", "(", ")", "\n", "return", ...
// expireMsgsLocked removes all messages that have expired in this channel. // Store lock is assumed held on entry
[ "expireMsgsLocked", "removes", "all", "messages", "that", "have", "expired", "in", "this", "channel", ".", "Store", "lock", "is", "assumed", "held", "on", "entry" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/sqlstore.go#L1522-L1591
train
nats-io/nats-streaming-server
stores/sqlstore.go
Flush
func (ms *SQLMsgStore) Flush() error { ms.Lock() err := ms.flush() ms.Unlock() return err }
go
func (ms *SQLMsgStore) Flush() error { ms.Lock() err := ms.flush() ms.Unlock() return err }
[ "func", "(", "ms", "*", "SQLMsgStore", ")", "Flush", "(", ")", "error", "{", "ms", ".", "Lock", "(", ")", "\n", "err", ":=", "ms", ".", "flush", "(", ")", "\n", "ms", ".", "Unlock", "(", ")", "\n", "return", "err", "\n", "}" ]
// Flush implements the MsgStore interface
[ "Flush", "implements", "the", "MsgStore", "interface" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/sqlstore.go#L1674-L1679
train
nats-io/nats-streaming-server
stores/sqlstore.go
UpdateSub
func (ss *SQLSubStore) UpdateSub(sub *spb.SubState) error { ss.Lock() defer ss.Unlock() subBytes, _ := sub.Marshal() r, err := ss.sqlStore.preparedStmts[sqlUpdateSub].Exec(subBytes, ss.channelID, sub.ID) if err != nil { return sqlStmtError(sqlUpdateSub, err) } // FileSubStoe supports updating a subscription fo...
go
func (ss *SQLSubStore) UpdateSub(sub *spb.SubState) error { ss.Lock() defer ss.Unlock() subBytes, _ := sub.Marshal() r, err := ss.sqlStore.preparedStmts[sqlUpdateSub].Exec(subBytes, ss.channelID, sub.ID) if err != nil { return sqlStmtError(sqlUpdateSub, err) } // FileSubStoe supports updating a subscription fo...
[ "func", "(", "ss", "*", "SQLSubStore", ")", "UpdateSub", "(", "sub", "*", "spb", ".", "SubState", ")", "error", "{", "ss", ".", "Lock", "(", ")", "\n", "defer", "ss", ".", "Unlock", "(", ")", "\n", "subBytes", ",", "_", ":=", "sub", ".", "Marshal...
// UpdateSub implements the SubStore interface
[ "UpdateSub", "implements", "the", "SubStore", "interface" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/sqlstore.go#L1737-L1758
train
nats-io/nats-streaming-server
stores/sqlstore.go
DeleteSub
func (ss *SQLSubStore) DeleteSub(subid uint64) error { ss.Lock() defer ss.Unlock() if subid == atomic.LoadUint64(ss.maxSubID) { if _, err := ss.sqlStore.preparedStmts[sqlMarkSubscriptionAsDeleted].Exec(ss.channelID, subid); err != nil { return sqlStmtError(sqlMarkSubscriptionAsDeleted, err) } ss.hasMarkedAs...
go
func (ss *SQLSubStore) DeleteSub(subid uint64) error { ss.Lock() defer ss.Unlock() if subid == atomic.LoadUint64(ss.maxSubID) { if _, err := ss.sqlStore.preparedStmts[sqlMarkSubscriptionAsDeleted].Exec(ss.channelID, subid); err != nil { return sqlStmtError(sqlMarkSubscriptionAsDeleted, err) } ss.hasMarkedAs...
[ "func", "(", "ss", "*", "SQLSubStore", ")", "DeleteSub", "(", "subid", "uint64", ")", "error", "{", "ss", ".", "Lock", "(", ")", "\n", "defer", "ss", ".", "Unlock", "(", ")", "\n", "if", "subid", "==", "atomic", ".", "LoadUint64", "(", "ss", ".", ...
// DeleteSub implements the SubStore interface
[ "DeleteSub", "implements", "the", "SubStore", "interface" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/sqlstore.go#L1761-L1783
train
nats-io/nats-streaming-server
stores/sqlstore.go
getOrCreateAcksPending
func (ss *SQLSubStore) getOrCreateAcksPending(subid, seqno uint64) *sqlSubAcksPending { if !ss.cache.needsFlush { ss.cache.needsFlush = true ss.sqlStore.scheduleSubStoreFlush(ss) } ap := ss.cache.subs[subid] if ap == nil { ap = &sqlSubAcksPending{ msgToRow: make(map[uint64]*sqlSubsPendingRow), ackToRow:...
go
func (ss *SQLSubStore) getOrCreateAcksPending(subid, seqno uint64) *sqlSubAcksPending { if !ss.cache.needsFlush { ss.cache.needsFlush = true ss.sqlStore.scheduleSubStoreFlush(ss) } ap := ss.cache.subs[subid] if ap == nil { ap = &sqlSubAcksPending{ msgToRow: make(map[uint64]*sqlSubsPendingRow), ackToRow:...
[ "func", "(", "ss", "*", "SQLSubStore", ")", "getOrCreateAcksPending", "(", "subid", ",", "seqno", "uint64", ")", "*", "sqlSubAcksPending", "{", "if", "!", "ss", ".", "cache", ".", "needsFlush", "{", "ss", ".", "cache", ".", "needsFlush", "=", "true", "\n...
// This returns the structure responsible to keep track of // pending messages and acks for a given subscription ID.
[ "This", "returns", "the", "structure", "responsible", "to", "keep", "track", "of", "pending", "messages", "and", "acks", "for", "a", "given", "subscription", "ID", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/sqlstore.go#L1787-L1806
train
nats-io/nats-streaming-server
stores/sqlstore.go
addSeq
func (ss *SQLSubStore) addSeq(subid, seqno uint64) bool { ap := ss.getOrCreateAcksPending(subid, seqno) ap.msgs[seqno] = struct{}{} return len(ap.msgs) >= sqlMaxPendingAcks }
go
func (ss *SQLSubStore) addSeq(subid, seqno uint64) bool { ap := ss.getOrCreateAcksPending(subid, seqno) ap.msgs[seqno] = struct{}{} return len(ap.msgs) >= sqlMaxPendingAcks }
[ "func", "(", "ss", "*", "SQLSubStore", ")", "addSeq", "(", "subid", ",", "seqno", "uint64", ")", "bool", "{", "ap", ":=", "ss", ".", "getOrCreateAcksPending", "(", "subid", ",", "seqno", ")", "\n", "ap", ".", "msgs", "[", "seqno", "]", "=", "struct",...
// Adds the given sequence to the list of pending messages. // Returns true if the number of pending messages has // reached a certain threshold, indicating that the // store should be flushed.
[ "Adds", "the", "given", "sequence", "to", "the", "list", "of", "pending", "messages", ".", "Returns", "true", "if", "the", "number", "of", "pending", "messages", "has", "reached", "a", "certain", "threshold", "indicating", "that", "the", "store", "should", "...
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/sqlstore.go#L1812-L1816
train
nats-io/nats-streaming-server
stores/sqlstore.go
ackSeq
func (ss *SQLSubStore) ackSeq(subid, seqno uint64) (bool, error) { ap := ss.getOrCreateAcksPending(subid, seqno) // If still in cache and not persisted into a row, // then simply remove from map and do not persist the ack. if _, exists := ap.msgs[seqno]; exists { delete(ap.msgs, seqno) } else if row := ap.msgToR...
go
func (ss *SQLSubStore) ackSeq(subid, seqno uint64) (bool, error) { ap := ss.getOrCreateAcksPending(subid, seqno) // If still in cache and not persisted into a row, // then simply remove from map and do not persist the ack. if _, exists := ap.msgs[seqno]; exists { delete(ap.msgs, seqno) } else if row := ap.msgToR...
[ "func", "(", "ss", "*", "SQLSubStore", ")", "ackSeq", "(", "subid", ",", "seqno", "uint64", ")", "(", "bool", ",", "error", ")", "{", "ap", ":=", "ss", ".", "getOrCreateAcksPending", "(", "subid", ",", "seqno", ")", "\n", "// If still in cache and not pers...
// Adds the given sequence to the list of acks and possibly // delete rows that have all their pending messages acknowledged. // Returns true if the number of acks has reached a certain threshold, // indicating that the store should be flushed.
[ "Adds", "the", "given", "sequence", "to", "the", "list", "of", "acks", "and", "possibly", "delete", "rows", "that", "have", "all", "their", "pending", "messages", "acknowledged", ".", "Returns", "true", "if", "the", "number", "of", "acks", "has", "reached", ...
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/sqlstore.go#L1822-L1877
train
nats-io/nats-streaming-server
stores/sqlstore.go
AddSeqPending
func (ss *SQLSubStore) AddSeqPending(subid, seqno uint64) error { var err error ss.Lock() if !ss.closed { if ss.cache != nil { if isFull := ss.addSeq(subid, seqno); isFull { err = ss.flush() } } else { ls := ss.subLastSent[subid] if seqno > ls { ss.subLastSent[subid] = seqno } ss.curRow...
go
func (ss *SQLSubStore) AddSeqPending(subid, seqno uint64) error { var err error ss.Lock() if !ss.closed { if ss.cache != nil { if isFull := ss.addSeq(subid, seqno); isFull { err = ss.flush() } } else { ls := ss.subLastSent[subid] if seqno > ls { ss.subLastSent[subid] = seqno } ss.curRow...
[ "func", "(", "ss", "*", "SQLSubStore", ")", "AddSeqPending", "(", "subid", ",", "seqno", "uint64", ")", "error", "{", "var", "err", "error", "\n", "ss", ".", "Lock", "(", ")", "\n", "if", "!", "ss", ".", "closed", "{", "if", "ss", ".", "cache", "...
// AddSeqPending implements the SubStore interface
[ "AddSeqPending", "implements", "the", "SubStore", "interface" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/sqlstore.go#L1880-L1902
train
nats-io/nats-streaming-server
stores/sqlstore.go
AckSeqPending
func (ss *SQLSubStore) AckSeqPending(subid, seqno uint64) error { var err error ss.Lock() if !ss.closed { if ss.cache != nil { var isFull bool isFull, err = ss.ackSeq(subid, seqno) if err == nil && isFull { err = ss.flush() } } else { updateLastSent := false ls := ss.subLastSent[subid] i...
go
func (ss *SQLSubStore) AckSeqPending(subid, seqno uint64) error { var err error ss.Lock() if !ss.closed { if ss.cache != nil { var isFull bool isFull, err = ss.ackSeq(subid, seqno) if err == nil && isFull { err = ss.flush() } } else { updateLastSent := false ls := ss.subLastSent[subid] i...
[ "func", "(", "ss", "*", "SQLSubStore", ")", "AckSeqPending", "(", "subid", ",", "seqno", "uint64", ")", "error", "{", "var", "err", "error", "\n", "ss", ".", "Lock", "(", ")", "\n", "if", "!", "ss", ".", "closed", "{", "if", "ss", ".", "cache", "...
// AckSeqPending implements the SubStore interface
[ "AckSeqPending", "implements", "the", "SubStore", "interface" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/sqlstore.go#L1905-L1938
train
nats-io/nats-streaming-server
stores/sqlstore.go
Flush
func (ss *SQLSubStore) Flush() error { ss.Lock() err := ss.flush() ss.Unlock() return err }
go
func (ss *SQLSubStore) Flush() error { ss.Lock() err := ss.flush() ss.Unlock() return err }
[ "func", "(", "ss", "*", "SQLSubStore", ")", "Flush", "(", ")", "error", "{", "ss", ".", "Lock", "(", ")", "\n", "err", ":=", "ss", ".", "flush", "(", ")", "\n", "ss", ".", "Unlock", "(", ")", "\n", "return", "err", "\n", "}" ]
// Flush implements the SubStore interface
[ "Flush", "implements", "the", "SubStore", "interface" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/sqlstore.go#L2015-L2020
train
nats-io/nats-streaming-server
stores/sqlstore.go
Close
func (ss *SQLSubStore) Close() error { ss.Lock() if ss.closed { ss.Unlock() return nil } // Flush before switching the state to closed. err := ss.flush() ss.closed = true ss.Unlock() return err }
go
func (ss *SQLSubStore) Close() error { ss.Lock() if ss.closed { ss.Unlock() return nil } // Flush before switching the state to closed. err := ss.flush() ss.closed = true ss.Unlock() return err }
[ "func", "(", "ss", "*", "SQLSubStore", ")", "Close", "(", ")", "error", "{", "ss", ".", "Lock", "(", ")", "\n", "if", "ss", ".", "closed", "{", "ss", ".", "Unlock", "(", ")", "\n", "return", "nil", "\n", "}", "\n", "// Flush before switching the stat...
// Close implements the SubStore interface
[ "Close", "implements", "the", "SubStore", "interface" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/sqlstore.go#L2136-L2147
train
nats-io/nats-streaming-server
util/channels.go
SendChannelsList
func SendChannelsList(channels []string, sendInbox, replyInbox string, nc *nats.Conn, serverID string) error { // Since the NATS message payload is limited, we need to repeat // requests if all channels can't fit in a request. maxPayload := int(nc.MaxPayload()) // Reuse this request object to send the (possibly man...
go
func SendChannelsList(channels []string, sendInbox, replyInbox string, nc *nats.Conn, serverID string) error { // Since the NATS message payload is limited, we need to repeat // requests if all channels can't fit in a request. maxPayload := int(nc.MaxPayload()) // Reuse this request object to send the (possibly man...
[ "func", "SendChannelsList", "(", "channels", "[", "]", "string", ",", "sendInbox", ",", "replyInbox", "string", ",", "nc", "*", "nats", ".", "Conn", ",", "serverID", "string", ")", "error", "{", "// Since the NATS message payload is limited, we need to repeat", "// ...
// SendsChannelsList sends the list of channels to the given subject, possibly // splitting the list in several requests if it cannot fit in a single message.
[ "SendsChannelsList", "sends", "the", "list", "of", "channels", "to", "the", "given", "subject", "possibly", "splitting", "the", "list", "in", "several", "requests", "if", "it", "cannot", "fit", "in", "a", "single", "message", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/util/channels.go#L30-L57
train
nats-io/nats-streaming-server
util/channels.go
DecodeChannels
func DecodeChannels(data []byte) ([]string, error) { channels := []string{} pos := 0 for pos < len(data) { if pos+2 > len(data) { return nil, fmt.Errorf("unable to decode size, pos=%v len=%v", pos, len(data)) } cl := int(ByteOrder.Uint16(data[pos:])) pos += encodedChannelLen end := pos + cl if end > l...
go
func DecodeChannels(data []byte) ([]string, error) { channels := []string{} pos := 0 for pos < len(data) { if pos+2 > len(data) { return nil, fmt.Errorf("unable to decode size, pos=%v len=%v", pos, len(data)) } cl := int(ByteOrder.Uint16(data[pos:])) pos += encodedChannelLen end := pos + cl if end > l...
[ "func", "DecodeChannels", "(", "data", "[", "]", "byte", ")", "(", "[", "]", "string", ",", "error", ")", "{", "channels", ":=", "[", "]", "string", "{", "}", "\n", "pos", ":=", "0", "\n", "for", "pos", "<", "len", "(", "data", ")", "{", "if", ...
// DecodeChannels decodes from the given byte array the list of channel names // and return them as an array of strings.
[ "DecodeChannels", "decodes", "from", "the", "given", "byte", "array", "the", "list", "of", "channel", "names", "and", "return", "them", "as", "an", "array", "of", "strings", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/util/channels.go#L61-L80
train
nats-io/nats-streaming-server
server/ft.go
ftStart
func (s *StanServer) ftStart() (retErr error) { s.log.Noticef("Starting in standby mode") // For tests purposes if ftPauseBeforeFirstAttempt { <-ftPauseCh } print, _ := util.NewBackoffTimeCheck(time.Second, 2, time.Minute) for { select { case <-s.ftQuit: // we are done return nil case <-s.ftHBCh: ...
go
func (s *StanServer) ftStart() (retErr error) { s.log.Noticef("Starting in standby mode") // For tests purposes if ftPauseBeforeFirstAttempt { <-ftPauseCh } print, _ := util.NewBackoffTimeCheck(time.Second, 2, time.Minute) for { select { case <-s.ftQuit: // we are done return nil case <-s.ftHBCh: ...
[ "func", "(", "s", "*", "StanServer", ")", "ftStart", "(", ")", "(", "retErr", "error", ")", "{", "s", ".", "log", ".", "Noticef", "(", "\"", "\"", ")", "\n", "// For tests purposes", "if", "ftPauseBeforeFirstAttempt", "{", "<-", "ftPauseCh", "\n", "}", ...
// ftStart will return only when this server has become active // and was able to get the store's exclusive lock. // This is running in a separate go-routine so if server state // changes, take care of using the server's lock.
[ "ftStart", "will", "return", "only", "when", "this", "server", "has", "become", "active", "and", "was", "able", "to", "get", "the", "store", "s", "exclusive", "lock", ".", "This", "is", "running", "in", "a", "separate", "go", "-", "routine", "so", "if", ...
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/ft.go#L56-L102
train
nats-io/nats-streaming-server
server/ft.go
ftGetStoreLock
func (s *StanServer) ftGetStoreLock() (bool, error) { // Normally, the store would be set early and is immutable, but some // FT tests do set a mock store after the server is created, so use // locking here to avoid race reports. s.mu.Lock() store := s.store s.mu.Unlock() if ok, err := store.GetExclusiveLock(); ...
go
func (s *StanServer) ftGetStoreLock() (bool, error) { // Normally, the store would be set early and is immutable, but some // FT tests do set a mock store after the server is created, so use // locking here to avoid race reports. s.mu.Lock() store := s.store s.mu.Unlock() if ok, err := store.GetExclusiveLock(); ...
[ "func", "(", "s", "*", "StanServer", ")", "ftGetStoreLock", "(", ")", "(", "bool", ",", "error", ")", "{", "// Normally, the store would be set early and is immutable, but some", "// FT tests do set a mock store after the server is created, so use", "// locking here to avoid race r...
// ftGetStoreLock returns true if the server was able to get the // exclusive store lock, false othewise, or if there was a fatal error doing so.
[ "ftGetStoreLock", "returns", "true", "if", "the", "server", "was", "able", "to", "get", "the", "exclusive", "store", "lock", "false", "othewise", "or", "if", "there", "was", "a", "fatal", "error", "doing", "so", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/ft.go#L106-L123
train
nats-io/nats-streaming-server
server/ft.go
ftSendHBLoop
func (s *StanServer) ftSendHBLoop(activationTime time.Time) { // Release the wait group on exit defer s.wg.Done() timeAsBytes, _ := activationTime.MarshalBinary() ftHB := &spb.CtrlMsg{ MsgType: spb.CtrlMsg_FTHeartbeat, ServerID: s.serverID, Data: timeAsBytes, } ftHBBytes, _ := ftHB.Marshal() print, _...
go
func (s *StanServer) ftSendHBLoop(activationTime time.Time) { // Release the wait group on exit defer s.wg.Done() timeAsBytes, _ := activationTime.MarshalBinary() ftHB := &spb.CtrlMsg{ MsgType: spb.CtrlMsg_FTHeartbeat, ServerID: s.serverID, Data: timeAsBytes, } ftHBBytes, _ := ftHB.Marshal() print, _...
[ "func", "(", "s", "*", "StanServer", ")", "ftSendHBLoop", "(", "activationTime", "time", ".", "Time", ")", "{", "// Release the wait group on exit", "defer", "s", ".", "wg", ".", "Done", "(", ")", "\n\n", "timeAsBytes", ",", "_", ":=", "activationTime", ".",...
// ftSendHBLoop is used by an active server to send HB to the FT subject. // Standby servers receiving those HBs do not attempt to lock the store. // When they miss HBs, they will.
[ "ftSendHBLoop", "is", "used", "by", "an", "active", "server", "to", "send", "HB", "to", "the", "FT", "subject", ".", "Standby", "servers", "receiving", "those", "HBs", "do", "not", "attempt", "to", "lock", "the", "store", ".", "When", "they", "miss", "HB...
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/ft.go#L128-L181
train
nats-io/nats-streaming-server
server/ft.go
ftSetup
func (s *StanServer) ftSetup() error { // Check that store type is ok. So far only support for FileStore if s.opts.StoreType != stores.TypeFile && s.opts.StoreType != stores.TypeSQL { return fmt.Errorf("ft: only %v or %v stores supported in FT mode", stores.TypeFile, stores.TypeSQL) } // So far, those are not exp...
go
func (s *StanServer) ftSetup() error { // Check that store type is ok. So far only support for FileStore if s.opts.StoreType != stores.TypeFile && s.opts.StoreType != stores.TypeSQL { return fmt.Errorf("ft: only %v or %v stores supported in FT mode", stores.TypeFile, stores.TypeSQL) } // So far, those are not exp...
[ "func", "(", "s", "*", "StanServer", ")", "ftSetup", "(", ")", "error", "{", "// Check that store type is ok. So far only support for FileStore", "if", "s", ".", "opts", ".", "StoreType", "!=", "stores", ".", "TypeFile", "&&", "s", ".", "opts", ".", "StoreType",...
// ftSetup checks that all required FT parameters have been specified and // create the channel required for shutdown. // Note that FTGroupName has to be set before server invokes this function, // so this parameter is not checked here.
[ "ftSetup", "checks", "that", "all", "required", "FT", "parameters", "have", "been", "specified", "and", "create", "the", "channel", "required", "for", "shutdown", ".", "Note", "that", "FTGroupName", "has", "to", "be", "set", "before", "server", "invokes", "thi...
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/ft.go#L187-L225
train
nats-io/nats-streaming-server
server/client.go
newClientStore
func newClientStore(store stores.Store) *clientStore { return &clientStore{ clients: make(map[string]*client), connIDs: make(map[string]*client), knownInvalid: make(map[string]struct{}), store: store, } }
go
func newClientStore(store stores.Store) *clientStore { return &clientStore{ clients: make(map[string]*client), connIDs: make(map[string]*client), knownInvalid: make(map[string]struct{}), store: store, } }
[ "func", "newClientStore", "(", "store", "stores", ".", "Store", ")", "*", "clientStore", "{", "return", "&", "clientStore", "{", "clients", ":", "make", "(", "map", "[", "string", "]", "*", "client", ")", ",", "connIDs", ":", "make", "(", "map", "[", ...
// newClientStore creates a new clientStore instance using `store` as the backing storage.
[ "newClientStore", "creates", "a", "new", "clientStore", "instance", "using", "store", "as", "the", "backing", "storage", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/client.go#L51-L58
train
nats-io/nats-streaming-server
server/client.go
getSubsCopy
func (c *client) getSubsCopy() []*subState { subs := make([]*subState, len(c.subs)) copy(subs, c.subs) return subs }
go
func (c *client) getSubsCopy() []*subState { subs := make([]*subState, len(c.subs)) copy(subs, c.subs) return subs }
[ "func", "(", "c", "*", "client", ")", "getSubsCopy", "(", ")", "[", "]", "*", "subState", "{", "subs", ":=", "make", "(", "[", "]", "*", "subState", ",", "len", "(", "c", ".", "subs", ")", ")", "\n", "copy", "(", "subs", ",", "c", ".", "subs"...
// getSubsCopy returns a copy of the client's subscribers array. // At least Read-lock must be held by the caller.
[ "getSubsCopy", "returns", "a", "copy", "of", "the", "client", "s", "subscribers", "array", ".", "At", "least", "Read", "-", "lock", "must", "be", "held", "by", "the", "caller", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/client.go#L62-L66
train
nats-io/nats-streaming-server
server/client.go
register
func (cs *clientStore) register(info *spb.ClientInfo) (*client, error) { cs.Lock() defer cs.Unlock() c := cs.clients[info.ID] if c != nil { return nil, ErrInvalidClient } sc, err := cs.store.AddClient(info) if err != nil { return nil, err } c = &client{info: sc, subs: make([]*subState, 0, 4)} cs.clients[c...
go
func (cs *clientStore) register(info *spb.ClientInfo) (*client, error) { cs.Lock() defer cs.Unlock() c := cs.clients[info.ID] if c != nil { return nil, ErrInvalidClient } sc, err := cs.store.AddClient(info) if err != nil { return nil, err } c = &client{info: sc, subs: make([]*subState, 0, 4)} cs.clients[c...
[ "func", "(", "cs", "*", "clientStore", ")", "register", "(", "info", "*", "spb", ".", "ClientInfo", ")", "(", "*", "client", ",", "error", ")", "{", "cs", ".", "Lock", "(", ")", "\n", "defer", "cs", ".", "Unlock", "(", ")", "\n", "c", ":=", "cs...
// Register a new client. Returns ErrInvalidClient if client is already registered.
[ "Register", "a", "new", "client", ".", "Returns", "ErrInvalidClient", "if", "client", "is", "already", "registered", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/client.go#L76-L101
train
nats-io/nats-streaming-server
server/client.go
unregister
func (cs *clientStore) unregister(ID string) (*client, error) { cs.Lock() defer cs.Unlock() c := cs.clients[ID] if c == nil { return nil, nil } c.Lock() if c.hbt != nil { c.hbt.Stop() c.hbt = nil } connID := c.info.ConnID c.Unlock() delete(cs.clients, ID) if len(connID) > 0 { delete(cs.connIDs, stri...
go
func (cs *clientStore) unregister(ID string) (*client, error) { cs.Lock() defer cs.Unlock() c := cs.clients[ID] if c == nil { return nil, nil } c.Lock() if c.hbt != nil { c.hbt.Stop() c.hbt = nil } connID := c.info.ConnID c.Unlock() delete(cs.clients, ID) if len(connID) > 0 { delete(cs.connIDs, stri...
[ "func", "(", "cs", "*", "clientStore", ")", "unregister", "(", "ID", "string", ")", "(", "*", "client", ",", "error", ")", "{", "cs", ".", "Lock", "(", ")", "\n", "defer", "cs", ".", "Unlock", "(", ")", "\n", "c", ":=", "cs", ".", "clients", "[...
// Unregister a client.
[ "Unregister", "a", "client", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/client.go#L104-L127
train
nats-io/nats-streaming-server
server/client.go
isValid
func (cs *clientStore) isValid(ID string, connID []byte) bool { cs.RLock() valid := cs.lookupByConnIDOrID(ID, connID) != nil cs.RUnlock() return valid }
go
func (cs *clientStore) isValid(ID string, connID []byte) bool { cs.RLock() valid := cs.lookupByConnIDOrID(ID, connID) != nil cs.RUnlock() return valid }
[ "func", "(", "cs", "*", "clientStore", ")", "isValid", "(", "ID", "string", ",", "connID", "[", "]", "byte", ")", "bool", "{", "cs", ".", "RLock", "(", ")", "\n", "valid", ":=", "cs", ".", "lookupByConnIDOrID", "(", "ID", ",", "connID", ")", "!=", ...
// IsValid returns true if the client is registered, false otherwise.
[ "IsValid", "returns", "true", "if", "the", "client", "is", "registered", "false", "otherwise", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/client.go#L130-L135
train
nats-io/nats-streaming-server
server/client.go
lookupByConnIDOrID
func (cs *clientStore) lookupByConnIDOrID(ID string, connID []byte) *client { var c *client if len(connID) > 0 { c = cs.connIDs[string(connID)] } else { c = cs.clients[ID] } return c }
go
func (cs *clientStore) lookupByConnIDOrID(ID string, connID []byte) *client { var c *client if len(connID) > 0 { c = cs.connIDs[string(connID)] } else { c = cs.clients[ID] } return c }
[ "func", "(", "cs", "*", "clientStore", ")", "lookupByConnIDOrID", "(", "ID", "string", ",", "connID", "[", "]", "byte", ")", "*", "client", "{", "var", "c", "*", "client", "\n", "if", "len", "(", "connID", ")", ">", "0", "{", "c", "=", "cs", ".",...
// Lookup client by ConnID if not nil, otherwise by clientID. // Assume at least clientStore RLock is held on entry.
[ "Lookup", "client", "by", "ConnID", "if", "not", "nil", "otherwise", "by", "clientID", ".", "Assume", "at", "least", "clientStore", "RLock", "is", "held", "on", "entry", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/client.go#L197-L205
train
nats-io/nats-streaming-server
server/client.go
lookup
func (cs *clientStore) lookup(ID string) *client { cs.RLock() c := cs.clients[ID] cs.RUnlock() return c }
go
func (cs *clientStore) lookup(ID string) *client { cs.RLock() c := cs.clients[ID] cs.RUnlock() return c }
[ "func", "(", "cs", "*", "clientStore", ")", "lookup", "(", "ID", "string", ")", "*", "client", "{", "cs", ".", "RLock", "(", ")", "\n", "c", ":=", "cs", ".", "clients", "[", "ID", "]", "\n", "cs", ".", "RUnlock", "(", ")", "\n", "return", "c", ...
// Lookup a client
[ "Lookup", "a", "client" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/client.go#L208-L213
train
nats-io/nats-streaming-server
server/client.go
lookupByConnID
func (cs *clientStore) lookupByConnID(connID []byte) *client { cs.RLock() c := cs.connIDs[string(connID)] cs.RUnlock() return c }
go
func (cs *clientStore) lookupByConnID(connID []byte) *client { cs.RLock() c := cs.connIDs[string(connID)] cs.RUnlock() return c }
[ "func", "(", "cs", "*", "clientStore", ")", "lookupByConnID", "(", "connID", "[", "]", "byte", ")", "*", "client", "{", "cs", ".", "RLock", "(", ")", "\n", "c", ":=", "cs", ".", "connIDs", "[", "string", "(", "connID", ")", "]", "\n", "cs", ".", ...
// Lookup a client by connection ID
[ "Lookup", "a", "client", "by", "connection", "ID" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/client.go#L216-L221
train
nats-io/nats-streaming-server
server/client.go
getSubs
func (cs *clientStore) getSubs(ID string) []*subState { cs.RLock() defer cs.RUnlock() c := cs.clients[ID] if c == nil { return nil } c.RLock() subs := c.getSubsCopy() c.RUnlock() return subs }
go
func (cs *clientStore) getSubs(ID string) []*subState { cs.RLock() defer cs.RUnlock() c := cs.clients[ID] if c == nil { return nil } c.RLock() subs := c.getSubsCopy() c.RUnlock() return subs }
[ "func", "(", "cs", "*", "clientStore", ")", "getSubs", "(", "ID", "string", ")", "[", "]", "*", "subState", "{", "cs", ".", "RLock", "(", ")", "\n", "defer", "cs", ".", "RUnlock", "(", ")", "\n", "c", ":=", "cs", ".", "clients", "[", "ID", "]",...
// GetSubs returns the list of subscriptions for the client identified by ID, // or nil if such client is not found.
[ "GetSubs", "returns", "the", "list", "of", "subscriptions", "for", "the", "client", "identified", "by", "ID", "or", "nil", "if", "such", "client", "is", "not", "found", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/client.go#L225-L236
train