Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

working on stake-weight round robin #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions docker/Dockerfile.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
FROM golang:1.22-alpine AS builder

ARG VERSION="nightly"

RUN apk add --update git

WORKDIR /src

# Copy go.mod and go.sum first (if they exist) to cache dependencies
COPY go.mod go.sum* ./
RUN go mod download

# Clone natscli separately to cache it
RUN mkdir -p src/github.com/nats-io && \
cd src/github.com/nats-io/ && \
git clone https://github.com/nats-io/natscli.git && \
cd natscli/nats && \
go mod download

# Install nsc separately to cache it
RUN go install github.com/nats-io/nsc/v2@latest

# Now copy the rest of the source code and build
COPY . .

RUN go build -ldflags "-w -X main.version=${VERSION}" -o /nats-server

# Build nats cli
RUN cd src/github.com/nats-io/natscli/nats && \
go build -ldflags "-w -X main.version=${VERSION}" -o /nats

FROM alpine:latest

RUN apk add --update ca-certificates && mkdir -p /nats/bin && mkdir /nats/conf

COPY docker/nats-server.conf /nats/conf/nats-server.conf
COPY --from=builder /nats-server /bin/nats-server
COPY --from=builder /nats /bin/nats
COPY --from=builder /go/bin/nsc /bin/nsc

EXPOSE 4222 8222 6222 5222

ENTRYPOINT ["/bin/nats-server"]
CMD ["-c", "/nats/conf/nats-server.conf"]
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ require (
golang.org/x/sys v0.28.0
golang.org/x/time v0.8.0
)

require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/redis/go-redis/v9 v9.7.0 // indirect
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/google/go-tpm v0.9.3 h1:+yx0/anQuGzi+ssRqeD6WpXjW2L/V0dItUayO0i9sRc=
github.com/google/go-tpm v0.9.3/go.mod h1:h9jEsEECg7gtLis0upRBQU+GhYVH6jMjrFxI8u6bVUY=
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
Expand All @@ -18,6 +22,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U=
github.com/redis/go-redis/v9 v9.7.0 h1:HhLSs+B6O021gwzl+locl0zEDnyNkxMtf/Z3NNBMa9E=
github.com/redis/go-redis/v9 v9.7.0/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
go.uber.org/automaxprocs v1.6.0 h1:O3y2/QNTOdbF+e/dpXNNW7Rx2hZ4sTIPyybbxyNqTUs=
Expand Down
104 changes: 49 additions & 55 deletions server/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,62 +52,56 @@ var maxSubLimitReportThreshold = defaultMaxSubLimitReportThreshold
type Account struct {
stats
gwReplyMapping
Name string
LogicalName string
Nkey string
Issuer string
claimJWT string
updated time.Time
mu sync.RWMutex
sqmu sync.Mutex
sl *Sublist
ic *client
sq *sendq
isid uint64
etmr *time.Timer
ctmr *time.Timer
strack map[string]sconns
nrclients int32
sysclients int32
nleafs int32
nrleafs int32
clients map[*client]struct{}
rm map[string]int32
lqws map[string]int32
usersRevoked map[string]int64
mappings []*mapping
hasMapped atomic.Bool
lmu sync.RWMutex
lleafs []*client
leafClusters map[string]uint64
imports importMap
exports exportMap
js *jsAccount
jsLimits map[string]JetStreamAccountLimits
Name string `json:"name"`
LogicalName string `json:"logical_name"`
Nkey string `json:"nkey"`
Issuer string `json:"issuer"`
claimJWT string `json:"claim_jwt"`
updated time.Time `json:"updated"`
mu sync.RWMutex `json:"-"`
sqmu sync.Mutex `json:"-"`
sl *Sublist `json:"-"`
ic *client `json:"-"`
sq *sendq `json:"-"`
isid uint64 `json:"isid"`
etmr *time.Timer `json:"-"`
ctmr *time.Timer `json:"-"`
strack map[string]sconns `json:"-"`
nrclients int32 `json:"nr_clients"`
sysclients int32 `json:"sys_clients"`
nleafs int32 `json:"nleafs"`
nrleafs int32 `json:"nr_leafs"`
clients map[*client]struct{} `json:"-"`
rm map[string]int32 `json:"-"`
lqws map[string]int32 `json:"-"`
usersRevoked map[string]int64 `json:"-"`
mappings []*mapping `json:"-"`
hasMapped atomic.Bool `json:"-"`
lmu sync.RWMutex `json:"-"`
lleafs []*client `json:"-"`
leafClusters map[string]uint64 `json:"-"`
imports importMap `json:"-"`
exports exportMap `json:"-"`
js *jsAccount `json:"-"`
jsLimits map[string]JetStreamAccountLimits `json:"-"`
limits
expired atomic.Bool
incomplete bool
signingKeys map[string]jwt.Scope
extAuth *jwt.ExternalAuthorization
srv *Server // server this account is registered with (possibly nil)
lds string // loop detection subject for leaf nodes
siReply []byte // service reply prefix, will form wildcard subscription.
eventIds *nuid.NUID
eventIdsMu sync.Mutex
defaultPerms *Permissions
tags jwt.TagList
nameTag string
lastLimErr int64
routePoolIdx int
// If the trace destination is specified and a message with a traceParentHdr
// is received, and has the least significant bit of the last token set to 1,
// then if traceDestSampling is > 0 and < 100, a random value will be selected
// and if it falls between 0 and that value, message tracing will be triggered.
traceDest string
traceDestSampling int
// Guarantee that only one goroutine can be running either checkJetStreamMigrate
// or clearObserverState at a given time for this account to prevent interleaving.
jscmMu sync.Mutex
expired atomic.Bool `json:"-"`
incomplete bool `json:"incomplete"`
signingKeys map[string]jwt.Scope `json:"-"`
extAuth *jwt.ExternalAuthorization `json:"-"`
srv *Server `json:"-"`
lds string `json:"lds"`
siReply []byte `json:"-"`
eventIds *nuid.NUID `json:"-"`
eventIdsMu sync.Mutex `json:"-"`
defaultPerms *Permissions `json:"-"`
tags jwt.TagList `json:"-"`
nameTag string `json:"name_tag"`
lastLimErr int64 `json:"last_lim_err"`
routePoolIdx int `json:"route_pool_idx"`
traceDest string `json:"trace_dest"`
traceDestSampling int `json:"trace_dest_sampling"`
jscmMu sync.Mutex `json:"-"`
}

const (
Expand Down
Loading