id
int32
0
167k
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
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
26,800
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
26,801
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
26,802
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
26,803
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
26,804
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
26,805
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
26,806
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
26,807
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
26,808
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
26,809
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
26,810
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
26,811
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
26,812
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
26,813
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
26,814
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
26,815
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
26,816
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
26,817
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
26,818
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
26,819
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
26,820
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
26,821
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
26,822
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
26,823
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
26,824
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
26,825
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
26,826
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
26,827
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
26,828
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
26,829
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
26,830
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
26,831
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
26,832
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
26,833
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
26,834
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
26,835
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
26,836
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
26,837
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
26,838
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
26,839
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
26,840
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
26,841
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
26,842
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
26,843
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
26,844
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
26,845
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
26,846
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
26,847
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
26,848
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
26,849
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
26,850
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
26,851
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
26,852
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
26,853
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
26,854
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
26,855
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
26,856
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
26,857
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
26,858
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
26,859
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
26,860
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
26,861
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
26,862
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
26,863
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
26,864
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
26,865
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
26,866
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
26,867
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
26,868
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
26,869
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
26,870
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
26,871
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
26,872
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
26,873
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
26,874
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
26,875
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
26,876
nats-io/nats-streaming-server
server/client.go
addSub
func (cs *clientStore) addSub(ID string, sub *subState) bool { cs.RLock() defer cs.RUnlock() c := cs.clients[ID] if c == nil { return false } c.Lock() c.subs = append(c.subs, sub) c.Unlock() return true }
go
func (cs *clientStore) addSub(ID string, sub *subState) bool { cs.RLock() defer cs.RUnlock() c := cs.clients[ID] if c == nil { return false } c.Lock() c.subs = append(c.subs, sub) c.Unlock() return true }
[ "func", "(", "cs", "*", "clientStore", ")", "addSub", "(", "ID", "string", ",", "sub", "*", "subState", ")", "bool", "{", "cs", ".", "RLock", "(", ")", "\n", "defer", "cs", ".", "RUnlock", "(", ")", "\n", "c", ":=", "cs", ".", "clients", "[", "...
// AddSub adds the subscription to the client identified by clientID // and returns true only if the client has not been unregistered, // otherwise returns false.
[ "AddSub", "adds", "the", "subscription", "to", "the", "client", "identified", "by", "clientID", "and", "returns", "true", "only", "if", "the", "client", "has", "not", "been", "unregistered", "otherwise", "returns", "false", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/client.go#L241-L252
26,877
nats-io/nats-streaming-server
server/client.go
removeSub
func (cs *clientStore) removeSub(ID string, sub *subState) bool { cs.RLock() defer cs.RUnlock() c := cs.clients[ID] if c == nil { return false } c.Lock() removed := false c.subs, removed = sub.deleteFromList(c.subs) c.Unlock() return removed }
go
func (cs *clientStore) removeSub(ID string, sub *subState) bool { cs.RLock() defer cs.RUnlock() c := cs.clients[ID] if c == nil { return false } c.Lock() removed := false c.subs, removed = sub.deleteFromList(c.subs) c.Unlock() return removed }
[ "func", "(", "cs", "*", "clientStore", ")", "removeSub", "(", "ID", "string", ",", "sub", "*", "subState", ")", "bool", "{", "cs", ".", "RLock", "(", ")", "\n", "defer", "cs", ".", "RUnlock", "(", ")", "\n", "c", ":=", "cs", ".", "clients", "[", ...
// RemoveSub removes the subscription from the client identified by clientID // and returns true only if the client has not been unregistered and that // the subscription was found, otherwise returns false.
[ "RemoveSub", "removes", "the", "subscription", "from", "the", "client", "identified", "by", "clientID", "and", "returns", "true", "only", "if", "the", "client", "has", "not", "been", "unregistered", "and", "that", "the", "subscription", "was", "found", "otherwis...
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/client.go#L257-L269
26,878
nats-io/nats-streaming-server
server/client.go
recoverClients
func (cs *clientStore) recoverClients(clients []*stores.Client) { cs.Lock() for _, sc := range clients { client := &client{info: sc, subs: make([]*subState, 0, 4)} cs.clients[client.info.ID] = client if len(client.info.ConnID) > 0 { cs.connIDs[string(client.info.ConnID)] = client } } cs.Unlock() }
go
func (cs *clientStore) recoverClients(clients []*stores.Client) { cs.Lock() for _, sc := range clients { client := &client{info: sc, subs: make([]*subState, 0, 4)} cs.clients[client.info.ID] = client if len(client.info.ConnID) > 0 { cs.connIDs[string(client.info.ConnID)] = client } } cs.Unlock() }
[ "func", "(", "cs", "*", "clientStore", ")", "recoverClients", "(", "clients", "[", "]", "*", "stores", ".", "Client", ")", "{", "cs", ".", "Lock", "(", ")", "\n", "for", "_", ",", "sc", ":=", "range", "clients", "{", "client", ":=", "&", "client", ...
// recoverClients recreates the content of the client store based on clients // information recovered from the Store.
[ "recoverClients", "recreates", "the", "content", "of", "the", "client", "store", "based", "on", "clients", "information", "recovered", "from", "the", "Store", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/client.go#L273-L283
26,879
nats-io/nats-streaming-server
server/client.go
setClientHB
func (cs *clientStore) setClientHB(ID string, interval time.Duration, f func()) { cs.RLock() defer cs.RUnlock() c := cs.clients[ID] if c == nil { return } c.Lock() if c.hbt == nil { c.hbt = time.AfterFunc(interval, f) } c.Unlock() }
go
func (cs *clientStore) setClientHB(ID string, interval time.Duration, f func()) { cs.RLock() defer cs.RUnlock() c := cs.clients[ID] if c == nil { return } c.Lock() if c.hbt == nil { c.hbt = time.AfterFunc(interval, f) } c.Unlock() }
[ "func", "(", "cs", "*", "clientStore", ")", "setClientHB", "(", "ID", "string", ",", "interval", "time", ".", "Duration", ",", "f", "func", "(", ")", ")", "{", "cs", ".", "RLock", "(", ")", "\n", "defer", "cs", ".", "RUnlock", "(", ")", "\n", "c"...
// setClientHB will lookup the client `ID` and, if present, set the // client's timer with the given interval and function.
[ "setClientHB", "will", "lookup", "the", "client", "ID", "and", "if", "present", "set", "the", "client", "s", "timer", "with", "the", "given", "interval", "and", "function", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/client.go#L287-L299
26,880
nats-io/nats-streaming-server
server/client.go
removeClientHB
func (cs *clientStore) removeClientHB(c *client) { if c == nil { return } c.Lock() if c.hbt != nil { c.hbt.Stop() c.hbt = nil } c.Unlock() }
go
func (cs *clientStore) removeClientHB(c *client) { if c == nil { return } c.Lock() if c.hbt != nil { c.hbt.Stop() c.hbt = nil } c.Unlock() }
[ "func", "(", "cs", "*", "clientStore", ")", "removeClientHB", "(", "c", "*", "client", ")", "{", "if", "c", "==", "nil", "{", "return", "\n", "}", "\n", "c", ".", "Lock", "(", ")", "\n", "if", "c", ".", "hbt", "!=", "nil", "{", "c", ".", "hbt...
// removeClientHB will stop and remove the client's heartbeat timer, if // present.
[ "removeClientHB", "will", "stop", "and", "remove", "the", "client", "s", "heartbeat", "timer", "if", "present", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/client.go#L303-L313
26,881
nats-io/nats-streaming-server
server/client.go
count
func (cs *clientStore) count() int { cs.RLock() total := len(cs.clients) cs.RUnlock() return total }
go
func (cs *clientStore) count() int { cs.RLock() total := len(cs.clients) cs.RUnlock() return total }
[ "func", "(", "cs", "*", "clientStore", ")", "count", "(", ")", "int", "{", "cs", ".", "RLock", "(", ")", "\n", "total", ":=", "len", "(", "cs", ".", "clients", ")", "\n", "cs", ".", "RUnlock", "(", ")", "\n", "return", "total", "\n", "}" ]
// count returns the number of registered clients
[ "count", "returns", "the", "number", "of", "registered", "clients" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/client.go#L329-L334
26,882
nats-io/nats-streaming-server
server/clustering.go
shutdown
func (r *raftNode) shutdown() error { r.Lock() if r.closed { r.Unlock() return nil } r.closed = true r.Unlock() if r.Raft != nil { if err := r.Raft.Shutdown().Error(); err != nil { return err } } if r.transport != nil { if err := r.transport.Close(); err != nil { return err } } if r.store !=...
go
func (r *raftNode) shutdown() error { r.Lock() if r.closed { r.Unlock() return nil } r.closed = true r.Unlock() if r.Raft != nil { if err := r.Raft.Shutdown().Error(); err != nil { return err } } if r.transport != nil { if err := r.transport.Close(); err != nil { return err } } if r.store !=...
[ "func", "(", "r", "*", "raftNode", ")", "shutdown", "(", ")", "error", "{", "r", ".", "Lock", "(", ")", "\n", "if", "r", ".", "closed", "{", "r", ".", "Unlock", "(", ")", "\n", "return", "nil", "\n", "}", "\n", "r", ".", "closed", "=", "true"...
// shutdown attempts to stop the Raft node.
[ "shutdown", "attempts", "to", "stop", "the", "Raft", "node", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/clustering.go#L96-L130
26,883
nats-io/nats-streaming-server
server/clustering.go
createServerRaftNode
func (s *StanServer) createServerRaftNode(hasStreamingState bool) error { var ( name = s.info.ClusterID addr = s.getClusteringAddr(name) existingState, err = s.createRaftNode(name) ) if err != nil { return err } if !existingState && hasStreamingState { return fmt.Errorf("strea...
go
func (s *StanServer) createServerRaftNode(hasStreamingState bool) error { var ( name = s.info.ClusterID addr = s.getClusteringAddr(name) existingState, err = s.createRaftNode(name) ) if err != nil { return err } if !existingState && hasStreamingState { return fmt.Errorf("strea...
[ "func", "(", "s", "*", "StanServer", ")", "createServerRaftNode", "(", "hasStreamingState", "bool", ")", "error", "{", "var", "(", "name", "=", "s", ".", "info", ".", "ClusterID", "\n", "addr", "=", "s", ".", "getClusteringAddr", "(", "name", ")", "\n", ...
// createRaftNode creates and starts a new Raft node.
[ "createRaftNode", "creates", "and", "starts", "a", "new", "Raft", "node", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/clustering.go#L133-L199
26,884
nats-io/nats-streaming-server
server/clustering.go
bootstrapCluster
func (s *StanServer) bootstrapCluster(name string, node *raft.Raft) error { var ( addr = s.getClusteringAddr(name) // Include ourself in the cluster. servers = []raft.Server{raft.Server{ ID: raft.ServerID(s.opts.Clustering.NodeID), Address: raft.ServerAddress(addr), }} ) if len(s.opts.Clustering.P...
go
func (s *StanServer) bootstrapCluster(name string, node *raft.Raft) error { var ( addr = s.getClusteringAddr(name) // Include ourself in the cluster. servers = []raft.Server{raft.Server{ ID: raft.ServerID(s.opts.Clustering.NodeID), Address: raft.ServerAddress(addr), }} ) if len(s.opts.Clustering.P...
[ "func", "(", "s", "*", "StanServer", ")", "bootstrapCluster", "(", "name", "string", ",", "node", "*", "raft", ".", "Raft", ")", "error", "{", "var", "(", "addr", "=", "s", ".", "getClusteringAddr", "(", "name", ")", "\n", "// Include ourself in the cluste...
// bootstrapCluster bootstraps the node for the provided Raft group either as a // seed node or with the given peer configuration, depending on configuration // and with the latter taking precedence.
[ "bootstrapCluster", "bootstraps", "the", "node", "for", "the", "provided", "Raft", "group", "either", "as", "a", "seed", "node", "or", "with", "the", "given", "peer", "configuration", "depending", "on", "configuration", "and", "with", "the", "latter", "taking", ...
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/clustering.go#L420-L444
26,885
nats-io/nats-streaming-server
server/clustering.go
Apply
func (r *raftFSM) Apply(l *raft.Log) interface{} { s := r.server op := &spb.RaftOperation{} if err := op.Unmarshal(l.Data); err != nil { panic(err) } switch op.OpType { case spb.RaftOperation_Publish: // Message replication. var ( c *channel err error lastSeq uint64 ) for _, msg := ra...
go
func (r *raftFSM) Apply(l *raft.Log) interface{} { s := r.server op := &spb.RaftOperation{} if err := op.Unmarshal(l.Data); err != nil { panic(err) } switch op.OpType { case spb.RaftOperation_Publish: // Message replication. var ( c *channel err error lastSeq uint64 ) for _, msg := ra...
[ "func", "(", "r", "*", "raftFSM", ")", "Apply", "(", "l", "*", "raft", ".", "Log", ")", "interface", "{", "}", "{", "s", ":=", "r", ".", "server", "\n", "op", ":=", "&", "spb", ".", "RaftOperation", "{", "}", "\n", "if", "err", ":=", "op", "....
// Apply log is invoked once a log entry is committed. // It returns a value which will be made available in the // ApplyFuture returned by Raft.Apply method if that // method was called on the same Raft node as the FSM.
[ "Apply", "log", "is", "invoked", "once", "a", "log", "entry", "is", "committed", ".", "It", "returns", "a", "value", "which", "will", "be", "made", "available", "in", "the", "ApplyFuture", "returned", "by", "Raft", ".", "Apply", "method", "if", "that", "...
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/clustering.go#L458-L525
26,886
nats-io/nats-streaming-server
util/util.go
EnsureBufBigEnough
func EnsureBufBigEnough(buf []byte, needed int) []byte { if buf == nil { return make([]byte, needed) } else if needed > len(buf) { return make([]byte, int(float32(needed)*1.1)) } return buf }
go
func EnsureBufBigEnough(buf []byte, needed int) []byte { if buf == nil { return make([]byte, needed) } else if needed > len(buf) { return make([]byte, int(float32(needed)*1.1)) } return buf }
[ "func", "EnsureBufBigEnough", "(", "buf", "[", "]", "byte", ",", "needed", "int", ")", "[", "]", "byte", "{", "if", "buf", "==", "nil", "{", "return", "make", "(", "[", "]", "byte", ",", "needed", ")", "\n", "}", "else", "if", "needed", ">", "len...
// EnsureBufBigEnough checks that given buffer is big enough to hold 'needed' // bytes, otherwise returns a buffer of a size of at least 'needed' bytes.
[ "EnsureBufBigEnough", "checks", "that", "given", "buffer", "is", "big", "enough", "to", "hold", "needed", "bytes", "otherwise", "returns", "a", "buffer", "of", "a", "size", "of", "at", "least", "needed", "bytes", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/util/util.go#L109-L116
26,887
nats-io/nats-streaming-server
util/util.go
CloseFile
func CloseFile(err error, f io.Closer) error { if lerr := f.Close(); lerr != nil && err == nil { err = lerr } return err }
go
func CloseFile(err error, f io.Closer) error { if lerr := f.Close(); lerr != nil && err == nil { err = lerr } return err }
[ "func", "CloseFile", "(", "err", "error", ",", "f", "io", ".", "Closer", ")", "error", "{", "if", "lerr", ":=", "f", ".", "Close", "(", ")", ";", "lerr", "!=", "nil", "&&", "err", "==", "nil", "{", "err", "=", "lerr", "\n", "}", "\n", "return",...
// CloseFile closes the given file and report the possible error only // if the given error `err` is not already set.
[ "CloseFile", "closes", "the", "given", "file", "and", "report", "the", "possible", "error", "only", "if", "the", "given", "error", "err", "is", "not", "already", "set", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/util/util.go#L144-L149
26,888
nats-io/nats-streaming-server
util/util.go
FriendlyBytes
func FriendlyBytes(bytes int64) string { fbytes := float64(bytes) base := 1024 pre := []string{"K", "M", "G", "T", "P", "E"} if fbytes < float64(base) { return fmt.Sprintf("%v B", fbytes) } exp := int(math.Log(fbytes) / math.Log(float64(base))) index := exp - 1 return fmt.Sprintf("%.2f %sB", fbytes/math.Pow(f...
go
func FriendlyBytes(bytes int64) string { fbytes := float64(bytes) base := 1024 pre := []string{"K", "M", "G", "T", "P", "E"} if fbytes < float64(base) { return fmt.Sprintf("%v B", fbytes) } exp := int(math.Log(fbytes) / math.Log(float64(base))) index := exp - 1 return fmt.Sprintf("%.2f %sB", fbytes/math.Pow(f...
[ "func", "FriendlyBytes", "(", "bytes", "int64", ")", "string", "{", "fbytes", ":=", "float64", "(", "bytes", ")", "\n", "base", ":=", "1024", "\n", "pre", ":=", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"...
// FriendlyBytes returns a string with the given bytes int64 // represented as a size, such as 1KB, 10MB, etc...
[ "FriendlyBytes", "returns", "a", "string", "with", "the", "given", "bytes", "int64", "represented", "as", "a", "size", "such", "as", "1KB", "10MB", "etc", "..." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/util/util.go#L207-L217
26,889
nats-io/nats-streaming-server
stores/cryptostore.go
Encrypt
func (s *EDStore) Encrypt(pbuf *[]byte, data []byte) ([]byte, error) { var buf []byte // If given a buffer, use that one if pbuf != nil { buf = *pbuf } // Make sure size is ok, expand if necessary buf = util.EnsureBufBigEnough(buf, 1+s.nonceSize+s.cryptoOverhead+len(data)) // If buffer was passed, update the r...
go
func (s *EDStore) Encrypt(pbuf *[]byte, data []byte) ([]byte, error) { var buf []byte // If given a buffer, use that one if pbuf != nil { buf = *pbuf } // Make sure size is ok, expand if necessary buf = util.EnsureBufBigEnough(buf, 1+s.nonceSize+s.cryptoOverhead+len(data)) // If buffer was passed, update the r...
[ "func", "(", "s", "*", "EDStore", ")", "Encrypt", "(", "pbuf", "*", "[", "]", "byte", ",", "data", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "buf", "[", "]", "byte", "\n", "// If given a buffer, use that one", "if...
// Encrypt returns the encrypted data or an error
[ "Encrypt", "returns", "the", "encrypted", "data", "or", "an", "error" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/cryptostore.go#L201-L225
26,890
nats-io/nats-streaming-server
stores/cryptostore.go
Decrypt
func (s *EDStore) Decrypt(dst []byte, cipherText []byte) ([]byte, error) { var gcm cipher.AEAD if len(cipherText) > 0 { switch cipherText[0] { case CryptoCodeAES: gcm = s.aesgcm case CryptoCodeChaCha: gcm = s.chachagcm default: // Anything else, assume no algo or something we don't know how to decryp...
go
func (s *EDStore) Decrypt(dst []byte, cipherText []byte) ([]byte, error) { var gcm cipher.AEAD if len(cipherText) > 0 { switch cipherText[0] { case CryptoCodeAES: gcm = s.aesgcm case CryptoCodeChaCha: gcm = s.chachagcm default: // Anything else, assume no algo or something we don't know how to decryp...
[ "func", "(", "s", "*", "EDStore", ")", "Decrypt", "(", "dst", "[", "]", "byte", ",", "cipherText", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "gcm", "cipher", ".", "AEAD", "\n", "if", "len", "(", "cipherText", ...
// Decrypt returns the decrypted data or an error
[ "Decrypt", "returns", "the", "decrypted", "data", "or", "an", "error" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/cryptostore.go#L228-L249
26,891
nats-io/nats-streaming-server
stores/cryptostore.go
NewCryptoStore
func NewCryptoStore(s Store, encryptionCipher string, encryptionKey []byte) (*CryptoStore, error) { code, mkh, err := createMasterKeyHash(encryptionCipher, encryptionKey) if err != nil { return nil, err } cs := &CryptoStore{ Store: s, code: code, mkh: mkh, } // On success, erase the key for i := 0; i ...
go
func NewCryptoStore(s Store, encryptionCipher string, encryptionKey []byte) (*CryptoStore, error) { code, mkh, err := createMasterKeyHash(encryptionCipher, encryptionKey) if err != nil { return nil, err } cs := &CryptoStore{ Store: s, code: code, mkh: mkh, } // On success, erase the key for i := 0; i ...
[ "func", "NewCryptoStore", "(", "s", "Store", ",", "encryptionCipher", "string", ",", "encryptionKey", "[", "]", "byte", ")", "(", "*", "CryptoStore", ",", "error", ")", "{", "code", ",", "mkh", ",", "err", ":=", "createMasterKeyHash", "(", "encryptionCipher"...
// NewCryptoStore returns a CryptoStore instance with // given underlying store.
[ "NewCryptoStore", "returns", "a", "CryptoStore", "instance", "with", "given", "underlying", "store", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/cryptostore.go#L253-L268
26,892
nats-io/nats-streaming-server
stores/limits.go
Clone
func (sl *StoreLimits) Clone() *StoreLimits { cloned := *sl cloned.PerChannel = sl.ClonePerChannelMap() return &cloned }
go
func (sl *StoreLimits) Clone() *StoreLimits { cloned := *sl cloned.PerChannel = sl.ClonePerChannelMap() return &cloned }
[ "func", "(", "sl", "*", "StoreLimits", ")", "Clone", "(", ")", "*", "StoreLimits", "{", "cloned", ":=", "*", "sl", "\n", "cloned", ".", "PerChannel", "=", "sl", ".", "ClonePerChannelMap", "(", ")", "\n", "return", "&", "cloned", "\n", "}" ]
// Clone returns a copy of the store limits
[ "Clone", "returns", "a", "copy", "of", "the", "store", "limits" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/limits.go#L31-L35
26,893
nats-io/nats-streaming-server
stores/limits.go
ClonePerChannelMap
func (sl *StoreLimits) ClonePerChannelMap() map[string]*ChannelLimits { if sl.PerChannel == nil { return nil } clone := make(map[string]*ChannelLimits, len(sl.PerChannel)) for k, v := range sl.PerChannel { copyVal := *v clone[k] = &copyVal } return clone }
go
func (sl *StoreLimits) ClonePerChannelMap() map[string]*ChannelLimits { if sl.PerChannel == nil { return nil } clone := make(map[string]*ChannelLimits, len(sl.PerChannel)) for k, v := range sl.PerChannel { copyVal := *v clone[k] = &copyVal } return clone }
[ "func", "(", "sl", "*", "StoreLimits", ")", "ClonePerChannelMap", "(", ")", "map", "[", "string", "]", "*", "ChannelLimits", "{", "if", "sl", ".", "PerChannel", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "clone", ":=", "make", "(", "map", "[...
// ClonePerChannelMap returns a deep copy of the StoreLimits's PerChannel map
[ "ClonePerChannelMap", "returns", "a", "deep", "copy", "of", "the", "StoreLimits", "s", "PerChannel", "map" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/limits.go#L38-L48
26,894
nats-io/nats-streaming-server
stores/limits.go
Print
func (sl *StoreLimits) Print() []string { sublist := util.NewSublist() for cn, cl := range sl.PerChannel { sublist.Insert(cn, &channelLimitInfo{ name: cn, limits: cl, isLiteral: util.IsChannelNameLiteral(cn), }) } maxLevels := sublist.NumLevels() txt := []string{} title := "---------- Store L...
go
func (sl *StoreLimits) Print() []string { sublist := util.NewSublist() for cn, cl := range sl.PerChannel { sublist.Insert(cn, &channelLimitInfo{ name: cn, limits: cl, isLiteral: util.IsChannelNameLiteral(cn), }) } maxLevels := sublist.NumLevels() txt := []string{} title := "---------- Store L...
[ "func", "(", "sl", "*", "StoreLimits", ")", "Print", "(", ")", "[", "]", "string", "{", "sublist", ":=", "util", ".", "NewSublist", "(", ")", "\n", "for", "cn", ",", "cl", ":=", "range", "sl", ".", "PerChannel", "{", "sublist", ".", "Insert", "(", ...
// Print returns an array of strings suitable for printing the store limits.
[ "Print", "returns", "an", "array", "of", "strings", "suitable", "for", "printing", "the", "store", "limits", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/limits.go#L188-L242
26,895
jasonlvhit/gocron
gocron.go
NewJob
func NewJob(intervel uint64) *Job { return &Job{ intervel, "", "", "", time.Unix(0, 0), time.Unix(0, 0), 0, time.Sunday, make(map[string]interface{}), make(map[string]([]interface{})), } }
go
func NewJob(intervel uint64) *Job { return &Job{ intervel, "", "", "", time.Unix(0, 0), time.Unix(0, 0), 0, time.Sunday, make(map[string]interface{}), make(map[string]([]interface{})), } }
[ "func", "NewJob", "(", "intervel", "uint64", ")", "*", "Job", "{", "return", "&", "Job", "{", "intervel", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "time", ".", "Unix", "(", "0", ",", "0", ")", ",", "time", ".", "Unix", "(", "0"...
// Create a new job with the time interval.
[ "Create", "a", "new", "job", "with", "the", "time", "interval", "." ]
5bcdd9fcfa9bf10574722841a11ccb2a57866dc8
https://github.com/jasonlvhit/gocron/blob/5bcdd9fcfa9bf10574722841a11ccb2a57866dc8/gocron.go#L72-L82
26,896
jasonlvhit/gocron
gocron.go
run
func (j *Job) run() (result []reflect.Value, err error) { f := reflect.ValueOf(j.funcs[j.jobFunc]) params := j.fparams[j.jobFunc] if len(params) != f.Type().NumIn() { err = errors.New("the number of param is not adapted") return } in := make([]reflect.Value, len(params)) for k, param := range params { in[k]...
go
func (j *Job) run() (result []reflect.Value, err error) { f := reflect.ValueOf(j.funcs[j.jobFunc]) params := j.fparams[j.jobFunc] if len(params) != f.Type().NumIn() { err = errors.New("the number of param is not adapted") return } in := make([]reflect.Value, len(params)) for k, param := range params { in[k]...
[ "func", "(", "j", "*", "Job", ")", "run", "(", ")", "(", "result", "[", "]", "reflect", ".", "Value", ",", "err", "error", ")", "{", "f", ":=", "reflect", ".", "ValueOf", "(", "j", ".", "funcs", "[", "j", ".", "jobFunc", "]", ")", "\n", "para...
//Run the job and immediately reschedule it
[ "Run", "the", "job", "and", "immediately", "reschedule", "it" ]
5bcdd9fcfa9bf10574722841a11ccb2a57866dc8
https://github.com/jasonlvhit/gocron/blob/5bcdd9fcfa9bf10574722841a11ccb2a57866dc8/gocron.go#L90-L105
26,897
jasonlvhit/gocron
gocron.go
getFunctionName
func getFunctionName(fn interface{}) string { return runtime.FuncForPC(reflect.ValueOf((fn)).Pointer()).Name() }
go
func getFunctionName(fn interface{}) string { return runtime.FuncForPC(reflect.ValueOf((fn)).Pointer()).Name() }
[ "func", "getFunctionName", "(", "fn", "interface", "{", "}", ")", "string", "{", "return", "runtime", ".", "FuncForPC", "(", "reflect", ".", "ValueOf", "(", "(", "fn", ")", ")", ".", "Pointer", "(", ")", ")", ".", "Name", "(", ")", "\n", "}" ]
// for given function fn, get the name of function.
[ "for", "given", "function", "fn", "get", "the", "name", "of", "function", "." ]
5bcdd9fcfa9bf10574722841a11ccb2a57866dc8
https://github.com/jasonlvhit/gocron/blob/5bcdd9fcfa9bf10574722841a11ccb2a57866dc8/gocron.go#L108-L110
26,898
jasonlvhit/gocron
gocron.go
Do
func (j *Job) Do(jobFun interface{}, params ...interface{}) { typ := reflect.TypeOf(jobFun) if typ.Kind() != reflect.Func { panic("only function can be schedule into the job queue.") } fname := getFunctionName(jobFun) j.funcs[fname] = jobFun j.fparams[fname] = params j.jobFunc = fname //schedule the next run...
go
func (j *Job) Do(jobFun interface{}, params ...interface{}) { typ := reflect.TypeOf(jobFun) if typ.Kind() != reflect.Func { panic("only function can be schedule into the job queue.") } fname := getFunctionName(jobFun) j.funcs[fname] = jobFun j.fparams[fname] = params j.jobFunc = fname //schedule the next run...
[ "func", "(", "j", "*", "Job", ")", "Do", "(", "jobFun", "interface", "{", "}", ",", "params", "...", "interface", "{", "}", ")", "{", "typ", ":=", "reflect", ".", "TypeOf", "(", "jobFun", ")", "\n", "if", "typ", ".", "Kind", "(", ")", "!=", "re...
// Specifies the jobFunc that should be called every time the job runs //
[ "Specifies", "the", "jobFunc", "that", "should", "be", "called", "every", "time", "the", "job", "runs" ]
5bcdd9fcfa9bf10574722841a11ccb2a57866dc8
https://github.com/jasonlvhit/gocron/blob/5bcdd9fcfa9bf10574722841a11ccb2a57866dc8/gocron.go#L114-L126
26,899
jasonlvhit/gocron
gocron.go
scheduleNextRun
func (j *Job) scheduleNextRun() { if j.lastRun == time.Unix(0, 0) { if j.unit == "weeks" { i := time.Now().Weekday() - j.startDay if i < 0 { i = 7 + i } j.lastRun = time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day()-int(i), 0, 0, 0, 0, loc) } else { j.lastRun = time.Now() } } ...
go
func (j *Job) scheduleNextRun() { if j.lastRun == time.Unix(0, 0) { if j.unit == "weeks" { i := time.Now().Weekday() - j.startDay if i < 0 { i = 7 + i } j.lastRun = time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day()-int(i), 0, 0, 0, 0, loc) } else { j.lastRun = time.Now() } } ...
[ "func", "(", "j", "*", "Job", ")", "scheduleNextRun", "(", ")", "{", "if", "j", ".", "lastRun", "==", "time", ".", "Unix", "(", "0", ",", "0", ")", "{", "if", "j", ".", "unit", "==", "\"", "\"", "{", "i", ":=", "time", ".", "Now", "(", ")",...
//Compute the instant when this job should run next
[ "Compute", "the", "instant", "when", "this", "job", "should", "run", "next" ]
5bcdd9fcfa9bf10574722841a11ccb2a57866dc8
https://github.com/jasonlvhit/gocron/blob/5bcdd9fcfa9bf10574722841a11ccb2a57866dc8/gocron.go#L184-L220