repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
dgraph-io/badger
compaction.go
compareAndAdd
func (cs *compactStatus) compareAndAdd(_ thisAndNextLevelRLocked, cd compactDef) bool { cs.Lock() defer cs.Unlock() level := cd.thisLevel.level y.AssertTruef(level < len(cs.levels)-1, "Got level %d. Max levels: %d", level, len(cs.levels)) thisLevel := cs.levels[level] nextLevel := cs.levels[level+1] if thisLe...
go
func (cs *compactStatus) compareAndAdd(_ thisAndNextLevelRLocked, cd compactDef) bool { cs.Lock() defer cs.Unlock() level := cd.thisLevel.level y.AssertTruef(level < len(cs.levels)-1, "Got level %d. Max levels: %d", level, len(cs.levels)) thisLevel := cs.levels[level] nextLevel := cs.levels[level+1] if thisLe...
[ "func", "(", "cs", "*", "compactStatus", ")", "compareAndAdd", "(", "_", "thisAndNextLevelRLocked", ",", "cd", "compactDef", ")", "bool", "{", "cs", ".", "Lock", "(", ")", "\n", "defer", "cs", ".", "Unlock", "(", ")", "\n", "level", ":=", "cd", ".", ...
// compareAndAdd will check whether we can run this compactDef. That it doesn't overlap with any // other running compaction. If it can be run, it would store this run in the compactStatus state.
[ "compareAndAdd", "will", "check", "whether", "we", "can", "run", "this", "compactDef", ".", "That", "it", "doesn", "t", "overlap", "with", "any", "other", "running", "compaction", ".", "If", "it", "can", "be", "run", "it", "would", "store", "this", "run", ...
6b796b3ebec3ff006fcb1b425836cd784651e9fd
https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/compaction.go#L159-L184
test
dgraph-io/badger
skl/arena.go
newArena
func newArena(n int64) *Arena { // Don't store data at position 0 in order to reserve offset=0 as a kind // of nil pointer. out := &Arena{ n: 1, buf: make([]byte, n), } return out }
go
func newArena(n int64) *Arena { // Don't store data at position 0 in order to reserve offset=0 as a kind // of nil pointer. out := &Arena{ n: 1, buf: make([]byte, n), } return out }
[ "func", "newArena", "(", "n", "int64", ")", "*", "Arena", "{", "out", ":=", "&", "Arena", "{", "n", ":", "1", ",", "buf", ":", "make", "(", "[", "]", "byte", ",", "n", ")", ",", "}", "\n", "return", "out", "\n", "}" ]
// newArena returns a new arena.
[ "newArena", "returns", "a", "new", "arena", "." ]
6b796b3ebec3ff006fcb1b425836cd784651e9fd
https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/skl/arena.go#L43-L51
test
dgraph-io/badger
skl/arena.go
putNode
func (s *Arena) putNode(height int) uint32 { // Compute the amount of the tower that will never be used, since the height // is less than maxHeight. unusedSize := (maxHeight - height) * offsetSize // Pad the allocation with enough bytes to ensure pointer alignment. l := uint32(MaxNodeSize - unusedSize + nodeAlign...
go
func (s *Arena) putNode(height int) uint32 { // Compute the amount of the tower that will never be used, since the height // is less than maxHeight. unusedSize := (maxHeight - height) * offsetSize // Pad the allocation with enough bytes to ensure pointer alignment. l := uint32(MaxNodeSize - unusedSize + nodeAlign...
[ "func", "(", "s", "*", "Arena", ")", "putNode", "(", "height", "int", ")", "uint32", "{", "unusedSize", ":=", "(", "maxHeight", "-", "height", ")", "*", "offsetSize", "\n", "l", ":=", "uint32", "(", "MaxNodeSize", "-", "unusedSize", "+", "nodeAlign", "...
// putNode allocates a node in the arena. The node is aligned on a pointer-sized // boundary. The arena offset of the node is returned.
[ "putNode", "allocates", "a", "node", "in", "the", "arena", ".", "The", "node", "is", "aligned", "on", "a", "pointer", "-", "sized", "boundary", ".", "The", "arena", "offset", "of", "the", "node", "is", "returned", "." ]
6b796b3ebec3ff006fcb1b425836cd784651e9fd
https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/skl/arena.go#L63-L78
test
dgraph-io/badger
skl/arena.go
getNode
func (s *Arena) getNode(offset uint32) *node { if offset == 0 { return nil } return (*node)(unsafe.Pointer(&s.buf[offset])) }
go
func (s *Arena) getNode(offset uint32) *node { if offset == 0 { return nil } return (*node)(unsafe.Pointer(&s.buf[offset])) }
[ "func", "(", "s", "*", "Arena", ")", "getNode", "(", "offset", "uint32", ")", "*", "node", "{", "if", "offset", "==", "0", "{", "return", "nil", "\n", "}", "\n", "return", "(", "*", "node", ")", "(", "unsafe", ".", "Pointer", "(", "&", "s", "."...
// getNode returns a pointer to the node located at offset. If the offset is // zero, then the nil node pointer is returned.
[ "getNode", "returns", "a", "pointer", "to", "the", "node", "located", "at", "offset", ".", "If", "the", "offset", "is", "zero", "then", "the", "nil", "node", "pointer", "is", "returned", "." ]
6b796b3ebec3ff006fcb1b425836cd784651e9fd
https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/skl/arena.go#L108-L114
test
dgraph-io/badger
skl/arena.go
getKey
func (s *Arena) getKey(offset uint32, size uint16) []byte { return s.buf[offset : offset+uint32(size)] }
go
func (s *Arena) getKey(offset uint32, size uint16) []byte { return s.buf[offset : offset+uint32(size)] }
[ "func", "(", "s", "*", "Arena", ")", "getKey", "(", "offset", "uint32", ",", "size", "uint16", ")", "[", "]", "byte", "{", "return", "s", ".", "buf", "[", "offset", ":", "offset", "+", "uint32", "(", "size", ")", "]", "\n", "}" ]
// getKey returns byte slice at offset.
[ "getKey", "returns", "byte", "slice", "at", "offset", "." ]
6b796b3ebec3ff006fcb1b425836cd784651e9fd
https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/skl/arena.go#L117-L119
test
dgraph-io/badger
skl/arena.go
getVal
func (s *Arena) getVal(offset uint32, size uint16) (ret y.ValueStruct) { ret.Decode(s.buf[offset : offset+uint32(size)]) return }
go
func (s *Arena) getVal(offset uint32, size uint16) (ret y.ValueStruct) { ret.Decode(s.buf[offset : offset+uint32(size)]) return }
[ "func", "(", "s", "*", "Arena", ")", "getVal", "(", "offset", "uint32", ",", "size", "uint16", ")", "(", "ret", "y", ".", "ValueStruct", ")", "{", "ret", ".", "Decode", "(", "s", ".", "buf", "[", "offset", ":", "offset", "+", "uint32", "(", "size...
// getVal returns byte slice at offset. The given size should be just the value // size and should NOT include the meta bytes.
[ "getVal", "returns", "byte", "slice", "at", "offset", ".", "The", "given", "size", "should", "be", "just", "the", "value", "size", "and", "should", "NOT", "include", "the", "meta", "bytes", "." ]
6b796b3ebec3ff006fcb1b425836cd784651e9fd
https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/skl/arena.go#L123-L126
test
dgraph-io/badger
skl/arena.go
getNodeOffset
func (s *Arena) getNodeOffset(nd *node) uint32 { if nd == nil { return 0 } return uint32(uintptr(unsafe.Pointer(nd)) - uintptr(unsafe.Pointer(&s.buf[0]))) }
go
func (s *Arena) getNodeOffset(nd *node) uint32 { if nd == nil { return 0 } return uint32(uintptr(unsafe.Pointer(nd)) - uintptr(unsafe.Pointer(&s.buf[0]))) }
[ "func", "(", "s", "*", "Arena", ")", "getNodeOffset", "(", "nd", "*", "node", ")", "uint32", "{", "if", "nd", "==", "nil", "{", "return", "0", "\n", "}", "\n", "return", "uint32", "(", "uintptr", "(", "unsafe", ".", "Pointer", "(", "nd", ")", ")"...
// getNodeOffset returns the offset of node in the arena. If the node pointer is // nil, then the zero offset is returned.
[ "getNodeOffset", "returns", "the", "offset", "of", "node", "in", "the", "arena", ".", "If", "the", "node", "pointer", "is", "nil", "then", "the", "zero", "offset", "is", "returned", "." ]
6b796b3ebec3ff006fcb1b425836cd784651e9fd
https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/skl/arena.go#L130-L136
test
dgraph-io/badger
y/metrics.go
init
func init() { NumReads = expvar.NewInt("badger_disk_reads_total") NumWrites = expvar.NewInt("badger_disk_writes_total") NumBytesRead = expvar.NewInt("badger_read_bytes") NumBytesWritten = expvar.NewInt("badger_written_bytes") NumLSMGets = expvar.NewMap("badger_lsm_level_gets_total") NumLSMBloomHits = expvar.NewMa...
go
func init() { NumReads = expvar.NewInt("badger_disk_reads_total") NumWrites = expvar.NewInt("badger_disk_writes_total") NumBytesRead = expvar.NewInt("badger_read_bytes") NumBytesWritten = expvar.NewInt("badger_written_bytes") NumLSMGets = expvar.NewMap("badger_lsm_level_gets_total") NumLSMBloomHits = expvar.NewMa...
[ "func", "init", "(", ")", "{", "NumReads", "=", "expvar", ".", "NewInt", "(", "\"badger_disk_reads_total\"", ")", "\n", "NumWrites", "=", "expvar", ".", "NewInt", "(", "\"badger_disk_writes_total\"", ")", "\n", "NumBytesRead", "=", "expvar", ".", "NewInt", "("...
// These variables are global and have cumulative values for all kv stores.
[ "These", "variables", "are", "global", "and", "have", "cumulative", "values", "for", "all", "kv", "stores", "." ]
6b796b3ebec3ff006fcb1b425836cd784651e9fd
https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/y/metrics.go#L54-L68
test
dgraph-io/badger
levels.go
revertToManifest
func revertToManifest(kv *DB, mf *Manifest, idMap map[uint64]struct{}) error { // 1. Check all files in manifest exist. for id := range mf.Tables { if _, ok := idMap[id]; !ok { return fmt.Errorf("file does not exist for table %d", id) } } // 2. Delete files that shouldn't exist. for id := range idMap { i...
go
func revertToManifest(kv *DB, mf *Manifest, idMap map[uint64]struct{}) error { // 1. Check all files in manifest exist. for id := range mf.Tables { if _, ok := idMap[id]; !ok { return fmt.Errorf("file does not exist for table %d", id) } } // 2. Delete files that shouldn't exist. for id := range idMap { i...
[ "func", "revertToManifest", "(", "kv", "*", "DB", ",", "mf", "*", "Manifest", ",", "idMap", "map", "[", "uint64", "]", "struct", "{", "}", ")", "error", "{", "for", "id", ":=", "range", "mf", ".", "Tables", "{", "if", "_", ",", "ok", ":=", "idMap...
// revertToManifest checks that all necessary table files exist and removes all table files not // referenced by the manifest. idMap is a set of table file id's that were read from the directory // listing.
[ "revertToManifest", "checks", "that", "all", "necessary", "table", "files", "exist", "and", "removes", "all", "table", "files", "not", "referenced", "by", "the", "manifest", ".", "idMap", "is", "a", "set", "of", "table", "file", "id", "s", "that", "were", ...
6b796b3ebec3ff006fcb1b425836cd784651e9fd
https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/levels.go#L58-L78
test
dgraph-io/badger
levels.go
dropTree
func (s *levelsController) dropTree() (int, error) { // First pick all tables, so we can create a manifest changelog. var all []*table.Table for _, l := range s.levels { l.RLock() all = append(all, l.tables...) l.RUnlock() } if len(all) == 0 { return 0, nil } // Generate the manifest changes. changes :...
go
func (s *levelsController) dropTree() (int, error) { // First pick all tables, so we can create a manifest changelog. var all []*table.Table for _, l := range s.levels { l.RLock() all = append(all, l.tables...) l.RUnlock() } if len(all) == 0 { return 0, nil } // Generate the manifest changes. changes :...
[ "func", "(", "s", "*", "levelsController", ")", "dropTree", "(", ")", "(", "int", ",", "error", ")", "{", "var", "all", "[", "]", "*", "table", ".", "Table", "\n", "for", "_", ",", "l", ":=", "range", "s", ".", "levels", "{", "l", ".", "RLock",...
// dropTree picks all tables from all levels, creates a manifest changeset, // applies it, and then decrements the refs of these tables, which would result // in their deletion.
[ "dropTree", "picks", "all", "tables", "from", "all", "levels", "creates", "a", "manifest", "changeset", "applies", "it", "and", "then", "decrements", "the", "refs", "of", "these", "tables", "which", "would", "result", "in", "their", "deletion", "." ]
6b796b3ebec3ff006fcb1b425836cd784651e9fd
https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/levels.go#L222-L257
test
dgraph-io/badger
levels.go
dropPrefix
func (s *levelsController) dropPrefix(prefix []byte) error { opt := s.kv.opt for _, l := range s.levels { l.RLock() if l.level == 0 { size := len(l.tables) l.RUnlock() if size > 0 { cp := compactionPriority{ level: 0, score: 1.74, // A unique number greater than 1.0 does two things. H...
go
func (s *levelsController) dropPrefix(prefix []byte) error { opt := s.kv.opt for _, l := range s.levels { l.RLock() if l.level == 0 { size := len(l.tables) l.RUnlock() if size > 0 { cp := compactionPriority{ level: 0, score: 1.74, // A unique number greater than 1.0 does two things. H...
[ "func", "(", "s", "*", "levelsController", ")", "dropPrefix", "(", "prefix", "[", "]", "byte", ")", "error", "{", "opt", ":=", "s", ".", "kv", ".", "opt", "\n", "for", "_", ",", "l", ":=", "range", "s", ".", "levels", "{", "l", ".", "RLock", "(...
// dropPrefix runs a L0->L1 compaction, and then runs same level compaction on the rest of the // levels. For L0->L1 compaction, it runs compactions normally, but skips over all the keys with the // provided prefix. For Li->Li compactions, it picks up the tables which would have the prefix. The // tables who only have ...
[ "dropPrefix", "runs", "a", "L0", "-", ">", "L1", "compaction", "and", "then", "runs", "same", "level", "compaction", "on", "the", "rest", "of", "the", "levels", ".", "For", "L0", "-", ">", "L1", "compaction", "it", "runs", "compactions", "normally", "but...
6b796b3ebec3ff006fcb1b425836cd784651e9fd
https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/levels.go#L265-L323
test
dgraph-io/badger
levels.go
isLevel0Compactable
func (s *levelsController) isLevel0Compactable() bool { return s.levels[0].numTables() >= s.kv.opt.NumLevelZeroTables }
go
func (s *levelsController) isLevel0Compactable() bool { return s.levels[0].numTables() >= s.kv.opt.NumLevelZeroTables }
[ "func", "(", "s", "*", "levelsController", ")", "isLevel0Compactable", "(", ")", "bool", "{", "return", "s", ".", "levels", "[", "0", "]", ".", "numTables", "(", ")", ">=", "s", ".", "kv", ".", "opt", ".", "NumLevelZeroTables", "\n", "}" ]
// Returns true if level zero may be compacted, without accounting for compactions that already // might be happening.
[ "Returns", "true", "if", "level", "zero", "may", "be", "compacted", "without", "accounting", "for", "compactions", "that", "already", "might", "be", "happening", "." ]
6b796b3ebec3ff006fcb1b425836cd784651e9fd
https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/levels.go#L369-L371
test
dgraph-io/badger
levels.go
doCompact
func (s *levelsController) doCompact(p compactionPriority) error { l := p.level y.AssertTrue(l+1 < s.kv.opt.MaxLevels) // Sanity check. cd := compactDef{ elog: trace.New(fmt.Sprintf("Badger.L%d", l), "Compact"), thisLevel: s.levels[l], nextLevel: s.levels[l+1], dropPrefix: p.dropPrefix, } cd.elog....
go
func (s *levelsController) doCompact(p compactionPriority) error { l := p.level y.AssertTrue(l+1 < s.kv.opt.MaxLevels) // Sanity check. cd := compactDef{ elog: trace.New(fmt.Sprintf("Badger.L%d", l), "Compact"), thisLevel: s.levels[l], nextLevel: s.levels[l+1], dropPrefix: p.dropPrefix, } cd.elog....
[ "func", "(", "s", "*", "levelsController", ")", "doCompact", "(", "p", "compactionPriority", ")", "error", "{", "l", ":=", "p", ".", "level", "\n", "y", ".", "AssertTrue", "(", "l", "+", "1", "<", "s", ".", "kv", ".", "opt", ".", "MaxLevels", ")", ...
// doCompact picks some table on level l and compacts it away to the next level.
[ "doCompact", "picks", "some", "table", "on", "level", "l", "and", "compacts", "it", "away", "to", "the", "next", "level", "." ]
6b796b3ebec3ff006fcb1b425836cd784651e9fd
https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/levels.go#L798-L838
test
dgraph-io/badger
levels.go
get
func (s *levelsController) get(key []byte, maxVs *y.ValueStruct) (y.ValueStruct, error) { // It's important that we iterate the levels from 0 on upward. The reason is, if we iterated // in opposite order, or in parallel (naively calling all the h.RLock() in some order) we could // read level L's tables post-compact...
go
func (s *levelsController) get(key []byte, maxVs *y.ValueStruct) (y.ValueStruct, error) { // It's important that we iterate the levels from 0 on upward. The reason is, if we iterated // in opposite order, or in parallel (naively calling all the h.RLock() in some order) we could // read level L's tables post-compact...
[ "func", "(", "s", "*", "levelsController", ")", "get", "(", "key", "[", "]", "byte", ",", "maxVs", "*", "y", ".", "ValueStruct", ")", "(", "y", ".", "ValueStruct", ",", "error", ")", "{", "version", ":=", "y", ".", "ParseTs", "(", "key", ")", "\n...
// get returns the found value if any. If not found, we return nil.
[ "get", "returns", "the", "found", "value", "if", "any", ".", "If", "not", "found", "we", "return", "nil", "." ]
6b796b3ebec3ff006fcb1b425836cd784651e9fd
https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/levels.go#L898-L924
test
dgraph-io/badger
badger/cmd/bank.go
seekTotal
func seekTotal(txn *badger.Txn) ([]account, error) { expected := uint64(numAccounts) * uint64(initialBal) var accounts []account var total uint64 for i := 0; i < numAccounts; i++ { item, err := txn.Get(key(i)) if err != nil { log.Printf("Error for account: %d. err=%v. key=%q\n", i, err, key(i)) return ac...
go
func seekTotal(txn *badger.Txn) ([]account, error) { expected := uint64(numAccounts) * uint64(initialBal) var accounts []account var total uint64 for i := 0; i < numAccounts; i++ { item, err := txn.Get(key(i)) if err != nil { log.Printf("Error for account: %d. err=%v. key=%q\n", i, err, key(i)) return ac...
[ "func", "seekTotal", "(", "txn", "*", "badger", ".", "Txn", ")", "(", "[", "]", "account", ",", "error", ")", "{", "expected", ":=", "uint64", "(", "numAccounts", ")", "*", "uint64", "(", "initialBal", ")", "\n", "var", "accounts", "[", "]", "account...
// seekTotal retrives the total of all accounts by seeking for each account key.
[ "seekTotal", "retrives", "the", "total", "of", "all", "accounts", "by", "seeking", "for", "each", "account", "key", "." ]
6b796b3ebec3ff006fcb1b425836cd784651e9fd
https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/badger/cmd/bank.go#L181-L210
test
dgraph-io/badger
badger/cmd/bank.go
findFirstInvalidTxn
func findFirstInvalidTxn(db *badger.DB, lowTs, highTs uint64) uint64 { checkAt := func(ts uint64) error { txn := db.NewTransactionAt(ts, false) _, err := seekTotal(txn) txn.Discard() return err } if highTs-lowTs < 1 { log.Printf("Checking at lowTs: %d\n", lowTs) err := checkAt(lowTs) if err == errFail...
go
func findFirstInvalidTxn(db *badger.DB, lowTs, highTs uint64) uint64 { checkAt := func(ts uint64) error { txn := db.NewTransactionAt(ts, false) _, err := seekTotal(txn) txn.Discard() return err } if highTs-lowTs < 1 { log.Printf("Checking at lowTs: %d\n", lowTs) err := checkAt(lowTs) if err == errFail...
[ "func", "findFirstInvalidTxn", "(", "db", "*", "badger", ".", "DB", ",", "lowTs", ",", "highTs", "uint64", ")", "uint64", "{", "checkAt", ":=", "func", "(", "ts", "uint64", ")", "error", "{", "txn", ":=", "db", ".", "NewTransactionAt", "(", "ts", ",", ...
// Range is [lowTs, highTs).
[ "Range", "is", "[", "lowTs", "highTs", ")", "." ]
6b796b3ebec3ff006fcb1b425836cd784651e9fd
https://github.com/dgraph-io/badger/blob/6b796b3ebec3ff006fcb1b425836cd784651e9fd/badger/cmd/bank.go#L213-L245
test
hashicorp/raft
inmem_snapshot.go
Create
func (m *InmemSnapshotStore) Create(version SnapshotVersion, index, term uint64, configuration Configuration, configurationIndex uint64, trans Transport) (SnapshotSink, error) { // We only support version 1 snapshots at this time. if version != 1 { return nil, fmt.Errorf("unsupported snapshot version %d", version)...
go
func (m *InmemSnapshotStore) Create(version SnapshotVersion, index, term uint64, configuration Configuration, configurationIndex uint64, trans Transport) (SnapshotSink, error) { // We only support version 1 snapshots at this time. if version != 1 { return nil, fmt.Errorf("unsupported snapshot version %d", version)...
[ "func", "(", "m", "*", "InmemSnapshotStore", ")", "Create", "(", "version", "SnapshotVersion", ",", "index", ",", "term", "uint64", ",", "configuration", "Configuration", ",", "configurationIndex", "uint64", ",", "trans", "Transport", ")", "(", "SnapshotSink", "...
// Create replaces the stored snapshot with a new one using the given args
[ "Create", "replaces", "the", "stored", "snapshot", "with", "a", "new", "one", "using", "the", "given", "args" ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/inmem_snapshot.go#L35-L63
test
hashicorp/raft
inmem_snapshot.go
List
func (m *InmemSnapshotStore) List() ([]*SnapshotMeta, error) { m.RLock() defer m.RUnlock() if !m.hasSnapshot { return []*SnapshotMeta{}, nil } return []*SnapshotMeta{&m.latest.meta}, nil }
go
func (m *InmemSnapshotStore) List() ([]*SnapshotMeta, error) { m.RLock() defer m.RUnlock() if !m.hasSnapshot { return []*SnapshotMeta{}, nil } return []*SnapshotMeta{&m.latest.meta}, nil }
[ "func", "(", "m", "*", "InmemSnapshotStore", ")", "List", "(", ")", "(", "[", "]", "*", "SnapshotMeta", ",", "error", ")", "{", "m", ".", "RLock", "(", ")", "\n", "defer", "m", ".", "RUnlock", "(", ")", "\n", "if", "!", "m", ".", "hasSnapshot", ...
// List returns the latest snapshot taken
[ "List", "returns", "the", "latest", "snapshot", "taken" ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/inmem_snapshot.go#L66-L74
test
hashicorp/raft
inmem_snapshot.go
Open
func (m *InmemSnapshotStore) Open(id string) (*SnapshotMeta, io.ReadCloser, error) { m.RLock() defer m.RUnlock() if m.latest.meta.ID != id { return nil, nil, fmt.Errorf("[ERR] snapshot: failed to open snapshot id: %s", id) } return &m.latest.meta, ioutil.NopCloser(m.latest.contents), nil }
go
func (m *InmemSnapshotStore) Open(id string) (*SnapshotMeta, io.ReadCloser, error) { m.RLock() defer m.RUnlock() if m.latest.meta.ID != id { return nil, nil, fmt.Errorf("[ERR] snapshot: failed to open snapshot id: %s", id) } return &m.latest.meta, ioutil.NopCloser(m.latest.contents), nil }
[ "func", "(", "m", "*", "InmemSnapshotStore", ")", "Open", "(", "id", "string", ")", "(", "*", "SnapshotMeta", ",", "io", ".", "ReadCloser", ",", "error", ")", "{", "m", ".", "RLock", "(", ")", "\n", "defer", "m", ".", "RUnlock", "(", ")", "\n", "...
// Open wraps an io.ReadCloser around the snapshot contents
[ "Open", "wraps", "an", "io", ".", "ReadCloser", "around", "the", "snapshot", "contents" ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/inmem_snapshot.go#L77-L86
test
hashicorp/raft
inmem_snapshot.go
Write
func (s *InmemSnapshotSink) Write(p []byte) (n int, err error) { written, err := io.Copy(s.contents, bytes.NewReader(p)) s.meta.Size += written return int(written), err }
go
func (s *InmemSnapshotSink) Write(p []byte) (n int, err error) { written, err := io.Copy(s.contents, bytes.NewReader(p)) s.meta.Size += written return int(written), err }
[ "func", "(", "s", "*", "InmemSnapshotSink", ")", "Write", "(", "p", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "written", ",", "err", ":=", "io", ".", "Copy", "(", "s", ".", "contents", ",", "bytes", ".", "NewReader", ...
// Write appends the given bytes to the snapshot contents
[ "Write", "appends", "the", "given", "bytes", "to", "the", "snapshot", "contents" ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/inmem_snapshot.go#L89-L93
test
hashicorp/raft
file_snapshot.go
NewFileSnapshotStoreWithLogger
func NewFileSnapshotStoreWithLogger(base string, retain int, logger *log.Logger) (*FileSnapshotStore, error) { if retain < 1 { return nil, fmt.Errorf("must retain at least one snapshot") } if logger == nil { logger = log.New(os.Stderr, "", log.LstdFlags) } // Ensure our path exists path := filepath.Join(base...
go
func NewFileSnapshotStoreWithLogger(base string, retain int, logger *log.Logger) (*FileSnapshotStore, error) { if retain < 1 { return nil, fmt.Errorf("must retain at least one snapshot") } if logger == nil { logger = log.New(os.Stderr, "", log.LstdFlags) } // Ensure our path exists path := filepath.Join(base...
[ "func", "NewFileSnapshotStoreWithLogger", "(", "base", "string", ",", "retain", "int", ",", "logger", "*", "log", ".", "Logger", ")", "(", "*", "FileSnapshotStore", ",", "error", ")", "{", "if", "retain", "<", "1", "{", "return", "nil", ",", "fmt", ".", ...
// NewFileSnapshotStoreWithLogger creates a new FileSnapshotStore based // on a base directory. The `retain` parameter controls how many // snapshots are retained. Must be at least 1.
[ "NewFileSnapshotStoreWithLogger", "creates", "a", "new", "FileSnapshotStore", "based", "on", "a", "base", "directory", ".", "The", "retain", "parameter", "controls", "how", "many", "snapshots", "are", "retained", ".", "Must", "be", "at", "least", "1", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/file_snapshot.go#L79-L105
test
hashicorp/raft
file_snapshot.go
NewFileSnapshotStore
func NewFileSnapshotStore(base string, retain int, logOutput io.Writer) (*FileSnapshotStore, error) { if logOutput == nil { logOutput = os.Stderr } return NewFileSnapshotStoreWithLogger(base, retain, log.New(logOutput, "", log.LstdFlags)) }
go
func NewFileSnapshotStore(base string, retain int, logOutput io.Writer) (*FileSnapshotStore, error) { if logOutput == nil { logOutput = os.Stderr } return NewFileSnapshotStoreWithLogger(base, retain, log.New(logOutput, "", log.LstdFlags)) }
[ "func", "NewFileSnapshotStore", "(", "base", "string", ",", "retain", "int", ",", "logOutput", "io", ".", "Writer", ")", "(", "*", "FileSnapshotStore", ",", "error", ")", "{", "if", "logOutput", "==", "nil", "{", "logOutput", "=", "os", ".", "Stderr", "\...
// NewFileSnapshotStore creates a new FileSnapshotStore based // on a base directory. The `retain` parameter controls how many // snapshots are retained. Must be at least 1.
[ "NewFileSnapshotStore", "creates", "a", "new", "FileSnapshotStore", "based", "on", "a", "base", "directory", ".", "The", "retain", "parameter", "controls", "how", "many", "snapshots", "are", "retained", ".", "Must", "be", "at", "least", "1", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/file_snapshot.go#L110-L115
test
hashicorp/raft
file_snapshot.go
snapshotName
func snapshotName(term, index uint64) string { now := time.Now() msec := now.UnixNano() / int64(time.Millisecond) return fmt.Sprintf("%d-%d-%d", term, index, msec) }
go
func snapshotName(term, index uint64) string { now := time.Now() msec := now.UnixNano() / int64(time.Millisecond) return fmt.Sprintf("%d-%d-%d", term, index, msec) }
[ "func", "snapshotName", "(", "term", ",", "index", "uint64", ")", "string", "{", "now", ":=", "time", ".", "Now", "(", ")", "\n", "msec", ":=", "now", ".", "UnixNano", "(", ")", "/", "int64", "(", "time", ".", "Millisecond", ")", "\n", "return", "f...
// snapshotName generates a name for the snapshot.
[ "snapshotName", "generates", "a", "name", "for", "the", "snapshot", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/file_snapshot.go#L136-L140
test
hashicorp/raft
file_snapshot.go
Create
func (f *FileSnapshotStore) Create(version SnapshotVersion, index, term uint64, configuration Configuration, configurationIndex uint64, trans Transport) (SnapshotSink, error) { // We only support version 1 snapshots at this time. if version != 1 { return nil, fmt.Errorf("unsupported snapshot version %d", version) ...
go
func (f *FileSnapshotStore) Create(version SnapshotVersion, index, term uint64, configuration Configuration, configurationIndex uint64, trans Transport) (SnapshotSink, error) { // We only support version 1 snapshots at this time. if version != 1 { return nil, fmt.Errorf("unsupported snapshot version %d", version) ...
[ "func", "(", "f", "*", "FileSnapshotStore", ")", "Create", "(", "version", "SnapshotVersion", ",", "index", ",", "term", "uint64", ",", "configuration", "Configuration", ",", "configurationIndex", "uint64", ",", "trans", "Transport", ")", "(", "SnapshotSink", ",...
// Create is used to start a new snapshot
[ "Create", "is", "used", "to", "start", "a", "new", "snapshot" ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/file_snapshot.go#L143-L205
test
hashicorp/raft
file_snapshot.go
List
func (f *FileSnapshotStore) List() ([]*SnapshotMeta, error) { // Get the eligible snapshots snapshots, err := f.getSnapshots() if err != nil { f.logger.Printf("[ERR] snapshot: Failed to get snapshots: %v", err) return nil, err } var snapMeta []*SnapshotMeta for _, meta := range snapshots { snapMeta = appen...
go
func (f *FileSnapshotStore) List() ([]*SnapshotMeta, error) { // Get the eligible snapshots snapshots, err := f.getSnapshots() if err != nil { f.logger.Printf("[ERR] snapshot: Failed to get snapshots: %v", err) return nil, err } var snapMeta []*SnapshotMeta for _, meta := range snapshots { snapMeta = appen...
[ "func", "(", "f", "*", "FileSnapshotStore", ")", "List", "(", ")", "(", "[", "]", "*", "SnapshotMeta", ",", "error", ")", "{", "snapshots", ",", "err", ":=", "f", ".", "getSnapshots", "(", ")", "\n", "if", "err", "!=", "nil", "{", "f", ".", "logg...
// List returns available snapshots in the store.
[ "List", "returns", "available", "snapshots", "in", "the", "store", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/file_snapshot.go#L208-L224
test
hashicorp/raft
file_snapshot.go
getSnapshots
func (f *FileSnapshotStore) getSnapshots() ([]*fileSnapshotMeta, error) { // Get the eligible snapshots snapshots, err := ioutil.ReadDir(f.path) if err != nil { f.logger.Printf("[ERR] snapshot: Failed to scan snapshot dir: %v", err) return nil, err } // Populate the metadata var snapMeta []*fileSnapshotMeta ...
go
func (f *FileSnapshotStore) getSnapshots() ([]*fileSnapshotMeta, error) { // Get the eligible snapshots snapshots, err := ioutil.ReadDir(f.path) if err != nil { f.logger.Printf("[ERR] snapshot: Failed to scan snapshot dir: %v", err) return nil, err } // Populate the metadata var snapMeta []*fileSnapshotMeta ...
[ "func", "(", "f", "*", "FileSnapshotStore", ")", "getSnapshots", "(", ")", "(", "[", "]", "*", "fileSnapshotMeta", ",", "error", ")", "{", "snapshots", ",", "err", ":=", "ioutil", ".", "ReadDir", "(", "f", ".", "path", ")", "\n", "if", "err", "!=", ...
// getSnapshots returns all the known snapshots.
[ "getSnapshots", "returns", "all", "the", "known", "snapshots", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/file_snapshot.go#L227-L271
test
hashicorp/raft
file_snapshot.go
readMeta
func (f *FileSnapshotStore) readMeta(name string) (*fileSnapshotMeta, error) { // Open the meta file metaPath := filepath.Join(f.path, name, metaFilePath) fh, err := os.Open(metaPath) if err != nil { return nil, err } defer fh.Close() // Buffer the file IO buffered := bufio.NewReader(fh) // Read in the JSO...
go
func (f *FileSnapshotStore) readMeta(name string) (*fileSnapshotMeta, error) { // Open the meta file metaPath := filepath.Join(f.path, name, metaFilePath) fh, err := os.Open(metaPath) if err != nil { return nil, err } defer fh.Close() // Buffer the file IO buffered := bufio.NewReader(fh) // Read in the JSO...
[ "func", "(", "f", "*", "FileSnapshotStore", ")", "readMeta", "(", "name", "string", ")", "(", "*", "fileSnapshotMeta", ",", "error", ")", "{", "metaPath", ":=", "filepath", ".", "Join", "(", "f", ".", "path", ",", "name", ",", "metaFilePath", ")", "\n"...
// readMeta is used to read the meta data for a given named backup
[ "readMeta", "is", "used", "to", "read", "the", "meta", "data", "for", "a", "given", "named", "backup" ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/file_snapshot.go#L274-L293
test
hashicorp/raft
file_snapshot.go
Open
func (f *FileSnapshotStore) Open(id string) (*SnapshotMeta, io.ReadCloser, error) { // Get the metadata meta, err := f.readMeta(id) if err != nil { f.logger.Printf("[ERR] snapshot: Failed to get meta data to open snapshot: %v", err) return nil, nil, err } // Open the state file statePath := filepath.Join(f.p...
go
func (f *FileSnapshotStore) Open(id string) (*SnapshotMeta, io.ReadCloser, error) { // Get the metadata meta, err := f.readMeta(id) if err != nil { f.logger.Printf("[ERR] snapshot: Failed to get meta data to open snapshot: %v", err) return nil, nil, err } // Open the state file statePath := filepath.Join(f.p...
[ "func", "(", "f", "*", "FileSnapshotStore", ")", "Open", "(", "id", "string", ")", "(", "*", "SnapshotMeta", ",", "io", ".", "ReadCloser", ",", "error", ")", "{", "meta", ",", "err", ":=", "f", ".", "readMeta", "(", "id", ")", "\n", "if", "err", ...
// Open takes a snapshot ID and returns a ReadCloser for that snapshot.
[ "Open", "takes", "a", "snapshot", "ID", "and", "returns", "a", "ReadCloser", "for", "that", "snapshot", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/file_snapshot.go#L296-L346
test
hashicorp/raft
file_snapshot.go
ReapSnapshots
func (f *FileSnapshotStore) ReapSnapshots() error { snapshots, err := f.getSnapshots() if err != nil { f.logger.Printf("[ERR] snapshot: Failed to get snapshots: %v", err) return err } for i := f.retain; i < len(snapshots); i++ { path := filepath.Join(f.path, snapshots[i].ID) f.logger.Printf("[INFO] snapsho...
go
func (f *FileSnapshotStore) ReapSnapshots() error { snapshots, err := f.getSnapshots() if err != nil { f.logger.Printf("[ERR] snapshot: Failed to get snapshots: %v", err) return err } for i := f.retain; i < len(snapshots); i++ { path := filepath.Join(f.path, snapshots[i].ID) f.logger.Printf("[INFO] snapsho...
[ "func", "(", "f", "*", "FileSnapshotStore", ")", "ReapSnapshots", "(", ")", "error", "{", "snapshots", ",", "err", ":=", "f", ".", "getSnapshots", "(", ")", "\n", "if", "err", "!=", "nil", "{", "f", ".", "logger", ".", "Printf", "(", "\"[ERR] snapshot:...
// ReapSnapshots reaps any snapshots beyond the retain count.
[ "ReapSnapshots", "reaps", "any", "snapshots", "beyond", "the", "retain", "count", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/file_snapshot.go#L349-L365
test
hashicorp/raft
file_snapshot.go
Write
func (s *FileSnapshotSink) Write(b []byte) (int, error) { return s.buffered.Write(b) }
go
func (s *FileSnapshotSink) Write(b []byte) (int, error) { return s.buffered.Write(b) }
[ "func", "(", "s", "*", "FileSnapshotSink", ")", "Write", "(", "b", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "return", "s", ".", "buffered", ".", "Write", "(", "b", ")", "\n", "}" ]
// Write is used to append to the state file. We write to the // buffered IO object to reduce the amount of context switches.
[ "Write", "is", "used", "to", "append", "to", "the", "state", "file", ".", "We", "write", "to", "the", "buffered", "IO", "object", "to", "reduce", "the", "amount", "of", "context", "switches", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/file_snapshot.go#L375-L377
test
hashicorp/raft
file_snapshot.go
Close
func (s *FileSnapshotSink) Close() error { // Make sure close is idempotent if s.closed { return nil } s.closed = true // Close the open handles if err := s.finalize(); err != nil { s.logger.Printf("[ERR] snapshot: Failed to finalize snapshot: %v", err) if delErr := os.RemoveAll(s.dir); delErr != nil { ...
go
func (s *FileSnapshotSink) Close() error { // Make sure close is idempotent if s.closed { return nil } s.closed = true // Close the open handles if err := s.finalize(); err != nil { s.logger.Printf("[ERR] snapshot: Failed to finalize snapshot: %v", err) if delErr := os.RemoveAll(s.dir); delErr != nil { ...
[ "func", "(", "s", "*", "FileSnapshotSink", ")", "Close", "(", ")", "error", "{", "if", "s", ".", "closed", "{", "return", "nil", "\n", "}", "\n", "s", ".", "closed", "=", "true", "\n", "if", "err", ":=", "s", ".", "finalize", "(", ")", ";", "er...
// Close is used to indicate a successful end.
[ "Close", "is", "used", "to", "indicate", "a", "successful", "end", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/file_snapshot.go#L380-L430
test
hashicorp/raft
file_snapshot.go
Cancel
func (s *FileSnapshotSink) Cancel() error { // Make sure close is idempotent if s.closed { return nil } s.closed = true // Close the open handles if err := s.finalize(); err != nil { s.logger.Printf("[ERR] snapshot: Failed to finalize snapshot: %v", err) return err } // Attempt to remove all artifacts ...
go
func (s *FileSnapshotSink) Cancel() error { // Make sure close is idempotent if s.closed { return nil } s.closed = true // Close the open handles if err := s.finalize(); err != nil { s.logger.Printf("[ERR] snapshot: Failed to finalize snapshot: %v", err) return err } // Attempt to remove all artifacts ...
[ "func", "(", "s", "*", "FileSnapshotSink", ")", "Cancel", "(", ")", "error", "{", "if", "s", ".", "closed", "{", "return", "nil", "\n", "}", "\n", "s", ".", "closed", "=", "true", "\n", "if", "err", ":=", "s", ".", "finalize", "(", ")", ";", "e...
// Cancel is used to indicate an unsuccessful end.
[ "Cancel", "is", "used", "to", "indicate", "an", "unsuccessful", "end", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/file_snapshot.go#L433-L448
test
hashicorp/raft
file_snapshot.go
finalize
func (s *FileSnapshotSink) finalize() error { // Flush any remaining data if err := s.buffered.Flush(); err != nil { return err } // Sync to force fsync to disk if err := s.stateFile.Sync(); err != nil { return err } // Get the file size stat, statErr := s.stateFile.Stat() // Close the file if err := s...
go
func (s *FileSnapshotSink) finalize() error { // Flush any remaining data if err := s.buffered.Flush(); err != nil { return err } // Sync to force fsync to disk if err := s.stateFile.Sync(); err != nil { return err } // Get the file size stat, statErr := s.stateFile.Stat() // Close the file if err := s...
[ "func", "(", "s", "*", "FileSnapshotSink", ")", "finalize", "(", ")", "error", "{", "if", "err", ":=", "s", ".", "buffered", ".", "Flush", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "err", ":=", "s", ".", "s...
// finalize is used to close all of our resources.
[ "finalize", "is", "used", "to", "close", "all", "of", "our", "resources", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/file_snapshot.go#L451-L479
test
hashicorp/raft
file_snapshot.go
writeMeta
func (s *FileSnapshotSink) writeMeta() error { // Open the meta file metaPath := filepath.Join(s.dir, metaFilePath) fh, err := os.Create(metaPath) if err != nil { return err } defer fh.Close() // Buffer the file IO buffered := bufio.NewWriter(fh) // Write out as JSON enc := json.NewEncoder(buffered) if e...
go
func (s *FileSnapshotSink) writeMeta() error { // Open the meta file metaPath := filepath.Join(s.dir, metaFilePath) fh, err := os.Create(metaPath) if err != nil { return err } defer fh.Close() // Buffer the file IO buffered := bufio.NewWriter(fh) // Write out as JSON enc := json.NewEncoder(buffered) if e...
[ "func", "(", "s", "*", "FileSnapshotSink", ")", "writeMeta", "(", ")", "error", "{", "metaPath", ":=", "filepath", ".", "Join", "(", "s", ".", "dir", ",", "metaFilePath", ")", "\n", "fh", ",", "err", ":=", "os", ".", "Create", "(", "metaPath", ")", ...
// writeMeta is used to write out the metadata we have.
[ "writeMeta", "is", "used", "to", "write", "out", "the", "metadata", "we", "have", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/file_snapshot.go#L482-L509
test
hashicorp/raft
net_transport.go
NewNetworkTransportWithConfig
func NewNetworkTransportWithConfig( config *NetworkTransportConfig, ) *NetworkTransport { if config.Logger == nil { config.Logger = log.New(os.Stderr, "", log.LstdFlags) } trans := &NetworkTransport{ connPool: make(map[ServerAddress][]*netConn), consumeCh: make(chan RPC), logger: ...
go
func NewNetworkTransportWithConfig( config *NetworkTransportConfig, ) *NetworkTransport { if config.Logger == nil { config.Logger = log.New(os.Stderr, "", log.LstdFlags) } trans := &NetworkTransport{ connPool: make(map[ServerAddress][]*netConn), consumeCh: make(chan RPC), logger: ...
[ "func", "NewNetworkTransportWithConfig", "(", "config", "*", "NetworkTransportConfig", ",", ")", "*", "NetworkTransport", "{", "if", "config", ".", "Logger", "==", "nil", "{", "config", ".", "Logger", "=", "log", ".", "New", "(", "os", ".", "Stderr", ",", ...
// NewNetworkTransportWithConfig creates a new network transport with the given config struct
[ "NewNetworkTransportWithConfig", "creates", "a", "new", "network", "transport", "with", "the", "given", "config", "struct" ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/net_transport.go#L146-L169
test
hashicorp/raft
net_transport.go
setupStreamContext
func (n *NetworkTransport) setupStreamContext() { ctx, cancel := context.WithCancel(context.Background()) n.streamCtx = ctx n.streamCancel = cancel }
go
func (n *NetworkTransport) setupStreamContext() { ctx, cancel := context.WithCancel(context.Background()) n.streamCtx = ctx n.streamCancel = cancel }
[ "func", "(", "n", "*", "NetworkTransport", ")", "setupStreamContext", "(", ")", "{", "ctx", ",", "cancel", ":=", "context", ".", "WithCancel", "(", "context", ".", "Background", "(", ")", ")", "\n", "n", ".", "streamCtx", "=", "ctx", "\n", "n", ".", ...
// setupStreamContext is used to create a new stream context. This should be // called with the stream lock held.
[ "setupStreamContext", "is", "used", "to", "create", "a", "new", "stream", "context", ".", "This", "should", "be", "called", "with", "the", "stream", "lock", "held", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/net_transport.go#L205-L209
test
hashicorp/raft
net_transport.go
getStreamContext
func (n *NetworkTransport) getStreamContext() context.Context { n.streamCtxLock.RLock() defer n.streamCtxLock.RUnlock() return n.streamCtx }
go
func (n *NetworkTransport) getStreamContext() context.Context { n.streamCtxLock.RLock() defer n.streamCtxLock.RUnlock() return n.streamCtx }
[ "func", "(", "n", "*", "NetworkTransport", ")", "getStreamContext", "(", ")", "context", ".", "Context", "{", "n", ".", "streamCtxLock", ".", "RLock", "(", ")", "\n", "defer", "n", ".", "streamCtxLock", ".", "RUnlock", "(", ")", "\n", "return", "n", "....
// getStreamContext is used retrieve the current stream context.
[ "getStreamContext", "is", "used", "retrieve", "the", "current", "stream", "context", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/net_transport.go#L212-L216
test
hashicorp/raft
net_transport.go
SetHeartbeatHandler
func (n *NetworkTransport) SetHeartbeatHandler(cb func(rpc RPC)) { n.heartbeatFnLock.Lock() defer n.heartbeatFnLock.Unlock() n.heartbeatFn = cb }
go
func (n *NetworkTransport) SetHeartbeatHandler(cb func(rpc RPC)) { n.heartbeatFnLock.Lock() defer n.heartbeatFnLock.Unlock() n.heartbeatFn = cb }
[ "func", "(", "n", "*", "NetworkTransport", ")", "SetHeartbeatHandler", "(", "cb", "func", "(", "rpc", "RPC", ")", ")", "{", "n", ".", "heartbeatFnLock", ".", "Lock", "(", ")", "\n", "defer", "n", ".", "heartbeatFnLock", ".", "Unlock", "(", ")", "\n", ...
// SetHeartbeatHandler is used to setup a heartbeat handler // as a fast-pass. This is to avoid head-of-line blocking from // disk IO.
[ "SetHeartbeatHandler", "is", "used", "to", "setup", "a", "heartbeat", "handler", "as", "a", "fast", "-", "pass", ".", "This", "is", "to", "avoid", "head", "-", "of", "-", "line", "blocking", "from", "disk", "IO", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/net_transport.go#L221-L225
test
hashicorp/raft
net_transport.go
CloseStreams
func (n *NetworkTransport) CloseStreams() { n.connPoolLock.Lock() defer n.connPoolLock.Unlock() // Close all the connections in the connection pool and then remove their // entry. for k, e := range n.connPool { for _, conn := range e { conn.Release() } delete(n.connPool, k) } // Cancel the existing c...
go
func (n *NetworkTransport) CloseStreams() { n.connPoolLock.Lock() defer n.connPoolLock.Unlock() // Close all the connections in the connection pool and then remove their // entry. for k, e := range n.connPool { for _, conn := range e { conn.Release() } delete(n.connPool, k) } // Cancel the existing c...
[ "func", "(", "n", "*", "NetworkTransport", ")", "CloseStreams", "(", ")", "{", "n", ".", "connPoolLock", ".", "Lock", "(", ")", "\n", "defer", "n", ".", "connPoolLock", ".", "Unlock", "(", ")", "\n", "for", "k", ",", "e", ":=", "range", "n", ".", ...
// CloseStreams closes the current streams.
[ "CloseStreams", "closes", "the", "current", "streams", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/net_transport.go#L228-L250
test
hashicorp/raft
net_transport.go
Close
func (n *NetworkTransport) Close() error { n.shutdownLock.Lock() defer n.shutdownLock.Unlock() if !n.shutdown { close(n.shutdownCh) n.stream.Close() n.shutdown = true } return nil }
go
func (n *NetworkTransport) Close() error { n.shutdownLock.Lock() defer n.shutdownLock.Unlock() if !n.shutdown { close(n.shutdownCh) n.stream.Close() n.shutdown = true } return nil }
[ "func", "(", "n", "*", "NetworkTransport", ")", "Close", "(", ")", "error", "{", "n", ".", "shutdownLock", ".", "Lock", "(", ")", "\n", "defer", "n", ".", "shutdownLock", ".", "Unlock", "(", ")", "\n", "if", "!", "n", ".", "shutdown", "{", "close",...
// Close is used to stop the network transport.
[ "Close", "is", "used", "to", "stop", "the", "network", "transport", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/net_transport.go#L253-L263
test
hashicorp/raft
net_transport.go
getPooledConn
func (n *NetworkTransport) getPooledConn(target ServerAddress) *netConn { n.connPoolLock.Lock() defer n.connPoolLock.Unlock() conns, ok := n.connPool[target] if !ok || len(conns) == 0 { return nil } var conn *netConn num := len(conns) conn, conns[num-1] = conns[num-1], nil n.connPool[target] = conns[:num-1...
go
func (n *NetworkTransport) getPooledConn(target ServerAddress) *netConn { n.connPoolLock.Lock() defer n.connPoolLock.Unlock() conns, ok := n.connPool[target] if !ok || len(conns) == 0 { return nil } var conn *netConn num := len(conns) conn, conns[num-1] = conns[num-1], nil n.connPool[target] = conns[:num-1...
[ "func", "(", "n", "*", "NetworkTransport", ")", "getPooledConn", "(", "target", "ServerAddress", ")", "*", "netConn", "{", "n", ".", "connPoolLock", ".", "Lock", "(", ")", "\n", "defer", "n", ".", "connPoolLock", ".", "Unlock", "(", ")", "\n", "conns", ...
// getExistingConn is used to grab a pooled connection.
[ "getExistingConn", "is", "used", "to", "grab", "a", "pooled", "connection", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/net_transport.go#L286-L300
test
hashicorp/raft
net_transport.go
getConnFromAddressProvider
func (n *NetworkTransport) getConnFromAddressProvider(id ServerID, target ServerAddress) (*netConn, error) { address := n.getProviderAddressOrFallback(id, target) return n.getConn(address) }
go
func (n *NetworkTransport) getConnFromAddressProvider(id ServerID, target ServerAddress) (*netConn, error) { address := n.getProviderAddressOrFallback(id, target) return n.getConn(address) }
[ "func", "(", "n", "*", "NetworkTransport", ")", "getConnFromAddressProvider", "(", "id", "ServerID", ",", "target", "ServerAddress", ")", "(", "*", "netConn", ",", "error", ")", "{", "address", ":=", "n", ".", "getProviderAddressOrFallback", "(", "id", ",", ...
// getConnFromAddressProvider returns a connection from the server address provider if available, or defaults to a connection using the target server address
[ "getConnFromAddressProvider", "returns", "a", "connection", "from", "the", "server", "address", "provider", "if", "available", "or", "defaults", "to", "a", "connection", "using", "the", "target", "server", "address" ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/net_transport.go#L303-L306
test
hashicorp/raft
net_transport.go
getConn
func (n *NetworkTransport) getConn(target ServerAddress) (*netConn, error) { // Check for a pooled conn if conn := n.getPooledConn(target); conn != nil { return conn, nil } // Dial a new connection conn, err := n.stream.Dial(target, n.timeout) if err != nil { return nil, err } // Wrap the conn netConn :=...
go
func (n *NetworkTransport) getConn(target ServerAddress) (*netConn, error) { // Check for a pooled conn if conn := n.getPooledConn(target); conn != nil { return conn, nil } // Dial a new connection conn, err := n.stream.Dial(target, n.timeout) if err != nil { return nil, err } // Wrap the conn netConn :=...
[ "func", "(", "n", "*", "NetworkTransport", ")", "getConn", "(", "target", "ServerAddress", ")", "(", "*", "netConn", ",", "error", ")", "{", "if", "conn", ":=", "n", ".", "getPooledConn", "(", "target", ")", ";", "conn", "!=", "nil", "{", "return", "...
// getConn is used to get a connection from the pool.
[ "getConn", "is", "used", "to", "get", "a", "connection", "from", "the", "pool", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/net_transport.go#L321-L347
test
hashicorp/raft
net_transport.go
returnConn
func (n *NetworkTransport) returnConn(conn *netConn) { n.connPoolLock.Lock() defer n.connPoolLock.Unlock() key := conn.target conns, _ := n.connPool[key] if !n.IsShutdown() && len(conns) < n.maxPool { n.connPool[key] = append(conns, conn) } else { conn.Release() } }
go
func (n *NetworkTransport) returnConn(conn *netConn) { n.connPoolLock.Lock() defer n.connPoolLock.Unlock() key := conn.target conns, _ := n.connPool[key] if !n.IsShutdown() && len(conns) < n.maxPool { n.connPool[key] = append(conns, conn) } else { conn.Release() } }
[ "func", "(", "n", "*", "NetworkTransport", ")", "returnConn", "(", "conn", "*", "netConn", ")", "{", "n", ".", "connPoolLock", ".", "Lock", "(", ")", "\n", "defer", "n", ".", "connPoolLock", ".", "Unlock", "(", ")", "\n", "key", ":=", "conn", ".", ...
// returnConn returns a connection back to the pool.
[ "returnConn", "returns", "a", "connection", "back", "to", "the", "pool", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/net_transport.go#L350-L362
test
hashicorp/raft
net_transport.go
listen
func (n *NetworkTransport) listen() { const baseDelay = 5 * time.Millisecond const maxDelay = 1 * time.Second var loopDelay time.Duration for { // Accept incoming connections conn, err := n.stream.Accept() if err != nil { if loopDelay == 0 { loopDelay = baseDelay } else { loopDelay *= 2 } ...
go
func (n *NetworkTransport) listen() { const baseDelay = 5 * time.Millisecond const maxDelay = 1 * time.Second var loopDelay time.Duration for { // Accept incoming connections conn, err := n.stream.Accept() if err != nil { if loopDelay == 0 { loopDelay = baseDelay } else { loopDelay *= 2 } ...
[ "func", "(", "n", "*", "NetworkTransport", ")", "listen", "(", ")", "{", "const", "baseDelay", "=", "5", "*", "time", ".", "Millisecond", "\n", "const", "maxDelay", "=", "1", "*", "time", ".", "Second", "\n", "var", "loopDelay", "time", ".", "Duration"...
// listen is used to handling incoming connections.
[ "listen", "is", "used", "to", "handling", "incoming", "connections", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/net_transport.go#L463-L501
test
hashicorp/raft
net_transport.go
handleConn
func (n *NetworkTransport) handleConn(connCtx context.Context, conn net.Conn) { defer conn.Close() r := bufio.NewReader(conn) w := bufio.NewWriter(conn) dec := codec.NewDecoder(r, &codec.MsgpackHandle{}) enc := codec.NewEncoder(w, &codec.MsgpackHandle{}) for { select { case <-connCtx.Done(): n.logger.Prin...
go
func (n *NetworkTransport) handleConn(connCtx context.Context, conn net.Conn) { defer conn.Close() r := bufio.NewReader(conn) w := bufio.NewWriter(conn) dec := codec.NewDecoder(r, &codec.MsgpackHandle{}) enc := codec.NewEncoder(w, &codec.MsgpackHandle{}) for { select { case <-connCtx.Done(): n.logger.Prin...
[ "func", "(", "n", "*", "NetworkTransport", ")", "handleConn", "(", "connCtx", "context", ".", "Context", ",", "conn", "net", ".", "Conn", ")", "{", "defer", "conn", ".", "Close", "(", ")", "\n", "r", ":=", "bufio", ".", "NewReader", "(", "conn", ")",...
// handleConn is used to handle an inbound connection for its lifespan. The // handler will exit when the passed context is cancelled or the connection is // closed.
[ "handleConn", "is", "used", "to", "handle", "an", "inbound", "connection", "for", "its", "lifespan", ".", "The", "handler", "will", "exit", "when", "the", "passed", "context", "is", "cancelled", "or", "the", "connection", "is", "closed", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/net_transport.go#L506-L532
test
hashicorp/raft
net_transport.go
handleCommand
func (n *NetworkTransport) handleCommand(r *bufio.Reader, dec *codec.Decoder, enc *codec.Encoder) error { // Get the rpc type rpcType, err := r.ReadByte() if err != nil { return err } // Create the RPC object respCh := make(chan RPCResponse, 1) rpc := RPC{ RespChan: respCh, } // Decode the command isHea...
go
func (n *NetworkTransport) handleCommand(r *bufio.Reader, dec *codec.Decoder, enc *codec.Encoder) error { // Get the rpc type rpcType, err := r.ReadByte() if err != nil { return err } // Create the RPC object respCh := make(chan RPCResponse, 1) rpc := RPC{ RespChan: respCh, } // Decode the command isHea...
[ "func", "(", "n", "*", "NetworkTransport", ")", "handleCommand", "(", "r", "*", "bufio", ".", "Reader", ",", "dec", "*", "codec", ".", "Decoder", ",", "enc", "*", "codec", ".", "Encoder", ")", "error", "{", "rpcType", ",", "err", ":=", "r", ".", "R...
// handleCommand is used to decode and dispatch a single command.
[ "handleCommand", "is", "used", "to", "decode", "and", "dispatch", "a", "single", "command", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/net_transport.go#L535-L623
test
hashicorp/raft
net_transport.go
decodeResponse
func decodeResponse(conn *netConn, resp interface{}) (bool, error) { // Decode the error if any var rpcError string if err := conn.dec.Decode(&rpcError); err != nil { conn.Release() return false, err } // Decode the response if err := conn.dec.Decode(resp); err != nil { conn.Release() return false, err ...
go
func decodeResponse(conn *netConn, resp interface{}) (bool, error) { // Decode the error if any var rpcError string if err := conn.dec.Decode(&rpcError); err != nil { conn.Release() return false, err } // Decode the response if err := conn.dec.Decode(resp); err != nil { conn.Release() return false, err ...
[ "func", "decodeResponse", "(", "conn", "*", "netConn", ",", "resp", "interface", "{", "}", ")", "(", "bool", ",", "error", ")", "{", "var", "rpcError", "string", "\n", "if", "err", ":=", "conn", ".", "dec", ".", "Decode", "(", "&", "rpcError", ")", ...
// decodeResponse is used to decode an RPC response and reports whether // the connection can be reused.
[ "decodeResponse", "is", "used", "to", "decode", "an", "RPC", "response", "and", "reports", "whether", "the", "connection", "can", "be", "reused", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/net_transport.go#L627-L646
test
hashicorp/raft
net_transport.go
sendRPC
func sendRPC(conn *netConn, rpcType uint8, args interface{}) error { // Write the request type if err := conn.w.WriteByte(rpcType); err != nil { conn.Release() return err } // Send the request if err := conn.enc.Encode(args); err != nil { conn.Release() return err } // Flush if err := conn.w.Flush(); ...
go
func sendRPC(conn *netConn, rpcType uint8, args interface{}) error { // Write the request type if err := conn.w.WriteByte(rpcType); err != nil { conn.Release() return err } // Send the request if err := conn.enc.Encode(args); err != nil { conn.Release() return err } // Flush if err := conn.w.Flush(); ...
[ "func", "sendRPC", "(", "conn", "*", "netConn", ",", "rpcType", "uint8", ",", "args", "interface", "{", "}", ")", "error", "{", "if", "err", ":=", "conn", ".", "w", ".", "WriteByte", "(", "rpcType", ")", ";", "err", "!=", "nil", "{", "conn", ".", ...
// sendRPC is used to encode and send the RPC.
[ "sendRPC", "is", "used", "to", "encode", "and", "send", "the", "RPC", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/net_transport.go#L649-L668
test
hashicorp/raft
net_transport.go
newNetPipeline
func newNetPipeline(trans *NetworkTransport, conn *netConn) *netPipeline { n := &netPipeline{ conn: conn, trans: trans, doneCh: make(chan AppendFuture, rpcMaxPipeline), inprogressCh: make(chan *appendFuture, rpcMaxPipeline), shutdownCh: make(chan struct{}), } go n.decodeResponses() ...
go
func newNetPipeline(trans *NetworkTransport, conn *netConn) *netPipeline { n := &netPipeline{ conn: conn, trans: trans, doneCh: make(chan AppendFuture, rpcMaxPipeline), inprogressCh: make(chan *appendFuture, rpcMaxPipeline), shutdownCh: make(chan struct{}), } go n.decodeResponses() ...
[ "func", "newNetPipeline", "(", "trans", "*", "NetworkTransport", ",", "conn", "*", "netConn", ")", "*", "netPipeline", "{", "n", ":=", "&", "netPipeline", "{", "conn", ":", "conn", ",", "trans", ":", "trans", ",", "doneCh", ":", "make", "(", "chan", "A...
// newNetPipeline is used to construct a netPipeline from a given // transport and connection.
[ "newNetPipeline", "is", "used", "to", "construct", "a", "netPipeline", "from", "a", "given", "transport", "and", "connection", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/net_transport.go#L672-L682
test
hashicorp/raft
net_transport.go
decodeResponses
func (n *netPipeline) decodeResponses() { timeout := n.trans.timeout for { select { case future := <-n.inprogressCh: if timeout > 0 { n.conn.conn.SetReadDeadline(time.Now().Add(timeout)) } _, err := decodeResponse(n.conn, future.resp) future.respond(err) select { case n.doneCh <- future: ...
go
func (n *netPipeline) decodeResponses() { timeout := n.trans.timeout for { select { case future := <-n.inprogressCh: if timeout > 0 { n.conn.conn.SetReadDeadline(time.Now().Add(timeout)) } _, err := decodeResponse(n.conn, future.resp) future.respond(err) select { case n.doneCh <- future: ...
[ "func", "(", "n", "*", "netPipeline", ")", "decodeResponses", "(", ")", "{", "timeout", ":=", "n", ".", "trans", ".", "timeout", "\n", "for", "{", "select", "{", "case", "future", ":=", "<-", "n", ".", "inprogressCh", ":", "if", "timeout", ">", "0", ...
// decodeResponses is a long running routine that decodes the responses // sent on the connection.
[ "decodeResponses", "is", "a", "long", "running", "routine", "that", "decodes", "the", "responses", "sent", "on", "the", "connection", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/net_transport.go#L686-L706
test
hashicorp/raft
net_transport.go
AppendEntries
func (n *netPipeline) AppendEntries(args *AppendEntriesRequest, resp *AppendEntriesResponse) (AppendFuture, error) { // Create a new future future := &appendFuture{ start: time.Now(), args: args, resp: resp, } future.init() // Add a send timeout if timeout := n.trans.timeout; timeout > 0 { n.conn.conn....
go
func (n *netPipeline) AppendEntries(args *AppendEntriesRequest, resp *AppendEntriesResponse) (AppendFuture, error) { // Create a new future future := &appendFuture{ start: time.Now(), args: args, resp: resp, } future.init() // Add a send timeout if timeout := n.trans.timeout; timeout > 0 { n.conn.conn....
[ "func", "(", "n", "*", "netPipeline", ")", "AppendEntries", "(", "args", "*", "AppendEntriesRequest", ",", "resp", "*", "AppendEntriesResponse", ")", "(", "AppendFuture", ",", "error", ")", "{", "future", ":=", "&", "appendFuture", "{", "start", ":", "time",...
// AppendEntries is used to pipeline a new append entries request.
[ "AppendEntries", "is", "used", "to", "pipeline", "a", "new", "append", "entries", "request", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/net_transport.go#L709-L736
test
hashicorp/raft
net_transport.go
Close
func (n *netPipeline) Close() error { n.shutdownLock.Lock() defer n.shutdownLock.Unlock() if n.shutdown { return nil } // Release the connection n.conn.Release() n.shutdown = true close(n.shutdownCh) return nil }
go
func (n *netPipeline) Close() error { n.shutdownLock.Lock() defer n.shutdownLock.Unlock() if n.shutdown { return nil } // Release the connection n.conn.Release() n.shutdown = true close(n.shutdownCh) return nil }
[ "func", "(", "n", "*", "netPipeline", ")", "Close", "(", ")", "error", "{", "n", ".", "shutdownLock", ".", "Lock", "(", ")", "\n", "defer", "n", ".", "shutdownLock", ".", "Unlock", "(", ")", "\n", "if", "n", ".", "shutdown", "{", "return", "nil", ...
// Closed is used to shutdown the pipeline connection.
[ "Closed", "is", "used", "to", "shutdown", "the", "pipeline", "connection", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/net_transport.go#L744-L757
test
hashicorp/raft
observer.go
NewObserver
func NewObserver(channel chan Observation, blocking bool, filter FilterFn) *Observer { return &Observer{ channel: channel, blocking: blocking, filter: filter, id: atomic.AddUint64(&nextObserverID, 1), } }
go
func NewObserver(channel chan Observation, blocking bool, filter FilterFn) *Observer { return &Observer{ channel: channel, blocking: blocking, filter: filter, id: atomic.AddUint64(&nextObserverID, 1), } }
[ "func", "NewObserver", "(", "channel", "chan", "Observation", ",", "blocking", "bool", ",", "filter", "FilterFn", ")", "*", "Observer", "{", "return", "&", "Observer", "{", "channel", ":", "channel", ",", "blocking", ":", "blocking", ",", "filter", ":", "f...
// NewObserver creates a new observer that can be registered // to make observations on a Raft instance. Observations // will be sent on the given channel if they satisfy the // given filter. // // If blocking is true, the observer will block when it can't // send on the channel, otherwise it may discard events.
[ "NewObserver", "creates", "a", "new", "observer", "that", "can", "be", "registered", "to", "make", "observations", "on", "a", "Raft", "instance", ".", "Observations", "will", "be", "sent", "on", "the", "given", "channel", "if", "they", "satisfy", "the", "giv...
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/observer.go#L60-L67
test
hashicorp/raft
observer.go
RegisterObserver
func (r *Raft) RegisterObserver(or *Observer) { r.observersLock.Lock() defer r.observersLock.Unlock() r.observers[or.id] = or }
go
func (r *Raft) RegisterObserver(or *Observer) { r.observersLock.Lock() defer r.observersLock.Unlock() r.observers[or.id] = or }
[ "func", "(", "r", "*", "Raft", ")", "RegisterObserver", "(", "or", "*", "Observer", ")", "{", "r", ".", "observersLock", ".", "Lock", "(", ")", "\n", "defer", "r", ".", "observersLock", ".", "Unlock", "(", ")", "\n", "r", ".", "observers", "[", "or...
// RegisterObserver registers a new observer.
[ "RegisterObserver", "registers", "a", "new", "observer", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/observer.go#L80-L84
test
hashicorp/raft
observer.go
DeregisterObserver
func (r *Raft) DeregisterObserver(or *Observer) { r.observersLock.Lock() defer r.observersLock.Unlock() delete(r.observers, or.id) }
go
func (r *Raft) DeregisterObserver(or *Observer) { r.observersLock.Lock() defer r.observersLock.Unlock() delete(r.observers, or.id) }
[ "func", "(", "r", "*", "Raft", ")", "DeregisterObserver", "(", "or", "*", "Observer", ")", "{", "r", ".", "observersLock", ".", "Lock", "(", ")", "\n", "defer", "r", ".", "observersLock", ".", "Unlock", "(", ")", "\n", "delete", "(", "r", ".", "obs...
// DeregisterObserver deregisters an observer.
[ "DeregisterObserver", "deregisters", "an", "observer", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/observer.go#L87-L91
test
hashicorp/raft
observer.go
observe
func (r *Raft) observe(o interface{}) { // In general observers should not block. But in any case this isn't // disastrous as we only hold a read lock, which merely prevents // registration / deregistration of observers. r.observersLock.RLock() defer r.observersLock.RUnlock() for _, or := range r.observers { //...
go
func (r *Raft) observe(o interface{}) { // In general observers should not block. But in any case this isn't // disastrous as we only hold a read lock, which merely prevents // registration / deregistration of observers. r.observersLock.RLock() defer r.observersLock.RUnlock() for _, or := range r.observers { //...
[ "func", "(", "r", "*", "Raft", ")", "observe", "(", "o", "interface", "{", "}", ")", "{", "r", ".", "observersLock", ".", "RLock", "(", ")", "\n", "defer", "r", ".", "observersLock", ".", "RUnlock", "(", ")", "\n", "for", "_", ",", "or", ":=", ...
// observe sends an observation to every observer.
[ "observe", "sends", "an", "observation", "to", "every", "observer", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/observer.go#L94-L122
test
hashicorp/raft
inmem_store.go
NewInmemStore
func NewInmemStore() *InmemStore { i := &InmemStore{ logs: make(map[uint64]*Log), kv: make(map[string][]byte), kvInt: make(map[string]uint64), } return i }
go
func NewInmemStore() *InmemStore { i := &InmemStore{ logs: make(map[uint64]*Log), kv: make(map[string][]byte), kvInt: make(map[string]uint64), } return i }
[ "func", "NewInmemStore", "(", ")", "*", "InmemStore", "{", "i", ":=", "&", "InmemStore", "{", "logs", ":", "make", "(", "map", "[", "uint64", "]", "*", "Log", ")", ",", "kv", ":", "make", "(", "map", "[", "string", "]", "[", "]", "byte", ")", "...
// NewInmemStore returns a new in-memory backend. Do not ever // use for production. Only for testing.
[ "NewInmemStore", "returns", "a", "new", "in", "-", "memory", "backend", ".", "Do", "not", "ever", "use", "for", "production", ".", "Only", "for", "testing", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/inmem_store.go#L22-L29
test
hashicorp/raft
inmem_store.go
FirstIndex
func (i *InmemStore) FirstIndex() (uint64, error) { i.l.RLock() defer i.l.RUnlock() return i.lowIndex, nil }
go
func (i *InmemStore) FirstIndex() (uint64, error) { i.l.RLock() defer i.l.RUnlock() return i.lowIndex, nil }
[ "func", "(", "i", "*", "InmemStore", ")", "FirstIndex", "(", ")", "(", "uint64", ",", "error", ")", "{", "i", ".", "l", ".", "RLock", "(", ")", "\n", "defer", "i", ".", "l", ".", "RUnlock", "(", ")", "\n", "return", "i", ".", "lowIndex", ",", ...
// FirstIndex implements the LogStore interface.
[ "FirstIndex", "implements", "the", "LogStore", "interface", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/inmem_store.go#L32-L36
test
hashicorp/raft
inmem_store.go
LastIndex
func (i *InmemStore) LastIndex() (uint64, error) { i.l.RLock() defer i.l.RUnlock() return i.highIndex, nil }
go
func (i *InmemStore) LastIndex() (uint64, error) { i.l.RLock() defer i.l.RUnlock() return i.highIndex, nil }
[ "func", "(", "i", "*", "InmemStore", ")", "LastIndex", "(", ")", "(", "uint64", ",", "error", ")", "{", "i", ".", "l", ".", "RLock", "(", ")", "\n", "defer", "i", ".", "l", ".", "RUnlock", "(", ")", "\n", "return", "i", ".", "highIndex", ",", ...
// LastIndex implements the LogStore interface.
[ "LastIndex", "implements", "the", "LogStore", "interface", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/inmem_store.go#L39-L43
test
hashicorp/raft
inmem_store.go
GetLog
func (i *InmemStore) GetLog(index uint64, log *Log) error { i.l.RLock() defer i.l.RUnlock() l, ok := i.logs[index] if !ok { return ErrLogNotFound } *log = *l return nil }
go
func (i *InmemStore) GetLog(index uint64, log *Log) error { i.l.RLock() defer i.l.RUnlock() l, ok := i.logs[index] if !ok { return ErrLogNotFound } *log = *l return nil }
[ "func", "(", "i", "*", "InmemStore", ")", "GetLog", "(", "index", "uint64", ",", "log", "*", "Log", ")", "error", "{", "i", ".", "l", ".", "RLock", "(", ")", "\n", "defer", "i", ".", "l", ".", "RUnlock", "(", ")", "\n", "l", ",", "ok", ":=", ...
// GetLog implements the LogStore interface.
[ "GetLog", "implements", "the", "LogStore", "interface", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/inmem_store.go#L46-L55
test
hashicorp/raft
inmem_store.go
StoreLog
func (i *InmemStore) StoreLog(log *Log) error { return i.StoreLogs([]*Log{log}) }
go
func (i *InmemStore) StoreLog(log *Log) error { return i.StoreLogs([]*Log{log}) }
[ "func", "(", "i", "*", "InmemStore", ")", "StoreLog", "(", "log", "*", "Log", ")", "error", "{", "return", "i", ".", "StoreLogs", "(", "[", "]", "*", "Log", "{", "log", "}", ")", "\n", "}" ]
// StoreLog implements the LogStore interface.
[ "StoreLog", "implements", "the", "LogStore", "interface", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/inmem_store.go#L58-L60
test
hashicorp/raft
inmem_store.go
StoreLogs
func (i *InmemStore) StoreLogs(logs []*Log) error { i.l.Lock() defer i.l.Unlock() for _, l := range logs { i.logs[l.Index] = l if i.lowIndex == 0 { i.lowIndex = l.Index } if l.Index > i.highIndex { i.highIndex = l.Index } } return nil }
go
func (i *InmemStore) StoreLogs(logs []*Log) error { i.l.Lock() defer i.l.Unlock() for _, l := range logs { i.logs[l.Index] = l if i.lowIndex == 0 { i.lowIndex = l.Index } if l.Index > i.highIndex { i.highIndex = l.Index } } return nil }
[ "func", "(", "i", "*", "InmemStore", ")", "StoreLogs", "(", "logs", "[", "]", "*", "Log", ")", "error", "{", "i", ".", "l", ".", "Lock", "(", ")", "\n", "defer", "i", ".", "l", ".", "Unlock", "(", ")", "\n", "for", "_", ",", "l", ":=", "ran...
// StoreLogs implements the LogStore interface.
[ "StoreLogs", "implements", "the", "LogStore", "interface", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/inmem_store.go#L63-L76
test
hashicorp/raft
inmem_store.go
DeleteRange
func (i *InmemStore) DeleteRange(min, max uint64) error { i.l.Lock() defer i.l.Unlock() for j := min; j <= max; j++ { delete(i.logs, j) } if min <= i.lowIndex { i.lowIndex = max + 1 } if max >= i.highIndex { i.highIndex = min - 1 } if i.lowIndex > i.highIndex { i.lowIndex = 0 i.highIndex = 0 } retu...
go
func (i *InmemStore) DeleteRange(min, max uint64) error { i.l.Lock() defer i.l.Unlock() for j := min; j <= max; j++ { delete(i.logs, j) } if min <= i.lowIndex { i.lowIndex = max + 1 } if max >= i.highIndex { i.highIndex = min - 1 } if i.lowIndex > i.highIndex { i.lowIndex = 0 i.highIndex = 0 } retu...
[ "func", "(", "i", "*", "InmemStore", ")", "DeleteRange", "(", "min", ",", "max", "uint64", ")", "error", "{", "i", ".", "l", ".", "Lock", "(", ")", "\n", "defer", "i", ".", "l", ".", "Unlock", "(", ")", "\n", "for", "j", ":=", "min", ";", "j"...
// DeleteRange implements the LogStore interface.
[ "DeleteRange", "implements", "the", "LogStore", "interface", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/inmem_store.go#L79-L96
test
hashicorp/raft
inmem_store.go
Set
func (i *InmemStore) Set(key []byte, val []byte) error { i.l.Lock() defer i.l.Unlock() i.kv[string(key)] = val return nil }
go
func (i *InmemStore) Set(key []byte, val []byte) error { i.l.Lock() defer i.l.Unlock() i.kv[string(key)] = val return nil }
[ "func", "(", "i", "*", "InmemStore", ")", "Set", "(", "key", "[", "]", "byte", ",", "val", "[", "]", "byte", ")", "error", "{", "i", ".", "l", ".", "Lock", "(", ")", "\n", "defer", "i", ".", "l", ".", "Unlock", "(", ")", "\n", "i", ".", "...
// Set implements the StableStore interface.
[ "Set", "implements", "the", "StableStore", "interface", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/inmem_store.go#L99-L104
test
hashicorp/raft
inmem_store.go
Get
func (i *InmemStore) Get(key []byte) ([]byte, error) { i.l.RLock() defer i.l.RUnlock() val := i.kv[string(key)] if val == nil { return nil, errors.New("not found") } return val, nil }
go
func (i *InmemStore) Get(key []byte) ([]byte, error) { i.l.RLock() defer i.l.RUnlock() val := i.kv[string(key)] if val == nil { return nil, errors.New("not found") } return val, nil }
[ "func", "(", "i", "*", "InmemStore", ")", "Get", "(", "key", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "i", ".", "l", ".", "RLock", "(", ")", "\n", "defer", "i", ".", "l", ".", "RUnlock", "(", ")", "\n", "val", ...
// Get implements the StableStore interface.
[ "Get", "implements", "the", "StableStore", "interface", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/inmem_store.go#L107-L115
test
hashicorp/raft
inmem_store.go
SetUint64
func (i *InmemStore) SetUint64(key []byte, val uint64) error { i.l.Lock() defer i.l.Unlock() i.kvInt[string(key)] = val return nil }
go
func (i *InmemStore) SetUint64(key []byte, val uint64) error { i.l.Lock() defer i.l.Unlock() i.kvInt[string(key)] = val return nil }
[ "func", "(", "i", "*", "InmemStore", ")", "SetUint64", "(", "key", "[", "]", "byte", ",", "val", "uint64", ")", "error", "{", "i", ".", "l", ".", "Lock", "(", ")", "\n", "defer", "i", ".", "l", ".", "Unlock", "(", ")", "\n", "i", ".", "kvInt"...
// SetUint64 implements the StableStore interface.
[ "SetUint64", "implements", "the", "StableStore", "interface", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/inmem_store.go#L118-L123
test
hashicorp/raft
inmem_store.go
GetUint64
func (i *InmemStore) GetUint64(key []byte) (uint64, error) { i.l.RLock() defer i.l.RUnlock() return i.kvInt[string(key)], nil }
go
func (i *InmemStore) GetUint64(key []byte) (uint64, error) { i.l.RLock() defer i.l.RUnlock() return i.kvInt[string(key)], nil }
[ "func", "(", "i", "*", "InmemStore", ")", "GetUint64", "(", "key", "[", "]", "byte", ")", "(", "uint64", ",", "error", ")", "{", "i", ".", "l", ".", "RLock", "(", ")", "\n", "defer", "i", ".", "l", ".", "RUnlock", "(", ")", "\n", "return", "i...
// GetUint64 implements the StableStore interface.
[ "GetUint64", "implements", "the", "StableStore", "interface", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/inmem_store.go#L126-L130
test
hashicorp/raft
log_cache.go
NewLogCache
func NewLogCache(capacity int, store LogStore) (*LogCache, error) { if capacity <= 0 { return nil, fmt.Errorf("capacity must be positive") } c := &LogCache{ store: store, cache: make([]*Log, capacity), } return c, nil }
go
func NewLogCache(capacity int, store LogStore) (*LogCache, error) { if capacity <= 0 { return nil, fmt.Errorf("capacity must be positive") } c := &LogCache{ store: store, cache: make([]*Log, capacity), } return c, nil }
[ "func", "NewLogCache", "(", "capacity", "int", ",", "store", "LogStore", ")", "(", "*", "LogCache", ",", "error", ")", "{", "if", "capacity", "<=", "0", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"capacity must be positive\"", ")", "\n", "}"...
// NewLogCache is used to create a new LogCache with the // given capacity and backend store.
[ "NewLogCache", "is", "used", "to", "create", "a", "new", "LogCache", "with", "the", "given", "capacity", "and", "backend", "store", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/log_cache.go#L22-L31
test
hashicorp/raft
inmem_transport.go
Connect
func (i *InmemTransport) Connect(peer ServerAddress, t Transport) { trans := t.(*InmemTransport) i.Lock() defer i.Unlock() i.peers[peer] = trans }
go
func (i *InmemTransport) Connect(peer ServerAddress, t Transport) { trans := t.(*InmemTransport) i.Lock() defer i.Unlock() i.peers[peer] = trans }
[ "func", "(", "i", "*", "InmemTransport", ")", "Connect", "(", "peer", "ServerAddress", ",", "t", "Transport", ")", "{", "trans", ":=", "t", ".", "(", "*", "InmemTransport", ")", "\n", "i", ".", "Lock", "(", ")", "\n", "defer", "i", ".", "Unlock", "...
// Connect is used to connect this transport to another transport for // a given peer name. This allows for local routing.
[ "Connect", "is", "used", "to", "connect", "this", "transport", "to", "another", "transport", "for", "a", "given", "peer", "name", ".", "This", "allows", "for", "local", "routing", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/inmem_transport.go#L186-L191
test
hashicorp/raft
inmem_transport.go
Disconnect
func (i *InmemTransport) Disconnect(peer ServerAddress) { i.Lock() defer i.Unlock() delete(i.peers, peer) // Disconnect any pipelines n := len(i.pipelines) for idx := 0; idx < n; idx++ { if i.pipelines[idx].peerAddr == peer { i.pipelines[idx].Close() i.pipelines[idx], i.pipelines[n-1] = i.pipelines[n-1],...
go
func (i *InmemTransport) Disconnect(peer ServerAddress) { i.Lock() defer i.Unlock() delete(i.peers, peer) // Disconnect any pipelines n := len(i.pipelines) for idx := 0; idx < n; idx++ { if i.pipelines[idx].peerAddr == peer { i.pipelines[idx].Close() i.pipelines[idx], i.pipelines[n-1] = i.pipelines[n-1],...
[ "func", "(", "i", "*", "InmemTransport", ")", "Disconnect", "(", "peer", "ServerAddress", ")", "{", "i", ".", "Lock", "(", ")", "\n", "defer", "i", ".", "Unlock", "(", ")", "\n", "delete", "(", "i", ".", "peers", ",", "peer", ")", "\n", "n", ":="...
// Disconnect is used to remove the ability to route to a given peer.
[ "Disconnect", "is", "used", "to", "remove", "the", "ability", "to", "route", "to", "a", "given", "peer", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/inmem_transport.go#L194-L210
test
hashicorp/raft
inmem_transport.go
DisconnectAll
func (i *InmemTransport) DisconnectAll() { i.Lock() defer i.Unlock() i.peers = make(map[ServerAddress]*InmemTransport) // Handle pipelines for _, pipeline := range i.pipelines { pipeline.Close() } i.pipelines = nil }
go
func (i *InmemTransport) DisconnectAll() { i.Lock() defer i.Unlock() i.peers = make(map[ServerAddress]*InmemTransport) // Handle pipelines for _, pipeline := range i.pipelines { pipeline.Close() } i.pipelines = nil }
[ "func", "(", "i", "*", "InmemTransport", ")", "DisconnectAll", "(", ")", "{", "i", ".", "Lock", "(", ")", "\n", "defer", "i", ".", "Unlock", "(", ")", "\n", "i", ".", "peers", "=", "make", "(", "map", "[", "ServerAddress", "]", "*", "InmemTransport...
// DisconnectAll is used to remove all routes to peers.
[ "DisconnectAll", "is", "used", "to", "remove", "all", "routes", "to", "peers", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/inmem_transport.go#L213-L223
test
hashicorp/raft
transport.go
Respond
func (r *RPC) Respond(resp interface{}, err error) { r.RespChan <- RPCResponse{resp, err} }
go
func (r *RPC) Respond(resp interface{}, err error) { r.RespChan <- RPCResponse{resp, err} }
[ "func", "(", "r", "*", "RPC", ")", "Respond", "(", "resp", "interface", "{", "}", ",", "err", "error", ")", "{", "r", ".", "RespChan", "<-", "RPCResponse", "{", "resp", ",", "err", "}", "\n", "}" ]
// Respond is used to respond with a response, error or both
[ "Respond", "is", "used", "to", "respond", "with", "a", "response", "error", "or", "both" ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/transport.go#L22-L24
test
hashicorp/raft
future.go
Open
func (u *userSnapshotFuture) Open() (*SnapshotMeta, io.ReadCloser, error) { if u.opener == nil { return nil, nil, fmt.Errorf("no snapshot available") } else { // Invalidate the opener so it can't get called multiple times, // which isn't generally safe. defer func() { u.opener = nil }() return u.opener...
go
func (u *userSnapshotFuture) Open() (*SnapshotMeta, io.ReadCloser, error) { if u.opener == nil { return nil, nil, fmt.Errorf("no snapshot available") } else { // Invalidate the opener so it can't get called multiple times, // which isn't generally safe. defer func() { u.opener = nil }() return u.opener...
[ "func", "(", "u", "*", "userSnapshotFuture", ")", "Open", "(", ")", "(", "*", "SnapshotMeta", ",", "io", ".", "ReadCloser", ",", "error", ")", "{", "if", "u", ".", "opener", "==", "nil", "{", "return", "nil", ",", "nil", ",", "fmt", ".", "Errorf", ...
// Open is a function you can call to access the underlying snapshot and its // metadata.
[ "Open", "is", "a", "function", "you", "can", "call", "to", "access", "the", "underlying", "snapshot", "and", "its", "metadata", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/future.go#L177-L188
test
hashicorp/raft
future.go
vote
func (v *verifyFuture) vote(leader bool) { v.voteLock.Lock() defer v.voteLock.Unlock() // Guard against having notified already if v.notifyCh == nil { return } if leader { v.votes++ if v.votes >= v.quorumSize { v.notifyCh <- v v.notifyCh = nil } } else { v.notifyCh <- v v.notifyCh = nil } }
go
func (v *verifyFuture) vote(leader bool) { v.voteLock.Lock() defer v.voteLock.Unlock() // Guard against having notified already if v.notifyCh == nil { return } if leader { v.votes++ if v.votes >= v.quorumSize { v.notifyCh <- v v.notifyCh = nil } } else { v.notifyCh <- v v.notifyCh = nil } }
[ "func", "(", "v", "*", "verifyFuture", ")", "vote", "(", "leader", "bool", ")", "{", "v", ".", "voteLock", ".", "Lock", "(", ")", "\n", "defer", "v", ".", "voteLock", ".", "Unlock", "(", ")", "\n", "if", "v", ".", "notifyCh", "==", "nil", "{", ...
// vote is used to respond to a verifyFuture. // This may block when responding on the notifyCh.
[ "vote", "is", "used", "to", "respond", "to", "a", "verifyFuture", ".", "This", "may", "block", "when", "responding", "on", "the", "notifyCh", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/future.go#L249-L268
test
hashicorp/raft
replication.go
notifyAll
func (s *followerReplication) notifyAll(leader bool) { // Clear the waiting notifies minimizing lock time s.notifyLock.Lock() n := s.notify s.notify = make(map[*verifyFuture]struct{}) s.notifyLock.Unlock() // Submit our votes for v, _ := range n { v.vote(leader) } }
go
func (s *followerReplication) notifyAll(leader bool) { // Clear the waiting notifies minimizing lock time s.notifyLock.Lock() n := s.notify s.notify = make(map[*verifyFuture]struct{}) s.notifyLock.Unlock() // Submit our votes for v, _ := range n { v.vote(leader) } }
[ "func", "(", "s", "*", "followerReplication", ")", "notifyAll", "(", "leader", "bool", ")", "{", "s", ".", "notifyLock", ".", "Lock", "(", ")", "\n", "n", ":=", "s", ".", "notify", "\n", "s", ".", "notify", "=", "make", "(", "map", "[", "*", "ver...
// notifyAll is used to notify all the waiting verify futures // if the follower believes we are still the leader.
[ "notifyAll", "is", "used", "to", "notify", "all", "the", "waiting", "verify", "futures", "if", "the", "follower", "believes", "we", "are", "still", "the", "leader", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/replication.go#L84-L95
test
hashicorp/raft
replication.go
cleanNotify
func (s *followerReplication) cleanNotify(v *verifyFuture) { s.notifyLock.Lock() delete(s.notify, v) s.notifyLock.Unlock() }
go
func (s *followerReplication) cleanNotify(v *verifyFuture) { s.notifyLock.Lock() delete(s.notify, v) s.notifyLock.Unlock() }
[ "func", "(", "s", "*", "followerReplication", ")", "cleanNotify", "(", "v", "*", "verifyFuture", ")", "{", "s", ".", "notifyLock", ".", "Lock", "(", ")", "\n", "delete", "(", "s", ".", "notify", ",", "v", ")", "\n", "s", ".", "notifyLock", ".", "Un...
// cleanNotify is used to delete notify, .
[ "cleanNotify", "is", "used", "to", "delete", "notify", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/replication.go#L98-L102
test
hashicorp/raft
replication.go
LastContact
func (s *followerReplication) LastContact() time.Time { s.lastContactLock.RLock() last := s.lastContact s.lastContactLock.RUnlock() return last }
go
func (s *followerReplication) LastContact() time.Time { s.lastContactLock.RLock() last := s.lastContact s.lastContactLock.RUnlock() return last }
[ "func", "(", "s", "*", "followerReplication", ")", "LastContact", "(", ")", "time", ".", "Time", "{", "s", ".", "lastContactLock", ".", "RLock", "(", ")", "\n", "last", ":=", "s", ".", "lastContact", "\n", "s", ".", "lastContactLock", ".", "RUnlock", "...
// LastContact returns the time of last contact.
[ "LastContact", "returns", "the", "time", "of", "last", "contact", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/replication.go#L105-L110
test
hashicorp/raft
replication.go
setLastContact
func (s *followerReplication) setLastContact() { s.lastContactLock.Lock() s.lastContact = time.Now() s.lastContactLock.Unlock() }
go
func (s *followerReplication) setLastContact() { s.lastContactLock.Lock() s.lastContact = time.Now() s.lastContactLock.Unlock() }
[ "func", "(", "s", "*", "followerReplication", ")", "setLastContact", "(", ")", "{", "s", ".", "lastContactLock", ".", "Lock", "(", ")", "\n", "s", ".", "lastContact", "=", "time", ".", "Now", "(", ")", "\n", "s", ".", "lastContactLock", ".", "Unlock", ...
// setLastContact sets the last contact to the current time.
[ "setLastContact", "sets", "the", "last", "contact", "to", "the", "current", "time", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/replication.go#L113-L117
test
hashicorp/raft
replication.go
replicate
func (r *Raft) replicate(s *followerReplication) { // Start an async heartbeating routing stopHeartbeat := make(chan struct{}) defer close(stopHeartbeat) r.goFunc(func() { r.heartbeat(s, stopHeartbeat) }) RPC: shouldStop := false for !shouldStop { select { case maxIndex := <-s.stopCh: // Make a best effor...
go
func (r *Raft) replicate(s *followerReplication) { // Start an async heartbeating routing stopHeartbeat := make(chan struct{}) defer close(stopHeartbeat) r.goFunc(func() { r.heartbeat(s, stopHeartbeat) }) RPC: shouldStop := false for !shouldStop { select { case maxIndex := <-s.stopCh: // Make a best effor...
[ "func", "(", "r", "*", "Raft", ")", "replicate", "(", "s", "*", "followerReplication", ")", "{", "stopHeartbeat", ":=", "make", "(", "chan", "struct", "{", "}", ")", "\n", "defer", "close", "(", "stopHeartbeat", ")", "\n", "r", ".", "goFunc", "(", "f...
// replicate is a long running routine that replicates log entries to a single // follower.
[ "replicate", "is", "a", "long", "running", "routine", "that", "replicates", "log", "entries", "to", "a", "single", "follower", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/replication.go#L121-L170
test
hashicorp/raft
replication.go
pipelineReplicate
func (r *Raft) pipelineReplicate(s *followerReplication) error { // Create a new pipeline pipeline, err := r.trans.AppendEntriesPipeline(s.peer.ID, s.peer.Address) if err != nil { return err } defer pipeline.Close() // Log start and stop of pipeline r.logger.Info(fmt.Sprintf("pipelining replication to peer %v...
go
func (r *Raft) pipelineReplicate(s *followerReplication) error { // Create a new pipeline pipeline, err := r.trans.AppendEntriesPipeline(s.peer.ID, s.peer.Address) if err != nil { return err } defer pipeline.Close() // Log start and stop of pipeline r.logger.Info(fmt.Sprintf("pipelining replication to peer %v...
[ "func", "(", "r", "*", "Raft", ")", "pipelineReplicate", "(", "s", "*", "followerReplication", ")", "error", "{", "pipeline", ",", "err", ":=", "r", ".", "trans", ".", "AppendEntriesPipeline", "(", "s", ".", "peer", ".", "ID", ",", "s", ".", "peer", ...
// pipelineReplicate is used when we have synchronized our state with the follower, // and want to switch to a higher performance pipeline mode of replication. // We only pipeline AppendEntries commands, and if we ever hit an error, we fall // back to the standard replication which can handle more complex situations.
[ "pipelineReplicate", "is", "used", "when", "we", "have", "synchronized", "our", "state", "with", "the", "follower", "and", "want", "to", "switch", "to", "a", "higher", "performance", "pipeline", "mode", "of", "replication", ".", "We", "only", "pipeline", "Appe...
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/replication.go#L380-L430
test
hashicorp/raft
replication.go
pipelineSend
func (r *Raft) pipelineSend(s *followerReplication, p AppendPipeline, nextIdx *uint64, lastIndex uint64) (shouldStop bool) { // Create a new append request req := new(AppendEntriesRequest) if err := r.setupAppendEntries(s, req, *nextIdx, lastIndex); err != nil { return true } // Pipeline the append entries if ...
go
func (r *Raft) pipelineSend(s *followerReplication, p AppendPipeline, nextIdx *uint64, lastIndex uint64) (shouldStop bool) { // Create a new append request req := new(AppendEntriesRequest) if err := r.setupAppendEntries(s, req, *nextIdx, lastIndex); err != nil { return true } // Pipeline the append entries if ...
[ "func", "(", "r", "*", "Raft", ")", "pipelineSend", "(", "s", "*", "followerReplication", ",", "p", "AppendPipeline", ",", "nextIdx", "*", "uint64", ",", "lastIndex", "uint64", ")", "(", "shouldStop", "bool", ")", "{", "req", ":=", "new", "(", "AppendEnt...
// pipelineSend is used to send data over a pipeline. It is a helper to // pipelineReplicate.
[ "pipelineSend", "is", "used", "to", "send", "data", "over", "a", "pipeline", ".", "It", "is", "a", "helper", "to", "pipelineReplicate", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/replication.go#L434-L453
test
hashicorp/raft
replication.go
pipelineDecode
func (r *Raft) pipelineDecode(s *followerReplication, p AppendPipeline, stopCh, finishCh chan struct{}) { defer close(finishCh) respCh := p.Consumer() for { select { case ready := <-respCh: req, resp := ready.Request(), ready.Response() appendStats(string(s.peer.ID), ready.Start(), float32(len(req.Entries)...
go
func (r *Raft) pipelineDecode(s *followerReplication, p AppendPipeline, stopCh, finishCh chan struct{}) { defer close(finishCh) respCh := p.Consumer() for { select { case ready := <-respCh: req, resp := ready.Request(), ready.Response() appendStats(string(s.peer.ID), ready.Start(), float32(len(req.Entries)...
[ "func", "(", "r", "*", "Raft", ")", "pipelineDecode", "(", "s", "*", "followerReplication", ",", "p", "AppendPipeline", ",", "stopCh", ",", "finishCh", "chan", "struct", "{", "}", ")", "{", "defer", "close", "(", "finishCh", ")", "\n", "respCh", ":=", ...
// pipelineDecode is used to decode the responses of pipelined requests.
[ "pipelineDecode", "is", "used", "to", "decode", "the", "responses", "of", "pipelined", "requests", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/replication.go#L456-L485
test
hashicorp/raft
replication.go
setupAppendEntries
func (r *Raft) setupAppendEntries(s *followerReplication, req *AppendEntriesRequest, nextIndex, lastIndex uint64) error { req.RPCHeader = r.getRPCHeader() req.Term = s.currentTerm req.Leader = r.trans.EncodePeer(r.localID, r.localAddr) req.LeaderCommitIndex = r.getCommitIndex() if err := r.setPreviousLog(req, next...
go
func (r *Raft) setupAppendEntries(s *followerReplication, req *AppendEntriesRequest, nextIndex, lastIndex uint64) error { req.RPCHeader = r.getRPCHeader() req.Term = s.currentTerm req.Leader = r.trans.EncodePeer(r.localID, r.localAddr) req.LeaderCommitIndex = r.getCommitIndex() if err := r.setPreviousLog(req, next...
[ "func", "(", "r", "*", "Raft", ")", "setupAppendEntries", "(", "s", "*", "followerReplication", ",", "req", "*", "AppendEntriesRequest", ",", "nextIndex", ",", "lastIndex", "uint64", ")", "error", "{", "req", ".", "RPCHeader", "=", "r", ".", "getRPCHeader", ...
// setupAppendEntries is used to setup an append entries request.
[ "setupAppendEntries", "is", "used", "to", "setup", "an", "append", "entries", "request", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/replication.go#L488-L500
test
hashicorp/raft
replication.go
setPreviousLog
func (r *Raft) setPreviousLog(req *AppendEntriesRequest, nextIndex uint64) error { // Guard for the first index, since there is no 0 log entry // Guard against the previous index being a snapshot as well lastSnapIdx, lastSnapTerm := r.getLastSnapshot() if nextIndex == 1 { req.PrevLogEntry = 0 req.PrevLogTerm = ...
go
func (r *Raft) setPreviousLog(req *AppendEntriesRequest, nextIndex uint64) error { // Guard for the first index, since there is no 0 log entry // Guard against the previous index being a snapshot as well lastSnapIdx, lastSnapTerm := r.getLastSnapshot() if nextIndex == 1 { req.PrevLogEntry = 0 req.PrevLogTerm = ...
[ "func", "(", "r", "*", "Raft", ")", "setPreviousLog", "(", "req", "*", "AppendEntriesRequest", ",", "nextIndex", "uint64", ")", "error", "{", "lastSnapIdx", ",", "lastSnapTerm", ":=", "r", ".", "getLastSnapshot", "(", ")", "\n", "if", "nextIndex", "==", "1...
// setPreviousLog is used to setup the PrevLogEntry and PrevLogTerm for an // AppendEntriesRequest given the next index to replicate.
[ "setPreviousLog", "is", "used", "to", "setup", "the", "PrevLogEntry", "and", "PrevLogTerm", "for", "an", "AppendEntriesRequest", "given", "the", "next", "index", "to", "replicate", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/replication.go#L504-L528
test
hashicorp/raft
replication.go
setNewLogs
func (r *Raft) setNewLogs(req *AppendEntriesRequest, nextIndex, lastIndex uint64) error { // Append up to MaxAppendEntries or up to the lastIndex req.Entries = make([]*Log, 0, r.conf.MaxAppendEntries) maxIndex := min(nextIndex+uint64(r.conf.MaxAppendEntries)-1, lastIndex) for i := nextIndex; i <= maxIndex; i++ { ...
go
func (r *Raft) setNewLogs(req *AppendEntriesRequest, nextIndex, lastIndex uint64) error { // Append up to MaxAppendEntries or up to the lastIndex req.Entries = make([]*Log, 0, r.conf.MaxAppendEntries) maxIndex := min(nextIndex+uint64(r.conf.MaxAppendEntries)-1, lastIndex) for i := nextIndex; i <= maxIndex; i++ { ...
[ "func", "(", "r", "*", "Raft", ")", "setNewLogs", "(", "req", "*", "AppendEntriesRequest", ",", "nextIndex", ",", "lastIndex", "uint64", ")", "error", "{", "req", ".", "Entries", "=", "make", "(", "[", "]", "*", "Log", ",", "0", ",", "r", ".", "con...
// setNewLogs is used to setup the logs which should be appended for a request.
[ "setNewLogs", "is", "used", "to", "setup", "the", "logs", "which", "should", "be", "appended", "for", "a", "request", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/replication.go#L531-L544
test
hashicorp/raft
replication.go
appendStats
func appendStats(peer string, start time.Time, logs float32) { metrics.MeasureSince([]string{"raft", "replication", "appendEntries", "rpc", peer}, start) metrics.IncrCounter([]string{"raft", "replication", "appendEntries", "logs", peer}, logs) }
go
func appendStats(peer string, start time.Time, logs float32) { metrics.MeasureSince([]string{"raft", "replication", "appendEntries", "rpc", peer}, start) metrics.IncrCounter([]string{"raft", "replication", "appendEntries", "logs", peer}, logs) }
[ "func", "appendStats", "(", "peer", "string", ",", "start", "time", ".", "Time", ",", "logs", "float32", ")", "{", "metrics", ".", "MeasureSince", "(", "[", "]", "string", "{", "\"raft\"", ",", "\"replication\"", ",", "\"appendEntries\"", ",", "\"rpc\"", "...
// appendStats is used to emit stats about an AppendEntries invocation.
[ "appendStats", "is", "used", "to", "emit", "stats", "about", "an", "AppendEntries", "invocation", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/replication.go#L547-L550
test
hashicorp/raft
replication.go
handleStaleTerm
func (r *Raft) handleStaleTerm(s *followerReplication) { r.logger.Error(fmt.Sprintf("peer %v has newer term, stopping replication", s.peer)) s.notifyAll(false) // No longer leader asyncNotifyCh(s.stepDown) }
go
func (r *Raft) handleStaleTerm(s *followerReplication) { r.logger.Error(fmt.Sprintf("peer %v has newer term, stopping replication", s.peer)) s.notifyAll(false) // No longer leader asyncNotifyCh(s.stepDown) }
[ "func", "(", "r", "*", "Raft", ")", "handleStaleTerm", "(", "s", "*", "followerReplication", ")", "{", "r", ".", "logger", ".", "Error", "(", "fmt", ".", "Sprintf", "(", "\"peer %v has newer term, stopping replication\"", ",", "s", ".", "peer", ")", ")", "...
// handleStaleTerm is used when a follower indicates that we have a stale term.
[ "handleStaleTerm", "is", "used", "when", "a", "follower", "indicates", "that", "we", "have", "a", "stale", "term", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/replication.go#L553-L557
test
hashicorp/raft
fuzzy/transport.go
AppendEntries
func (t *transport) AppendEntries(id raft.ServerID, target raft.ServerAddress, args *raft.AppendEntriesRequest, resp *raft.AppendEntriesResponse) error { ae := appendEntries{ source: t.node, target: target, firstIndex: firstIndex(args), lastIndex: lastIndex(args), commitIndex: args.LeaderCommitI...
go
func (t *transport) AppendEntries(id raft.ServerID, target raft.ServerAddress, args *raft.AppendEntriesRequest, resp *raft.AppendEntriesResponse) error { ae := appendEntries{ source: t.node, target: target, firstIndex: firstIndex(args), lastIndex: lastIndex(args), commitIndex: args.LeaderCommitI...
[ "func", "(", "t", "*", "transport", ")", "AppendEntries", "(", "id", "raft", ".", "ServerID", ",", "target", "raft", ".", "ServerAddress", ",", "args", "*", "raft", ".", "AppendEntriesRequest", ",", "resp", "*", "raft", ".", "AppendEntriesResponse", ")", "...
// AppendEntries sends the appropriate RPC to the target node.
[ "AppendEntries", "sends", "the", "appropriate", "RPC", "to", "the", "target", "node", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/fuzzy/transport.go#L170-L182
test
hashicorp/raft
fuzzy/transport.go
RequestVote
func (t *transport) RequestVote(id raft.ServerID, target raft.ServerAddress, args *raft.RequestVoteRequest, resp *raft.RequestVoteResponse) error { return t.sendRPC(string(target), args, resp) }
go
func (t *transport) RequestVote(id raft.ServerID, target raft.ServerAddress, args *raft.RequestVoteRequest, resp *raft.RequestVoteResponse) error { return t.sendRPC(string(target), args, resp) }
[ "func", "(", "t", "*", "transport", ")", "RequestVote", "(", "id", "raft", ".", "ServerID", ",", "target", "raft", ".", "ServerAddress", ",", "args", "*", "raft", ".", "RequestVoteRequest", ",", "resp", "*", "raft", ".", "RequestVoteResponse", ")", "error"...
// RequestVote sends the appropriate RPC to the target node.
[ "RequestVote", "sends", "the", "appropriate", "RPC", "to", "the", "target", "node", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/fuzzy/transport.go#L210-L212
test
hashicorp/raft
fuzzy/transport.go
InstallSnapshot
func (t *transport) InstallSnapshot(id raft.ServerID, target raft.ServerAddress, args *raft.InstallSnapshotRequest, resp *raft.InstallSnapshotResponse, data io.Reader) error { t.log.Printf("INSTALL SNAPSHOT *************************************") return errors.New("huh") }
go
func (t *transport) InstallSnapshot(id raft.ServerID, target raft.ServerAddress, args *raft.InstallSnapshotRequest, resp *raft.InstallSnapshotResponse, data io.Reader) error { t.log.Printf("INSTALL SNAPSHOT *************************************") return errors.New("huh") }
[ "func", "(", "t", "*", "transport", ")", "InstallSnapshot", "(", "id", "raft", ".", "ServerID", ",", "target", "raft", ".", "ServerAddress", ",", "args", "*", "raft", ".", "InstallSnapshotRequest", ",", "resp", "*", "raft", ".", "InstallSnapshotResponse", ",...
// InstallSnapshot is used to push a snapshot down to a follower. The data is read from // the ReadCloser and streamed to the client.
[ "InstallSnapshot", "is", "used", "to", "push", "a", "snapshot", "down", "to", "a", "follower", ".", "The", "data", "is", "read", "from", "the", "ReadCloser", "and", "streamed", "to", "the", "client", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/fuzzy/transport.go#L216-L219
test
hashicorp/raft
fuzzy/transport.go
EncodePeer
func (t *transport) EncodePeer(id raft.ServerID, p raft.ServerAddress) []byte { return []byte(p) }
go
func (t *transport) EncodePeer(id raft.ServerID, p raft.ServerAddress) []byte { return []byte(p) }
[ "func", "(", "t", "*", "transport", ")", "EncodePeer", "(", "id", "raft", ".", "ServerID", ",", "p", "raft", ".", "ServerAddress", ")", "[", "]", "byte", "{", "return", "[", "]", "byte", "(", "p", ")", "\n", "}" ]
// EncodePeer is used to serialize a peer name.
[ "EncodePeer", "is", "used", "to", "serialize", "a", "peer", "name", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/fuzzy/transport.go#L222-L224
test
hashicorp/raft
fuzzy/transport.go
DecodePeer
func (t *transport) DecodePeer(p []byte) raft.ServerAddress { return raft.ServerAddress(p) }
go
func (t *transport) DecodePeer(p []byte) raft.ServerAddress { return raft.ServerAddress(p) }
[ "func", "(", "t", "*", "transport", ")", "DecodePeer", "(", "p", "[", "]", "byte", ")", "raft", ".", "ServerAddress", "{", "return", "raft", ".", "ServerAddress", "(", "p", ")", "\n", "}" ]
// DecodePeer is used to deserialize a peer name.
[ "DecodePeer", "is", "used", "to", "deserialize", "a", "peer", "name", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/fuzzy/transport.go#L227-L229
test
hashicorp/raft
fuzzy/transport.go
AppendEntries
func (p *pipeline) AppendEntries(args *raft.AppendEntriesRequest, resp *raft.AppendEntriesResponse) (raft.AppendFuture, error) { e := &appendEntry{ req: args, res: resp, start: time.Now(), ready: make(chan error), consumer: p.consumer, } p.work <- e return e, nil }
go
func (p *pipeline) AppendEntries(args *raft.AppendEntriesRequest, resp *raft.AppendEntriesResponse) (raft.AppendFuture, error) { e := &appendEntry{ req: args, res: resp, start: time.Now(), ready: make(chan error), consumer: p.consumer, } p.work <- e return e, nil }
[ "func", "(", "p", "*", "pipeline", ")", "AppendEntries", "(", "args", "*", "raft", ".", "AppendEntriesRequest", ",", "resp", "*", "raft", ".", "AppendEntriesResponse", ")", "(", "raft", ".", "AppendFuture", ",", "error", ")", "{", "e", ":=", "&", "append...
// AppendEntries is used to add another request to the pipeline. // The send may block which is an effective form of back-pressure.
[ "AppendEntries", "is", "used", "to", "add", "another", "request", "to", "the", "pipeline", ".", "The", "send", "may", "block", "which", "is", "an", "effective", "form", "of", "back", "-", "pressure", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/fuzzy/transport.go#L302-L312
test
hashicorp/raft
peersjson.go
ReadPeersJSON
func ReadPeersJSON(path string) (Configuration, error) { // Read in the file. buf, err := ioutil.ReadFile(path) if err != nil { return Configuration{}, err } // Parse it as JSON. var peers []string dec := json.NewDecoder(bytes.NewReader(buf)) if err := dec.Decode(&peers); err != nil { return Configuration{...
go
func ReadPeersJSON(path string) (Configuration, error) { // Read in the file. buf, err := ioutil.ReadFile(path) if err != nil { return Configuration{}, err } // Parse it as JSON. var peers []string dec := json.NewDecoder(bytes.NewReader(buf)) if err := dec.Decode(&peers); err != nil { return Configuration{...
[ "func", "ReadPeersJSON", "(", "path", "string", ")", "(", "Configuration", ",", "error", ")", "{", "buf", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "Configuration", "{", "}", ",", "e...
// ReadPeersJSON consumes a legacy peers.json file in the format of the old JSON // peer store and creates a new-style configuration structure. This can be used // to migrate this data or perform manual recovery when running protocol versions // that can interoperate with older, unversioned Raft servers. This should no...
[ "ReadPeersJSON", "consumes", "a", "legacy", "peers", ".", "json", "file", "in", "the", "format", "of", "the", "old", "JSON", "peer", "store", "and", "creates", "a", "new", "-", "style", "configuration", "structure", ".", "This", "can", "be", "used", "to", ...
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/peersjson.go#L15-L46
test
hashicorp/raft
peersjson.go
ReadConfigJSON
func ReadConfigJSON(path string) (Configuration, error) { // Read in the file. buf, err := ioutil.ReadFile(path) if err != nil { return Configuration{}, err } // Parse it as JSON. var peers []configEntry dec := json.NewDecoder(bytes.NewReader(buf)) if err := dec.Decode(&peers); err != nil { return Configur...
go
func ReadConfigJSON(path string) (Configuration, error) { // Read in the file. buf, err := ioutil.ReadFile(path) if err != nil { return Configuration{}, err } // Parse it as JSON. var peers []configEntry dec := json.NewDecoder(bytes.NewReader(buf)) if err := dec.Decode(&peers); err != nil { return Configur...
[ "func", "ReadConfigJSON", "(", "path", "string", ")", "(", "Configuration", ",", "error", ")", "{", "buf", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "Configuration", "{", "}", ",", "...
// ReadConfigJSON reads a new-style peers.json and returns a configuration // structure. This can be used to perform manual recovery when running protocol // versions that use server IDs.
[ "ReadConfigJSON", "reads", "a", "new", "-", "style", "peers", ".", "json", "and", "returns", "a", "configuration", "structure", ".", "This", "can", "be", "used", "to", "perform", "manual", "recovery", "when", "running", "protocol", "versions", "that", "use", ...
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/peersjson.go#L64-L98
test
hashicorp/raft
tcp_transport.go
NewTCPTransport
func NewTCPTransport( bindAddr string, advertise net.Addr, maxPool int, timeout time.Duration, logOutput io.Writer, ) (*NetworkTransport, error) { return newTCPTransport(bindAddr, advertise, func(stream StreamLayer) *NetworkTransport { return NewNetworkTransport(stream, maxPool, timeout, logOutput) }) }
go
func NewTCPTransport( bindAddr string, advertise net.Addr, maxPool int, timeout time.Duration, logOutput io.Writer, ) (*NetworkTransport, error) { return newTCPTransport(bindAddr, advertise, func(stream StreamLayer) *NetworkTransport { return NewNetworkTransport(stream, maxPool, timeout, logOutput) }) }
[ "func", "NewTCPTransport", "(", "bindAddr", "string", ",", "advertise", "net", ".", "Addr", ",", "maxPool", "int", ",", "timeout", "time", ".", "Duration", ",", "logOutput", "io", ".", "Writer", ",", ")", "(", "*", "NetworkTransport", ",", "error", ")", ...
// NewTCPTransport returns a NetworkTransport that is built on top of // a TCP streaming transport layer.
[ "NewTCPTransport", "returns", "a", "NetworkTransport", "that", "is", "built", "on", "top", "of", "a", "TCP", "streaming", "transport", "layer", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/tcp_transport.go#L24-L34
test
hashicorp/raft
tcp_transport.go
NewTCPTransportWithLogger
func NewTCPTransportWithLogger( bindAddr string, advertise net.Addr, maxPool int, timeout time.Duration, logger *log.Logger, ) (*NetworkTransport, error) { return newTCPTransport(bindAddr, advertise, func(stream StreamLayer) *NetworkTransport { return NewNetworkTransportWithLogger(stream, maxPool, timeout, logg...
go
func NewTCPTransportWithLogger( bindAddr string, advertise net.Addr, maxPool int, timeout time.Duration, logger *log.Logger, ) (*NetworkTransport, error) { return newTCPTransport(bindAddr, advertise, func(stream StreamLayer) *NetworkTransport { return NewNetworkTransportWithLogger(stream, maxPool, timeout, logg...
[ "func", "NewTCPTransportWithLogger", "(", "bindAddr", "string", ",", "advertise", "net", ".", "Addr", ",", "maxPool", "int", ",", "timeout", "time", ".", "Duration", ",", "logger", "*", "log", ".", "Logger", ",", ")", "(", "*", "NetworkTransport", ",", "er...
// NewTCPTransportWithLogger returns a NetworkTransport that is built on top of // a TCP streaming transport layer, with log output going to the supplied Logger
[ "NewTCPTransportWithLogger", "returns", "a", "NetworkTransport", "that", "is", "built", "on", "top", "of", "a", "TCP", "streaming", "transport", "layer", "with", "log", "output", "going", "to", "the", "supplied", "Logger" ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/tcp_transport.go#L38-L48
test
hashicorp/raft
tcp_transport.go
NewTCPTransportWithConfig
func NewTCPTransportWithConfig( bindAddr string, advertise net.Addr, config *NetworkTransportConfig, ) (*NetworkTransport, error) { return newTCPTransport(bindAddr, advertise, func(stream StreamLayer) *NetworkTransport { config.Stream = stream return NewNetworkTransportWithConfig(config) }) }
go
func NewTCPTransportWithConfig( bindAddr string, advertise net.Addr, config *NetworkTransportConfig, ) (*NetworkTransport, error) { return newTCPTransport(bindAddr, advertise, func(stream StreamLayer) *NetworkTransport { config.Stream = stream return NewNetworkTransportWithConfig(config) }) }
[ "func", "NewTCPTransportWithConfig", "(", "bindAddr", "string", ",", "advertise", "net", ".", "Addr", ",", "config", "*", "NetworkTransportConfig", ",", ")", "(", "*", "NetworkTransport", ",", "error", ")", "{", "return", "newTCPTransport", "(", "bindAddr", ",",...
// NewTCPTransportWithConfig returns a NetworkTransport that is built on top of // a TCP streaming transport layer, using the given config struct.
[ "NewTCPTransportWithConfig", "returns", "a", "NetworkTransport", "that", "is", "built", "on", "top", "of", "a", "TCP", "streaming", "transport", "layer", "using", "the", "given", "config", "struct", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/tcp_transport.go#L52-L61
test
hashicorp/raft
tcp_transport.go
Dial
func (t *TCPStreamLayer) Dial(address ServerAddress, timeout time.Duration) (net.Conn, error) { return net.DialTimeout("tcp", string(address), timeout) }
go
func (t *TCPStreamLayer) Dial(address ServerAddress, timeout time.Duration) (net.Conn, error) { return net.DialTimeout("tcp", string(address), timeout) }
[ "func", "(", "t", "*", "TCPStreamLayer", ")", "Dial", "(", "address", "ServerAddress", ",", "timeout", "time", ".", "Duration", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "return", "net", ".", "DialTimeout", "(", "\"tcp\"", ",", "string", "(...
// Dial implements the StreamLayer interface.
[ "Dial", "implements", "the", "StreamLayer", "interface", "." ]
773bcaa2009bf059c5c06457b9fccd156d5e91e7
https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/tcp_transport.go#L95-L97
test