<commit_before>// Copyright 2016 Apcera Inc. All rights reserved.

package stores

import (
	"errors"
	"sync"
	"time"

	"github.com/nats-io/nats"
	"github.com/nats-io/stan/pb"
)

const (
	AllChannels = "*"
)

type channelMap struct {
	sync.RWMutex
	channels map[string]*channelStore
}

// channelStore holds our known state of all messages and subscribers for a given channel/subject.
type channelStore struct {
	subs *subStore // All subscribers
	msgs *msgStore // All messages
}

// subStore holds all known state for all subscriptions
type subStore struct {
	sync.RWMutex
	psubs    []*subState            // plain subscribers
	qsubs    map[string]*queueState // queue subscribers
	durables map[string]*subState   // durables lookup
	acks     map[string]*subState   // ack inbox lookup
}

// Per channel/subject message store
type msgStore struct {
	sync.RWMutex
	subject string // Can't be wildcard
	first   uint64
	last    uint64
	msgs    map[uint64]*pb.MsgProto
}

// Holds all queue subsribers for a subject/group and
// tracks lastSent for the group.
type queueState struct {
	sync.RWMutex
	lastSent uint64
	subs     []*subState
	stalled  bool
}

// Holds Subscription state
// FIXME(dlc) - Use embedded proto
type subState struct {
	sync.RWMutex
	clientID      string
	subject       string
	qgroup        string
	inbox         string
	ackInbox      string
	durableName   string
	qstate        *queueState
	lastSent      uint64
	ackWaitInSecs time.Duration
	ackTimer      *time.Timer
	ackSub        *nats.Subscription
	acksPending   map[uint64]*pb.MsgProto
	maxInFlight   int
	stalled       bool
}

// MemoryStore will hold messages and subscription state in memory.
type MemoryStore struct {
	channels *channelMap
	limits   ChannelLimits
}

type ChannelLimits struct {
	MaxNumMsgs  int
	MaxMsgBytes uint64
	MaxMsgAge   time.Duration
	MaxSubs     int<commit_msg>memstore<commit_after>// Copyright 2016 Apcera Inc. All rights reserved.

package stores

import (
	"errors"
	"time"

	"github.com/nats-io/stan/pb"
)

const (
	AllChannels = "*"
)

// MemoryStore will hold messages and subscription state in memory.
type MemoryStore struct {
	channels *channelMap
	limits   ChannelLimits
}

type ChannelLimits struct {
	MaxNumMsgs  int
	MaxMsgBytes uint64
	MaxMsgAge   time.Duration
	MaxSubs     int
{'fraction_non_alphanumeric': 0.07127335940895263, 'fraction_numerical': 0.010430247718383311, 'mean_word_length': 3.223853211009174, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3173902', 'n_tokens_mistral': 762, 'n_tokens_neox': 743, 'n_words': 228}