id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
26,700
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
26,701
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
26,702
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
26,703
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
26,704
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
26,705
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
26,706
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
26,707
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
26,708
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
26,709
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
26,710
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
26,711
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
26,712
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
26,713
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
26,714
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
26,715
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
26,716
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
26,717
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
26,718
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
26,719
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
26,720
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
26,721
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
26,722
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
26,723
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
26,724
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
26,725
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
26,726
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
26,727
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
26,728
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
26,729
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
26,730
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
26,731
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
26,732
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
26,733
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
26,734
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
26,735
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
26,736
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
26,737
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
26,738
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
26,739
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
26,740
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
26,741
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
26,742
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
26,743
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
26,744
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
26,745
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
26,746
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
26,747
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
26,748
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
26,749
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
26,750
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
26,751
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
26,752
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
26,753
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
26,754
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
26,755
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
26,756
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
26,757
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
26,758
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
26,759
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
26,760
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
26,761
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
26,762
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
26,763
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
26,764
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
26,765
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
26,766
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
26,767
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
26,768
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
26,769
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
26,770
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
26,771
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
26,772
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
26,773
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
26,774
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
26,775
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
26,776
nats-io/nats-streaming-server
stores/filestore.go
FileDescriptorsLimit
func FileDescriptorsLimit(limit int64) FileStoreOption { return func(o *FileStoreOptions) error { if limit < 0 { return fmt.Errorf("file descriptor limit must be a positive number") } o.FileDescriptorsLimit = limit return nil } }
go
func FileDescriptorsLimit(limit int64) FileStoreOption { return func(o *FileStoreOptions) error { if limit < 0 { return fmt.Errorf("file descriptor limit must be a positive number") } o.FileDescriptorsLimit = limit return nil } }
[ "func", "FileDescriptorsLimit", "(", "limit", "int64", ")", "FileStoreOption", "{", "return", "func", "(", "o", "*", "FileStoreOptions", ")", "error", "{", "if", "limit", "<", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "...
// FileDescriptorsLimit is a soft limit hinting at FileStore to try to // limit the number of concurrent opened files to that limit.
[ "FileDescriptorsLimit", "is", "a", "soft", "limit", "hinting", "at", "FileStore", "to", "try", "to", "limit", "the", "number", "of", "concurrent", "opened", "files", "to", "that", "limit", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L316-L324
26,777
nats-io/nats-streaming-server
stores/filestore.go
ParallelRecovery
func ParallelRecovery(count int) FileStoreOption { return func(o *FileStoreOptions) error { if count <= 0 { return fmt.Errorf("parallel recovery value must be at least 1") } o.ParallelRecovery = count return nil } }
go
func ParallelRecovery(count int) FileStoreOption { return func(o *FileStoreOptions) error { if count <= 0 { return fmt.Errorf("parallel recovery value must be at least 1") } o.ParallelRecovery = count return nil } }
[ "func", "ParallelRecovery", "(", "count", "int", ")", "FileStoreOption", "{", "return", "func", "(", "o", "*", "FileStoreOptions", ")", "error", "{", "if", "count", "<=", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", ...
// ParallelRecovery is a FileStore option that allows the parallel // recovery of channels. When running with SSDs, try to use a higher // value than the default number of 1. When running with HDDs, // performance may be better if it stays at 1.
[ "ParallelRecovery", "is", "a", "FileStore", "option", "that", "allows", "the", "parallel", "recovery", "of", "channels", ".", "When", "running", "with", "SSDs", "try", "to", "use", "a", "higher", "value", "than", "the", "default", "number", "of", "1", ".", ...
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L330-L338
26,778
nats-io/nats-streaming-server
stores/filestore.go
AllOptions
func AllOptions(opts *FileStoreOptions) FileStoreOption { return func(o *FileStoreOptions) error { if err := BufferSize(opts.BufferSize)(o); err != nil { return err } if err := CompactInterval(opts.CompactInterval)(o); err != nil { return err } if err := CompactFragmentation(opts.CompactFragmentation)(...
go
func AllOptions(opts *FileStoreOptions) FileStoreOption { return func(o *FileStoreOptions) error { if err := BufferSize(opts.BufferSize)(o); err != nil { return err } if err := CompactInterval(opts.CompactInterval)(o); err != nil { return err } if err := CompactFragmentation(opts.CompactFragmentation)(...
[ "func", "AllOptions", "(", "opts", "*", "FileStoreOptions", ")", "FileStoreOption", "{", "return", "func", "(", "o", "*", "FileStoreOptions", ")", "error", "{", "if", "err", ":=", "BufferSize", "(", "opts", ".", "BufferSize", ")", "(", "o", ")", ";", "er...
// AllOptions is a convenient option to pass all options from a FileStoreOptions // structure to the constructor.
[ "AllOptions", "is", "a", "convenient", "option", "to", "pass", "all", "options", "from", "a", "FileStoreOptions", "structure", "to", "the", "constructor", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L354-L386
26,779
nats-io/nats-streaming-server
stores/filestore.go
checkFileVersion
func checkFileVersion(r io.Reader) error { fv, err := util.ReadInt(r) if err != nil { return fmt.Errorf("unable to verify file version: %v", err) } if fv == 0 || fv > fileVersion { return fmt.Errorf("unsupported file version: %v (supports [1..%v])", fv, fileVersion) } return nil }
go
func checkFileVersion(r io.Reader) error { fv, err := util.ReadInt(r) if err != nil { return fmt.Errorf("unable to verify file version: %v", err) } if fv == 0 || fv > fileVersion { return fmt.Errorf("unsupported file version: %v (supports [1..%v])", fv, fileVersion) } return nil }
[ "func", "checkFileVersion", "(", "r", "io", ".", "Reader", ")", "error", "{", "fv", ",", "err", ":=", "util", ".", "ReadInt", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", ...
// check that the version of the file is understood by this interface
[ "check", "that", "the", "version", "of", "the", "file", "is", "understood", "by", "this", "interface" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L660-L669
26,780
nats-io/nats-streaming-server
stores/filestore.go
createNewWriter
func (w *bufferedWriter) createNewWriter(file *os.File) io.Writer { w.buf = bufio.NewWriterSize(file, w.bufSize) return w.buf }
go
func (w *bufferedWriter) createNewWriter(file *os.File) io.Writer { w.buf = bufio.NewWriterSize(file, w.bufSize) return w.buf }
[ "func", "(", "w", "*", "bufferedWriter", ")", "createNewWriter", "(", "file", "*", "os", ".", "File", ")", "io", ".", "Writer", "{", "w", ".", "buf", "=", "bufio", ".", "NewWriterSize", "(", "file", ",", "w", ".", "bufSize", ")", "\n", "return", "w...
// createNewWriter creates a new buffer writer for `file` with // the bufferedWriter's current buffer size.
[ "createNewWriter", "creates", "a", "new", "buffer", "writer", "for", "file", "with", "the", "bufferedWriter", "s", "current", "buffer", "size", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L781-L784
26,781
nats-io/nats-streaming-server
stores/filestore.go
tryShrinkBuffer
func (w *bufferedWriter) tryShrinkBuffer(file *os.File) (io.Writer, error) { // Nothing to do if we are already at the lowest // or file not set/opened. if w.bufSize == w.minShrinkSize || file == nil { return w.buf, nil } if !w.shrinkReq { percentFilled := w.buf.Buffered() * 100 / w.bufSize if percentFilled...
go
func (w *bufferedWriter) tryShrinkBuffer(file *os.File) (io.Writer, error) { // Nothing to do if we are already at the lowest // or file not set/opened. if w.bufSize == w.minShrinkSize || file == nil { return w.buf, nil } if !w.shrinkReq { percentFilled := w.buf.Buffered() * 100 / w.bufSize if percentFilled...
[ "func", "(", "w", "*", "bufferedWriter", ")", "tryShrinkBuffer", "(", "file", "*", "os", ".", "File", ")", "(", "io", ".", "Writer", ",", "error", ")", "{", "// Nothing to do if we are already at the lowest", "// or file not set/opened.", "if", "w", ".", "bufSiz...
// tryShrinkBuffer checks and possibly shrinks the buffer
[ "tryShrinkBuffer", "checks", "and", "possibly", "shrinks", "the", "buffer" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L811-L840
26,782
nats-io/nats-streaming-server
stores/filestore.go
checkShrinkRequest
func (w *bufferedWriter) checkShrinkRequest() { percentFilled := w.buf.Buffered() * 100 / w.bufSize // If above the threshold, cancel the request. if percentFilled > bufShrinkThreshold { w.shrinkReq = false } }
go
func (w *bufferedWriter) checkShrinkRequest() { percentFilled := w.buf.Buffered() * 100 / w.bufSize // If above the threshold, cancel the request. if percentFilled > bufShrinkThreshold { w.shrinkReq = false } }
[ "func", "(", "w", "*", "bufferedWriter", ")", "checkShrinkRequest", "(", ")", "{", "percentFilled", ":=", "w", ".", "buf", ".", "Buffered", "(", ")", "*", "100", "/", "w", ".", "bufSize", "\n", "// If above the threshold, cancel the request.", "if", "percentFi...
// checkShrinkRequest checks how full the buffer is, and if is above a certain // threshold, cancels the shrink request
[ "checkShrinkRequest", "checks", "how", "full", "the", "buffer", "is", "and", "if", "is", "above", "a", "certain", "threshold", "cancels", "the", "shrink", "request" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L844-L850
26,783
nats-io/nats-streaming-server
stores/filestore.go
openFile
func (fm *filesManager) openFile(file *file) error { fm.Lock() if fm.isClosed { fm.Unlock() return fmt.Errorf("unable to open file %q, store is being closed", file.name) } curState := atomic.LoadInt32(&file.state) if curState == fileRemoved { fm.Unlock() return fmt.Errorf("unable to open file %q, it has be...
go
func (fm *filesManager) openFile(file *file) error { fm.Lock() if fm.isClosed { fm.Unlock() return fmt.Errorf("unable to open file %q, store is being closed", file.name) } curState := atomic.LoadInt32(&file.state) if curState == fileRemoved { fm.Unlock() return fmt.Errorf("unable to open file %q, it has be...
[ "func", "(", "fm", "*", "filesManager", ")", "openFile", "(", "file", "*", "file", ")", "error", "{", "fm", ".", "Lock", "(", ")", "\n", "if", "fm", ".", "isClosed", "{", "fm", ".", "Unlock", "(", ")", "\n", "return", "fmt", ".", "Errorf", "(", ...
// openFile opens the given file and sets its state to `fileInUse`. // If the file manager has been closed or the file removed, this call // returns an error. // Otherwise, if the file's state is not `fileClosed` this call will panic. // This call will possibly cause opened but unused files to be closed if the // numbe...
[ "openFile", "opens", "the", "given", "file", "and", "sets", "its", "state", "to", "fileInUse", ".", "If", "the", "file", "manager", "has", "been", "closed", "or", "the", "file", "removed", "this", "call", "returns", "an", "error", ".", "Otherwise", "if", ...
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L926-L952
26,784
nats-io/nats-streaming-server
stores/filestore.go
closeLockedFile
func (fm *filesManager) closeLockedFile(file *file) error { if !atomic.CompareAndSwapInt32(&file.state, fileInUse, fileClosing) { panic(fmt.Errorf("file %q is requested to be closed but was not locked by caller", file.name)) } fm.Lock() err := fm.doClose(file) fm.Unlock() return err }
go
func (fm *filesManager) closeLockedFile(file *file) error { if !atomic.CompareAndSwapInt32(&file.state, fileInUse, fileClosing) { panic(fmt.Errorf("file %q is requested to be closed but was not locked by caller", file.name)) } fm.Lock() err := fm.doClose(file) fm.Unlock() return err }
[ "func", "(", "fm", "*", "filesManager", ")", "closeLockedFile", "(", "file", "*", "file", ")", "error", "{", "if", "!", "atomic", ".", "CompareAndSwapInt32", "(", "&", "file", ".", "state", ",", "fileInUse", ",", "fileClosing", ")", "{", "panic", "(", ...
// closeLockedFile closes the handle of the given file, but only if the caller // has locked the file. Will panic otherwise. // If the file's beforeClose callback is not nil, this callback is invoked // before the file handle is closed.
[ "closeLockedFile", "closes", "the", "handle", "of", "the", "given", "file", "but", "only", "if", "the", "caller", "has", "locked", "the", "file", ".", "Will", "panic", "otherwise", ".", "If", "the", "file", "s", "beforeClose", "callback", "is", "not", "nil...
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L958-L966
26,785
nats-io/nats-streaming-server
stores/filestore.go
closeFileIfOpened
func (fm *filesManager) closeFileIfOpened(file *file) error { if !atomic.CompareAndSwapInt32(&file.state, fileOpened, fileClosing) { return nil } fm.Lock() err := fm.doClose(file) fm.Unlock() return err }
go
func (fm *filesManager) closeFileIfOpened(file *file) error { if !atomic.CompareAndSwapInt32(&file.state, fileOpened, fileClosing) { return nil } fm.Lock() err := fm.doClose(file) fm.Unlock() return err }
[ "func", "(", "fm", "*", "filesManager", ")", "closeFileIfOpened", "(", "file", "*", "file", ")", "error", "{", "if", "!", "atomic", ".", "CompareAndSwapInt32", "(", "&", "file", ".", "state", ",", "fileOpened", ",", "fileClosing", ")", "{", "return", "ni...
// closeFileIfOpened closes the handle of the given file, but only if the // file is opened and not currently locked. Does not return any error or panic // if file is in any other state. // If the file's beforeClose callback is not nil, this callback is invoked // before the file handle is closed.
[ "closeFileIfOpened", "closes", "the", "handle", "of", "the", "given", "file", "but", "only", "if", "the", "file", "is", "opened", "and", "not", "currently", "locked", ".", "Does", "not", "return", "any", "error", "or", "panic", "if", "file", "is", "in", ...
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L973-L981
26,786
nats-io/nats-streaming-server
stores/filestore.go
doClose
func (fm *filesManager) doClose(file *file) error { var err error if file.beforeClose != nil { err = file.beforeClose() } util.CloseFile(err, file.handle) // Regardless of error, we need to change the state to closed. file.handle = nil atomic.StoreInt32(&file.state, fileClosed) fm.openedFDs-- return err }
go
func (fm *filesManager) doClose(file *file) error { var err error if file.beforeClose != nil { err = file.beforeClose() } util.CloseFile(err, file.handle) // Regardless of error, we need to change the state to closed. file.handle = nil atomic.StoreInt32(&file.state, fileClosed) fm.openedFDs-- return err }
[ "func", "(", "fm", "*", "filesManager", ")", "doClose", "(", "file", "*", "file", ")", "error", "{", "var", "err", "error", "\n", "if", "file", ".", "beforeClose", "!=", "nil", "{", "err", "=", "file", ".", "beforeClose", "(", ")", "\n", "}", "\n",...
// doClose closes the file handle, setting it to nil and switching state to `fileClosed`. // If a `beforeClose` callback was registered on file creation, it is invoked // before the file handler is actually closed. // Lock is required on entry.
[ "doClose", "closes", "the", "file", "handle", "setting", "it", "to", "nil", "and", "switching", "state", "to", "fileClosed", ".", "If", "a", "beforeClose", "callback", "was", "registered", "on", "file", "creation", "it", "is", "invoked", "before", "the", "fi...
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L1006-L1017
26,787
nats-io/nats-streaming-server
stores/filestore.go
lockFile
func (fm *filesManager) lockFile(file *file) (bool, error) { if atomic.CompareAndSwapInt32(&file.state, fileOpened, fileInUse) { return true, nil } return false, fm.openFile(file) }
go
func (fm *filesManager) lockFile(file *file) (bool, error) { if atomic.CompareAndSwapInt32(&file.state, fileOpened, fileInUse) { return true, nil } return false, fm.openFile(file) }
[ "func", "(", "fm", "*", "filesManager", ")", "lockFile", "(", "file", "*", "file", ")", "(", "bool", ",", "error", ")", "{", "if", "atomic", ".", "CompareAndSwapInt32", "(", "&", "file", ".", "state", ",", "fileOpened", ",", "fileInUse", ")", "{", "r...
// lockFile locks the given file. // If the file was already opened, the boolean returned is true, // otherwise, the file is opened and the call returns false.
[ "lockFile", "locks", "the", "given", "file", ".", "If", "the", "file", "was", "already", "opened", "the", "boolean", "returned", "is", "true", "otherwise", "the", "file", "is", "opened", "and", "the", "call", "returns", "false", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L1022-L1027
26,788
nats-io/nats-streaming-server
stores/filestore.go
unlockFile
func (fm *filesManager) unlockFile(file *file) { if !atomic.CompareAndSwapInt32(&file.state, fileInUse, fileOpened) { panic(fmt.Errorf("failed to switch state from fileInUse to fileOpened for file %q, state=%v", file.name, file.state)) } }
go
func (fm *filesManager) unlockFile(file *file) { if !atomic.CompareAndSwapInt32(&file.state, fileInUse, fileOpened) { panic(fmt.Errorf("failed to switch state from fileInUse to fileOpened for file %q, state=%v", file.name, file.state)) } }
[ "func", "(", "fm", "*", "filesManager", ")", "unlockFile", "(", "file", "*", "file", ")", "{", "if", "!", "atomic", ".", "CompareAndSwapInt32", "(", "&", "file", ".", "state", ",", "fileInUse", ",", "fileOpened", ")", "{", "panic", "(", "fmt", ".", "...
// unlockFile unlocks the file if currently locked, otherwise panic.
[ "unlockFile", "unlocks", "the", "file", "if", "currently", "locked", "otherwise", "panic", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L1036-L1041
26,789
nats-io/nats-streaming-server
stores/filestore.go
trySwitchState
func (fm *filesManager) trySwitchState(file *file, newState int32) (bool, error) { wasOpened := false wasClosed := false for i := 0; i < 10000; i++ { if atomic.CompareAndSwapInt32(&file.state, fileOpened, newState) { wasOpened = true break } if atomic.CompareAndSwapInt32(&file.state, fileClosed, newState...
go
func (fm *filesManager) trySwitchState(file *file, newState int32) (bool, error) { wasOpened := false wasClosed := false for i := 0; i < 10000; i++ { if atomic.CompareAndSwapInt32(&file.state, fileOpened, newState) { wasOpened = true break } if atomic.CompareAndSwapInt32(&file.state, fileClosed, newState...
[ "func", "(", "fm", "*", "filesManager", ")", "trySwitchState", "(", "file", "*", "file", ",", "newState", "int32", ")", "(", "bool", ",", "error", ")", "{", "wasOpened", ":=", "false", "\n", "wasClosed", ":=", "false", "\n", "for", "i", ":=", "0", ";...
// trySwitchState attempts to switch an initial state of `fileOpened` // or `fileClosed` to the given newState. If it can't it will return an // error, otherwise, returned a boolean to indicate if the initial state // was `fileOpened`.
[ "trySwitchState", "attempts", "to", "switch", "an", "initial", "state", "of", "fileOpened", "or", "fileClosed", "to", "the", "given", "newState", ".", "If", "it", "can", "t", "it", "will", "return", "an", "error", "otherwise", "returned", "a", "boolean", "to...
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L1047-L1067
26,790
nats-io/nats-streaming-server
stores/filestore.go
close
func (fm *filesManager) close() error { fm.Lock() if fm.isClosed { fm.Unlock() return nil } fm.isClosed = true files := make([]*file, 0, len(fm.files)) for _, file := range fm.files { files = append(files, file) } fm.files = nil fm.Unlock() var err error for _, file := range files { wasOpened, sser...
go
func (fm *filesManager) close() error { fm.Lock() if fm.isClosed { fm.Unlock() return nil } fm.isClosed = true files := make([]*file, 0, len(fm.files)) for _, file := range fm.files { files = append(files, file) } fm.files = nil fm.Unlock() var err error for _, file := range files { wasOpened, sser...
[ "func", "(", "fm", "*", "filesManager", ")", "close", "(", ")", "error", "{", "fm", ".", "Lock", "(", ")", "\n", "if", "fm", ".", "isClosed", "{", "fm", ".", "Unlock", "(", ")", "\n", "return", "nil", "\n", "}", "\n", "fm", ".", "isClosed", "="...
// close the files manager, including all files currently opened. // Returns the first error encountered when closing the files.
[ "close", "the", "files", "manager", "including", "all", "files", "currently", "opened", ".", "Returns", "the", "first", "error", "encountered", "when", "closing", "the", "files", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L1147-L1178
26,791
nats-io/nats-streaming-server
stores/filestore.go
Init
func (fs *FileStore) Init(info *spb.ServerInfo) error { fs.Lock() defer fs.Unlock() if fs.serverFile == nil { var err error // Open/Create the server file (note that this file must not be opened, // in APPEND mode to allow truncate to work). fs.serverFile, err = fs.fm.createFile(serverFileName, os.O_RDWR|os...
go
func (fs *FileStore) Init(info *spb.ServerInfo) error { fs.Lock() defer fs.Unlock() if fs.serverFile == nil { var err error // Open/Create the server file (note that this file must not be opened, // in APPEND mode to allow truncate to work). fs.serverFile, err = fs.fm.createFile(serverFileName, os.O_RDWR|os...
[ "func", "(", "fs", "*", "FileStore", ")", "Init", "(", "info", "*", "spb", ".", "ServerInfo", ")", "error", "{", "fs", ".", "Lock", "(", ")", "\n", "defer", "fs", ".", "Unlock", "(", ")", "\n\n", "if", "fs", ".", "serverFile", "==", "nil", "{", ...
// Init is used to persist server's information after the first start
[ "Init", "is", "used", "to", "persist", "server", "s", "information", "after", "the", "first", "start" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L1461-L1495
26,792
nats-io/nats-streaming-server
stores/filestore.go
recoverClients
func (fs *FileStore) recoverClients() ([]*Client, error) { var err error var recType recordType var recSize int _buf := [256]byte{} buf := _buf[:] offset := int64(4) // Create a buffered reader to speed-up recovery br := bufio.NewReaderSize(fs.clientsFile.handle, defaultBufSize) for { buf, recSize, recTyp...
go
func (fs *FileStore) recoverClients() ([]*Client, error) { var err error var recType recordType var recSize int _buf := [256]byte{} buf := _buf[:] offset := int64(4) // Create a buffered reader to speed-up recovery br := bufio.NewReaderSize(fs.clientsFile.handle, defaultBufSize) for { buf, recSize, recTyp...
[ "func", "(", "fs", "*", "FileStore", ")", "recoverClients", "(", ")", "(", "[", "]", "*", "Client", ",", "error", ")", "{", "var", "err", "error", "\n", "var", "recType", "recordType", "\n", "var", "recSize", "int", "\n\n", "_buf", ":=", "[", "256", ...
// recoverClients reads the client files and returns an array of RecoveredClient
[ "recoverClients", "reads", "the", "client", "files", "and", "returns", "an", "array", "of", "RecoveredClient" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L1498-L1557
26,793
nats-io/nats-streaming-server
stores/filestore.go
recoverServerInfo
func (fs *FileStore) recoverServerInfo() (*spb.ServerInfo, error) { info := &spb.ServerInfo{} buf, size, _, err := readRecord(fs.serverFile.handle, nil, false, fs.crcTable, fs.opts.DoCRC) if err != nil { if err == io.EOF { // We are done, no state recovered return nil, nil } fs.log.Errorf("Server file %q...
go
func (fs *FileStore) recoverServerInfo() (*spb.ServerInfo, error) { info := &spb.ServerInfo{} buf, size, _, err := readRecord(fs.serverFile.handle, nil, false, fs.crcTable, fs.opts.DoCRC) if err != nil { if err == io.EOF { // We are done, no state recovered return nil, nil } fs.log.Errorf("Server file %q...
[ "func", "(", "fs", "*", "FileStore", ")", "recoverServerInfo", "(", ")", "(", "*", "spb", ".", "ServerInfo", ",", "error", ")", "{", "info", ":=", "&", "spb", ".", "ServerInfo", "{", "}", "\n", "buf", ",", "size", ",", "_", ",", "err", ":=", "rea...
// recoverServerInfo reads the server file and returns a ServerInfo structure
[ "recoverServerInfo", "reads", "the", "server", "file", "and", "returns", "a", "ServerInfo", "structure" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L1560-L1590
26,794
nats-io/nats-streaming-server
stores/filestore.go
shouldCompactClientFile
func (fs *FileStore) shouldCompactClientFile() bool { // Global switch if !fs.opts.CompactEnabled { return false } // Check that if minimum file size is set, the client file // is at least at the minimum. if fs.opts.CompactMinFileSize > 0 && fs.cliFileSize < fs.opts.CompactMinFileSize { return false } // Ch...
go
func (fs *FileStore) shouldCompactClientFile() bool { // Global switch if !fs.opts.CompactEnabled { return false } // Check that if minimum file size is set, the client file // is at least at the minimum. if fs.opts.CompactMinFileSize > 0 && fs.cliFileSize < fs.opts.CompactMinFileSize { return false } // Ch...
[ "func", "(", "fs", "*", "FileStore", ")", "shouldCompactClientFile", "(", ")", "bool", "{", "// Global switch", "if", "!", "fs", ".", "opts", ".", "CompactEnabled", "{", "return", "false", "\n", "}", "\n", "// Check that if minimum file size is set, the client file"...
// shouldCompactClientFile returns true if the client file should be compacted // Lock is held by caller
[ "shouldCompactClientFile", "returns", "true", "if", "the", "client", "file", "should", "be", "compacted", "Lock", "is", "held", "by", "caller" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L1704-L1724
26,795
nats-io/nats-streaming-server
stores/filestore.go
compactClientFile
func (fs *FileStore) compactClientFile(orgFileName string) error { // Open a temporary file tmpFile, err := getTempFile(fs.fm.rootDir, clientsFileName) if err != nil { return err } defer func() { if tmpFile != nil { tmpFile.Close() os.Remove(tmpFile.Name()) } }() bw := bufio.NewWriterSize(tmpFile, de...
go
func (fs *FileStore) compactClientFile(orgFileName string) error { // Open a temporary file tmpFile, err := getTempFile(fs.fm.rootDir, clientsFileName) if err != nil { return err } defer func() { if tmpFile != nil { tmpFile.Close() os.Remove(tmpFile.Name()) } }() bw := bufio.NewWriterSize(tmpFile, de...
[ "func", "(", "fs", "*", "FileStore", ")", "compactClientFile", "(", "orgFileName", "string", ")", "error", "{", "// Open a temporary file", "tmpFile", ",", "err", ":=", "getTempFile", "(", "fs", ".", "fm", ".", "rootDir", ",", "clientsFileName", ")", "\n", "...
// Rewrite the content of the clients map into a temporary file, // then swap back to active file. // Store lock held on entry
[ "Rewrite", "the", "content", "of", "the", "clients", "map", "into", "a", "temporary", "file", "then", "swap", "back", "to", "active", "file", ".", "Store", "lock", "held", "on", "entry" ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L1729-L1773
26,796
nats-io/nats-streaming-server
stores/filestore.go
Close
func (fs *FileStore) Close() error { fs.Lock() if fs.closed { fs.Unlock() return nil } fs.closed = true err := fs.genericStore.close() fm := fs.fm lockFile := fs.lockFile fs.Unlock() if fm != nil { if fmerr := fm.close(); fmerr != nil && err == nil { err = fmerr } } if lockFile != nil { err =...
go
func (fs *FileStore) Close() error { fs.Lock() if fs.closed { fs.Unlock() return nil } fs.closed = true err := fs.genericStore.close() fm := fs.fm lockFile := fs.lockFile fs.Unlock() if fm != nil { if fmerr := fm.close(); fmerr != nil && err == nil { err = fmerr } } if lockFile != nil { err =...
[ "func", "(", "fs", "*", "FileStore", ")", "Close", "(", ")", "error", "{", "fs", ".", "Lock", "(", ")", "\n", "if", "fs", ".", "closed", "{", "fs", ".", "Unlock", "(", ")", "\n", "return", "nil", "\n", "}", "\n", "fs", ".", "closed", "=", "tr...
// Close closes all stores.
[ "Close", "closes", "all", "stores", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L1788-L1811
26,797
nats-io/nats-streaming-server
stores/filestore.go
beforeDataFileCloseCb
func (ms *FileMsgStore) beforeDataFileCloseCb(fslice *fileSlice) beforeFileClose { return func() error { if fslice != ms.writeSlice { return nil } if ms.bw != nil && ms.bw.buf != nil && ms.bw.buf.Buffered() > 0 { if err := ms.bw.buf.Flush(); err != nil { return err } } if ms.fstore.opts.DoSync {...
go
func (ms *FileMsgStore) beforeDataFileCloseCb(fslice *fileSlice) beforeFileClose { return func() error { if fslice != ms.writeSlice { return nil } if ms.bw != nil && ms.bw.buf != nil && ms.bw.buf.Buffered() > 0 { if err := ms.bw.buf.Flush(); err != nil { return err } } if ms.fstore.opts.DoSync {...
[ "func", "(", "ms", "*", "FileMsgStore", ")", "beforeDataFileCloseCb", "(", "fslice", "*", "fileSlice", ")", "beforeFileClose", "{", "return", "func", "(", ")", "error", "{", "if", "fslice", "!=", "ms", ".", "writeSlice", "{", "return", "nil", "\n", "}", ...
// beforeDataFileCloseCb returns a beforeFileClose callback to be used // by FileMsgStore's files when a data file for that slice is being closed. // This is invoked asynchronously and should not acquire the store's lock. // That being said, we have the guarantee that this will be not be invoked // concurrently for a g...
[ "beforeDataFileCloseCb", "returns", "a", "beforeFileClose", "callback", "to", "be", "used", "by", "FileMsgStore", "s", "files", "when", "a", "data", "file", "for", "that", "slice", "is", "being", "closed", ".", "This", "is", "invoked", "asynchronously", "and", ...
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L2069-L2087
26,798
nats-io/nats-streaming-server
stores/filestore.go
beforeIndexFileCloseCb
func (ms *FileMsgStore) beforeIndexFileCloseCb(fslice *fileSlice) beforeFileClose { return func() error { if fslice != ms.writeSlice { return nil } if len(ms.bufferedMsgs) > 0 { if err := ms.processBufferedMsgs(fslice); err != nil { return err } } if ms.fstore.opts.DoSync { if err := fslice.i...
go
func (ms *FileMsgStore) beforeIndexFileCloseCb(fslice *fileSlice) beforeFileClose { return func() error { if fslice != ms.writeSlice { return nil } if len(ms.bufferedMsgs) > 0 { if err := ms.processBufferedMsgs(fslice); err != nil { return err } } if ms.fstore.opts.DoSync { if err := fslice.i...
[ "func", "(", "ms", "*", "FileMsgStore", ")", "beforeIndexFileCloseCb", "(", "fslice", "*", "fileSlice", ")", "beforeFileClose", "{", "return", "func", "(", ")", "error", "{", "if", "fslice", "!=", "ms", ".", "writeSlice", "{", "return", "nil", "\n", "}", ...
// beforeIndexFileCloseCb returns a beforeFileClose callback to be used // by FileMsgStore's files when an index file for that slice is being closed. // This is invoked asynchronously and should not acquire the store's lock. // That being said, we have the guarantee that this will be not be invoked // concurrently for ...
[ "beforeIndexFileCloseCb", "returns", "a", "beforeFileClose", "callback", "to", "be", "used", "by", "FileMsgStore", "s", "files", "when", "an", "index", "file", "for", "that", "slice", "is", "being", "closed", ".", "This", "is", "invoked", "asynchronously", "and"...
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L2094-L2111
26,799
nats-io/nats-streaming-server
stores/filestore.go
setFile
func (ms *FileMsgStore) setFile(fslice *fileSlice, offset int64) error { var err error file := fslice.file.handle ms.writer = file if file != nil && ms.bw != nil { ms.writer = ms.bw.createNewWriter(file) } if offset == -1 { ms.wOffset, err = file.Seek(0, io.SeekEnd) } else { ms.wOffset = offset } return ...
go
func (ms *FileMsgStore) setFile(fslice *fileSlice, offset int64) error { var err error file := fslice.file.handle ms.writer = file if file != nil && ms.bw != nil { ms.writer = ms.bw.createNewWriter(file) } if offset == -1 { ms.wOffset, err = file.Seek(0, io.SeekEnd) } else { ms.wOffset = offset } return ...
[ "func", "(", "ms", "*", "FileMsgStore", ")", "setFile", "(", "fslice", "*", "fileSlice", ",", "offset", "int64", ")", "error", "{", "var", "err", "error", "\n", "file", ":=", "fslice", ".", "file", ".", "handle", "\n", "ms", ".", "writer", "=", "file...
// setFile sets the current data and index file. // The buffered writer is recreated.
[ "setFile", "sets", "the", "current", "data", "and", "index", "file", ".", "The", "buffered", "writer", "is", "recreated", "." ]
57c6c84265c0012a1efef365703c221329804d4c
https://github.com/nats-io/nats-streaming-server/blob/57c6c84265c0012a1efef365703c221329804d4c/stores/filestore.go#L2115-L2128