id
stringlengths
2
7
text
stringlengths
17
51.2k
title
stringclasses
1 value
c26800
return ms.doLockFiles(fslice, false) }
c26801
return ms.doLockFiles(fslice, true) }
c26802
*fileSlice) { ms.fm.unlockFile(fslice.idxFile) }
c26803
ms.fm.unlockFile(fslice.file) ms.fm.unlockFile(fslice.idxFile) }
c26804
ms.addIndex(buf, seq, offset, timestamp, msgSize) _, err := w.Write(buf[:msgIndexRecSize]) return err }
c26805
crc32.Checksum(buf[:msgIndexRecSize-crcSize], ms.fstore.crcTable) util.ByteOrder.PutUint32(buf[msgIndexRecSize-crcSize:], crc) }
c26806
if storedCRC == 0 { return 0, nil, errNeedRewind } } if ms.fstore.opts.DoCRC { storedCRC := util.ByteOrder.Uint32(buf[msgIndexRecSize-crcSize:]) crc := crc32.Checksum(buf[:msgIndexRecSize-crcSize], ms.fstore.crcTable) if storedCRC != crc { return 0, nil, fmt.Errorf("corrupted data, expected crc to be ...
c26807
bufOffset += msgIndexRecSize delete(ms.bufferedMsgs, pseq) } } if bufOffset > 0 { if _, err := fslice.idxFile.handle.Write(ms.tmpMsgBuf[:bufOffset]); err != nil { return err } } ms.bufferedSeqs = ms.bufferedSeqs[:0] return nil }
c26808
ms.readIndex(slice.idxFile.handle) if err != nil { return nil, err } if seqInIndexFile != seq { return nil, fmt.Errorf("wrong sequence, wanted %v got %v", seq, seqInIndexFile) } return msgIndex, nil }
c26809
we count the size of serialized message + record header + // the corresponding index record size := uint64(firstMsgSize + msgRecordOverhead) // Keep track of number of "removed" messages in this slice slice.rmCount++ // Update total counts ms.totalCount-- ms.totalBytes -= size // Messages sequence is increment...
c26810
// to remove the original files. remove = false // We run the script in a go routine to not block the server. ms.allDone.Add(1) go func(subj, dat, idx string) { defer ms.allDone.Done() cmd := exec.Command(script, subj, dat, idx) output, err := cmd.CombinedOutput() if err != nil { ms....
c26811
sequence, so // no dichotomy, but simple iteration of the map, which in Go is // random. for _, slice := range ms.files { if (slice.firstSeq <= seq) && (seq <= slice.lastSeq) { return slice } } return nil }
c26812
nextExpiration > 0 && timeTick >= nextExpiration { ms.Lock() // Expire messages nextExpiration = ms.expireMsgs(timeTick, maxAge) ms.Unlock() } // Check for message caching if timeTick >= lastCacheCheck+cacheTTL { tryEvict := atomic.LoadInt32(&ms.cache.tryEvict) if tryEvict == 1 { ms.Lock()...
c26813
_, err = file.Seek(msgIndex.offset, io.SeekStart) if err == nil { ms.tmpMsgBuf, _, _, err = readRecord(file, ms.tmpMsgBuf, false, ms.fstore.crcTable, ms.fstore.opts.DoCRC) } } ms.unlockFiles(fslice) if err != nil || msgIndex == nil { return nil, err } // Recover this message msg = &pb.MsgProto...
c26814
seqMaps: make(map[uint64]*cachedMsg), } }
c26815
< c.tail.expiration { cMsg.expiration = c.tail.expiration } } cMsg.prev = c.tail c.tail = cMsg c.seqMaps[seq] = cMsg if len(c.seqMaps) == 1 { atomic.StoreInt32(&c.tryEvict, 1) } }
c26816
c.head = cMsg.next } cMsg.prev = c.tail c.tail.next = cMsg cMsg.next = nil // Ensure last expiration is at least >= previous one. if cMsg.expiration < c.tail.expiration { cMsg.expiration = c.tail.expiration } c.tail = cMsg } return cMsg.msg }
c26817
cMsg := c.head for cMsg != nil && cMsg.expiration <= now { delete(c.seqMaps, cMsg.msg.Sequence) cMsg = cMsg.next } if cMsg != c.head { // There should be at least one left, otherwise, they // would all have been bulk removed at top of this function. cMsg.prev = nil c.head = cMsg } }
c26818
0) c.head, c.tail = nil, nil c.seqMaps = make(map[uint64]*cachedMsg) }
c26819
err = ms.flush(ms.writeSlice) ms.unlockFiles(ms.writeSlice) } } ms.Unlock() return err }
c26820
a copy of the passed sub, we can't hold a reference // to it. csub := *sub s := &subscription{sub: &csub, seqnos: make(map[uint64]struct{})} ss.subs[sub.ID] = s return nil }
c26821
copy of the passed sub, we can't hold a reference // to it. csub := *sub si := ss.subs[sub.ID] if si != nil { s := si.(*subscription) s.sub = &csub } else { s := &subscription{sub: &csub, seqnos: make(map[uint64]struct{})} ss.subs[sub.ID] = s } return nil }
c26822
ss.delRecs * 100 / ss.numRecs } if frag < ss.opts.CompactFragmentation { return false } // Check that we don't compact too often if time.Since(ss.compactTS) < ss.compactItvl { return false } return true }
c26823
if si != nil { s := si.(*subscription) if seqno > s.sub.LastSent { s.sub.LastSent = seqno } s.seqnos[seqno] = struct{}{} } ss.Unlock() return nil }
c26824
{ ss.Unlock() return err } si := ss.subs[subid] if si != nil { s := si.(*subscription) delete(s.seqnos, seqno) // Test if we should compact if ss.shouldCompact() { ss.fm.closeFileIfOpened(ss.file) ss.compact(ss.file.name) } } ss.Unlock() return nil }
c26825
err = ss.writeRecord(tmpBW, subRecMsg, &ss.updateSub) if err != nil { return err } } } // Flush and sync the temporary file err = tmpBW.Flush() if err != nil { return err } err = tmpFile.Sync() if err != nil { return err } // Start by closing the temporary file. if err := tmpFile.Close(); err...
c26826
!= nil { if needsUnlock { ss.fm.unlockFile(ss.file) } return err } if bwBuf != nil && ss.bw.shrinkReq { ss.bw.checkShrinkRequest() } // Indicate that we wrote something to the buffer/file ss.activity = true switch recType { case subRecNew: ss.numRecs++ case subRecMsg: ss.numRecs++ case subRecAc...
c26827
= ss.flush() ss.fm.unlockFile(ss.file) } ss.Unlock() return err }
c26828
var err error if ss.fm.remove(ss.file) { if ss.file.handle != nil { err = ss.flush() err = util.CloseFile(err, ss.file.handle) } } ss.Unlock() return err }
c26829
return nil, err } // Make connect request to peer. msg, err := n.conn.Request(fmt.Sprintf(natsConnectInbox, address), data, timeout) if err != nil { sub.Unsubscribe() return nil, err } var resp connectResponseProto if err := json.Unmarshal(msg.Data, &resp); err != nil { sub.Unsubscribe() return nil, e...
c26830
{ if logOutput == nil { logOutput = os.Stderr } return newNATSTransportWithLogger(id, conn, timeout, log.New(logOutput, "", log.LstdFlags)) }
c26831
*raft.NetworkTransport { return raft.NewNetworkTransportWithLogger(stream, 3, timeout, logger) }) }
c26832
conn, config.Logger, config.Timeout, func(stream raft.StreamLayer) *raft.NetworkTransport { config.Stream = stream return raft.NewNetworkTransportWithConfig(config) }) }
c26833
elapsed := now - m.Timestamp if elapsed >= maxAge { ms.removeFirstMsg() } else { if elapsed < 0 { ms.ageTimer.Reset(time.Duration(m.Timestamp - now + maxAge)) } else { ms.ageTimer.Reset(time.Duration(maxAge - elapsed)) } return } } }
c26834
ms.totalCount-- delete(ms.msgs, ms.first) ms.first++ }
c26835
o.NoCaching = noCaching return nil } }
c26836
o.MaxOpenConns = max return nil } }
c26837
o.NoCaching = opts.NoCaching o.MaxOpenConns = opts.MaxOpenConns return nil } }
c26838
return fmt.Errorf("sql: error executing %q: %v", sqlStmts[code], err) }
c26839
// something is really wrong, abort right away. stopNow := !hasLock && err == nil if err != nil { failed++ s.log.Errorf("Unable to update store lock (failed=%v err=%v)", failed, err) } if stopNow || failed == sqlLockLostCount { if sqlNoPanic { s.log.Fatalf("Aborting") retu...
c26840
false, "", 0, sqlStmtError(sqlDBLockSelect, err) } if err == sql.ErrNoRows || steal || lockID == "" || lockID == s.dbLock.id { // If we are stealing, reset tick to 0 (so it will become 1 in update statement) if steal { tick = 0 } stmt := sqlStmts[sqlDBLockUpdate] if err == sql.ErrNoRows { stmt = sqlS...
c26841
s.dbLock.Unlock() if s.dbLock.isOwner { s.dbLock.db.Exec(sqlStmts[sqlDBLockUpdate], "", 0) } }
c26842
f.Unlock() if needSignal { select { case f.signalCh <- struct{}{}: default: } } }
c26843
s, channelID: channelID, } msgStore.init(channel, s.log, limits) if !s.opts.NoCaching { msgStore.writeCache = &sqlMsgsCache{msgs: make(map[uint64]*sqlCachedMsg)} } return msgStore }
c26844
subStore.subLastSent = make(map[uint64]uint64) } else { subStore.cache = &sqlSubAcksPendingCache{ subs: make(map[uint64]*sqlSubAcksPending), } } return subStore }
c26845
} sqlStmts[i] = stmt } // Replace `row` with row for i, stmt := range sqlStmts { stmt := strings.Replace(stmt, "`row`", "row", -1) sqlStmts[i] = stmt } // OVER (PARTITION ...) is not supported in older MySQL servers. // So the default SQL statement is specific to MySQL and uses variables. // F...
c26846
sqlVersion); err != nil { return sqlStmtError(sqlAddServerInfo, err) } } else { if _, err := s.db.Exec(sqlStmts[sqlUpdateServerInfo], info.ClusterID, infoBytes, sqlVersion); err != nil { return sqlStmtError(sqlUpdateServerInfo, err) } } return nil }
c26847
:= ps.Close(); lerr != nil && err == nil { err = lerr } } if db != nil { if s.dbLock != nil { s.releaseDBLockIfOwner() } if lerr := db.Close(); lerr != nil && err == nil { err = lerr } } s.Unlock() return err }
c26848
seq := uint64(0) err := r.Scan(&seq) if err == sql.ErrNoRows { return ms.last + 1, nil } if err != nil { return 0, sqlStmtError(sqlGetSequenceFromTimestamp, err) } return seq, nil }
c26849
{ ms.Lock() msg, err := ms.lookup(ms.last) ms.Unlock() return msg, err }
c26850
count > 0 { if maxSeq == ms.last { if _, err := ms.sqlStore.preparedStmts[sqlUpdateChannelMaxSeq].Exec(maxSeq, ms.channelID); err != nil { processErr(sqlUpdateChannelMaxSeq, err) return } } if _, err := ms.sqlStore.preparedStmts[sqlDeletedMsgsWithSeqLowerThan].Exec(ms.channelID, maxSeq); err...
c26851
:= ms.flush() ms.Unlock() return err }
c26852
if err != nil { return err } if c == 0 { if _, err := ss.sqlStore.preparedStmts[sqlCreateSub].Exec(ss.channelID, sub.ID, subBytes); err != nil { return sqlStmtError(sqlCreateSub, err) } } return nil }
c26853
delete(ss.cache.subs, subid) } else { delete(ss.subLastSent, subid) } // Ignore error on this since subscription would not be recovered // if above executed ok. ss.sqlStore.preparedStmts[sqlDeleteSubPendingMessages].Exec(subid) return nil }
c26854
ackToRow: make(map[uint64]*sqlSubsPendingRow), msgs: make(map[uint64]struct{}), acks: make(map[uint64]struct{}), } ss.cache.subs[subid] = ap } if seqno > ap.lastSent { ap.lastSent = seqno } return ap }
c26855
struct{}{} return len(ap.msgs) >= sqlMaxPendingAcks }
c26856
count. // delete(ap.ackToRow, seq) ackRow.acksRefs-- // If all acks for that row are no longer needed and // that row has also no pending messages, then ok to // delete. if ackRow.acksRefs == 0 && ackRow.msgsRefs == 0 { if err := ss.deleteSubPendingRow(subid, ackRow.ID); err != nil ...
c26857
_, err = ss.sqlStore.preparedStmts[sqlSubAddPending].Exec(subid, ss.curRow, seqno) if err != nil { err = sqlStmtError(sqlSubAddPending, err) } } } ss.Unlock() return err }
c26858
if updateLastSent { if _, err := ss.sqlStore.preparedStmts[sqlSubUpdateLastSent].Exec(seqno, ss.channelID, subid); err != nil { ss.Unlock() return sqlStmtError(sqlSubUpdateLastSent, err) } } _, err = ss.sqlStore.preparedStmts[sqlSubDeletePending].Exec(subid, seqno) if err != nil { err ...
c26859
:= ss.flush() ss.Unlock() return err }
c26860
state to closed. err := ss.flush() ss.closed = true ss.Unlock() return err }
c26861
channels added to the request ) for start := 0; start != len(channels); start += count { bytes, n, count = encodeChannelsRequest(header, channels, bytes, headerSize, maxPayload, start) if count == 0 { return errors.New("message payload too small to send channels list") } if err := nc.PublishRequest(sendIn...
c26862
len(data) { return nil, fmt.Errorf("unable to decode channel, pos=%v len=%v max=%v (string=%v)", pos, cl, len(data), string(data[pos:])) } c := string(data[pos:end]) channels = append(channels, c) pos = end } return channels, nil }
c26863
fill up the log if print.Ok() { s.log.Noticef("ft: unable to get store lock at this time, going back to standby") } } // Capture the time this server activated. It will be used in case several // servers claim to be active. Not bulletproof since there could be clock // differences, etc... but when more than...
c26864
if err != nil { return false, fmt.Errorf("ft: fatal error getting the store lock: %v", err) } // If ok is false, it means that we did not get the lock. return false, nil } return true, nil }
c26865
{ s.log.Errorf("Error decoding activation time: %v", err) } else { // Step down if the peer's activation time is earlier than ours. err := fmt.Errorf("ft: serverID %q claims to be active", hb.ServerID) if peerActivationTime.Before(activationTime) { err = fmt.Errorf("%s, aborting", err) if ...
c26866
subject s.ftSubject = fmt.Sprintf("%s.%s.%s", ftHBPrefix, s.opts.ID, s.opts.FTGroupName) s.ftHBCh = make(chan *nats.Msg) sub, err := s.ftnc.Subscribe(s.ftSubject, func(m *nats.Msg) { // Dropping incoming FT HBs is not crucial, we will then check for // store lock. select { case s.ftHBCh <- m: default: }...
c26867
make(map[string]*client), knownInvalid: make(map[string]struct{}), store: store, } }
c26868
len(c.subs)) copy(subs, c.subs) return subs }
c26869
cs.connIDs[string(c.info.ConnID)] = c } delete(cs.knownInvalid, getKnownInvalidKey(info.ID, info.ConnID)) if cs.waitOnRegister != nil { ch := cs.waitOnRegister[c.info.ID] if ch != nil { ch <- struct{}{} delete(cs.waitOnRegister, c.info.ID) } } return c, nil }
c26870
if len(connID) > 0 { delete(cs.connIDs, string(connID)) } if cs.waitOnRegister != nil { delete(cs.waitOnRegister, ID) } err := cs.store.DeleteClient(ID) return c, err }
c26871
:= cs.lookupByConnIDOrID(ID, connID) != nil cs.RUnlock() return valid }
c26872
{ c = cs.connIDs[string(connID)] } else { c = cs.clients[ID] } return c }
c26873
c := cs.clients[ID] cs.RUnlock() return c }
c26874
c := cs.connIDs[string(connID)] cs.RUnlock() return c }
c26875
c := cs.clients[ID] if c == nil { return nil } c.RLock() subs := c.getSubsCopy() c.RUnlock() return subs }
c26876
c := cs.clients[ID] if c == nil { return false } c.Lock() c.subs = append(c.subs, sub) c.Unlock() return true }
c26877
false c.subs, removed = sub.deleteFromList(c.subs) c.Unlock() return removed }
c26878
client if len(client.info.ConnID) > 0 { cs.connIDs[string(client.info.ConnID)] = client } } cs.Unlock() }
c26879
if c.hbt == nil { c.hbt = time.AfterFunc(interval, f) } c.Unlock() }
c26880
if c.hbt != nil { c.hbt.Stop() c.hbt = nil } c.Unlock() }
c26881
total := len(cs.clients) cs.RUnlock() return total }
c26882
{ return err } } if r.joinSub != nil { if err := r.joinSub.Unsubscribe(); err != nil { return err } } if r.logInput != nil { if err := r.logInput.Close(); err != nil { return err } } return nil }
c26883
cluster if we're not bootstrapping. req, err := (&spb.RaftJoinRequest{NodeID: s.opts.Clustering.NodeID, NodeAddr: addr}).Marshal() if err != nil { panic(err) } var ( joined = false resp = &spb.RaftJoinResponse{} ) s.log.Debugf("Joining Raft group %s", name) // Attempt to join up to 5 times bef...
c26884
raft.ServerID(peer), Address: raft.ServerAddress(s.getClusteringPeerAddr(name, peer)), }) } } else { // Bootstrap as a seed node. s.log.Debugf("Bootstrapping Raft group %s as seed node", name) } config := raft.Configuration{Servers: servers} return node.BootstrapCluster(config).Error() }
c26885
return s.closeClient(op.ClientDisconnect.ClientID) case spb.RaftOperation_Subscribe: // Subscription replication. sub, err := s.processSub(nil, op.Sub.Request, op.Sub.AckInbox, op.Sub.ID) return &replicatedSub{sub: sub, err: err} case spb.RaftOperation_RemoveSubscription: fallthrough case spb.RaftOperation...
c26886
{ return make([]byte, int(float32(needed)*1.1)) } return buf }
c26887
lerr := f.Close(); lerr != nil && err == nil { err = lerr } return err }
c26888
return fmt.Sprintf("%v B", fbytes) } exp := int(math.Log(fbytes) / math.Log(float64(base))) index := exp - 1 return fmt.Sprintf("%.2f %sB", fbytes/math.Pow(float64(base), float64(exp)), pre[index]) }
c26889
: 1+s.nonceSize+len(data)] ed := s.gcm.Seal(dst[:0], s.nonce, dst, nil) for i := s.nonceSize - 1; i >= 0; i-- { s.nonce[i]++ if s.nonce[i] != 0 { break } } return buf[:1+s.nonceSize+len(ed)], nil }
c26890
data that is not (len=%v)", len(cipherText)) } dd, err := gcm.Open(dst, cipherText[1:1+s.nonceSize], cipherText[1+s.nonceSize:], nil) if err != nil { return nil, err } return dd, nil }
c26891
err != nil { return nil, err } cs := &CryptoStore{ Store: s, code: code, mkh: mkh, } // On success, erase the key for i := 0; i < len(encryptionKey); i++ { encryptionKey[i] = 'x' } return cs, nil }
c26892
= sl.ClonePerChannelMap() return &cloned }
c26893
for k, v := range sl.PerChannel { copyVal := *v clone[k] = &copyVal } return clone }
c26894
sublist.Subjects() channelLines := []string{} for _, cn := range channels { r := sublist.Match(cn) var prev *channelLimitInfo for i := 0; i < len(r); i++ { channel := r[i].(*channelLimitInfo) if channel.name == cn { var parentLimits *ChannelLimits if prev == nil { parentLimits = &s...
c26895
make(map[string]interface{}), make(map[string]([]interface{})), } }
c26896
:= make([]reflect.Value, len(params)) for k, param := range params { in[k] = reflect.ValueOf(param) } result = f.Call(in) j.lastRun = time.Now() j.scheduleNextRun() return }
c26897
runtime.FuncForPC(reflect.ValueOf((fn)).Pointer()).Name() }
c26898
can be schedule into the job queue.") } fname := getFunctionName(jobFun) j.funcs[fname] = jobFun j.fparams[fname] = params j.jobFunc = fname //schedule the next run j.scheduleNextRun() }
c26899
break case "hours": j.period = time.Duration(j.interval * 60 * 60) break case "days": j.period = time.Duration(j.interval * 60 * 60 * 24) break case "weeks": j.period = time.Duration(j.interval * 60 * 60 * 24 * 7) break case "seconds": j.period = time.Duration(j.interval) } j.nextRun =...