_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3
values | text stringlengths 52 85.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q26800 | lockFiles | train | func (ms *FileMsgStore) lockFiles(fslice *fileSlice) error {
return ms.doLockFiles(fslice, false)
} | go | {
"resource": ""
} |
q26801 | lockIndexFile | train | func (ms *FileMsgStore) lockIndexFile(fslice *fileSlice) error {
return ms.doLockFiles(fslice, true)
} | go | {
"resource": ""
} |
q26802 | unlockIndexFile | train | func (ms *FileMsgStore) unlockIndexFile(fslice *fileSlice) {
ms.fm.unlockFile(fslice.idxFile)
} | go | {
"resource": ""
} |
q26803 | unlockFiles | train | func (ms *FileMsgStore) unlockFiles(fslice *fileSlice) {
ms.fm.unlockFile(fslice.file)
ms.fm.unlockFile(fslice.idxFile)
} | go | {
"resource": ""
} |
q26804 | writeIndex | train | func (ms *FileMsgStore) writeIndex(w io.Writer, seq uint64, offset, timestamp int64, msgSize int) error {
_buf := [msgIndexRecSize]byte{}
buf := _buf[:]
ms.addIndex(buf, seq, offset, timestamp, msgSize)
_, err := w.Write(buf[:msgIndexRecSize])
return err
} | go | {
"resource": ""
} |
q26805 | addIndex | train | func (ms *FileMsgStore) addIndex(buf []byte, seq uint64, offset, timestamp int64, msgSize int) {
util.ByteOrder.PutUint64(buf, seq)
util.ByteOrder.PutUint64(buf[8:], uint64(offset))
util.ByteOrder.PutUint64(buf[16:], uint64(timestamp))
util.ByteOrder.PutUint32(buf[24:], uint32(msgSize))
crc := crc32.Checksum(buf[:... | go | {
"resource": ""
} |
q26806 | readIndex | train | func (ms *FileMsgStore) readIndex(r io.Reader) (uint64, *msgIndex, error) {
_buf := [msgIndexRecSize]byte{}
buf := _buf[:]
if _, err := io.ReadFull(r, buf); err != nil {
return 0, nil, err
}
mindex := &msgIndex{}
seq := util.ByteOrder.Uint64(buf)
mindex.offset = int64(util.ByteOrder.Uint64(buf[8:]))
mindex.ti... | go | {
"resource": ""
} |
q26807 | processBufferedMsgs | train | func (ms *FileMsgStore) processBufferedMsgs(fslice *fileSlice) error {
idxBufferSize := len(ms.bufferedMsgs) * msgIndexRecSize
ms.tmpMsgBuf = util.EnsureBufBigEnough(ms.tmpMsgBuf, idxBufferSize)
bufOffset := 0
for _, pseq := range ms.bufferedSeqs {
bm := ms.bufferedMsgs[pseq]
if bm != nil {
mindex := bm.inde... | go | {
"resource": ""
} |
q26808 | readMsgIndex | train | func (ms *FileMsgStore) readMsgIndex(slice *fileSlice, seq uint64) (*msgIndex, error) {
// Compute the offset in the index file itself.
idxFileOffset := 4 + (int64(seq-slice.firstSeq)+int64(slice.rmCount))*msgIndexRecSize
// Then position the file pointer of the index file.
if _, err := slice.idxFile.handle.Seek(id... | go | {
"resource": ""
} |
q26809 | removeFirstMsg | train | func (ms *FileMsgStore) removeFirstMsg(mindex *msgIndex, lockFile bool) error {
// Work with the first slice
slice := ms.files[ms.firstFSlSeq]
// Get the message index for the first valid message in this slice
if mindex == nil {
if lockFile || slice != ms.writeSlice {
ms.lockIndexFile(slice)
}
var err erro... | go | {
"resource": ""
} |
q26810 | removeFirstSlice | train | func (ms *FileMsgStore) removeFirstSlice() {
sl := ms.files[ms.firstFSlSeq]
// We may or may not have the first slice locked, so need to close
// the file knowing that files can be in either state.
ms.fm.closeLockedOrOpenedFile(sl.file)
ms.fm.remove(sl.file)
// Close index file too.
ms.fm.closeLockedOrOpenedFile... | go | {
"resource": ""
} |
q26811 | getFileSliceForSeq | train | func (ms *FileMsgStore) getFileSliceForSeq(seq uint64) *fileSlice {
if len(ms.files) == 0 {
return nil
}
// Start with write slice
slice := ms.writeSlice
if (slice.firstSeq <= seq) && (seq <= slice.lastSeq) {
return slice
}
// We want to support possible gaps in file slice sequence, so
// no dichotomy, but ... | go | {
"resource": ""
} |
q26812 | backgroundTasks | train | func (ms *FileMsgStore) backgroundTasks() {
defer ms.allDone.Done()
ms.RLock()
hasBuffer := ms.bw != nil
maxAge := int64(ms.limits.MaxAge)
nextExpiration := ms.expiration
lastCacheCheck := ms.timeTick
lastBufShrink := ms.timeTick
ms.RUnlock()
for {
// Update time
timeTick := time.Now().UnixNano()
atomi... | go | {
"resource": ""
} |
q26813 | lookup | train | func (ms *FileMsgStore) lookup(seq uint64) (*pb.MsgProto, error) {
// Reject message for sequence outside valid range
if seq < ms.first || seq > ms.last {
return nil, nil
}
// Check first if it's in the cache.
msg := ms.cache.get(seq)
if msg == nil && ms.bufferedMsgs != nil {
// Possibly in bufferedMsgs
bm ... | go | {
"resource": ""
} |
q26814 | initCache | train | func (ms *FileMsgStore) initCache() {
ms.cache = &msgsCache{
seqMaps: make(map[uint64]*cachedMsg),
}
} | go | {
"resource": ""
} |
q26815 | add | train | func (c *msgsCache) add(seq uint64, msg *pb.MsgProto, isNew bool) {
exp := cacheTTL
if isNew {
exp += msg.Timestamp
} else {
exp += time.Now().UnixNano()
}
cMsg := &cachedMsg{
expiration: exp,
msg: msg,
}
if c.tail == nil {
c.head = cMsg
} else {
c.tail.next = cMsg
// Ensure last expiration... | go | {
"resource": ""
} |
q26816 | get | train | func (c *msgsCache) get(seq uint64) *pb.MsgProto {
cMsg := c.seqMaps[seq]
if cMsg == nil {
return nil
}
// Bump the expiration
cMsg.expiration = time.Now().UnixNano() + cacheTTL
// If not already at the tail of the list, move it there
if cMsg != c.tail {
if cMsg.prev != nil {
cMsg.prev.next = cMsg.next
... | go | {
"resource": ""
} |
q26817 | evict | train | func (c *msgsCache) evict(now int64) {
if c.head == nil {
return
}
if now >= c.tail.expiration {
// Bulk remove
c.seqMaps = make(map[uint64]*cachedMsg)
c.head, c.tail, c.tryEvict = nil, nil, 0
return
}
cMsg := c.head
for cMsg != nil && cMsg.expiration <= now {
delete(c.seqMaps, cMsg.msg.Sequence)
cM... | go | {
"resource": ""
} |
q26818 | empty | train | func (c *msgsCache) empty() {
atomic.StoreInt32(&c.tryEvict, 0)
c.head, c.tail = nil, nil
c.seqMaps = make(map[uint64]*cachedMsg)
} | go | {
"resource": ""
} |
q26819 | Flush | train | func (ms *FileMsgStore) Flush() error {
ms.Lock()
var err error
if ms.writeSlice != nil {
err = ms.lockFiles(ms.writeSlice)
if err == nil {
err = ms.flush(ms.writeSlice)
ms.unlockFiles(ms.writeSlice)
}
}
ms.Unlock()
return err
} | go | {
"resource": ""
} |
q26820 | CreateSub | train | func (ss *FileSubStore) CreateSub(sub *spb.SubState) error {
// Check if we can create the subscription (check limits and update
// subscription count)
ss.Lock()
defer ss.Unlock()
if err := ss.createSub(sub); err != nil {
return err
}
if err := ss.writeRecord(nil, subRecNew, sub); err != nil {
delete(ss.subs... | go | {
"resource": ""
} |
q26821 | UpdateSub | train | func (ss *FileSubStore) UpdateSub(sub *spb.SubState) error {
ss.Lock()
defer ss.Unlock()
if err := ss.writeRecord(nil, subRecUpdate, sub); err != nil {
return err
}
// We need to get a 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.(*su... | go | {
"resource": ""
} |
q26822 | shouldCompact | train | func (ss *FileSubStore) shouldCompact() bool {
// Gobal switch
if !ss.opts.CompactEnabled {
return false
}
// Check that if minimum file size is set, the client file
// is at least at the minimum.
if ss.opts.CompactMinFileSize > 0 && ss.fileSize < ss.opts.CompactMinFileSize {
return false
}
// Check fragmen... | go | {
"resource": ""
} |
q26823 | AddSeqPending | train | func (ss *FileSubStore) AddSeqPending(subid, seqno uint64) error {
ss.Lock()
ss.updateSub.ID, ss.updateSub.Seqno = subid, seqno
if err := ss.writeRecord(nil, subRecMsg, &ss.updateSub); err != nil {
ss.Unlock()
return err
}
si := ss.subs[subid]
if si != nil {
s := si.(*subscription)
if seqno > s.sub.LastSe... | go | {
"resource": ""
} |
q26824 | AckSeqPending | train | func (ss *FileSubStore) AckSeqPending(subid, seqno uint64) error {
ss.Lock()
ss.updateSub.ID, ss.updateSub.Seqno = subid, seqno
if err := ss.writeRecord(nil, subRecAck, &ss.updateSub); err != nil {
ss.Unlock()
return err
}
si := ss.subs[subid]
if si != nil {
s := si.(*subscription)
delete(s.seqnos, seqno)... | go | {
"resource": ""
} |
q26825 | compact | train | func (ss *FileSubStore) compact(orgFileName string) error {
tmpFile, err := getTempFile(ss.fm.rootDir, "subs")
if err != nil {
return err
}
tmpBW := bufio.NewWriterSize(tmpFile, defaultBufSize)
// Save values in case of failed compaction
savedNumRecs := ss.numRecs
savedDelRecs := ss.delRecs
savedFileSize := s... | go | {
"resource": ""
} |
q26826 | writeRecord | train | func (ss *FileSubStore) writeRecord(w io.Writer, recType recordType, rec record) error {
var err error
totalSize := 0
recSize := rec.Size()
var bwBuf *bufio.Writer
needsUnlock := false
if w == nil {
if err := ss.lockFile(); err != nil {
return err
}
needsUnlock = true
if ss.bw != nil {
bwBuf = ss.... | go | {
"resource": ""
} |
q26827 | Flush | train | func (ss *FileSubStore) Flush() error {
ss.Lock()
err := ss.lockFile()
if err == nil {
err = ss.flush()
ss.fm.unlockFile(ss.file)
}
ss.Unlock()
return err
} | go | {
"resource": ""
} |
q26828 | Close | train | func (ss *FileSubStore) Close() error {
ss.Lock()
if ss.closed {
ss.Unlock()
return nil
}
ss.closed = true
if ss.shrinkTimer != nil {
if ss.shrinkTimer.Stop() {
// If we can stop, timer callback won't fire,
// so we need to decrement the wait group.
ss.allDone.Done()
}
}
ss.Unlock()
// Wait ... | go | {
"resource": ""
} |
q26829 | Dial | train | func (n *natsStreamLayer) Dial(address raft.ServerAddress, timeout time.Duration) (net.Conn, error) {
if !n.conn.IsConnected() {
return nil, errors.New("raft-nats: dial failed, not connected")
}
// QUESTION: The Raft NetTransport does connection pooling, which is useful
// for TCP sockets. The NATS transport sim... | go | {
"resource": ""
} |
q26830 | newNATSTransport | train | func newNATSTransport(id string, conn *nats.Conn, timeout time.Duration, logOutput io.Writer) (*raft.NetworkTransport, error) {
if logOutput == nil {
logOutput = os.Stderr
}
return newNATSTransportWithLogger(id, conn, timeout, log.New(logOutput, "", log.LstdFlags))
} | go | {
"resource": ""
} |
q26831 | newNATSTransportWithLogger | train | func newNATSTransportWithLogger(id string, conn *nats.Conn, timeout time.Duration, logger *log.Logger) (*raft.NetworkTransport, error) {
return createNATSTransport(id, conn, logger, timeout, func(stream raft.StreamLayer) *raft.NetworkTransport {
return raft.NewNetworkTransportWithLogger(stream, 3, timeout, logger)
... | go | {
"resource": ""
} |
q26832 | newNATSTransportWithConfig | train | func newNATSTransportWithConfig(id string, conn *nats.Conn, config *raft.NetworkTransportConfig) (*raft.NetworkTransport, error) {
if config.Timeout == 0 {
config.Timeout = 2 * time.Second
}
return createNATSTransport(id, conn, config.Logger, config.Timeout, func(stream raft.StreamLayer) *raft.NetworkTransport {
... | go | {
"resource": ""
} |
q26833 | expireMsgs | train | func (ms *MemoryMsgStore) expireMsgs() {
ms.Lock()
defer ms.Unlock()
if ms.closed {
ms.wg.Done()
return
}
now := time.Now().UnixNano()
maxAge := int64(ms.limits.MaxAge)
for {
m, ok := ms.msgs[ms.first]
if !ok {
if ms.first < ms.last {
ms.first++
continue
}
ms.ageTimer = nil
ms.wg.Don... | go | {
"resource": ""
} |
q26834 | removeFirstMsg | train | func (ms *MemoryMsgStore) removeFirstMsg() {
firstMsg := ms.msgs[ms.first]
ms.totalBytes -= uint64(firstMsg.Size())
ms.totalCount--
delete(ms.msgs, ms.first)
ms.first++
} | go | {
"resource": ""
} |
q26835 | SQLNoCaching | train | func SQLNoCaching(noCaching bool) SQLStoreOption {
return func(o *SQLStoreOptions) error {
o.NoCaching = noCaching
return nil
}
} | go | {
"resource": ""
} |
q26836 | SQLMaxOpenConns | train | func SQLMaxOpenConns(max int) SQLStoreOption {
return func(o *SQLStoreOptions) error {
o.MaxOpenConns = max
return nil
}
} | go | {
"resource": ""
} |
q26837 | SQLAllOptions | train | func SQLAllOptions(opts *SQLStoreOptions) SQLStoreOption {
return func(o *SQLStoreOptions) error {
o.NoCaching = opts.NoCaching
o.MaxOpenConns = opts.MaxOpenConns
return nil
}
} | go | {
"resource": ""
} |
q26838 | sqlStmtError | train | func sqlStmtError(code int, err error) error {
return fmt.Errorf("sql: error executing %q: %v", sqlStmts[code], err)
} | go | {
"resource": ""
} |
q26839 | updateDBLock | train | func (s *SQLStore) updateDBLock() {
defer s.wg.Done()
var (
ticker = time.NewTicker(sqlLockUpdateInterval)
hasLock = true
err error
failed int
)
for {
select {
case <-ticker.C:
hasLock, _, _, err = s.acquireDBLock(false)
if !hasLock || err != nil {
// If there is no error but we did not... | go | {
"resource": ""
} |
q26840 | acquireDBLock | train | func (s *SQLStore) acquireDBLock(steal bool) (bool, string, uint64, error) {
s.dbLock.Lock()
defer s.dbLock.Unlock()
var (
lockID string
tick uint64
hasLock bool
)
tx, err := s.dbLock.db.Begin()
if err != nil {
return false, "", 0, err
}
defer func() {
if tx != nil {
tx.Rollback()
}
}()
r :... | go | {
"resource": ""
} |
q26841 | releaseDBLockIfOwner | train | func (s *SQLStore) releaseDBLockIfOwner() {
s.dbLock.Lock()
defer s.dbLock.Unlock()
if s.dbLock.isOwner {
s.dbLock.db.Exec(sqlStmts[sqlDBLockUpdate], "", 0)
}
} | go | {
"resource": ""
} |
q26842 | scheduleSubStoreFlush | train | func (s *SQLStore) scheduleSubStoreFlush(ss *SQLSubStore) {
needSignal := false
f := s.ssFlusher
f.Lock()
f.stores[ss] = struct{}{}
if !f.signaled {
f.signaled = true
needSignal = true
}
f.Unlock()
if needSignal {
select {
case f.signalCh <- struct{}{}:
default:
}
}
} | go | {
"resource": ""
} |
q26843 | newSQLMsgStore | train | func (s *SQLStore) newSQLMsgStore(channel string, channelID int64, limits *MsgStoreLimits) *SQLMsgStore {
msgStore := &SQLMsgStore{
sqlStore: s,
channelID: channelID,
}
msgStore.init(channel, s.log, limits)
if !s.opts.NoCaching {
msgStore.writeCache = &sqlMsgsCache{msgs: make(map[uint64]*sqlCachedMsg)}
}
r... | go | {
"resource": ""
} |
q26844 | newSQLSubStore | train | func (s *SQLStore) newSQLSubStore(channelID int64, limits *SubStoreLimits) *SQLSubStore {
subStore := &SQLSubStore{
sqlStore: s,
channelID: channelID,
maxSubID: &s.maxSubID,
limits: *limits,
}
subStore.log = s.log
if s.opts.NoCaching {
subStore.subLastSent = make(map[uint64]uint64)
} else {
subSto... | go | {
"resource": ""
} |
q26845 | initSQLStmtsTable | train | func initSQLStmtsTable(driver string) {
// The sqlStmts table is initialized with MySQL statements.
// Update the statements for the selected driver.
switch driver {
case driverPostgres:
// Replace ? with $1, $2, etc...
for i, stmt := range sqlStmts {
n := 0
for strings.IndexByte(stmt, '?') != -1 {
n+... | go | {
"resource": ""
} |
q26846 | Init | train | func (s *SQLStore) Init(info *spb.ServerInfo) error {
s.Lock()
defer s.Unlock()
count := 0
r := s.db.QueryRow(sqlStmts[sqlHasServerInfoRow])
if err := r.Scan(&count); err != nil && err != sql.ErrNoRows {
return sqlStmtError(sqlHasServerInfoRow, err)
}
infoBytes, _ := info.Marshal()
if count == 0 {
if _, err... | go | {
"resource": ""
} |
q26847 | Close | train | func (s *SQLStore) Close() error {
s.Lock()
if s.closed {
s.Unlock()
return nil
}
s.closed = true
// This will cause MsgStore's and SubStore's to be closed.
err := s.close()
db := s.db
wg := &s.wg
// Signal background go-routines to quit
if s.doneCh != nil {
close(s.doneCh)
}
s.Unlock()
// Wait for ... | go | {
"resource": ""
} |
q26848 | GetSequenceFromTimestamp | train | func (ms *SQLMsgStore) GetSequenceFromTimestamp(timestamp int64) (uint64, error) {
ms.Lock()
defer ms.Unlock()
// No message ever stored
if ms.first == 0 {
return 0, nil
}
// All messages have expired
if ms.first > ms.last {
return ms.last + 1, nil
}
r := ms.sqlStore.preparedStmts[sqlGetSequenceFromTimesta... | go | {
"resource": ""
} |
q26849 | LastMsg | train | func (ms *SQLMsgStore) LastMsg() (*pb.MsgProto, error) {
ms.Lock()
msg, err := ms.lookup(ms.last)
ms.Unlock()
return msg, err
} | go | {
"resource": ""
} |
q26850 | expireMsgs | train | func (ms *SQLMsgStore) expireMsgs() {
ms.Lock()
defer ms.Unlock()
if ms.closed {
ms.wg.Done()
return
}
var (
count int
maxSeq uint64
totalSize uint64
timestamp int64
)
processErr := func(errCode int, err error) {
ms.log.Errorf("Unable to perform expiration for channel %q: %v", ms.subject, ... | go | {
"resource": ""
} |
q26851 | Flush | train | func (ms *SQLMsgStore) Flush() error {
ms.Lock()
err := ms.flush()
ms.Unlock()
return err
} | go | {
"resource": ""
} |
q26852 | UpdateSub | train | func (ss *SQLSubStore) UpdateSub(sub *spb.SubState) error {
ss.Lock()
defer ss.Unlock()
subBytes, _ := sub.Marshal()
r, err := ss.sqlStore.preparedStmts[sqlUpdateSub].Exec(subBytes, ss.channelID, sub.ID)
if err != nil {
return sqlStmtError(sqlUpdateSub, err)
}
// FileSubStoe supports updating a subscription fo... | go | {
"resource": ""
} |
q26853 | DeleteSub | train | func (ss *SQLSubStore) DeleteSub(subid uint64) error {
ss.Lock()
defer ss.Unlock()
if subid == atomic.LoadUint64(ss.maxSubID) {
if _, err := ss.sqlStore.preparedStmts[sqlMarkSubscriptionAsDeleted].Exec(ss.channelID, subid); err != nil {
return sqlStmtError(sqlMarkSubscriptionAsDeleted, err)
}
ss.hasMarkedAs... | go | {
"resource": ""
} |
q26854 | getOrCreateAcksPending | train | func (ss *SQLSubStore) getOrCreateAcksPending(subid, seqno uint64) *sqlSubAcksPending {
if !ss.cache.needsFlush {
ss.cache.needsFlush = true
ss.sqlStore.scheduleSubStoreFlush(ss)
}
ap := ss.cache.subs[subid]
if ap == nil {
ap = &sqlSubAcksPending{
msgToRow: make(map[uint64]*sqlSubsPendingRow),
ackToRow:... | go | {
"resource": ""
} |
q26855 | addSeq | train | func (ss *SQLSubStore) addSeq(subid, seqno uint64) bool {
ap := ss.getOrCreateAcksPending(subid, seqno)
ap.msgs[seqno] = struct{}{}
return len(ap.msgs) >= sqlMaxPendingAcks
} | go | {
"resource": ""
} |
q26856 | ackSeq | train | func (ss *SQLSubStore) ackSeq(subid, seqno uint64) (bool, error) {
ap := ss.getOrCreateAcksPending(subid, seqno)
// If still in cache and not persisted into a row,
// then simply remove from map and do not persist the ack.
if _, exists := ap.msgs[seqno]; exists {
delete(ap.msgs, seqno)
} else if row := ap.msgToR... | go | {
"resource": ""
} |
q26857 | AddSeqPending | train | func (ss *SQLSubStore) AddSeqPending(subid, seqno uint64) error {
var err error
ss.Lock()
if !ss.closed {
if ss.cache != nil {
if isFull := ss.addSeq(subid, seqno); isFull {
err = ss.flush()
}
} else {
ls := ss.subLastSent[subid]
if seqno > ls {
ss.subLastSent[subid] = seqno
}
ss.curRow... | go | {
"resource": ""
} |
q26858 | AckSeqPending | train | func (ss *SQLSubStore) AckSeqPending(subid, seqno uint64) error {
var err error
ss.Lock()
if !ss.closed {
if ss.cache != nil {
var isFull bool
isFull, err = ss.ackSeq(subid, seqno)
if err == nil && isFull {
err = ss.flush()
}
} else {
updateLastSent := false
ls := ss.subLastSent[subid]
i... | go | {
"resource": ""
} |
q26859 | Flush | train | func (ss *SQLSubStore) Flush() error {
ss.Lock()
err := ss.flush()
ss.Unlock()
return err
} | go | {
"resource": ""
} |
q26860 | Close | train | func (ss *SQLSubStore) Close() error {
ss.Lock()
if ss.closed {
ss.Unlock()
return nil
}
// Flush before switching the state to closed.
err := ss.flush()
ss.closed = true
ss.Unlock()
return err
} | go | {
"resource": ""
} |
q26861 | SendChannelsList | train | func SendChannelsList(channels []string, sendInbox, replyInbox string, nc *nats.Conn, serverID string) error {
// Since the NATS message payload is limited, we need to repeat
// requests if all channels can't fit in a request.
maxPayload := int(nc.MaxPayload())
// Reuse this request object to send the (possibly man... | go | {
"resource": ""
} |
q26862 | DecodeChannels | train | func DecodeChannels(data []byte) ([]string, error) {
channels := []string{}
pos := 0
for pos < len(data) {
if pos+2 > len(data) {
return nil, fmt.Errorf("unable to decode size, pos=%v len=%v", pos, len(data))
}
cl := int(ByteOrder.Uint16(data[pos:]))
pos += encodedChannelLen
end := pos + cl
if end > l... | go | {
"resource": ""
} |
q26863 | ftStart | train | func (s *StanServer) ftStart() (retErr error) {
s.log.Noticef("Starting in standby mode")
// For tests purposes
if ftPauseBeforeFirstAttempt {
<-ftPauseCh
}
print, _ := util.NewBackoffTimeCheck(time.Second, 2, time.Minute)
for {
select {
case <-s.ftQuit:
// we are done
return nil
case <-s.ftHBCh:
... | go | {
"resource": ""
} |
q26864 | ftGetStoreLock | train | func (s *StanServer) ftGetStoreLock() (bool, error) {
// Normally, the store would be set early and is immutable, but some
// FT tests do set a mock store after the server is created, so use
// locking here to avoid race reports.
s.mu.Lock()
store := s.store
s.mu.Unlock()
if ok, err := store.GetExclusiveLock(); ... | go | {
"resource": ""
} |
q26865 | ftSendHBLoop | train | func (s *StanServer) ftSendHBLoop(activationTime time.Time) {
// Release the wait group on exit
defer s.wg.Done()
timeAsBytes, _ := activationTime.MarshalBinary()
ftHB := &spb.CtrlMsg{
MsgType: spb.CtrlMsg_FTHeartbeat,
ServerID: s.serverID,
Data: timeAsBytes,
}
ftHBBytes, _ := ftHB.Marshal()
print, _... | go | {
"resource": ""
} |
q26866 | ftSetup | train | func (s *StanServer) ftSetup() error {
// Check that store type is ok. So far only support for FileStore
if s.opts.StoreType != stores.TypeFile && s.opts.StoreType != stores.TypeSQL {
return fmt.Errorf("ft: only %v or %v stores supported in FT mode", stores.TypeFile, stores.TypeSQL)
}
// So far, those are not exp... | go | {
"resource": ""
} |
q26867 | newClientStore | train | func newClientStore(store stores.Store) *clientStore {
return &clientStore{
clients: make(map[string]*client),
connIDs: make(map[string]*client),
knownInvalid: make(map[string]struct{}),
store: store,
}
} | go | {
"resource": ""
} |
q26868 | getSubsCopy | train | func (c *client) getSubsCopy() []*subState {
subs := make([]*subState, len(c.subs))
copy(subs, c.subs)
return subs
} | go | {
"resource": ""
} |
q26869 | register | train | func (cs *clientStore) register(info *spb.ClientInfo) (*client, error) {
cs.Lock()
defer cs.Unlock()
c := cs.clients[info.ID]
if c != nil {
return nil, ErrInvalidClient
}
sc, err := cs.store.AddClient(info)
if err != nil {
return nil, err
}
c = &client{info: sc, subs: make([]*subState, 0, 4)}
cs.clients[c... | go | {
"resource": ""
} |
q26870 | unregister | train | func (cs *clientStore) unregister(ID string) (*client, error) {
cs.Lock()
defer cs.Unlock()
c := cs.clients[ID]
if c == nil {
return nil, nil
}
c.Lock()
if c.hbt != nil {
c.hbt.Stop()
c.hbt = nil
}
connID := c.info.ConnID
c.Unlock()
delete(cs.clients, ID)
if len(connID) > 0 {
delete(cs.connIDs, stri... | go | {
"resource": ""
} |
q26871 | isValid | train | func (cs *clientStore) isValid(ID string, connID []byte) bool {
cs.RLock()
valid := cs.lookupByConnIDOrID(ID, connID) != nil
cs.RUnlock()
return valid
} | go | {
"resource": ""
} |
q26872 | lookupByConnIDOrID | train | func (cs *clientStore) lookupByConnIDOrID(ID string, connID []byte) *client {
var c *client
if len(connID) > 0 {
c = cs.connIDs[string(connID)]
} else {
c = cs.clients[ID]
}
return c
} | go | {
"resource": ""
} |
q26873 | lookup | train | func (cs *clientStore) lookup(ID string) *client {
cs.RLock()
c := cs.clients[ID]
cs.RUnlock()
return c
} | go | {
"resource": ""
} |
q26874 | lookupByConnID | train | func (cs *clientStore) lookupByConnID(connID []byte) *client {
cs.RLock()
c := cs.connIDs[string(connID)]
cs.RUnlock()
return c
} | go | {
"resource": ""
} |
q26875 | getSubs | train | func (cs *clientStore) getSubs(ID string) []*subState {
cs.RLock()
defer cs.RUnlock()
c := cs.clients[ID]
if c == nil {
return nil
}
c.RLock()
subs := c.getSubsCopy()
c.RUnlock()
return subs
} | go | {
"resource": ""
} |
q26876 | addSub | train | func (cs *clientStore) addSub(ID string, sub *subState) bool {
cs.RLock()
defer cs.RUnlock()
c := cs.clients[ID]
if c == nil {
return false
}
c.Lock()
c.subs = append(c.subs, sub)
c.Unlock()
return true
} | go | {
"resource": ""
} |
q26877 | removeSub | train | func (cs *clientStore) removeSub(ID string, sub *subState) bool {
cs.RLock()
defer cs.RUnlock()
c := cs.clients[ID]
if c == nil {
return false
}
c.Lock()
removed := false
c.subs, removed = sub.deleteFromList(c.subs)
c.Unlock()
return removed
} | go | {
"resource": ""
} |
q26878 | recoverClients | train | func (cs *clientStore) recoverClients(clients []*stores.Client) {
cs.Lock()
for _, sc := range clients {
client := &client{info: sc, subs: make([]*subState, 0, 4)}
cs.clients[client.info.ID] = client
if len(client.info.ConnID) > 0 {
cs.connIDs[string(client.info.ConnID)] = client
}
}
cs.Unlock()
} | go | {
"resource": ""
} |
q26879 | setClientHB | train | func (cs *clientStore) setClientHB(ID string, interval time.Duration, f func()) {
cs.RLock()
defer cs.RUnlock()
c := cs.clients[ID]
if c == nil {
return
}
c.Lock()
if c.hbt == nil {
c.hbt = time.AfterFunc(interval, f)
}
c.Unlock()
} | go | {
"resource": ""
} |
q26880 | removeClientHB | train | func (cs *clientStore) removeClientHB(c *client) {
if c == nil {
return
}
c.Lock()
if c.hbt != nil {
c.hbt.Stop()
c.hbt = nil
}
c.Unlock()
} | go | {
"resource": ""
} |
q26881 | count | train | func (cs *clientStore) count() int {
cs.RLock()
total := len(cs.clients)
cs.RUnlock()
return total
} | go | {
"resource": ""
} |
q26882 | shutdown | train | func (r *raftNode) shutdown() error {
r.Lock()
if r.closed {
r.Unlock()
return nil
}
r.closed = true
r.Unlock()
if r.Raft != nil {
if err := r.Raft.Shutdown().Error(); err != nil {
return err
}
}
if r.transport != nil {
if err := r.transport.Close(); err != nil {
return err
}
}
if r.store !=... | go | {
"resource": ""
} |
q26883 | createServerRaftNode | train | func (s *StanServer) createServerRaftNode(hasStreamingState bool) error {
var (
name = s.info.ClusterID
addr = s.getClusteringAddr(name)
existingState, err = s.createRaftNode(name)
)
if err != nil {
return err
}
if !existingState && hasStreamingState {
return fmt.Errorf("strea... | go | {
"resource": ""
} |
q26884 | bootstrapCluster | train | func (s *StanServer) bootstrapCluster(name string, node *raft.Raft) error {
var (
addr = s.getClusteringAddr(name)
// Include ourself in the cluster.
servers = []raft.Server{raft.Server{
ID: raft.ServerID(s.opts.Clustering.NodeID),
Address: raft.ServerAddress(addr),
}}
)
if len(s.opts.Clustering.P... | go | {
"resource": ""
} |
q26885 | Apply | train | func (r *raftFSM) Apply(l *raft.Log) interface{} {
s := r.server
op := &spb.RaftOperation{}
if err := op.Unmarshal(l.Data); err != nil {
panic(err)
}
switch op.OpType {
case spb.RaftOperation_Publish:
// Message replication.
var (
c *channel
err error
lastSeq uint64
)
for _, msg := ra... | go | {
"resource": ""
} |
q26886 | EnsureBufBigEnough | train | func EnsureBufBigEnough(buf []byte, needed int) []byte {
if buf == nil {
return make([]byte, needed)
} else if needed > len(buf) {
return make([]byte, int(float32(needed)*1.1))
}
return buf
} | go | {
"resource": ""
} |
q26887 | CloseFile | train | func CloseFile(err error, f io.Closer) error {
if lerr := f.Close(); lerr != nil && err == nil {
err = lerr
}
return err
} | go | {
"resource": ""
} |
q26888 | FriendlyBytes | train | func FriendlyBytes(bytes int64) string {
fbytes := float64(bytes)
base := 1024
pre := []string{"K", "M", "G", "T", "P", "E"}
if fbytes < float64(base) {
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(f... | go | {
"resource": ""
} |
q26889 | Encrypt | train | func (s *EDStore) Encrypt(pbuf *[]byte, data []byte) ([]byte, error) {
var buf []byte
// If given a buffer, use that one
if pbuf != nil {
buf = *pbuf
}
// Make sure size is ok, expand if necessary
buf = util.EnsureBufBigEnough(buf, 1+s.nonceSize+s.cryptoOverhead+len(data))
// If buffer was passed, update the r... | go | {
"resource": ""
} |
q26890 | Decrypt | train | func (s *EDStore) Decrypt(dst []byte, cipherText []byte) ([]byte, error) {
var gcm cipher.AEAD
if len(cipherText) > 0 {
switch cipherText[0] {
case CryptoCodeAES:
gcm = s.aesgcm
case CryptoCodeChaCha:
gcm = s.chachagcm
default:
// Anything else, assume no algo or something we don't know how to decryp... | go | {
"resource": ""
} |
q26891 | NewCryptoStore | train | func NewCryptoStore(s Store, encryptionCipher string, encryptionKey []byte) (*CryptoStore, error) {
code, mkh, err := createMasterKeyHash(encryptionCipher, encryptionKey)
if err != nil {
return nil, err
}
cs := &CryptoStore{
Store: s,
code: code,
mkh: mkh,
}
// On success, erase the key
for i := 0; i ... | go | {
"resource": ""
} |
q26892 | Clone | train | func (sl *StoreLimits) Clone() *StoreLimits {
cloned := *sl
cloned.PerChannel = sl.ClonePerChannelMap()
return &cloned
} | go | {
"resource": ""
} |
q26893 | ClonePerChannelMap | train | func (sl *StoreLimits) ClonePerChannelMap() map[string]*ChannelLimits {
if sl.PerChannel == nil {
return nil
}
clone := make(map[string]*ChannelLimits, len(sl.PerChannel))
for k, v := range sl.PerChannel {
copyVal := *v
clone[k] = ©Val
}
return clone
} | go | {
"resource": ""
} |
q26894 | Print | train | func (sl *StoreLimits) Print() []string {
sublist := util.NewSublist()
for cn, cl := range sl.PerChannel {
sublist.Insert(cn, &channelLimitInfo{
name: cn,
limits: cl,
isLiteral: util.IsChannelNameLiteral(cn),
})
}
maxLevels := sublist.NumLevels()
txt := []string{}
title := "---------- Store L... | go | {
"resource": ""
} |
q26895 | NewJob | train | func NewJob(intervel uint64) *Job {
return &Job{
intervel,
"", "", "",
time.Unix(0, 0),
time.Unix(0, 0), 0,
time.Sunday,
make(map[string]interface{}),
make(map[string]([]interface{})),
}
} | go | {
"resource": ""
} |
q26896 | run | train | func (j *Job) run() (result []reflect.Value, err error) {
f := reflect.ValueOf(j.funcs[j.jobFunc])
params := j.fparams[j.jobFunc]
if len(params) != f.Type().NumIn() {
err = errors.New("the number of param is not adapted")
return
}
in := make([]reflect.Value, len(params))
for k, param := range params {
in[k]... | go | {
"resource": ""
} |
q26897 | getFunctionName | train | func getFunctionName(fn interface{}) string {
return runtime.FuncForPC(reflect.ValueOf((fn)).Pointer()).Name()
} | go | {
"resource": ""
} |
q26898 | Do | train | func (j *Job) Do(jobFun interface{}, params ...interface{}) {
typ := reflect.TypeOf(jobFun)
if typ.Kind() != reflect.Func {
panic("only function 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... | go | {
"resource": ""
} |
q26899 | scheduleNextRun | train | func (j *Job) scheduleNextRun() {
if j.lastRun == time.Unix(0, 0) {
if j.unit == "weeks" {
i := time.Now().Weekday() - j.startDay
if i < 0 {
i = 7 + i
}
j.lastRun = time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day()-int(i), 0, 0, 0, 0, loc)
} else {
j.lastRun = time.Now()
}
}
... | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.