repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
nats-io/nats-streaming-server | server/partitions.go | initPartitions | func (s *StanServer) initPartitions() error {
// The option says that the server should only use the pre-defined channels,
// but none was specified. Don't see the point in continuing...
if len(s.opts.StoreLimits.PerChannel) == 0 {
return ErrNoChannel
}
nc, err := s.createNatsClientConn("pc")
if err != nil {
... | go | func (s *StanServer) initPartitions() error {
// The option says that the server should only use the pre-defined channels,
// but none was specified. Don't see the point in continuing...
if len(s.opts.StoreLimits.PerChannel) == 0 {
return ErrNoChannel
}
nc, err := s.createNatsClientConn("pc")
if err != nil {
... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"initPartitions",
"(",
")",
"error",
"{",
"// The option says that the server should only use the pre-defined channels,",
"// but none was specified. Don't see the point in continuing...",
"if",
"len",
"(",
"s",
".",
"opts",
".",
"Sto... | // Initialize the channels partitions objects and issue the first
// request to check if other servers in the cluster incorrectly have
// any of the channel that this server is supposed to handle. | [
"Initialize",
"the",
"channels",
"partitions",
"objects",
"and",
"issue",
"the",
"first",
"request",
"to",
"check",
"if",
"other",
"servers",
"in",
"the",
"cluster",
"incorrectly",
"have",
"any",
"of",
"the",
"channel",
"that",
"this",
"server",
"is",
"suppose... | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/partitions.go#L64-L107 | train |
nats-io/nats-streaming-server | server/partitions.go | createChannelsMapAndSublist | func (p *partitions) createChannelsMapAndSublist(storeChannels map[string]*stores.ChannelLimits) {
p.channels = make([]string, 0, len(storeChannels))
p.sl = util.NewSublist()
for c := range storeChannels {
p.channels = append(p.channels, c)
// When creating the store, we have already checked that channel names
... | go | func (p *partitions) createChannelsMapAndSublist(storeChannels map[string]*stores.ChannelLimits) {
p.channels = make([]string, 0, len(storeChannels))
p.sl = util.NewSublist()
for c := range storeChannels {
p.channels = append(p.channels, c)
// When creating the store, we have already checked that channel names
... | [
"func",
"(",
"p",
"*",
"partitions",
")",
"createChannelsMapAndSublist",
"(",
"storeChannels",
"map",
"[",
"string",
"]",
"*",
"stores",
".",
"ChannelLimits",
")",
"{",
"p",
".",
"channels",
"=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"... | // Creates the channels map based on the store's PerChannel map that was given. | [
"Creates",
"the",
"channels",
"map",
"based",
"on",
"the",
"store",
"s",
"PerChannel",
"map",
"that",
"was",
"given",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/partitions.go#L110-L119 | train |
nats-io/nats-streaming-server | server/partitions.go | topologyChanged | func (p *partitions) topologyChanged(_ *nats.Conn) {
p.Lock()
defer p.Unlock()
if p.isShutdown {
return
}
// Let's wait before checking (sending the list and waiting for a reply)
// so that the new NATS Server has a chance to send its local
// subscriptions to the rest of the cluster. That will reduce the risk... | go | func (p *partitions) topologyChanged(_ *nats.Conn) {
p.Lock()
defer p.Unlock()
if p.isShutdown {
return
}
// Let's wait before checking (sending the list and waiting for a reply)
// so that the new NATS Server has a chance to send its local
// subscriptions to the rest of the cluster. That will reduce the risk... | [
"func",
"(",
"p",
"*",
"partitions",
")",
"topologyChanged",
"(",
"_",
"*",
"nats",
".",
"Conn",
")",
"{",
"p",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Unlock",
"(",
")",
"\n",
"if",
"p",
".",
"isShutdown",
"{",
"return",
"\n",
"}",
"\... | // Topology changed. Sends the list of channels. | [
"Topology",
"changed",
".",
"Sends",
"the",
"list",
"of",
"channels",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/partitions.go#L122-L146 | train |
nats-io/nats-streaming-server | server/partitions.go | initSubscriptions | func (p *partitions) initSubscriptions() error {
// NOTE: Use the server's nc connection here, not the partitions' one.
for _, channelName := range p.channels {
pubSubject := fmt.Sprintf("%s.%s", p.s.info.Publish, channelName)
if _, err := p.s.nc.Subscribe(pubSubject, p.s.processClientPublish); err != nil {
re... | go | func (p *partitions) initSubscriptions() error {
// NOTE: Use the server's nc connection here, not the partitions' one.
for _, channelName := range p.channels {
pubSubject := fmt.Sprintf("%s.%s", p.s.info.Publish, channelName)
if _, err := p.s.nc.Subscribe(pubSubject, p.s.processClientPublish); err != nil {
re... | [
"func",
"(",
"p",
"*",
"partitions",
")",
"initSubscriptions",
"(",
")",
"error",
"{",
"// NOTE: Use the server's nc connection here, not the partitions' one.",
"for",
"_",
",",
"channelName",
":=",
"range",
"p",
".",
"channels",
"{",
"pubSubject",
":=",
"fmt",
".",... | // Create the internal subscriptions on the list of channels. | [
"Create",
"the",
"internal",
"subscriptions",
"on",
"the",
"list",
"of",
"channels",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/partitions.go#L149-L158 | train |
nats-io/nats-streaming-server | server/partitions.go | processChannelsListRequests | func (p *partitions) processChannelsListRequests(m *nats.Msg) {
// Message cannot be empty, we are supposed to receive
// a spb.CtrlMsg_Partitioning protocol. We should also
// have a repy subject
if len(m.Data) == 0 || m.Reply == "" {
return
}
req := spb.CtrlMsg{}
if err := req.Unmarshal(m.Data); err != nil {... | go | func (p *partitions) processChannelsListRequests(m *nats.Msg) {
// Message cannot be empty, we are supposed to receive
// a spb.CtrlMsg_Partitioning protocol. We should also
// have a repy subject
if len(m.Data) == 0 || m.Reply == "" {
return
}
req := spb.CtrlMsg{}
if err := req.Unmarshal(m.Data); err != nil {... | [
"func",
"(",
"p",
"*",
"partitions",
")",
"processChannelsListRequests",
"(",
"m",
"*",
"nats",
".",
"Msg",
")",
"{",
"// Message cannot be empty, we are supposed to receive",
"// a spb.CtrlMsg_Partitioning protocol. We should also",
"// have a repy subject",
"if",
"len",
"("... | // Decode the incoming partitioning protocol message.
// It can be an HB, in which case, if it is from a new server
// we send our list to the cluster, or it can be a request
// from another server. If so, we reply to the given inbox
// with either an empty Data field or the name of the first
// channel we have in comm... | [
"Decode",
"the",
"incoming",
"partitioning",
"protocol",
"message",
".",
"It",
"can",
"be",
"an",
"HB",
"in",
"which",
"case",
"if",
"it",
"is",
"from",
"a",
"new",
"server",
"we",
"send",
"our",
"list",
"to",
"the",
"cluster",
"or",
"it",
"can",
"be",... | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/partitions.go#L196-L249 | train |
nats-io/nats-streaming-server | server/partitions.go | shutdown | func (p *partitions) shutdown() {
p.Lock()
defer p.Unlock()
if p.isShutdown {
return
}
p.isShutdown = true
if p.nc != nil {
p.nc.Close()
}
} | go | func (p *partitions) shutdown() {
p.Lock()
defer p.Unlock()
if p.isShutdown {
return
}
p.isShutdown = true
if p.nc != nil {
p.nc.Close()
}
} | [
"func",
"(",
"p",
"*",
"partitions",
")",
"shutdown",
"(",
")",
"{",
"p",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Unlock",
"(",
")",
"\n",
"if",
"p",
".",
"isShutdown",
"{",
"return",
"\n",
"}",
"\n",
"p",
".",
"isShutdown",
"=",
"true... | // Notifies all go-routines used by partitioning code that the
// server is shuting down and closes the internal NATS connection. | [
"Notifies",
"all",
"go",
"-",
"routines",
"used",
"by",
"partitioning",
"code",
"that",
"the",
"server",
"is",
"shuting",
"down",
"and",
"closes",
"the",
"internal",
"NATS",
"connection",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/partitions.go#L253-L263 | train |
nats-io/nats-streaming-server | server/conf.go | checkType | func checkType(name string, kind reflect.Kind, v interface{}) error {
actualKind := reflect.TypeOf(v).Kind()
if actualKind != kind {
return fmt.Errorf("parameter %q value is expected to be %v, got %v",
name, kind.String(), actualKind.String())
}
return nil
} | go | func checkType(name string, kind reflect.Kind, v interface{}) error {
actualKind := reflect.TypeOf(v).Kind()
if actualKind != kind {
return fmt.Errorf("parameter %q value is expected to be %v, got %v",
name, kind.String(), actualKind.String())
}
return nil
} | [
"func",
"checkType",
"(",
"name",
"string",
",",
"kind",
"reflect",
".",
"Kind",
",",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"actualKind",
":=",
"reflect",
".",
"TypeOf",
"(",
"v",
")",
".",
"Kind",
"(",
")",
"\n",
"if",
"actualKind",
"!=",
... | // checkType returns a formatted error if `v` is not of the expected kind. | [
"checkType",
"returns",
"a",
"formatted",
"error",
"if",
"v",
"is",
"not",
"of",
"the",
"expected",
"kind",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/conf.go#L179-L186 | train |
nats-io/nats-streaming-server | server/conf.go | parseTLS | func parseTLS(itf interface{}, opts *Options) error {
m, ok := itf.(map[string]interface{})
if !ok {
return fmt.Errorf("expected TLS to be a map/struct, got %v", itf)
}
for k, v := range m {
name := strings.ToLower(k)
switch name {
case "client_cert":
if err := checkType(k, reflect.String, v); err != nil... | go | func parseTLS(itf interface{}, opts *Options) error {
m, ok := itf.(map[string]interface{})
if !ok {
return fmt.Errorf("expected TLS to be a map/struct, got %v", itf)
}
for k, v := range m {
name := strings.ToLower(k)
switch name {
case "client_cert":
if err := checkType(k, reflect.String, v); err != nil... | [
"func",
"parseTLS",
"(",
"itf",
"interface",
"{",
"}",
",",
"opts",
"*",
"Options",
")",
"error",
"{",
"m",
",",
"ok",
":=",
"itf",
".",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"fmt",
".... | // parseTLS updates `opts` with TLS config | [
"parseTLS",
"updates",
"opts",
"with",
"TLS",
"config"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/conf.go#L189-L215 | train |
nats-io/nats-streaming-server | server/conf.go | parseStoreLimits | func parseStoreLimits(itf interface{}, opts *Options) error {
m, ok := itf.(map[string]interface{})
if !ok {
return fmt.Errorf("expected store limits to be a map/struct, got %v", itf)
}
for k, v := range m {
name := strings.ToLower(k)
switch name {
case "mc", "max_channels", "maxchannels":
if err := chec... | go | func parseStoreLimits(itf interface{}, opts *Options) error {
m, ok := itf.(map[string]interface{})
if !ok {
return fmt.Errorf("expected store limits to be a map/struct, got %v", itf)
}
for k, v := range m {
name := strings.ToLower(k)
switch name {
case "mc", "max_channels", "maxchannels":
if err := chec... | [
"func",
"parseStoreLimits",
"(",
"itf",
"interface",
"{",
"}",
",",
"opts",
"*",
"Options",
")",
"error",
"{",
"m",
",",
"ok",
":=",
"itf",
".",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"fm... | // parseStoreLimits updates `opts` with store limits | [
"parseStoreLimits",
"updates",
"opts",
"with",
"store",
"limits"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/conf.go#L306-L331 | train |
nats-io/nats-streaming-server | server/conf.go | parseChannelLimits | func parseChannelLimits(cl *stores.ChannelLimits, k, name string, v interface{}, isGlobal bool) error {
switch name {
case "msu", "max_subs", "max_subscriptions", "maxsubscriptions":
if err := checkType(k, reflect.Int64, v); err != nil {
return err
}
cl.MaxSubscriptions = int(v.(int64))
if !isGlobal && cl.... | go | func parseChannelLimits(cl *stores.ChannelLimits, k, name string, v interface{}, isGlobal bool) error {
switch name {
case "msu", "max_subs", "max_subscriptions", "maxsubscriptions":
if err := checkType(k, reflect.Int64, v); err != nil {
return err
}
cl.MaxSubscriptions = int(v.(int64))
if !isGlobal && cl.... | [
"func",
"parseChannelLimits",
"(",
"cl",
"*",
"stores",
".",
"ChannelLimits",
",",
"k",
",",
"name",
"string",
",",
"v",
"interface",
"{",
"}",
",",
"isGlobal",
"bool",
")",
"error",
"{",
"switch",
"name",
"{",
"case",
"\"",
"\"",
",",
"\"",
"\"",
",... | // parseChannelLimits updates `cl` with channel limits. | [
"parseChannelLimits",
"updates",
"cl",
"with",
"channel",
"limits",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/conf.go#L334-L386 | train |
nats-io/nats-streaming-server | server/conf.go | parsePerChannelLimits | func parsePerChannelLimits(itf interface{}, opts *Options) error {
m, ok := itf.(map[string]interface{})
if !ok {
return fmt.Errorf("expected per channel limits to be a map/struct, got %v", itf)
}
for channelName, limits := range m {
limitsMap, ok := limits.(map[string]interface{})
if !ok {
return fmt.Erro... | go | func parsePerChannelLimits(itf interface{}, opts *Options) error {
m, ok := itf.(map[string]interface{})
if !ok {
return fmt.Errorf("expected per channel limits to be a map/struct, got %v", itf)
}
for channelName, limits := range m {
limitsMap, ok := limits.(map[string]interface{})
if !ok {
return fmt.Erro... | [
"func",
"parsePerChannelLimits",
"(",
"itf",
"interface",
"{",
"}",
",",
"opts",
"*",
"Options",
")",
"error",
"{",
"m",
",",
"ok",
":=",
"itf",
".",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
... | // parsePerChannelLimits updates `opts` with per channel limits. | [
"parsePerChannelLimits",
"updates",
"opts",
"with",
"per",
"channel",
"limits",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/conf.go#L389-L413 | train |
nats-io/nats-streaming-server | server/conf.go | getBytes | func getBytes(f *flag.Flag) (int64, error) {
var res map[string]interface{}
// Use NATS parser to do the conversion for us.
res, err := conf.Parse(fmt.Sprintf("bytes: %v", f.Value.String()))
if err != nil {
return 0, err
}
resVal := res["bytes"]
if resVal == nil || reflect.TypeOf(resVal).Kind() != reflect.Int6... | go | func getBytes(f *flag.Flag) (int64, error) {
var res map[string]interface{}
// Use NATS parser to do the conversion for us.
res, err := conf.Parse(fmt.Sprintf("bytes: %v", f.Value.String()))
if err != nil {
return 0, err
}
resVal := res["bytes"]
if resVal == nil || reflect.TypeOf(resVal).Kind() != reflect.Int6... | [
"func",
"getBytes",
"(",
"f",
"*",
"flag",
".",
"Flag",
")",
"(",
"int64",
",",
"error",
")",
"{",
"var",
"res",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"\n",
"// Use NATS parser to do the conversion for us.",
"res",
",",
"err",
":=",
"conf",
"... | // getBytes returns the number of bytes from the flag's String size.
// For instance, 1KB would return 1024. | [
"getBytes",
"returns",
"the",
"number",
"of",
"bytes",
"from",
"the",
"flag",
"s",
"String",
"size",
".",
"For",
"instance",
"1KB",
"would",
"return",
"1024",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/conf.go#L703-L715 | train |
nats-io/nats-streaming-server | util/sublist.go | addToCache | func (s *Sublist) addToCache(subject string, element interface{}) {
for k, r := range s.cache {
if matchLiteral(k, subject) {
// Copy since others may have a reference.
nr := append([]interface{}(nil), r...)
nr = append(nr, element)
s.cache[k] = nr
}
}
} | go | func (s *Sublist) addToCache(subject string, element interface{}) {
for k, r := range s.cache {
if matchLiteral(k, subject) {
// Copy since others may have a reference.
nr := append([]interface{}(nil), r...)
nr = append(nr, element)
s.cache[k] = nr
}
}
} | [
"func",
"(",
"s",
"*",
"Sublist",
")",
"addToCache",
"(",
"subject",
"string",
",",
"element",
"interface",
"{",
"}",
")",
"{",
"for",
"k",
",",
"r",
":=",
"range",
"s",
".",
"cache",
"{",
"if",
"matchLiteral",
"(",
"k",
",",
"subject",
")",
"{",
... | // addToCache will add the new entry to existing cache
// entries if needed. Assumes write lock is held. | [
"addToCache",
"will",
"add",
"the",
"new",
"entry",
"to",
"existing",
"cache",
"entries",
"if",
"needed",
".",
"Assumes",
"write",
"lock",
"is",
"held",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/util/sublist.go#L139-L148 | train |
nats-io/nats-streaming-server | util/sublist.go | removeFromCache | func (s *Sublist) removeFromCache(subject string) {
for k := range s.cache {
if !matchLiteral(k, subject) {
continue
}
// Since someone else may be referencing, can't modify the list
// safely, just let it re-populate.
delete(s.cache, k)
}
} | go | func (s *Sublist) removeFromCache(subject string) {
for k := range s.cache {
if !matchLiteral(k, subject) {
continue
}
// Since someone else may be referencing, can't modify the list
// safely, just let it re-populate.
delete(s.cache, k)
}
} | [
"func",
"(",
"s",
"*",
"Sublist",
")",
"removeFromCache",
"(",
"subject",
"string",
")",
"{",
"for",
"k",
":=",
"range",
"s",
".",
"cache",
"{",
"if",
"!",
"matchLiteral",
"(",
"k",
",",
"subject",
")",
"{",
"continue",
"\n",
"}",
"\n",
"// Since som... | // removeFromCache will remove any active cache entries on that subject.
// Assumes write lock is held. | [
"removeFromCache",
"will",
"remove",
"any",
"active",
"cache",
"entries",
"on",
"that",
"subject",
".",
"Assumes",
"write",
"lock",
"is",
"held",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/util/sublist.go#L152-L161 | train |
nats-io/nats-streaming-server | util/sublist.go | Match | func (s *Sublist) Match(subject string) []interface{} {
s.RLock()
rc, ok := s.cache[subject]
s.RUnlock()
if ok {
return rc
}
tsa := [32]string{}
tokens := tsa[:0]
start := 0
for i := 0; i < len(subject); i++ {
if subject[i] == btsep {
tokens = append(tokens, subject[start:i])
start = i + 1
}
}
t... | go | func (s *Sublist) Match(subject string) []interface{} {
s.RLock()
rc, ok := s.cache[subject]
s.RUnlock()
if ok {
return rc
}
tsa := [32]string{}
tokens := tsa[:0]
start := 0
for i := 0; i < len(subject); i++ {
if subject[i] == btsep {
tokens = append(tokens, subject[start:i])
start = i + 1
}
}
t... | [
"func",
"(",
"s",
"*",
"Sublist",
")",
"Match",
"(",
"subject",
"string",
")",
"[",
"]",
"interface",
"{",
"}",
"{",
"s",
".",
"RLock",
"(",
")",
"\n",
"rc",
",",
"ok",
":=",
"s",
".",
"cache",
"[",
"subject",
"]",
"\n",
"s",
".",
"RUnlock",
... | // Match will match all entries to the literal subject.
// It will return a set of results. | [
"Match",
"will",
"match",
"all",
"entries",
"to",
"the",
"literal",
"subject",
".",
"It",
"will",
"return",
"a",
"set",
"of",
"results",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/util/sublist.go#L165-L200 | train |
nats-io/nats-streaming-server | util/sublist.go | Remove | func (s *Sublist) Remove(subject string, element interface{}) error {
tsa := [32]string{}
tokens := tsa[:0]
start := 0
for i := 0; i < len(subject); i++ {
if subject[i] == btsep {
tokens = append(tokens, subject[start:i])
start = i + 1
}
}
tokens = append(tokens, subject[start:])
s.Lock()
defer s.Unl... | go | func (s *Sublist) Remove(subject string, element interface{}) error {
tsa := [32]string{}
tokens := tsa[:0]
start := 0
for i := 0; i < len(subject); i++ {
if subject[i] == btsep {
tokens = append(tokens, subject[start:i])
start = i + 1
}
}
tokens = append(tokens, subject[start:])
s.Lock()
defer s.Unl... | [
"func",
"(",
"s",
"*",
"Sublist",
")",
"Remove",
"(",
"subject",
"string",
",",
"element",
"interface",
"{",
"}",
")",
"error",
"{",
"tsa",
":=",
"[",
"32",
"]",
"string",
"{",
"}",
"\n",
"tokens",
":=",
"tsa",
"[",
":",
"0",
"]",
"\n",
"start",
... | // Remove will remove an element from the sublist. | [
"Remove",
"will",
"remove",
"an",
"element",
"from",
"the",
"sublist",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/util/sublist.go#L238-L296 | train |
nats-io/nats-streaming-server | util/sublist.go | removeFromList | func removeFromList(element interface{}, l []interface{}) ([]interface{}, bool) {
for i := 0; i < len(l); i++ {
if l[i] == element {
last := len(l) - 1
l[i] = l[last]
l[last] = nil
l = l[:last]
return shrinkAsNeeded(l), true
}
}
return l, false
} | go | func removeFromList(element interface{}, l []interface{}) ([]interface{}, bool) {
for i := 0; i < len(l); i++ {
if l[i] == element {
last := len(l) - 1
l[i] = l[last]
l[last] = nil
l = l[:last]
return shrinkAsNeeded(l), true
}
}
return l, false
} | [
"func",
"removeFromList",
"(",
"element",
"interface",
"{",
"}",
",",
"l",
"[",
"]",
"interface",
"{",
"}",
")",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"bool",
")",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"l",
")",
";",
"i"... | // Removes an element from a list. | [
"Removes",
"an",
"element",
"from",
"a",
"list",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/util/sublist.go#L336-L347 | train |
nats-io/nats-streaming-server | util/sublist.go | shrinkAsNeeded | func shrinkAsNeeded(l []interface{}) []interface{} {
ll := len(l)
cl := cap(l)
// Don't bother if list not too big
if cl <= 8 {
return l
}
pFree := float32(cl-ll) / float32(cl)
if pFree > 0.50 {
return append([]interface{}(nil), l...)
}
return l
} | go | func shrinkAsNeeded(l []interface{}) []interface{} {
ll := len(l)
cl := cap(l)
// Don't bother if list not too big
if cl <= 8 {
return l
}
pFree := float32(cl-ll) / float32(cl)
if pFree > 0.50 {
return append([]interface{}(nil), l...)
}
return l
} | [
"func",
"shrinkAsNeeded",
"(",
"l",
"[",
"]",
"interface",
"{",
"}",
")",
"[",
"]",
"interface",
"{",
"}",
"{",
"ll",
":=",
"len",
"(",
"l",
")",
"\n",
"cl",
":=",
"cap",
"(",
"l",
")",
"\n",
"// Don't bother if list not too big",
"if",
"cl",
"<=",
... | // Checks if we need to do a resize. This is for very large growth then
// subsequent return to a more normal size from unsubscribe. | [
"Checks",
"if",
"we",
"need",
"to",
"do",
"a",
"resize",
".",
"This",
"is",
"for",
"very",
"large",
"growth",
"then",
"subsequent",
"return",
"to",
"a",
"more",
"normal",
"size",
"from",
"unsubscribe",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/util/sublist.go#L360-L372 | train |
nats-io/nats-streaming-server | util/sublist.go | CacheCount | func (s *Sublist) CacheCount() int {
s.RLock()
defer s.RUnlock()
return len(s.cache)
} | go | func (s *Sublist) CacheCount() int {
s.RLock()
defer s.RUnlock()
return len(s.cache)
} | [
"func",
"(",
"s",
"*",
"Sublist",
")",
"CacheCount",
"(",
")",
"int",
"{",
"s",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"len",
"(",
"s",
".",
"cache",
")",
"\n",
"}"
] | // CacheCount returns the number of result sets in the cache. | [
"CacheCount",
"returns",
"the",
"number",
"of",
"result",
"sets",
"in",
"the",
"cache",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/util/sublist.go#L382-L386 | train |
nats-io/nats-streaming-server | server/server.go | startDeleteTimer | func (c *channel) startDeleteTimer() {
c.activity.last = time.Now()
c.resetDeleteTimer(c.activity.maxInactivity)
} | go | func (c *channel) startDeleteTimer() {
c.activity.last = time.Now()
c.resetDeleteTimer(c.activity.maxInactivity)
} | [
"func",
"(",
"c",
"*",
"channel",
")",
"startDeleteTimer",
"(",
")",
"{",
"c",
".",
"activity",
".",
"last",
"=",
"time",
".",
"Now",
"(",
")",
"\n",
"c",
".",
"resetDeleteTimer",
"(",
"c",
".",
"activity",
".",
"maxInactivity",
")",
"\n",
"}"
] | // Starts the delete timer that when firing will post
// a channel delete request to the ioLoop.
// The channelStore's mutex must be held on entry. | [
"Starts",
"the",
"delete",
"timer",
"that",
"when",
"firing",
"will",
"post",
"a",
"channel",
"delete",
"request",
"to",
"the",
"ioLoop",
".",
"The",
"channelStore",
"s",
"mutex",
"must",
"be",
"held",
"on",
"entry",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L453-L456 | train |
nats-io/nats-streaming-server | server/server.go | stopDeleteTimer | func (c *channel) stopDeleteTimer() {
if c.activity.timer != nil {
c.activity.timer.Stop()
c.activity.timerSet = false
if c.stan.debug {
c.stan.log.Debugf("Channel %q delete timer stopped", c.name)
}
}
} | go | func (c *channel) stopDeleteTimer() {
if c.activity.timer != nil {
c.activity.timer.Stop()
c.activity.timerSet = false
if c.stan.debug {
c.stan.log.Debugf("Channel %q delete timer stopped", c.name)
}
}
} | [
"func",
"(",
"c",
"*",
"channel",
")",
"stopDeleteTimer",
"(",
")",
"{",
"if",
"c",
".",
"activity",
".",
"timer",
"!=",
"nil",
"{",
"c",
".",
"activity",
".",
"timer",
".",
"Stop",
"(",
")",
"\n",
"c",
".",
"activity",
".",
"timerSet",
"=",
"fal... | // Stops the delete timer.
// The channelStore's mutex must be held on entry. | [
"Stops",
"the",
"delete",
"timer",
".",
"The",
"channelStore",
"s",
"mutex",
"must",
"be",
"held",
"on",
"entry",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L460-L468 | train |
nats-io/nats-streaming-server | server/server.go | resetDeleteTimer | func (c *channel) resetDeleteTimer(newDuration time.Duration) {
a := c.activity
if a.timer == nil {
a.timer = time.AfterFunc(newDuration, func() {
c.stan.sendDeleteChannelRequest(c)
})
} else {
a.timer.Reset(newDuration)
}
if c.stan.debug {
c.stan.log.Debugf("Channel %q delete timer set to fire in %v", ... | go | func (c *channel) resetDeleteTimer(newDuration time.Duration) {
a := c.activity
if a.timer == nil {
a.timer = time.AfterFunc(newDuration, func() {
c.stan.sendDeleteChannelRequest(c)
})
} else {
a.timer.Reset(newDuration)
}
if c.stan.debug {
c.stan.log.Debugf("Channel %q delete timer set to fire in %v", ... | [
"func",
"(",
"c",
"*",
"channel",
")",
"resetDeleteTimer",
"(",
"newDuration",
"time",
".",
"Duration",
")",
"{",
"a",
":=",
"c",
".",
"activity",
"\n",
"if",
"a",
".",
"timer",
"==",
"nil",
"{",
"a",
".",
"timer",
"=",
"time",
".",
"AfterFunc",
"(... | // Resets the delete timer to the given duration.
// If the timer was not created, this call will create it.
// The channelStore's mutex must be held on entry. | [
"Resets",
"the",
"delete",
"timer",
"to",
"the",
"given",
"duration",
".",
"If",
"the",
"timer",
"was",
"not",
"created",
"this",
"call",
"will",
"create",
"it",
".",
"The",
"channelStore",
"s",
"mutex",
"must",
"be",
"held",
"on",
"entry",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L473-L486 | train |
nats-io/nats-streaming-server | server/server.go | pubMsgToMsgProto | func (c *channel) pubMsgToMsgProto(pm *pb.PubMsg, seq uint64) *pb.MsgProto {
m := &pb.MsgProto{
Sequence: seq,
Subject: pm.Subject,
Reply: pm.Reply,
Data: pm.Data,
Timestamp: time.Now().UnixNano(),
}
if c.lTimestamp > 0 && m.Timestamp < c.lTimestamp {
m.Timestamp = c.lTimestamp
}
c.lTimesta... | go | func (c *channel) pubMsgToMsgProto(pm *pb.PubMsg, seq uint64) *pb.MsgProto {
m := &pb.MsgProto{
Sequence: seq,
Subject: pm.Subject,
Reply: pm.Reply,
Data: pm.Data,
Timestamp: time.Now().UnixNano(),
}
if c.lTimestamp > 0 && m.Timestamp < c.lTimestamp {
m.Timestamp = c.lTimestamp
}
c.lTimesta... | [
"func",
"(",
"c",
"*",
"channel",
")",
"pubMsgToMsgProto",
"(",
"pm",
"*",
"pb",
".",
"PubMsg",
",",
"seq",
"uint64",
")",
"*",
"pb",
".",
"MsgProto",
"{",
"m",
":=",
"&",
"pb",
".",
"MsgProto",
"{",
"Sequence",
":",
"seq",
",",
"Subject",
":",
"... | // pubMsgToMsgProto converts a PubMsg to a MsgProto and assigns a timestamp
// which is monotonic with respect to the channel. | [
"pubMsgToMsgProto",
"converts",
"a",
"PubMsg",
"to",
"a",
"MsgProto",
"and",
"assigns",
"a",
"timestamp",
"which",
"is",
"monotonic",
"with",
"respect",
"to",
"the",
"channel",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L490-L503 | train |
nats-io/nats-streaming-server | server/server.go | subToSnapshotRestoreRequests | func (s *StanServer) subToSnapshotRestoreRequests() error {
var (
msgBuf []byte
buf []byte
snapshotRestorePrefix = fmt.Sprintf("%s.%s.", defaultSnapshotPrefix, s.info.ClusterID)
prefixLen = len(snapshotRestorePrefix)
)
sub, err := s.ncsr.Subscribe(snapshotRestoreP... | go | func (s *StanServer) subToSnapshotRestoreRequests() error {
var (
msgBuf []byte
buf []byte
snapshotRestorePrefix = fmt.Sprintf("%s.%s.", defaultSnapshotPrefix, s.info.ClusterID)
prefixLen = len(snapshotRestorePrefix)
)
sub, err := s.ncsr.Subscribe(snapshotRestoreP... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"subToSnapshotRestoreRequests",
"(",
")",
"error",
"{",
"var",
"(",
"msgBuf",
"[",
"]",
"byte",
"\n",
"buf",
"[",
"]",
"byte",
"\n",
"snapshotRestorePrefix",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"d... | // Sets a subscription that will handle snapshot restore requests from followers. | [
"Sets",
"a",
"subscription",
"that",
"will",
"handle",
"snapshot",
"restore",
"requests",
"from",
"followers",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L506-L564 | train |
nats-io/nats-streaming-server | server/server.go | lookupOrCreateChannel | func (s *StanServer) lookupOrCreateChannel(name string) (*channel, error) {
cs := s.channels
cs.RLock()
c := cs.channels[name]
if c != nil {
if c.activity != nil && c.activity.deleteInProgress {
cs.RUnlock()
return nil, ErrChanDelInProgress
}
cs.RUnlock()
return c, nil
}
cs.RUnlock()
return cs.crea... | go | func (s *StanServer) lookupOrCreateChannel(name string) (*channel, error) {
cs := s.channels
cs.RLock()
c := cs.channels[name]
if c != nil {
if c.activity != nil && c.activity.deleteInProgress {
cs.RUnlock()
return nil, ErrChanDelInProgress
}
cs.RUnlock()
return c, nil
}
cs.RUnlock()
return cs.crea... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"lookupOrCreateChannel",
"(",
"name",
"string",
")",
"(",
"*",
"channel",
",",
"error",
")",
"{",
"cs",
":=",
"s",
".",
"channels",
"\n",
"cs",
".",
"RLock",
"(",
")",
"\n",
"c",
":=",
"cs",
".",
"channels"... | // Looks up, or create a new channel if it does not exist | [
"Looks",
"up",
"or",
"create",
"a",
"new",
"channel",
"if",
"it",
"does",
"not",
"exist"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L746-L760 | train |
nats-io/nats-streaming-server | server/server.go | createSubStore | func (s *StanServer) createSubStore() *subStore {
subs := &subStore{
psubs: make([]*subState, 0, 4),
qsubs: make(map[string]*queueState),
durables: make(map[string]*subState),
acks: make(map[string]*subState),
stan: s,
}
return subs
} | go | func (s *StanServer) createSubStore() *subStore {
subs := &subStore{
psubs: make([]*subState, 0, 4),
qsubs: make(map[string]*queueState),
durables: make(map[string]*subState),
acks: make(map[string]*subState),
stan: s,
}
return subs
} | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"createSubStore",
"(",
")",
"*",
"subStore",
"{",
"subs",
":=",
"&",
"subStore",
"{",
"psubs",
":",
"make",
"(",
"[",
"]",
"*",
"subState",
",",
"0",
",",
"4",
")",
",",
"qsubs",
":",
"make",
"(",
"map",
... | // createSubStore creates a new instance of `subStore`. | [
"createSubStore",
"creates",
"a",
"new",
"instance",
"of",
"subStore",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L788-L797 | train |
nats-io/nats-streaming-server | server/server.go | Store | func (ss *subStore) Store(sub *subState) error {
if sub == nil {
return nil
}
// Adds to storage.
// Use sub lock to avoid race with waitForAcks in some tests
sub.Lock()
err := sub.store.CreateSub(&sub.SubState)
sub.Unlock()
if err == nil {
err = sub.store.Flush()
}
if err != nil {
ss.stan.log.Errorf("... | go | func (ss *subStore) Store(sub *subState) error {
if sub == nil {
return nil
}
// Adds to storage.
// Use sub lock to avoid race with waitForAcks in some tests
sub.Lock()
err := sub.store.CreateSub(&sub.SubState)
sub.Unlock()
if err == nil {
err = sub.store.Flush()
}
if err != nil {
ss.stan.log.Errorf("... | [
"func",
"(",
"ss",
"*",
"subStore",
")",
"Store",
"(",
"sub",
"*",
"subState",
")",
"error",
"{",
"if",
"sub",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Adds to storage.",
"// Use sub lock to avoid race with waitForAcks in some tests",
"sub",
"."... | // Store adds this subscription to the server's `subStore` and also in storage | [
"Store",
"adds",
"this",
"subscription",
"to",
"the",
"server",
"s",
"subStore",
"and",
"also",
"in",
"storage"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L800-L823 | train |
nats-io/nats-streaming-server | server/server.go | hasActiveSubs | func (ss *subStore) hasActiveSubs() bool {
ss.RLock()
defer ss.RUnlock()
if len(ss.psubs) > 0 {
return true
}
for _, qsub := range ss.qsubs {
// For a durable queue group, when the group is offline,
// qsub.shadow is not nil, but the qsub.subs array should be
// empty.
if len(qsub.subs) > 0 {
return t... | go | func (ss *subStore) hasActiveSubs() bool {
ss.RLock()
defer ss.RUnlock()
if len(ss.psubs) > 0 {
return true
}
for _, qsub := range ss.qsubs {
// For a durable queue group, when the group is offline,
// qsub.shadow is not nil, but the qsub.subs array should be
// empty.
if len(qsub.subs) > 0 {
return t... | [
"func",
"(",
"ss",
"*",
"subStore",
")",
"hasActiveSubs",
"(",
")",
"bool",
"{",
"ss",
".",
"RLock",
"(",
")",
"\n",
"defer",
"ss",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"len",
"(",
"ss",
".",
"psubs",
")",
">",
"0",
"{",
"return",
"true",
"\n"... | // hasSubs returns true if there is any active subscription for this subStore.
// That is, offline durable subscriptions are ignored. | [
"hasSubs",
"returns",
"true",
"if",
"there",
"is",
"any",
"active",
"subscription",
"for",
"this",
"subStore",
".",
"That",
"is",
"offline",
"durable",
"subscriptions",
"are",
"ignored",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L907-L922 | train |
nats-io/nats-streaming-server | server/server.go | LookupByDurable | func (ss *subStore) LookupByDurable(durableName string) *subState {
ss.RLock()
sub := ss.durables[durableName]
ss.RUnlock()
return sub
} | go | func (ss *subStore) LookupByDurable(durableName string) *subState {
ss.RLock()
sub := ss.durables[durableName]
ss.RUnlock()
return sub
} | [
"func",
"(",
"ss",
"*",
"subStore",
")",
"LookupByDurable",
"(",
"durableName",
"string",
")",
"*",
"subState",
"{",
"ss",
".",
"RLock",
"(",
")",
"\n",
"sub",
":=",
"ss",
".",
"durables",
"[",
"durableName",
"]",
"\n",
"ss",
".",
"RUnlock",
"(",
")"... | // Lookup by durable name. | [
"Lookup",
"by",
"durable",
"name",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L1138-L1143 | train |
nats-io/nats-streaming-server | server/server.go | LookupByAckInbox | func (ss *subStore) LookupByAckInbox(ackInbox string) *subState {
ss.RLock()
sub := ss.acks[ackInbox]
ss.RUnlock()
return sub
} | go | func (ss *subStore) LookupByAckInbox(ackInbox string) *subState {
ss.RLock()
sub := ss.acks[ackInbox]
ss.RUnlock()
return sub
} | [
"func",
"(",
"ss",
"*",
"subStore",
")",
"LookupByAckInbox",
"(",
"ackInbox",
"string",
")",
"*",
"subState",
"{",
"ss",
".",
"RLock",
"(",
")",
"\n",
"sub",
":=",
"ss",
".",
"acks",
"[",
"ackInbox",
"]",
"\n",
"ss",
".",
"RUnlock",
"(",
")",
"\n",... | // Lookup by ackInbox name. | [
"Lookup",
"by",
"ackInbox",
"name",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L1146-L1151 | train |
nats-io/nats-streaming-server | server/server.go | Clone | func (o *Options) Clone() *Options {
// A simple copy covers pretty much everything
clone := *o
// But we have the problem of the PerChannel map that needs
// to be copied.
clone.PerChannel = (&o.StoreLimits).ClonePerChannelMap()
// Make a copy of the clustering peers
if len(o.Clustering.Peers) > 0 {
clone.Clu... | go | func (o *Options) Clone() *Options {
// A simple copy covers pretty much everything
clone := *o
// But we have the problem of the PerChannel map that needs
// to be copied.
clone.PerChannel = (&o.StoreLimits).ClonePerChannelMap()
// Make a copy of the clustering peers
if len(o.Clustering.Peers) > 0 {
clone.Clu... | [
"func",
"(",
"o",
"*",
"Options",
")",
"Clone",
"(",
")",
"*",
"Options",
"{",
"// A simple copy covers pretty much everything",
"clone",
":=",
"*",
"o",
"\n",
"// But we have the problem of the PerChannel map that needs",
"// to be copied.",
"clone",
".",
"PerChannel",
... | // Clone returns a deep copy of the Options object. | [
"Clone",
"returns",
"a",
"deep",
"copy",
"of",
"the",
"Options",
"object",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L1188-L1200 | train |
nats-io/nats-streaming-server | server/server.go | GetDefaultOptions | func GetDefaultOptions() (o *Options) {
opts := defaultOptions
opts.StoreLimits = stores.DefaultStoreLimits
return &opts
} | go | func GetDefaultOptions() (o *Options) {
opts := defaultOptions
opts.StoreLimits = stores.DefaultStoreLimits
return &opts
} | [
"func",
"GetDefaultOptions",
"(",
")",
"(",
"o",
"*",
"Options",
")",
"{",
"opts",
":=",
"defaultOptions",
"\n",
"opts",
".",
"StoreLimits",
"=",
"stores",
".",
"DefaultStoreLimits",
"\n",
"return",
"&",
"opts",
"\n",
"}"
] | // GetDefaultOptions returns default options for the NATS Streaming Server | [
"GetDefaultOptions",
"returns",
"default",
"options",
"for",
"the",
"NATS",
"Streaming",
"Server"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L1217-L1221 | train |
nats-io/nats-streaming-server | server/server.go | RunServer | func RunServer(ID string) (*StanServer, error) {
sOpts := GetDefaultOptions()
sOpts.ID = ID
nOpts := DefaultNatsServerOptions
return RunServerWithOpts(sOpts, &nOpts)
} | go | func RunServer(ID string) (*StanServer, error) {
sOpts := GetDefaultOptions()
sOpts.ID = ID
nOpts := DefaultNatsServerOptions
return RunServerWithOpts(sOpts, &nOpts)
} | [
"func",
"RunServer",
"(",
"ID",
"string",
")",
"(",
"*",
"StanServer",
",",
"error",
")",
"{",
"sOpts",
":=",
"GetDefaultOptions",
"(",
")",
"\n",
"sOpts",
".",
"ID",
"=",
"ID",
"\n",
"nOpts",
":=",
"DefaultNatsServerOptions",
"\n",
"return",
"RunServerWit... | // RunServer will startup an embedded NATS Streaming Server and a nats-server to support it. | [
"RunServer",
"will",
"startup",
"an",
"embedded",
"NATS",
"Streaming",
"Server",
"and",
"a",
"nats",
"-",
"server",
"to",
"support",
"it",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L1411-L1416 | train |
nats-io/nats-streaming-server | server/server.go | startRaftNode | func (s *StanServer) startRaftNode(hasStreamingState bool) error {
if err := s.createServerRaftNode(hasStreamingState); err != nil {
return err
}
node := s.raft
leaderWait := make(chan struct{}, 1)
leaderReady := func() {
select {
case leaderWait <- struct{}{}:
default:
}
}
if node.State() != raft.Lea... | go | func (s *StanServer) startRaftNode(hasStreamingState bool) error {
if err := s.createServerRaftNode(hasStreamingState); err != nil {
return err
}
node := s.raft
leaderWait := make(chan struct{}, 1)
leaderReady := func() {
select {
case leaderWait <- struct{}{}:
default:
}
}
if node.State() != raft.Lea... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"startRaftNode",
"(",
"hasStreamingState",
"bool",
")",
"error",
"{",
"if",
"err",
":=",
"s",
".",
"createServerRaftNode",
"(",
"hasStreamingState",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
... | // startRaftNode creates and starts the Raft group.
// This should only be called if the server is running in clustered mode. | [
"startRaftNode",
"creates",
"and",
"starts",
"the",
"Raft",
"group",
".",
"This",
"should",
"only",
"be",
"called",
"if",
"the",
"server",
"is",
"running",
"in",
"clustered",
"mode",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L1878-L1933 | train |
nats-io/nats-streaming-server | server/server.go | leadershipAcquired | func (s *StanServer) leadershipAcquired() error {
s.log.Noticef("server became leader, performing leader promotion actions")
defer s.log.Noticef("finished leader promotion actions")
// If we were not the leader, there should be nothing in the ioChannel
// (processing of client publishes). However, since a node cou... | go | func (s *StanServer) leadershipAcquired() error {
s.log.Noticef("server became leader, performing leader promotion actions")
defer s.log.Noticef("finished leader promotion actions")
// If we were not the leader, there should be nothing in the ioChannel
// (processing of client publishes). However, since a node cou... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"leadershipAcquired",
"(",
")",
"error",
"{",
"s",
".",
"log",
".",
"Noticef",
"(",
"\"",
"\"",
")",
"\n",
"defer",
"s",
".",
"log",
".",
"Noticef",
"(",
"\"",
"\"",
")",
"\n\n",
"// If we were not the leader, ... | // leadershipAcquired should be called when this node is elected leader.
// This should only be called when the server is running in clustered mode. | [
"leadershipAcquired",
"should",
"be",
"called",
"when",
"this",
"node",
"is",
"elected",
"leader",
".",
"This",
"should",
"only",
"be",
"called",
"when",
"the",
"server",
"is",
"running",
"in",
"clustered",
"mode",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L1945-L2037 | train |
nats-io/nats-streaming-server | server/server.go | leadershipLost | func (s *StanServer) leadershipLost() {
s.log.Noticef("server lost leadership, performing leader stepdown actions")
defer s.log.Noticef("finished leader stepdown actions")
// Cancel outstanding client heartbeats. We aren't concerned about races
// where new clients might be connecting because at this point, the se... | go | func (s *StanServer) leadershipLost() {
s.log.Noticef("server lost leadership, performing leader stepdown actions")
defer s.log.Noticef("finished leader stepdown actions")
// Cancel outstanding client heartbeats. We aren't concerned about races
// where new clients might be connecting because at this point, the se... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"leadershipLost",
"(",
")",
"{",
"s",
".",
"log",
".",
"Noticef",
"(",
"\"",
"\"",
")",
"\n",
"defer",
"s",
".",
"log",
".",
"Noticef",
"(",
"\"",
"\"",
")",
"\n\n",
"// Cancel outstanding client heartbeats. We a... | // leadershipLost should be called when this node loses leadership.
// This should only be called when the server is running in clustered mode. | [
"leadershipLost",
"should",
"be",
"called",
"when",
"this",
"node",
"loses",
"leadership",
".",
"This",
"should",
"only",
"be",
"called",
"when",
"the",
"server",
"is",
"running",
"in",
"clustered",
"mode",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L2041-L2074 | train |
nats-io/nats-streaming-server | server/server.go | ensureRunningStandAlone | func (s *StanServer) ensureRunningStandAlone() error {
clusterID := s.info.ClusterID
hbInbox := nats.NewInbox()
timeout := time.Millisecond * 250
// We cannot use the client's API here as it will create a dependency
// cycle in the streaming client, so build our request and see if we
// get a response.
req := &... | go | func (s *StanServer) ensureRunningStandAlone() error {
clusterID := s.info.ClusterID
hbInbox := nats.NewInbox()
timeout := time.Millisecond * 250
// We cannot use the client's API here as it will create a dependency
// cycle in the streaming client, so build our request and see if we
// get a response.
req := &... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"ensureRunningStandAlone",
"(",
")",
"error",
"{",
"clusterID",
":=",
"s",
".",
"info",
".",
"ClusterID",
"\n",
"hbInbox",
":=",
"nats",
".",
"NewInbox",
"(",
")",
"\n",
"timeout",
":=",
"time",
".",
"Millisecond... | // ensureRunningStandAlone prevents this streaming server from starting
// if another is found using the same cluster ID - a possibility when
// routing is enabled.
// This runs under sever's lock so nothing should grab the server lock here. | [
"ensureRunningStandAlone",
"prevents",
"this",
"streaming",
"server",
"from",
"starting",
"if",
"another",
"is",
"found",
"using",
"the",
"same",
"cluster",
"ID",
"-",
"a",
"possibility",
"when",
"routing",
"is",
"enabled",
".",
"This",
"runs",
"under",
"sever",... | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L2200-L2232 | train |
nats-io/nats-streaming-server | server/server.go | processRecoveredClients | func (s *StanServer) processRecoveredClients(clients []*stores.Client) {
if !s.isClustered {
s.clients.recoverClients(clients)
}
} | go | func (s *StanServer) processRecoveredClients(clients []*stores.Client) {
if !s.isClustered {
s.clients.recoverClients(clients)
}
} | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"processRecoveredClients",
"(",
"clients",
"[",
"]",
"*",
"stores",
".",
"Client",
")",
"{",
"if",
"!",
"s",
".",
"isClustered",
"{",
"s",
".",
"clients",
".",
"recoverClients",
"(",
"clients",
")",
"\n",
"}",
... | // Binds server's view of a client with stored Client objects. | [
"Binds",
"server",
"s",
"view",
"of",
"a",
"client",
"with",
"stored",
"Client",
"objects",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L2235-L2239 | train |
nats-io/nats-streaming-server | server/server.go | processRecoveredChannels | func (s *StanServer) processRecoveredChannels(channels map[string]*stores.RecoveredChannel) ([]*subState, error) {
allSubs := make([]*subState, 0, 16)
for channelName, recoveredChannel := range channels {
channel, err := s.channels.create(s, channelName, recoveredChannel.Channel)
if err != nil {
return nil, e... | go | func (s *StanServer) processRecoveredChannels(channels map[string]*stores.RecoveredChannel) ([]*subState, error) {
allSubs := make([]*subState, 0, 16)
for channelName, recoveredChannel := range channels {
channel, err := s.channels.create(s, channelName, recoveredChannel.Channel)
if err != nil {
return nil, e... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"processRecoveredChannels",
"(",
"channels",
"map",
"[",
"string",
"]",
"*",
"stores",
".",
"RecoveredChannel",
")",
"(",
"[",
"]",
"*",
"subState",
",",
"error",
")",
"{",
"allSubs",
":=",
"make",
"(",
"[",
"]... | // Reconstruct the subscription state on restart. | [
"Reconstruct",
"the",
"subscription",
"state",
"on",
"restart",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L2242-L2270 | train |
nats-io/nats-streaming-server | server/server.go | performRedeliveryOnStartup | func (s *StanServer) performRedeliveryOnStartup(recoveredSubs []*subState) {
queues := make(map[*queueState]*channel)
for _, sub := range recoveredSubs {
// Ignore subs that did not have any ack pendings on startup.
sub.Lock()
// Consider this subscription ready to receive messages
sub.initialized = true
/... | go | func (s *StanServer) performRedeliveryOnStartup(recoveredSubs []*subState) {
queues := make(map[*queueState]*channel)
for _, sub := range recoveredSubs {
// Ignore subs that did not have any ack pendings on startup.
sub.Lock()
// Consider this subscription ready to receive messages
sub.initialized = true
/... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"performRedeliveryOnStartup",
"(",
"recoveredSubs",
"[",
"]",
"*",
"subState",
")",
"{",
"queues",
":=",
"make",
"(",
"map",
"[",
"*",
"queueState",
"]",
"*",
"channel",
")",
"\n\n",
"for",
"_",
",",
"sub",
":=... | // Redelivers unacknowledged messages, releases the hold for new messages delivery,
// and kicks delivery of available messages. | [
"Redelivers",
"unacknowledged",
"messages",
"releases",
"the",
"hold",
"for",
"new",
"messages",
"delivery",
"and",
"kicks",
"delivery",
"of",
"available",
"messages",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L2389-L2432 | train |
nats-io/nats-streaming-server | server/server.go | initSubscriptions | func (s *StanServer) initSubscriptions() error {
// Do not create internal subscriptions in clustered mode,
// the leader will when it gets elected.
if !s.isClustered {
createSubOnClientPublish := true
if s.partitions != nil {
// Receive published messages from clients, but only on the list
// of static ... | go | func (s *StanServer) initSubscriptions() error {
// Do not create internal subscriptions in clustered mode,
// the leader will when it gets elected.
if !s.isClustered {
createSubOnClientPublish := true
if s.partitions != nil {
// Receive published messages from clients, but only on the list
// of static ... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"initSubscriptions",
"(",
")",
"error",
"{",
"// Do not create internal subscriptions in clustered mode,",
"// the leader will when it gets elected.",
"if",
"!",
"s",
".",
"isClustered",
"{",
"createSubOnClientPublish",
":=",
"true"... | // initSubscriptions will setup initial subscriptions for discovery etc. | [
"initSubscriptions",
"will",
"setup",
"initial",
"subscriptions",
"for",
"discovery",
"etc",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L2435-L2471 | train |
nats-io/nats-streaming-server | server/server.go | connectCB | func (s *StanServer) connectCB(m *nats.Msg) {
req := &pb.ConnectRequest{}
err := req.Unmarshal(m.Data)
if err != nil || req.HeartbeatInbox == "" {
s.log.Errorf("[Client:?] Invalid conn request: ClientID=%s, Inbox=%s, err=%v",
req.ClientID, req.HeartbeatInbox, err)
s.sendConnectErr(m.Reply, ErrInvalidConnReq.E... | go | func (s *StanServer) connectCB(m *nats.Msg) {
req := &pb.ConnectRequest{}
err := req.Unmarshal(m.Data)
if err != nil || req.HeartbeatInbox == "" {
s.log.Errorf("[Client:?] Invalid conn request: ClientID=%s, Inbox=%s, err=%v",
req.ClientID, req.HeartbeatInbox, err)
s.sendConnectErr(m.Reply, ErrInvalidConnReq.E... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"connectCB",
"(",
"m",
"*",
"nats",
".",
"Msg",
")",
"{",
"req",
":=",
"&",
"pb",
".",
"ConnectRequest",
"{",
"}",
"\n",
"err",
":=",
"req",
".",
"Unmarshal",
"(",
"m",
".",
"Data",
")",
"\n",
"if",
"er... | // Process a client connect request | [
"Process",
"a",
"client",
"connect",
"request"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L2558-L2613 | train |
nats-io/nats-streaming-server | server/server.go | isDuplicateConnect | func (s *StanServer) isDuplicateConnect(client *client) bool {
client.RLock()
hbInbox := client.info.HbInbox
client.RUnlock()
// This is the HbInbox from the "old" client. See if it is up and
// running by sending a ping to that inbox.
_, err := s.nc.Request(hbInbox, nil, s.dupCIDTimeout)
// If err is nil, the... | go | func (s *StanServer) isDuplicateConnect(client *client) bool {
client.RLock()
hbInbox := client.info.HbInbox
client.RUnlock()
// This is the HbInbox from the "old" client. See if it is up and
// running by sending a ping to that inbox.
_, err := s.nc.Request(hbInbox, nil, s.dupCIDTimeout)
// If err is nil, the... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"isDuplicateConnect",
"(",
"client",
"*",
"client",
")",
"bool",
"{",
"client",
".",
"RLock",
"(",
")",
"\n",
"hbInbox",
":=",
"client",
".",
"info",
".",
"HbInbox",
"\n",
"client",
".",
"RUnlock",
"(",
")",
... | // isDuplicateConnect determines if the given client ID is a duplicate
// connection by pinging the old client's heartbeat inbox and checking if it
// responds. If it does, it's a duplicate connection. | [
"isDuplicateConnect",
"determines",
"if",
"the",
"given",
"client",
"ID",
"is",
"a",
"duplicate",
"connection",
"by",
"pinging",
"the",
"old",
"client",
"s",
"heartbeat",
"inbox",
"and",
"checking",
"if",
"it",
"responds",
".",
"If",
"it",
"does",
"it",
"s",... | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L2638-L2650 | train |
nats-io/nats-streaming-server | server/server.go | replicateDeleteChannel | func (s *StanServer) replicateDeleteChannel(channel string) {
op := &spb.RaftOperation{
OpType: spb.RaftOperation_DeleteChannel,
Channel: channel,
}
data, err := op.Marshal()
if err != nil {
panic(err)
}
// Wait on result of replication.
if err = s.raft.Apply(data, 0).Error(); err != nil {
// If we have... | go | func (s *StanServer) replicateDeleteChannel(channel string) {
op := &spb.RaftOperation{
OpType: spb.RaftOperation_DeleteChannel,
Channel: channel,
}
data, err := op.Marshal()
if err != nil {
panic(err)
}
// Wait on result of replication.
if err = s.raft.Apply(data, 0).Error(); err != nil {
// If we have... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"replicateDeleteChannel",
"(",
"channel",
"string",
")",
"{",
"op",
":=",
"&",
"spb",
".",
"RaftOperation",
"{",
"OpType",
":",
"spb",
".",
"RaftOperation_DeleteChannel",
",",
"Channel",
":",
"channel",
",",
"}",
"... | // Leader invokes this to replicate the command to delete a channel. | [
"Leader",
"invokes",
"this",
"to",
"replicate",
"the",
"command",
"to",
"delete",
"a",
"channel",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L2672-L2692 | train |
nats-io/nats-streaming-server | server/server.go | handleChannelDelete | func (s *StanServer) handleChannelDelete(c *channel) {
delete := false
cs := s.channels
cs.Lock()
a := c.activity
if a.preventDelete || a.deleteInProgress || c.ss.hasActiveSubs() {
if s.debug {
s.log.Debugf("Channel %q cannot be deleted: preventDelete=%v inProgress=%v hasActiveSubs=%v",
c.name, a.preventD... | go | func (s *StanServer) handleChannelDelete(c *channel) {
delete := false
cs := s.channels
cs.Lock()
a := c.activity
if a.preventDelete || a.deleteInProgress || c.ss.hasActiveSubs() {
if s.debug {
s.log.Debugf("Channel %q cannot be deleted: preventDelete=%v inProgress=%v hasActiveSubs=%v",
c.name, a.preventD... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"handleChannelDelete",
"(",
"c",
"*",
"channel",
")",
"{",
"delete",
":=",
"false",
"\n",
"cs",
":=",
"s",
".",
"channels",
"\n",
"cs",
".",
"Lock",
"(",
")",
"\n",
"a",
":=",
"c",
".",
"activity",
"\n",
... | // Check if the channel can be deleted. If so, do it in place.
// This is called from the ioLoop by the leader or a standlone server. | [
"Check",
"if",
"the",
"channel",
"can",
"be",
"deleted",
".",
"If",
"so",
"do",
"it",
"in",
"place",
".",
"This",
"is",
"called",
"from",
"the",
"ioLoop",
"by",
"the",
"leader",
"or",
"a",
"standlone",
"server",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L2696-L2745 | train |
nats-io/nats-streaming-server | server/server.go | processDeleteChannel | func (s *StanServer) processDeleteChannel(channel string) {
cs := s.channels
cs.Lock()
defer cs.Unlock()
c := cs.channels[channel]
if c == nil {
s.log.Errorf("Error deleting channel %q: not found", channel)
return
}
if c.activity != nil && c.activity.preventDelete {
s.log.Errorf("The channel %q cannot be d... | go | func (s *StanServer) processDeleteChannel(channel string) {
cs := s.channels
cs.Lock()
defer cs.Unlock()
c := cs.channels[channel]
if c == nil {
s.log.Errorf("Error deleting channel %q: not found", channel)
return
}
if c.activity != nil && c.activity.preventDelete {
s.log.Errorf("The channel %q cannot be d... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"processDeleteChannel",
"(",
"channel",
"string",
")",
"{",
"cs",
":=",
"s",
".",
"channels",
"\n",
"cs",
".",
"Lock",
"(",
")",
"\n",
"defer",
"cs",
".",
"Unlock",
"(",
")",
"\n",
"c",
":=",
"cs",
".",
"... | // Actual deletetion of the channel. | [
"Actual",
"deletetion",
"of",
"the",
"channel",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L2748-L2772 | train |
nats-io/nats-streaming-server | server/server.go | checkClientHealth | func (s *StanServer) checkClientHealth(clientID string) {
client := s.clients.lookup(clientID)
if client == nil {
return
}
// If clustered and we lost leadership, we should stop
// heartbeating as the new leader will take over.
if s.isClustered && !s.isLeader() {
// Do not remove client HB here. We do that i... | go | func (s *StanServer) checkClientHealth(clientID string) {
client := s.clients.lookup(clientID)
if client == nil {
return
}
// If clustered and we lost leadership, we should stop
// heartbeating as the new leader will take over.
if s.isClustered && !s.isLeader() {
// Do not remove client HB here. We do that i... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"checkClientHealth",
"(",
"clientID",
"string",
")",
"{",
"client",
":=",
"s",
".",
"clients",
".",
"lookup",
"(",
"clientID",
")",
"\n",
"if",
"client",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"// If cl... | // Send a heartbeat call to the client. | [
"Send",
"a",
"heartbeat",
"call",
"to",
"the",
"client",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L2859-L2944 | train |
nats-io/nats-streaming-server | server/server.go | closeClient | func (s *StanServer) closeClient(clientID string) error {
s.closeMu.Lock()
defer s.closeMu.Unlock()
// Lookup client first, will unregister only after removing its subscriptions
client := s.clients.lookup(clientID)
if client == nil {
s.log.Errorf("Unknown client %q in close request", clientID)
return ErrUnknow... | go | func (s *StanServer) closeClient(clientID string) error {
s.closeMu.Lock()
defer s.closeMu.Unlock()
// Lookup client first, will unregister only after removing its subscriptions
client := s.clients.lookup(clientID)
if client == nil {
s.log.Errorf("Unknown client %q in close request", clientID)
return ErrUnknow... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"closeClient",
"(",
"clientID",
"string",
")",
"error",
"{",
"s",
".",
"closeMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"closeMu",
".",
"Unlock",
"(",
")",
"\n",
"// Lookup client first, will unregister o... | // Close a client | [
"Close",
"a",
"client"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L2947-L2972 | train |
nats-io/nats-streaming-server | server/server.go | processCloseRequest | func (s *StanServer) processCloseRequest(m *nats.Msg) {
req := &pb.CloseRequest{}
err := req.Unmarshal(m.Data)
if err != nil {
s.log.Errorf("Received invalid close request, subject=%s", m.Subject)
s.sendCloseResponse(m.Reply, ErrInvalidCloseReq)
return
}
s.barrier(func() {
var err error
// If clustered,... | go | func (s *StanServer) processCloseRequest(m *nats.Msg) {
req := &pb.CloseRequest{}
err := req.Unmarshal(m.Data)
if err != nil {
s.log.Errorf("Received invalid close request, subject=%s", m.Subject)
s.sendCloseResponse(m.Reply, ErrInvalidCloseReq)
return
}
s.barrier(func() {
var err error
// If clustered,... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"processCloseRequest",
"(",
"m",
"*",
"nats",
".",
"Msg",
")",
"{",
"req",
":=",
"&",
"pb",
".",
"CloseRequest",
"{",
"}",
"\n",
"err",
":=",
"req",
".",
"Unmarshal",
"(",
"m",
".",
"Data",
")",
"\n",
"if... | // processCloseRequest will process connection close requests from clients. | [
"processCloseRequest",
"will",
"process",
"connection",
"close",
"requests",
"from",
"clients",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L2975-L2997 | train |
nats-io/nats-streaming-server | server/server.go | processClientPublish | func (s *StanServer) processClientPublish(m *nats.Msg) {
iopm := &ioPendingMsg{m: m}
pm := &iopm.pm
if pm.Unmarshal(m.Data) != nil {
if s.processCtrlMsg(m) {
return
}
// else we will report an error below...
}
// Make sure we have a guid and valid channel name.
if pm.Guid == "" || !util.IsChannelNameVal... | go | func (s *StanServer) processClientPublish(m *nats.Msg) {
iopm := &ioPendingMsg{m: m}
pm := &iopm.pm
if pm.Unmarshal(m.Data) != nil {
if s.processCtrlMsg(m) {
return
}
// else we will report an error below...
}
// Make sure we have a guid and valid channel name.
if pm.Guid == "" || !util.IsChannelNameVal... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"processClientPublish",
"(",
"m",
"*",
"nats",
".",
"Msg",
")",
"{",
"iopm",
":=",
"&",
"ioPendingMsg",
"{",
"m",
":",
"m",
"}",
"\n",
"pm",
":=",
"&",
"iopm",
".",
"pm",
"\n",
"if",
"pm",
".",
"Unmarshal... | // processClientPublish process inbound messages from clients. | [
"processClientPublish",
"process",
"inbound",
"messages",
"from",
"clients",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L3030-L3070 | train |
nats-io/nats-streaming-server | server/server.go | processClientPings | func (s *StanServer) processClientPings(m *nats.Msg) {
if len(m.Data) == 0 {
return
}
ping := &pb.Ping{}
if err := ping.Unmarshal(m.Data); err != nil {
return
}
var reply []byte
client := s.clients.lookupByConnID(ping.ConnID)
if client != nil {
// If the client has failed heartbeats and since the
// ser... | go | func (s *StanServer) processClientPings(m *nats.Msg) {
if len(m.Data) == 0 {
return
}
ping := &pb.Ping{}
if err := ping.Unmarshal(m.Data); err != nil {
return
}
var reply []byte
client := s.clients.lookupByConnID(ping.ConnID)
if client != nil {
// If the client has failed heartbeats and since the
// ser... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"processClientPings",
"(",
"m",
"*",
"nats",
".",
"Msg",
")",
"{",
"if",
"len",
"(",
"m",
".",
"Data",
")",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n",
"ping",
":=",
"&",
"pb",
".",
"Ping",
"{",
"}",
"... | // processClientPings receives a PING from a client. The payload is the client's UID.
// If the client is present, a response with nil payload is sent back to indicate
// success, otherwise the payload contains an error message. | [
"processClientPings",
"receives",
"a",
"PING",
"from",
"a",
"client",
".",
"The",
"payload",
"is",
"the",
"client",
"s",
"UID",
".",
"If",
"the",
"client",
"is",
"present",
"a",
"response",
"with",
"nil",
"payload",
"is",
"sent",
"back",
"to",
"indicate",
... | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L3075-L3113 | train |
nats-io/nats-streaming-server | server/server.go | sendMsgToQueueGroup | func (s *StanServer) sendMsgToQueueGroup(qs *queueState, m *pb.MsgProto, force bool) (*subState, bool, bool) {
sub := findBestQueueSub(qs.subs)
if sub == nil {
return nil, false, false
}
sub.Lock()
wasStalled := sub.stalled
didSend, sendMore := s.sendMsgToSub(sub, m, force)
// If this is not a redelivery and t... | go | func (s *StanServer) sendMsgToQueueGroup(qs *queueState, m *pb.MsgProto, force bool) (*subState, bool, bool) {
sub := findBestQueueSub(qs.subs)
if sub == nil {
return nil, false, false
}
sub.Lock()
wasStalled := sub.stalled
didSend, sendMore := s.sendMsgToSub(sub, m, force)
// If this is not a redelivery and t... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"sendMsgToQueueGroup",
"(",
"qs",
"*",
"queueState",
",",
"m",
"*",
"pb",
".",
"MsgProto",
",",
"force",
"bool",
")",
"(",
"*",
"subState",
",",
"bool",
",",
"bool",
")",
"{",
"sub",
":=",
"findBestQueueSub",
... | // Send a message to the queue group
// Assumes qs lock held for write | [
"Send",
"a",
"message",
"to",
"the",
"queue",
"group",
"Assumes",
"qs",
"lock",
"held",
"for",
"write"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L3174-L3192 | train |
nats-io/nats-streaming-server | server/server.go | processMsg | func (s *StanServer) processMsg(c *channel) {
ss := c.ss
// Since we iterate through them all.
ss.RLock()
// Walk the plain subscribers and deliver to each one
for _, sub := range ss.psubs {
s.sendAvailableMessages(c, sub)
}
// Check the queue subscribers
for _, qs := range ss.qsubs {
s.sendAvailableMessa... | go | func (s *StanServer) processMsg(c *channel) {
ss := c.ss
// Since we iterate through them all.
ss.RLock()
// Walk the plain subscribers and deliver to each one
for _, sub := range ss.psubs {
s.sendAvailableMessages(c, sub)
}
// Check the queue subscribers
for _, qs := range ss.qsubs {
s.sendAvailableMessa... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"processMsg",
"(",
"c",
"*",
"channel",
")",
"{",
"ss",
":=",
"c",
".",
"ss",
"\n\n",
"// Since we iterate through them all.",
"ss",
".",
"RLock",
"(",
")",
"\n",
"// Walk the plain subscribers and deliver to each one",
... | // processMsg will process a message, and possibly send to clients, etc. | [
"processMsg",
"will",
"process",
"a",
"message",
"and",
"possibly",
"send",
"to",
"clients",
"etc",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L3195-L3210 | train |
nats-io/nats-streaming-server | server/server.go | makeSortedSequences | func makeSortedSequences(sequences map[uint64]int64) []uint64 {
results := make([]uint64, 0, len(sequences))
for seq := range sequences {
results = append(results, seq)
}
sort.Sort(bySeq(results))
return results
} | go | func makeSortedSequences(sequences map[uint64]int64) []uint64 {
results := make([]uint64, 0, len(sequences))
for seq := range sequences {
results = append(results, seq)
}
sort.Sort(bySeq(results))
return results
} | [
"func",
"makeSortedSequences",
"(",
"sequences",
"map",
"[",
"uint64",
"]",
"int64",
")",
"[",
"]",
"uint64",
"{",
"results",
":=",
"make",
"(",
"[",
"]",
"uint64",
",",
"0",
",",
"len",
"(",
"sequences",
")",
")",
"\n",
"for",
"seq",
":=",
"range",
... | // Returns an array of message sequence numbers ordered by sequence. | [
"Returns",
"an",
"array",
"of",
"message",
"sequence",
"numbers",
"ordered",
"by",
"sequence",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L3220-L3227 | train |
nats-io/nats-streaming-server | server/server.go | performDurableRedelivery | func (s *StanServer) performDurableRedelivery(c *channel, sub *subState) {
// Sort our messages outstanding from acksPending, grab some state and unlock.
sub.RLock()
sortedSeqs := makeSortedSequences(sub.acksPending)
clientID := sub.ClientID
newOnHold := sub.newOnHold
subID := sub.ID
sub.RUnlock()
if s.debug &... | go | func (s *StanServer) performDurableRedelivery(c *channel, sub *subState) {
// Sort our messages outstanding from acksPending, grab some state and unlock.
sub.RLock()
sortedSeqs := makeSortedSequences(sub.acksPending)
clientID := sub.ClientID
newOnHold := sub.newOnHold
subID := sub.ID
sub.RUnlock()
if s.debug &... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"performDurableRedelivery",
"(",
"c",
"*",
"channel",
",",
"sub",
"*",
"subState",
")",
"{",
"// Sort our messages outstanding from acksPending, grab some state and unlock.",
"sub",
".",
"RLock",
"(",
")",
"\n",
"sortedSeqs",
... | // Redeliver all outstanding messages to a durable subscriber, used on resubscribe. | [
"Redeliver",
"all",
"outstanding",
"messages",
"to",
"a",
"durable",
"subscriber",
"used",
"on",
"resubscribe",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L3256-L3303 | train |
nats-io/nats-streaming-server | server/server.go | collectSentOrAck | func (s *StanServer) collectSentOrAck(sub *subState, sent bool, sequence uint64) {
sr := s.ssarepl
if sub.replicate == nil {
sub.replicate = &subSentAndAck{
sent: make([]uint64, 0, 100),
ack: make([]uint64, 0, 100),
}
}
r := sub.replicate
if sent {
r.sent = append(r.sent, sequence)
} else {
r.ack =... | go | func (s *StanServer) collectSentOrAck(sub *subState, sent bool, sequence uint64) {
sr := s.ssarepl
if sub.replicate == nil {
sub.replicate = &subSentAndAck{
sent: make([]uint64, 0, 100),
ack: make([]uint64, 0, 100),
}
}
r := sub.replicate
if sent {
r.sent = append(r.sent, sequence)
} else {
r.ack =... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"collectSentOrAck",
"(",
"sub",
"*",
"subState",
",",
"sent",
"bool",
",",
"sequence",
"uint64",
")",
"{",
"sr",
":=",
"s",
".",
"ssarepl",
"\n",
"if",
"sub",
".",
"replicate",
"==",
"nil",
"{",
"sub",
".",
... | // Keep track of sent or ack messages.
// If the number of operations reach a certain threshold,
// the sub is added to list of subs that should be flushed asap.
// This call does not do actual RAFT replication and should not block.
// Caller holds the sub's Lock. | [
"Keep",
"track",
"of",
"sent",
"or",
"ack",
"messages",
".",
"If",
"the",
"number",
"of",
"operations",
"reach",
"a",
"certain",
"threshold",
"the",
"sub",
"is",
"added",
"to",
"list",
"of",
"subs",
"that",
"should",
"be",
"flushed",
"asap",
".",
"This",... | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L3466-L3491 | train |
nats-io/nats-streaming-server | server/server.go | replicateSubSentAndAck | func (s *StanServer) replicateSubSentAndAck(sub *subState) {
var data []byte
sr := s.ssarepl
sub.Lock()
r := sub.replicate
if r != nil && len(r.sent)+len(r.ack) > 0 {
data = createSubSentAndAckProto(sub, r)
r.sent = r.sent[:0]
r.ack = r.ack[:0]
r.applying = true
}
sub.Unlock()
if data != nil {
if te... | go | func (s *StanServer) replicateSubSentAndAck(sub *subState) {
var data []byte
sr := s.ssarepl
sub.Lock()
r := sub.replicate
if r != nil && len(r.sent)+len(r.ack) > 0 {
data = createSubSentAndAckProto(sub, r)
r.sent = r.sent[:0]
r.ack = r.ack[:0]
r.applying = true
}
sub.Unlock()
if data != nil {
if te... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"replicateSubSentAndAck",
"(",
"sub",
"*",
"subState",
")",
"{",
"var",
"data",
"[",
"]",
"byte",
"\n\n",
"sr",
":=",
"s",
".",
"ssarepl",
"\n",
"sub",
".",
"Lock",
"(",
")",
"\n",
"r",
":=",
"sub",
".",
... | // Replicates through RAFT | [
"Replicates",
"through",
"RAFT"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L3494-L3530 | train |
nats-io/nats-streaming-server | server/server.go | createSubSentAndAckProto | func createSubSentAndAckProto(sub *subState, r *subSentAndAck) []byte {
op := &spb.RaftOperation{
OpType: spb.RaftOperation_SendAndAck,
SubSentAck: &spb.SubSentAndAck{
Channel: sub.subject,
AckInbox: sub.AckInbox,
Sent: r.sent,
Ack: r.ack,
},
}
data, err := op.Marshal()
if err != nil {
... | go | func createSubSentAndAckProto(sub *subState, r *subSentAndAck) []byte {
op := &spb.RaftOperation{
OpType: spb.RaftOperation_SendAndAck,
SubSentAck: &spb.SubSentAndAck{
Channel: sub.subject,
AckInbox: sub.AckInbox,
Sent: r.sent,
Ack: r.ack,
},
}
data, err := op.Marshal()
if err != nil {
... | [
"func",
"createSubSentAndAckProto",
"(",
"sub",
"*",
"subState",
",",
"r",
"*",
"subSentAndAck",
")",
"[",
"]",
"byte",
"{",
"op",
":=",
"&",
"spb",
".",
"RaftOperation",
"{",
"OpType",
":",
"spb",
".",
"RaftOperation_SendAndAck",
",",
"SubSentAck",
":",
"... | // Little helper function to create a RaftOperation_SendAndAck protocol
// and serialize it. | [
"Little",
"helper",
"function",
"to",
"create",
"a",
"RaftOperation_SendAndAck",
"protocol",
"and",
"serialize",
"it",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L3534-L3549 | train |
nats-io/nats-streaming-server | server/server.go | clearSentAndAck | func (s *StanServer) clearSentAndAck(sub *subState) {
sr := s.ssarepl
sr.waiting.Delete(sub)
sr.ready.Delete(sub)
sub.replicate = nil
} | go | func (s *StanServer) clearSentAndAck(sub *subState) {
sr := s.ssarepl
sr.waiting.Delete(sub)
sr.ready.Delete(sub)
sub.replicate = nil
} | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"clearSentAndAck",
"(",
"sub",
"*",
"subState",
")",
"{",
"sr",
":=",
"s",
".",
"ssarepl",
"\n",
"sr",
".",
"waiting",
".",
"Delete",
"(",
"sub",
")",
"\n",
"sr",
".",
"ready",
".",
"Delete",
"(",
"sub",
... | // Sub lock is held on entry | [
"Sub",
"lock",
"is",
"held",
"on",
"entry"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L3588-L3593 | train |
nats-io/nats-streaming-server | server/server.go | sendMsgToSub | func (s *StanServer) sendMsgToSub(sub *subState, m *pb.MsgProto, force bool) (bool, bool) {
if sub == nil || m == nil || !sub.initialized || (sub.newOnHold && !m.Redelivered) {
return false, false
}
// Don't send if we have too many outstanding already, unless forced to send.
ap := int32(len(sub.acksPending))
i... | go | func (s *StanServer) sendMsgToSub(sub *subState, m *pb.MsgProto, force bool) (bool, bool) {
if sub == nil || m == nil || !sub.initialized || (sub.newOnHold && !m.Redelivered) {
return false, false
}
// Don't send if we have too many outstanding already, unless forced to send.
ap := int32(len(sub.acksPending))
i... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"sendMsgToSub",
"(",
"sub",
"*",
"subState",
",",
"m",
"*",
"pb",
".",
"MsgProto",
",",
"force",
"bool",
")",
"(",
"bool",
",",
"bool",
")",
"{",
"if",
"sub",
"==",
"nil",
"||",
"m",
"==",
"nil",
"||",
... | // Sends the message to the subscriber
// Unless `force` is true, in which case message is always sent, if the number
// of acksPending is greater or equal to the sub's MaxInFlight limit, messages
// are not sent and subscriber is marked as stalled.
// Sub lock should be held before calling. | [
"Sends",
"the",
"message",
"to",
"the",
"subscriber",
"Unless",
"force",
"is",
"true",
"in",
"which",
"case",
"message",
"is",
"always",
"sent",
"if",
"the",
"number",
"of",
"acksPending",
"is",
"greater",
"or",
"equal",
"to",
"the",
"sub",
"s",
"MaxInFlig... | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L3688-L3778 | train |
nats-io/nats-streaming-server | server/server.go | setupAckTimer | func (s *StanServer) setupAckTimer(sub *subState, d time.Duration) {
sub.ackTimer = time.AfterFunc(d, func() {
s.performAckExpirationRedelivery(sub, false)
})
} | go | func (s *StanServer) setupAckTimer(sub *subState, d time.Duration) {
sub.ackTimer = time.AfterFunc(d, func() {
s.performAckExpirationRedelivery(sub, false)
})
} | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"setupAckTimer",
"(",
"sub",
"*",
"subState",
",",
"d",
"time",
".",
"Duration",
")",
"{",
"sub",
".",
"ackTimer",
"=",
"time",
".",
"AfterFunc",
"(",
"d",
",",
"func",
"(",
")",
"{",
"s",
".",
"performAckE... | // Sets up the ackTimer to fire at the given duration.
// sub's lock held on entry. | [
"Sets",
"up",
"the",
"ackTimer",
"to",
"fire",
"at",
"the",
"given",
"duration",
".",
"sub",
"s",
"lock",
"held",
"on",
"entry",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L3782-L3786 | train |
nats-io/nats-streaming-server | server/server.go | sendDeleteChannelRequest | func (s *StanServer) sendDeleteChannelRequest(c *channel) {
iopm := &ioPendingMsg{c: c, dc: true}
s.ioChannel <- iopm
} | go | func (s *StanServer) sendDeleteChannelRequest(c *channel) {
iopm := &ioPendingMsg{c: c, dc: true}
s.ioChannel <- iopm
} | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"sendDeleteChannelRequest",
"(",
"c",
"*",
"channel",
")",
"{",
"iopm",
":=",
"&",
"ioPendingMsg",
"{",
"c",
":",
"c",
",",
"dc",
":",
"true",
"}",
"\n",
"s",
".",
"ioChannel",
"<-",
"iopm",
"\n",
"}"
] | // Sends a special ioPendingMsg to indicate that we should attempt
// to delete the given channel. | [
"Sends",
"a",
"special",
"ioPendingMsg",
"to",
"indicate",
"that",
"we",
"should",
"attempt",
"to",
"delete",
"the",
"given",
"channel",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L4007-L4010 | train |
nats-io/nats-streaming-server | server/server.go | ackPublisher | func (s *StanServer) ackPublisher(iopm *ioPendingMsg) {
msgAck := &iopm.pa
msgAck.Guid = iopm.pm.Guid
needed := msgAck.Size()
s.tmpBuf = util.EnsureBufBigEnough(s.tmpBuf, needed)
n, _ := msgAck.MarshalTo(s.tmpBuf)
if s.trace {
pm := &iopm.pm
s.log.Tracef("[Client:%s] Acking Publisher subj=%s guid=%s", pm.Clie... | go | func (s *StanServer) ackPublisher(iopm *ioPendingMsg) {
msgAck := &iopm.pa
msgAck.Guid = iopm.pm.Guid
needed := msgAck.Size()
s.tmpBuf = util.EnsureBufBigEnough(s.tmpBuf, needed)
n, _ := msgAck.MarshalTo(s.tmpBuf)
if s.trace {
pm := &iopm.pm
s.log.Tracef("[Client:%s] Acking Publisher subj=%s guid=%s", pm.Clie... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"ackPublisher",
"(",
"iopm",
"*",
"ioPendingMsg",
")",
"{",
"msgAck",
":=",
"&",
"iopm",
".",
"pa",
"\n",
"msgAck",
".",
"Guid",
"=",
"iopm",
".",
"pm",
".",
"Guid",
"\n",
"needed",
":=",
"msgAck",
".",
"Si... | // ackPublisher sends the ack for a message. | [
"ackPublisher",
"sends",
"the",
"ack",
"for",
"a",
"message",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L4052-L4063 | train |
nats-io/nats-streaming-server | server/server.go | deleteFromList | func (sub *subState) deleteFromList(sl []*subState) ([]*subState, bool) {
for i := 0; i < len(sl); i++ {
if sl[i] == sub {
sl[i] = sl[len(sl)-1]
sl[len(sl)-1] = nil
sl = sl[:len(sl)-1]
return shrinkSubListIfNeeded(sl), true
}
}
return sl, false
} | go | func (sub *subState) deleteFromList(sl []*subState) ([]*subState, bool) {
for i := 0; i < len(sl); i++ {
if sl[i] == sub {
sl[i] = sl[len(sl)-1]
sl[len(sl)-1] = nil
sl = sl[:len(sl)-1]
return shrinkSubListIfNeeded(sl), true
}
}
return sl, false
} | [
"func",
"(",
"sub",
"*",
"subState",
")",
"deleteFromList",
"(",
"sl",
"[",
"]",
"*",
"subState",
")",
"(",
"[",
"]",
"*",
"subState",
",",
"bool",
")",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"sl",
")",
";",
"i",
"++",
"{",
... | // Delete a sub from a given list. | [
"Delete",
"a",
"sub",
"from",
"a",
"given",
"list",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L4066-L4076 | train |
nats-io/nats-streaming-server | server/server.go | shrinkSubListIfNeeded | func shrinkSubListIfNeeded(sl []*subState) []*subState {
lsl := len(sl)
csl := cap(sl)
// Don't bother if list not too big
if csl <= 8 {
return sl
}
pFree := float32(csl-lsl) / float32(csl)
if pFree > 0.50 {
return append([]*subState(nil), sl...)
}
return sl
} | go | func shrinkSubListIfNeeded(sl []*subState) []*subState {
lsl := len(sl)
csl := cap(sl)
// Don't bother if list not too big
if csl <= 8 {
return sl
}
pFree := float32(csl-lsl) / float32(csl)
if pFree > 0.50 {
return append([]*subState(nil), sl...)
}
return sl
} | [
"func",
"shrinkSubListIfNeeded",
"(",
"sl",
"[",
"]",
"*",
"subState",
")",
"[",
"]",
"*",
"subState",
"{",
"lsl",
":=",
"len",
"(",
"sl",
")",
"\n",
"csl",
":=",
"cap",
"(",
"sl",
")",
"\n",
"// Don't bother if list not too big",
"if",
"csl",
"<=",
"8... | // Checks if we need to do a resize. This is for very large growth then
// subsequent return to a more normal size. | [
"Checks",
"if",
"we",
"need",
"to",
"do",
"a",
"resize",
".",
"This",
"is",
"for",
"very",
"large",
"growth",
"then",
"subsequent",
"return",
"to",
"a",
"more",
"normal",
"size",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L4080-L4092 | train |
nats-io/nats-streaming-server | server/server.go | removeAllNonDurableSubscribers | func (s *StanServer) removeAllNonDurableSubscribers(client *client) {
// client has been unregistered and no other routine can add/remove
// subscriptions, so it is safe to use the original.
client.RLock()
subs := client.subs
clientID := client.info.ID
client.RUnlock()
var (
storesToFlush = map[string]stores.S... | go | func (s *StanServer) removeAllNonDurableSubscribers(client *client) {
// client has been unregistered and no other routine can add/remove
// subscriptions, so it is safe to use the original.
client.RLock()
subs := client.subs
clientID := client.info.ID
client.RUnlock()
var (
storesToFlush = map[string]stores.S... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"removeAllNonDurableSubscribers",
"(",
"client",
"*",
"client",
")",
"{",
"// client has been unregistered and no other routine can add/remove",
"// subscriptions, so it is safe to use the original.",
"client",
".",
"RLock",
"(",
")",
... | // removeAllNonDurableSubscribers will remove all non-durable subscribers for the client. | [
"removeAllNonDurableSubscribers",
"will",
"remove",
"all",
"non",
"-",
"durable",
"subscribers",
"for",
"the",
"client",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L4095-L4137 | train |
nats-io/nats-streaming-server | server/server.go | processUnsubscribeRequest | func (s *StanServer) processUnsubscribeRequest(m *nats.Msg) {
req := &pb.UnsubscribeRequest{}
err := req.Unmarshal(m.Data)
if err != nil {
s.log.Errorf("Invalid unsub request from %s", m.Subject)
s.sendSubscriptionResponseErr(m.Reply, ErrInvalidUnsubReq)
return
}
s.performmUnsubOrCloseSubscription(m, req, fa... | go | func (s *StanServer) processUnsubscribeRequest(m *nats.Msg) {
req := &pb.UnsubscribeRequest{}
err := req.Unmarshal(m.Data)
if err != nil {
s.log.Errorf("Invalid unsub request from %s", m.Subject)
s.sendSubscriptionResponseErr(m.Reply, ErrInvalidUnsubReq)
return
}
s.performmUnsubOrCloseSubscription(m, req, fa... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"processUnsubscribeRequest",
"(",
"m",
"*",
"nats",
".",
"Msg",
")",
"{",
"req",
":=",
"&",
"pb",
".",
"UnsubscribeRequest",
"{",
"}",
"\n",
"err",
":=",
"req",
".",
"Unmarshal",
"(",
"m",
".",
"Data",
")",
... | // processUnsubscribeRequest will process a unsubscribe request. | [
"processUnsubscribeRequest",
"will",
"process",
"a",
"unsubscribe",
"request",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L4140-L4149 | train |
nats-io/nats-streaming-server | server/server.go | performmUnsubOrCloseSubscription | func (s *StanServer) performmUnsubOrCloseSubscription(m *nats.Msg, req *pb.UnsubscribeRequest, isSubClose bool) {
// With partitioning, first verify that this server is handling this
// channel. If not, do not return an error, since another server will
// handle it. If no other server is, the client will get a timeo... | go | func (s *StanServer) performmUnsubOrCloseSubscription(m *nats.Msg, req *pb.UnsubscribeRequest, isSubClose bool) {
// With partitioning, first verify that this server is handling this
// channel. If not, do not return an error, since another server will
// handle it. If no other server is, the client will get a timeo... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"performmUnsubOrCloseSubscription",
"(",
"m",
"*",
"nats",
".",
"Msg",
",",
"req",
"*",
"pb",
".",
"UnsubscribeRequest",
",",
"isSubClose",
"bool",
")",
"{",
"// With partitioning, first verify that this server is handling thi... | // performmUnsubOrCloseSubscription processes the unsub or close subscription
// request. | [
"performmUnsubOrCloseSubscription",
"processes",
"the",
"unsub",
"or",
"close",
"subscription",
"request",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L4184-L4219 | train |
nats-io/nats-streaming-server | server/server.go | clearAckTimer | func (sub *subState) clearAckTimer() {
if sub.ackTimer != nil {
sub.ackTimer.Stop()
sub.ackTimer = nil
}
} | go | func (sub *subState) clearAckTimer() {
if sub.ackTimer != nil {
sub.ackTimer.Stop()
sub.ackTimer = nil
}
} | [
"func",
"(",
"sub",
"*",
"subState",
")",
"clearAckTimer",
"(",
")",
"{",
"if",
"sub",
".",
"ackTimer",
"!=",
"nil",
"{",
"sub",
".",
"ackTimer",
".",
"Stop",
"(",
")",
"\n",
"sub",
".",
"ackTimer",
"=",
"nil",
"\n",
"}",
"\n",
"}"
] | // Clear the ackTimer.
// sub Lock held in entry. | [
"Clear",
"the",
"ackTimer",
".",
"sub",
"Lock",
"held",
"in",
"entry",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L4305-L4310 | train |
nats-io/nats-streaming-server | server/server.go | adjustAckTimer | func (sub *subState) adjustAckTimer(nextExpirationTime int64) {
sub.Lock()
defer sub.Unlock()
// Possible that the subscriber has been destroyed, and timer cleared
if sub.ackTimer == nil {
return
}
// Check if there are still pending acks
if len(sub.acksPending) > 0 {
// Capture time
now := time.Now().Un... | go | func (sub *subState) adjustAckTimer(nextExpirationTime int64) {
sub.Lock()
defer sub.Unlock()
// Possible that the subscriber has been destroyed, and timer cleared
if sub.ackTimer == nil {
return
}
// Check if there are still pending acks
if len(sub.acksPending) > 0 {
// Capture time
now := time.Now().Un... | [
"func",
"(",
"sub",
"*",
"subState",
")",
"adjustAckTimer",
"(",
"nextExpirationTime",
"int64",
")",
"{",
"sub",
".",
"Lock",
"(",
")",
"\n",
"defer",
"sub",
".",
"Unlock",
"(",
")",
"\n\n",
"// Possible that the subscriber has been destroyed, and timer cleared",
... | // adjustAckTimer adjusts the timer based on a given next
// expiration time.
// The timer will be stopped if there is no more pending ack.
// If there are pending acks, the timer will be reset to the
// default sub.ackWait value if the given expiration time is
// 0 or in the past. Otherwise, it is set to the remaining... | [
"adjustAckTimer",
"adjusts",
"the",
"timer",
"based",
"on",
"a",
"given",
"next",
"expiration",
"time",
".",
"The",
"timer",
"will",
"be",
"stopped",
"if",
"there",
"is",
"no",
"more",
"pending",
"ack",
".",
"If",
"there",
"are",
"pending",
"acks",
"the",
... | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L4319-L4347 | train |
nats-io/nats-streaming-server | server/server.go | startAckSub | func (sub *subState) startAckSub(nc *nats.Conn, cb nats.MsgHandler) error {
ackSub, err := nc.Subscribe(sub.AckInbox, cb)
if err != nil {
return err
}
sub.Lock()
// Should not occur, but if it was already set,
// unsubscribe old and replace.
sub.stopAckSub()
sub.ackSub = ackSub
sub.ackSub.SetPendingLimits(-1... | go | func (sub *subState) startAckSub(nc *nats.Conn, cb nats.MsgHandler) error {
ackSub, err := nc.Subscribe(sub.AckInbox, cb)
if err != nil {
return err
}
sub.Lock()
// Should not occur, but if it was already set,
// unsubscribe old and replace.
sub.stopAckSub()
sub.ackSub = ackSub
sub.ackSub.SetPendingLimits(-1... | [
"func",
"(",
"sub",
"*",
"subState",
")",
"startAckSub",
"(",
"nc",
"*",
"nats",
".",
"Conn",
",",
"cb",
"nats",
".",
"MsgHandler",
")",
"error",
"{",
"ackSub",
",",
"err",
":=",
"nc",
".",
"Subscribe",
"(",
"sub",
".",
"AckInbox",
",",
"cb",
")",
... | // Subscribes to the AckInbox subject in order to process subscription's acks
// if not already done.
// This function grabs and releases the sub's lock. | [
"Subscribes",
"to",
"the",
"AckInbox",
"subject",
"in",
"order",
"to",
"process",
"subscription",
"s",
"acks",
"if",
"not",
"already",
"done",
".",
"This",
"function",
"grabs",
"and",
"releases",
"the",
"sub",
"s",
"lock",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L4352-L4365 | train |
nats-io/nats-streaming-server | server/server.go | stopAckSub | func (sub *subState) stopAckSub() {
if sub.ackSub != nil {
sub.ackSub.Unsubscribe()
sub.ackSub = nil
}
} | go | func (sub *subState) stopAckSub() {
if sub.ackSub != nil {
sub.ackSub.Unsubscribe()
sub.ackSub = nil
}
} | [
"func",
"(",
"sub",
"*",
"subState",
")",
"stopAckSub",
"(",
")",
"{",
"if",
"sub",
".",
"ackSub",
"!=",
"nil",
"{",
"sub",
".",
"ackSub",
".",
"Unsubscribe",
"(",
")",
"\n",
"sub",
".",
"ackSub",
"=",
"nil",
"\n",
"}",
"\n",
"}"
] | // Stops subscribing to AckInbox.
// Lock assumed held on entry. | [
"Stops",
"subscribing",
"to",
"AckInbox",
".",
"Lock",
"assumed",
"held",
"on",
"entry",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L4369-L4374 | train |
nats-io/nats-streaming-server | server/server.go | isShadowQueueDurable | func (sub *subState) isShadowQueueDurable() bool {
return sub.IsDurable && sub.QGroup != "" && sub.ClientID == ""
} | go | func (sub *subState) isShadowQueueDurable() bool {
return sub.IsDurable && sub.QGroup != "" && sub.ClientID == ""
} | [
"func",
"(",
"sub",
"*",
"subState",
")",
"isShadowQueueDurable",
"(",
")",
"bool",
"{",
"return",
"sub",
".",
"IsDurable",
"&&",
"sub",
".",
"QGroup",
"!=",
"\"",
"\"",
"&&",
"sub",
".",
"ClientID",
"==",
"\"",
"\"",
"\n",
"}"
] | // Returns true if this is a "shadow" durable queue subscriber | [
"Returns",
"true",
"if",
"this",
"is",
"a",
"shadow",
"durable",
"queue",
"subscriber"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L4395-L4397 | train |
nats-io/nats-streaming-server | server/server.go | replicateSub | func (s *StanServer) replicateSub(sr *pb.SubscriptionRequest, ackInbox string, subID uint64) (*subState, error) {
op := &spb.RaftOperation{
OpType: spb.RaftOperation_Subscribe,
Sub: &spb.AddSubscription{
Request: sr,
AckInbox: ackInbox,
ID: subID,
},
}
data, err := op.Marshal()
if err != nil {... | go | func (s *StanServer) replicateSub(sr *pb.SubscriptionRequest, ackInbox string, subID uint64) (*subState, error) {
op := &spb.RaftOperation{
OpType: spb.RaftOperation_Subscribe,
Sub: &spb.AddSubscription{
Request: sr,
AckInbox: ackInbox,
ID: subID,
},
}
data, err := op.Marshal()
if err != nil {... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"replicateSub",
"(",
"sr",
"*",
"pb",
".",
"SubscriptionRequest",
",",
"ackInbox",
"string",
",",
"subID",
"uint64",
")",
"(",
"*",
"subState",
",",
"error",
")",
"{",
"op",
":=",
"&",
"spb",
".",
"RaftOperatio... | // replicateSub replicates the SubscriptionRequest to nodes in the cluster via
// Raft. | [
"replicateSub",
"replicates",
"the",
"SubscriptionRequest",
"to",
"nodes",
"in",
"the",
"cluster",
"via",
"Raft",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L4419-L4439 | train |
nats-io/nats-streaming-server | server/server.go | addSubscription | func (s *StanServer) addSubscription(ss *subStore, sub *subState) error {
// Store in client
if !s.clients.addSub(sub.ClientID, sub) {
return fmt.Errorf("can't find clientID: %v", sub.ClientID)
}
// Store this subscription in subStore
if err := ss.Store(sub); err != nil {
s.clients.removeSub(sub.ClientID, sub)... | go | func (s *StanServer) addSubscription(ss *subStore, sub *subState) error {
// Store in client
if !s.clients.addSub(sub.ClientID, sub) {
return fmt.Errorf("can't find clientID: %v", sub.ClientID)
}
// Store this subscription in subStore
if err := ss.Store(sub); err != nil {
s.clients.removeSub(sub.ClientID, sub)... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"addSubscription",
"(",
"ss",
"*",
"subStore",
",",
"sub",
"*",
"subState",
")",
"error",
"{",
"// Store in client",
"if",
"!",
"s",
".",
"clients",
".",
"addSub",
"(",
"sub",
".",
"ClientID",
",",
"sub",
")",
... | // addSubscription adds `sub` to the client and store. | [
"addSubscription",
"adds",
"sub",
"to",
"the",
"client",
"and",
"store",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L4442-L4453 | train |
nats-io/nats-streaming-server | server/server.go | updateDurable | func (s *StanServer) updateDurable(ss *subStore, sub *subState) error {
// Reset the hasFailedHB boolean since it may have been set
// if the client previously crashed and server set this
// flag to its subs.
sub.hasFailedHB = false
// Store in the client
if !s.clients.addSub(sub.ClientID, sub) {
return fmt.Err... | go | func (s *StanServer) updateDurable(ss *subStore, sub *subState) error {
// Reset the hasFailedHB boolean since it may have been set
// if the client previously crashed and server set this
// flag to its subs.
sub.hasFailedHB = false
// Store in the client
if !s.clients.addSub(sub.ClientID, sub) {
return fmt.Err... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"updateDurable",
"(",
"ss",
"*",
"subStore",
",",
"sub",
"*",
"subState",
")",
"error",
"{",
"// Reset the hasFailedHB boolean since it may have been set",
"// if the client previously crashed and server set this",
"// flag to its sub... | // updateDurable adds back `sub` to the client and updates the store.
// No lock is needed for `sub` since it has just been created. | [
"updateDurable",
"adds",
"back",
"sub",
"to",
"the",
"client",
"and",
"updates",
"the",
"store",
".",
"No",
"lock",
"is",
"needed",
"for",
"sub",
"since",
"it",
"has",
"just",
"been",
"created",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L4457-L4481 | train |
nats-io/nats-streaming-server | server/server.go | processAckMsg | func (s *StanServer) processAckMsg(m *nats.Msg) {
ack := &pb.Ack{}
if ack.Unmarshal(m.Data) != nil {
if s.processCtrlMsg(m) {
return
}
}
c := s.channels.get(ack.Subject)
if c == nil {
s.log.Errorf("Unable to process ack seq=%d, channel %s not found", ack.Sequence, ack.Subject)
return
}
sub := c.ss.Loo... | go | func (s *StanServer) processAckMsg(m *nats.Msg) {
ack := &pb.Ack{}
if ack.Unmarshal(m.Data) != nil {
if s.processCtrlMsg(m) {
return
}
}
c := s.channels.get(ack.Subject)
if c == nil {
s.log.Errorf("Unable to process ack seq=%d, channel %s not found", ack.Sequence, ack.Subject)
return
}
sub := c.ss.Loo... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"processAckMsg",
"(",
"m",
"*",
"nats",
".",
"Msg",
")",
"{",
"ack",
":=",
"&",
"pb",
".",
"Ack",
"{",
"}",
"\n",
"if",
"ack",
".",
"Unmarshal",
"(",
"m",
".",
"Data",
")",
"!=",
"nil",
"{",
"if",
"s"... | // processAckMsg processes inbound acks from clients for delivered messages. | [
"processAckMsg",
"processes",
"inbound",
"acks",
"from",
"clients",
"for",
"delivered",
"messages",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L4879-L4896 | train |
nats-io/nats-streaming-server | server/server.go | processAck | func (s *StanServer) processAck(c *channel, sub *subState, sequence uint64, fromUser bool) {
var stalled bool
// This is immutable, so can grab outside of sub's lock.
// If we have a queue group, we want to grab queue's lock before
// sub's lock.
qs := sub.qstate
if qs != nil {
qs.Lock()
}
sub.Lock()
pers... | go | func (s *StanServer) processAck(c *channel, sub *subState, sequence uint64, fromUser bool) {
var stalled bool
// This is immutable, so can grab outside of sub's lock.
// If we have a queue group, we want to grab queue's lock before
// sub's lock.
qs := sub.qstate
if qs != nil {
qs.Lock()
}
sub.Lock()
pers... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"processAck",
"(",
"c",
"*",
"channel",
",",
"sub",
"*",
"subState",
",",
"sequence",
"uint64",
",",
"fromUser",
"bool",
")",
"{",
"var",
"stalled",
"bool",
"\n\n",
"// This is immutable, so can grab outside of sub's loc... | // processAck processes an ack and if needed sends more messages. | [
"processAck",
"processes",
"an",
"ack",
"and",
"if",
"needed",
"sends",
"more",
"messages",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L4899-L4994 | train |
nats-io/nats-streaming-server | server/server.go | sendAvailableMessagesToQueue | func (s *StanServer) sendAvailableMessagesToQueue(c *channel, qs *queueState) {
if c == nil || qs == nil {
return
}
qs.Lock()
// Short circuit if no active members
if len(qs.subs) == 0 {
qs.Unlock()
return
}
// If redelivery at startup in progress, don't attempt to deliver new messages
if qs.newOnHold {
... | go | func (s *StanServer) sendAvailableMessagesToQueue(c *channel, qs *queueState) {
if c == nil || qs == nil {
return
}
qs.Lock()
// Short circuit if no active members
if len(qs.subs) == 0 {
qs.Unlock()
return
}
// If redelivery at startup in progress, don't attempt to deliver new messages
if qs.newOnHold {
... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"sendAvailableMessagesToQueue",
"(",
"c",
"*",
"channel",
",",
"qs",
"*",
"queueState",
")",
"{",
"if",
"c",
"==",
"nil",
"||",
"qs",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"qs",
".",
"Lock",
"(",
"... | // Send any messages that are ready to be sent that have been queued to the group. | [
"Send",
"any",
"messages",
"that",
"are",
"ready",
"to",
"be",
"sent",
"that",
"have",
"been",
"queued",
"to",
"the",
"group",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L4997-L5023 | train |
nats-io/nats-streaming-server | server/server.go | sendAvailableMessages | func (s *StanServer) sendAvailableMessages(c *channel, sub *subState) {
sub.Lock()
for nextSeq := sub.LastSent + 1; !sub.stalled; nextSeq++ {
nextMsg := s.getNextMsg(c, &nextSeq, &sub.LastSent)
if nextMsg == nil {
break
}
if sent, sendMore := s.sendMsgToSub(sub, nextMsg, honorMaxInFlight); !sent || !sendMo... | go | func (s *StanServer) sendAvailableMessages(c *channel, sub *subState) {
sub.Lock()
for nextSeq := sub.LastSent + 1; !sub.stalled; nextSeq++ {
nextMsg := s.getNextMsg(c, &nextSeq, &sub.LastSent)
if nextMsg == nil {
break
}
if sent, sendMore := s.sendMsgToSub(sub, nextMsg, honorMaxInFlight); !sent || !sendMo... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"sendAvailableMessages",
"(",
"c",
"*",
"channel",
",",
"sub",
"*",
"subState",
")",
"{",
"sub",
".",
"Lock",
"(",
")",
"\n",
"for",
"nextSeq",
":=",
"sub",
".",
"LastSent",
"+",
"1",
";",
"!",
"sub",
".",
... | // Send any messages that are ready to be sent that have been queued. | [
"Send",
"any",
"messages",
"that",
"are",
"ready",
"to",
"be",
"sent",
"that",
"have",
"been",
"queued",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L5026-L5038 | train |
nats-io/nats-streaming-server | server/server.go | setSubStartSequence | func (s *StanServer) setSubStartSequence(c *channel, sr *pb.SubscriptionRequest) (string, uint64, error) {
lastSent := uint64(0)
debugTrace := ""
// In all start position cases, if there is no message, ensure
// lastSent stays at 0.
switch sr.StartPosition {
case pb.StartPosition_NewOnly:
var err error
last... | go | func (s *StanServer) setSubStartSequence(c *channel, sr *pb.SubscriptionRequest) (string, uint64, error) {
lastSent := uint64(0)
debugTrace := ""
// In all start position cases, if there is no message, ensure
// lastSent stays at 0.
switch sr.StartPosition {
case pb.StartPosition_NewOnly:
var err error
last... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"setSubStartSequence",
"(",
"c",
"*",
"channel",
",",
"sr",
"*",
"pb",
".",
"SubscriptionRequest",
")",
"(",
"string",
",",
"uint64",
",",
"error",
")",
"{",
"lastSent",
":=",
"uint64",
"(",
"0",
")",
"\n",
"... | // Setup the start position for the subscriber. | [
"Setup",
"the",
"start",
"position",
"for",
"the",
"subscriber",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L5070-L5148 | train |
nats-io/nats-streaming-server | server/server.go | startGoRoutine | func (s *StanServer) startGoRoutine(f func()) {
s.mu.Lock()
if !s.shutdown {
s.wg.Add(1)
go f()
}
s.mu.Unlock()
} | go | func (s *StanServer) startGoRoutine(f func()) {
s.mu.Lock()
if !s.shutdown {
s.wg.Add(1)
go f()
}
s.mu.Unlock()
} | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"startGoRoutine",
"(",
"f",
"func",
"(",
")",
")",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"!",
"s",
".",
"shutdown",
"{",
"s",
".",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"f",... | // startGoRoutine starts the given function as a go routine if and only if
// the server was not shutdown at that time. This is required because
// we cannot increment the wait group after the shutdown process has started. | [
"startGoRoutine",
"starts",
"the",
"given",
"function",
"as",
"a",
"go",
"routine",
"if",
"and",
"only",
"if",
"the",
"server",
"was",
"not",
"shutdown",
"at",
"that",
"time",
".",
"This",
"is",
"required",
"because",
"we",
"cannot",
"increment",
"the",
"w... | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L5153-L5160 | train |
nats-io/nats-streaming-server | server/server.go | ClusterID | func (s *StanServer) ClusterID() string {
s.mu.RLock()
defer s.mu.RUnlock()
return s.info.ClusterID
} | go | func (s *StanServer) ClusterID() string {
s.mu.RLock()
defer s.mu.RUnlock()
return s.info.ClusterID
} | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"ClusterID",
"(",
")",
"string",
"{",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"s",
".",
"info",
".",
"ClusterID",
"\n",
"}"
] | // ClusterID returns the NATS Streaming Server's ID. | [
"ClusterID",
"returns",
"the",
"NATS",
"Streaming",
"Server",
"s",
"ID",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L5163-L5167 | train |
nats-io/nats-streaming-server | server/server.go | State | func (s *StanServer) State() State {
s.mu.RLock()
defer s.mu.RUnlock()
return s.state
} | go | func (s *StanServer) State() State {
s.mu.RLock()
defer s.mu.RUnlock()
return s.state
} | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"State",
"(",
")",
"State",
"{",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"s",
".",
"state",
"\n",
"}"
] | // State returns the state of this server. | [
"State",
"returns",
"the",
"state",
"of",
"this",
"server",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L5170-L5174 | train |
nats-io/nats-streaming-server | server/server.go | setLastError | func (s *StanServer) setLastError(err error) {
s.mu.Lock()
s.lastError = err
s.state = Failed
s.mu.Unlock()
s.log.Fatalf("%v", err)
} | go | func (s *StanServer) setLastError(err error) {
s.mu.Lock()
s.lastError = err
s.state = Failed
s.mu.Unlock()
s.log.Fatalf("%v", err)
} | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"setLastError",
"(",
"err",
"error",
")",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"s",
".",
"lastError",
"=",
"err",
"\n",
"s",
".",
"state",
"=",
"Failed",
"\n",
"s",
".",
"mu",
".",
"Unlock"... | // setLastError sets the last fatal error that occurred. This is
// used in case of an async error that cannot directly be reported
// to the user. | [
"setLastError",
"sets",
"the",
"last",
"fatal",
"error",
"that",
"occurred",
".",
"This",
"is",
"used",
"in",
"case",
"of",
"an",
"async",
"error",
"that",
"cannot",
"directly",
"be",
"reported",
"to",
"the",
"user",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L5179-L5185 | train |
nats-io/nats-streaming-server | server/server.go | LastError | func (s *StanServer) LastError() error {
s.mu.RLock()
defer s.mu.RUnlock()
return s.lastError
} | go | func (s *StanServer) LastError() error {
s.mu.RLock()
defer s.mu.RUnlock()
return s.lastError
} | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"LastError",
"(",
")",
"error",
"{",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"s",
".",
"lastError",
"\n",
"}"
] | // LastError returns the last fatal error the server experienced. | [
"LastError",
"returns",
"the",
"last",
"fatal",
"error",
"the",
"server",
"experienced",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L5188-L5192 | train |
nats-io/nats-streaming-server | server/server.go | Shutdown | func (s *StanServer) Shutdown() {
s.log.Noticef("Shutting down.")
s.mu.Lock()
if s.shutdown {
s.mu.Unlock()
return
}
close(s.shutdownCh)
// Allows Shutdown() to be idempotent
s.shutdown = true
// Change the state too
s.state = Shutdown
// We need to make sure that the storeIOLoop returns before
// cl... | go | func (s *StanServer) Shutdown() {
s.log.Noticef("Shutting down.")
s.mu.Lock()
if s.shutdown {
s.mu.Unlock()
return
}
close(s.shutdownCh)
// Allows Shutdown() to be idempotent
s.shutdown = true
// Change the state too
s.state = Shutdown
// We need to make sure that the storeIOLoop returns before
// cl... | [
"func",
"(",
"s",
"*",
"StanServer",
")",
"Shutdown",
"(",
")",
"{",
"s",
".",
"log",
".",
"Noticef",
"(",
"\"",
"\"",
")",
"\n\n",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"s",
".",
"shutdown",
"{",
"s",
".",
"mu",
".",
"Unlock",
... | // Shutdown will close our NATS connection and shutdown any embedded NATS server. | [
"Shutdown",
"will",
"close",
"our",
"NATS",
"connection",
"and",
"shutdown",
"any",
"embedded",
"NATS",
"server",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/server/server.go#L5195-L5289 | train |
nats-io/nats-streaming-server | logger/logger.go | SetLogger | func (s *StanLogger) SetLogger(log Logger, logtime, debug, trace bool, logfile string) {
s.mu.Lock()
s.log = log
s.ltime = logtime
s.debug = debug
s.trace = trace
s.lfile = logfile
s.mu.Unlock()
} | go | func (s *StanLogger) SetLogger(log Logger, logtime, debug, trace bool, logfile string) {
s.mu.Lock()
s.log = log
s.ltime = logtime
s.debug = debug
s.trace = trace
s.lfile = logfile
s.mu.Unlock()
} | [
"func",
"(",
"s",
"*",
"StanLogger",
")",
"SetLogger",
"(",
"log",
"Logger",
",",
"logtime",
",",
"debug",
",",
"trace",
"bool",
",",
"logfile",
"string",
")",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"s",
".",
"log",
"=",
"log",
"\n",
... | // SetLogger sets the logger, debug and trace | [
"SetLogger",
"sets",
"the",
"logger",
"debug",
"and",
"trace"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/logger/logger.go#L48-L56 | train |
nats-io/nats-streaming-server | logger/logger.go | GetLogger | func (s *StanLogger) GetLogger() Logger {
s.mu.RLock()
l := s.log
s.mu.RUnlock()
return l
} | go | func (s *StanLogger) GetLogger() Logger {
s.mu.RLock()
l := s.log
s.mu.RUnlock()
return l
} | [
"func",
"(",
"s",
"*",
"StanLogger",
")",
"GetLogger",
"(",
")",
"Logger",
"{",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"l",
":=",
"s",
".",
"log",
"\n",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"l",
"\n",
"}"
] | // GetLogger returns the logger | [
"GetLogger",
"returns",
"the",
"logger"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/logger/logger.go#L59-L64 | train |
nats-io/nats-streaming-server | logger/logger.go | ReopenLogFile | func (s *StanLogger) ReopenLogFile() {
s.mu.Lock()
if s.lfile == "" {
s.mu.Unlock()
s.Noticef("File log re-open ignored, not a file logger")
return
}
if l, ok := s.log.(io.Closer); ok {
if err := l.Close(); err != nil {
s.mu.Unlock()
s.Errorf("Unable to close logger: %v", err)
return
}
}
fileLo... | go | func (s *StanLogger) ReopenLogFile() {
s.mu.Lock()
if s.lfile == "" {
s.mu.Unlock()
s.Noticef("File log re-open ignored, not a file logger")
return
}
if l, ok := s.log.(io.Closer); ok {
if err := l.Close(); err != nil {
s.mu.Unlock()
s.Errorf("Unable to close logger: %v", err)
return
}
}
fileLo... | [
"func",
"(",
"s",
"*",
"StanLogger",
")",
"ReopenLogFile",
"(",
")",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"s",
".",
"lfile",
"==",
"\"",
"\"",
"{",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"s",
".",
"Noticef",
"(",
... | // ReopenLogFile closes and reopen the logfile.
// Does nothing if the logger is not a file based. | [
"ReopenLogFile",
"closes",
"and",
"reopen",
"the",
"logfile",
".",
"Does",
"nothing",
"if",
"the",
"logger",
"is",
"not",
"a",
"file",
"based",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/logger/logger.go#L68-L86 | train |
nats-io/nats-streaming-server | logger/logger.go | Close | func (s *StanLogger) Close() error {
s.mu.Lock()
defer s.mu.Unlock()
if l, ok := s.log.(io.Closer); ok {
return l.Close()
}
return nil
} | go | func (s *StanLogger) Close() error {
s.mu.Lock()
defer s.mu.Unlock()
if l, ok := s.log.(io.Closer); ok {
return l.Close()
}
return nil
} | [
"func",
"(",
"s",
"*",
"StanLogger",
")",
"Close",
"(",
")",
"error",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"l",
",",
"ok",
":=",
"s",
".",
"log",
".",
"(",
"io",
"... | // Close closes this logger, releasing possible held resources. | [
"Close",
"closes",
"this",
"logger",
"releasing",
"possible",
"held",
"resources",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/logger/logger.go#L89-L96 | train |
nats-io/nats-streaming-server | logger/logger.go | Errorf | func (s *StanLogger) Errorf(format string, v ...interface{}) {
s.executeLogCall(func(log Logger, format string, v ...interface{}) {
log.Errorf(format, v...)
}, format, v...)
} | go | func (s *StanLogger) Errorf(format string, v ...interface{}) {
s.executeLogCall(func(log Logger, format string, v ...interface{}) {
log.Errorf(format, v...)
}, format, v...)
} | [
"func",
"(",
"s",
"*",
"StanLogger",
")",
"Errorf",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"s",
".",
"executeLogCall",
"(",
"func",
"(",
"log",
"Logger",
",",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
... | // Errorf logs an error | [
"Errorf",
"logs",
"an",
"error"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/logger/logger.go#L106-L110 | train |
nats-io/nats-streaming-server | logger/logger.go | Warnf | func (s *StanLogger) Warnf(format string, v ...interface{}) {
s.executeLogCall(func(logger Logger, format string, v ...interface{}) {
logger.Warnf(format, v...)
}, format, v...)
} | go | func (s *StanLogger) Warnf(format string, v ...interface{}) {
s.executeLogCall(func(logger Logger, format string, v ...interface{}) {
logger.Warnf(format, v...)
}, format, v...)
} | [
"func",
"(",
"s",
"*",
"StanLogger",
")",
"Warnf",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"s",
".",
"executeLogCall",
"(",
"func",
"(",
"logger",
"Logger",
",",
"format",
"string",
",",
"v",
"...",
"interface",
"{"... | // Warnf logs a warning statement | [
"Warnf",
"logs",
"a",
"warning",
"statement"
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/logger/logger.go#L139-L143 | train |
nats-io/nats-streaming-server | stores/filestore.go | BufferSize | func BufferSize(size int) FileStoreOption {
return func(o *FileStoreOptions) error {
if size < 0 {
return fmt.Errorf("buffer size value must be a positive number")
}
o.BufferSize = size
return nil
}
} | go | func BufferSize(size int) FileStoreOption {
return func(o *FileStoreOptions) error {
if size < 0 {
return fmt.Errorf("buffer size value must be a positive number")
}
o.BufferSize = size
return nil
}
} | [
"func",
"BufferSize",
"(",
"size",
"int",
")",
"FileStoreOption",
"{",
"return",
"func",
"(",
"o",
"*",
"FileStoreOptions",
")",
"error",
"{",
"if",
"size",
"<",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"o",
... | // BufferSize is a FileStore option that sets the size of the buffer used
// during store writes. This can help improve write performance. | [
"BufferSize",
"is",
"a",
"FileStore",
"option",
"that",
"sets",
"the",
"size",
"of",
"the",
"buffer",
"used",
"during",
"store",
"writes",
".",
"This",
"can",
"help",
"improve",
"write",
"performance",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L210-L218 | train |
nats-io/nats-streaming-server | stores/filestore.go | CompactEnabled | func CompactEnabled(enabled bool) FileStoreOption {
return func(o *FileStoreOptions) error {
o.CompactEnabled = enabled
return nil
}
} | go | func CompactEnabled(enabled bool) FileStoreOption {
return func(o *FileStoreOptions) error {
o.CompactEnabled = enabled
return nil
}
} | [
"func",
"CompactEnabled",
"(",
"enabled",
"bool",
")",
"FileStoreOption",
"{",
"return",
"func",
"(",
"o",
"*",
"FileStoreOptions",
")",
"error",
"{",
"o",
".",
"CompactEnabled",
"=",
"enabled",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // CompactEnabled is a FileStore option that enables or disables file compaction.
// The value false will disable compaction. | [
"CompactEnabled",
"is",
"a",
"FileStore",
"option",
"that",
"enables",
"or",
"disables",
"file",
"compaction",
".",
"The",
"value",
"false",
"will",
"disable",
"compaction",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L222-L227 | train |
nats-io/nats-streaming-server | stores/filestore.go | CompactInterval | func CompactInterval(seconds int) FileStoreOption {
return func(o *FileStoreOptions) error {
if seconds <= 0 {
return fmt.Errorf("compact interval value must at least be 1 seconds")
}
o.CompactInterval = seconds
return nil
}
} | go | func CompactInterval(seconds int) FileStoreOption {
return func(o *FileStoreOptions) error {
if seconds <= 0 {
return fmt.Errorf("compact interval value must at least be 1 seconds")
}
o.CompactInterval = seconds
return nil
}
} | [
"func",
"CompactInterval",
"(",
"seconds",
"int",
")",
"FileStoreOption",
"{",
"return",
"func",
"(",
"o",
"*",
"FileStoreOptions",
")",
"error",
"{",
"if",
"seconds",
"<=",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n... | // CompactInterval is a FileStore option that defines the minimum compaction interval.
// Compaction is not timer based, but instead when things get "deleted". This value
// prevents compaction to happen too often. | [
"CompactInterval",
"is",
"a",
"FileStore",
"option",
"that",
"defines",
"the",
"minimum",
"compaction",
"interval",
".",
"Compaction",
"is",
"not",
"timer",
"based",
"but",
"instead",
"when",
"things",
"get",
"deleted",
".",
"This",
"value",
"prevents",
"compact... | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L232-L240 | train |
nats-io/nats-streaming-server | stores/filestore.go | CompactFragmentation | func CompactFragmentation(fragmentation int) FileStoreOption {
return func(o *FileStoreOptions) error {
if fragmentation <= 0 {
return fmt.Errorf("compact fragmentation value must at least be 1")
}
o.CompactFragmentation = fragmentation
return nil
}
} | go | func CompactFragmentation(fragmentation int) FileStoreOption {
return func(o *FileStoreOptions) error {
if fragmentation <= 0 {
return fmt.Errorf("compact fragmentation value must at least be 1")
}
o.CompactFragmentation = fragmentation
return nil
}
} | [
"func",
"CompactFragmentation",
"(",
"fragmentation",
"int",
")",
"FileStoreOption",
"{",
"return",
"func",
"(",
"o",
"*",
"FileStoreOptions",
")",
"error",
"{",
"if",
"fragmentation",
"<=",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"... | // CompactFragmentation is a FileStore option that defines the fragmentation ratio
// below which compaction would not occur. For instance, specifying 50 means that
// if other variables would allow for compaction, the compaction would occur only
// after 50% of the file has data that is no longer valid. | [
"CompactFragmentation",
"is",
"a",
"FileStore",
"option",
"that",
"defines",
"the",
"fragmentation",
"ratio",
"below",
"which",
"compaction",
"would",
"not",
"occur",
".",
"For",
"instance",
"specifying",
"50",
"means",
"that",
"if",
"other",
"variables",
"would",... | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L246-L254 | train |
nats-io/nats-streaming-server | stores/filestore.go | CompactMinFileSize | func CompactMinFileSize(fileSize int64) FileStoreOption {
return func(o *FileStoreOptions) error {
if fileSize < 0 {
return fmt.Errorf("compact minimum file size value must be a positive number")
}
o.CompactMinFileSize = fileSize
return nil
}
} | go | func CompactMinFileSize(fileSize int64) FileStoreOption {
return func(o *FileStoreOptions) error {
if fileSize < 0 {
return fmt.Errorf("compact minimum file size value must be a positive number")
}
o.CompactMinFileSize = fileSize
return nil
}
} | [
"func",
"CompactMinFileSize",
"(",
"fileSize",
"int64",
")",
"FileStoreOption",
"{",
"return",
"func",
"(",
"o",
"*",
"FileStoreOptions",
")",
"error",
"{",
"if",
"fileSize",
"<",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",... | // CompactMinFileSize is a FileStore option that defines the minimum file size below
// which compaction would not occur. Specify `0` if you don't want any minimum. | [
"CompactMinFileSize",
"is",
"a",
"FileStore",
"option",
"that",
"defines",
"the",
"minimum",
"file",
"size",
"below",
"which",
"compaction",
"would",
"not",
"occur",
".",
"Specify",
"0",
"if",
"you",
"don",
"t",
"want",
"any",
"minimum",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L258-L266 | train |
nats-io/nats-streaming-server | stores/filestore.go | DoCRC | func DoCRC(enableCRC bool) FileStoreOption {
return func(o *FileStoreOptions) error {
o.DoCRC = enableCRC
return nil
}
} | go | func DoCRC(enableCRC bool) FileStoreOption {
return func(o *FileStoreOptions) error {
o.DoCRC = enableCRC
return nil
}
} | [
"func",
"DoCRC",
"(",
"enableCRC",
"bool",
")",
"FileStoreOption",
"{",
"return",
"func",
"(",
"o",
"*",
"FileStoreOptions",
")",
"error",
"{",
"o",
".",
"DoCRC",
"=",
"enableCRC",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // DoCRC is a FileStore option that defines if a CRC checksum verification should
// be performed when records are read from disk. | [
"DoCRC",
"is",
"a",
"FileStore",
"option",
"that",
"defines",
"if",
"a",
"CRC",
"checksum",
"verification",
"should",
"be",
"performed",
"when",
"records",
"are",
"read",
"from",
"disk",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L270-L275 | train |
nats-io/nats-streaming-server | stores/filestore.go | SliceConfig | func SliceConfig(maxMsgs int, maxBytes int64, maxAge time.Duration, script string) FileStoreOption {
return func(o *FileStoreOptions) error {
if maxMsgs < 0 || maxBytes < 0 || maxAge < 0 {
return fmt.Errorf("slice max values must be positive numbers")
}
o.SliceMaxMsgs = maxMsgs
o.SliceMaxBytes = maxBytes
... | go | func SliceConfig(maxMsgs int, maxBytes int64, maxAge time.Duration, script string) FileStoreOption {
return func(o *FileStoreOptions) error {
if maxMsgs < 0 || maxBytes < 0 || maxAge < 0 {
return fmt.Errorf("slice max values must be positive numbers")
}
o.SliceMaxMsgs = maxMsgs
o.SliceMaxBytes = maxBytes
... | [
"func",
"SliceConfig",
"(",
"maxMsgs",
"int",
",",
"maxBytes",
"int64",
",",
"maxAge",
"time",
".",
"Duration",
",",
"script",
"string",
")",
"FileStoreOption",
"{",
"return",
"func",
"(",
"o",
"*",
"FileStoreOptions",
")",
"error",
"{",
"if",
"maxMsgs",
"... | // SliceConfig is a FileStore option that allows the configuration of
// file slice limits and optional archive script file name. | [
"SliceConfig",
"is",
"a",
"FileStore",
"option",
"that",
"allows",
"the",
"configuration",
"of",
"file",
"slice",
"limits",
"and",
"optional",
"archive",
"script",
"file",
"name",
"."
] | 57c6c84265c0012a1efef365703c221329804d4c | https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L301-L312 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.