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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
hashicorp/raft | tcp_transport.go | Accept | func (t *TCPStreamLayer) Accept() (c net.Conn, err error) {
return t.listener.Accept()
} | go | func (t *TCPStreamLayer) Accept() (c net.Conn, err error) {
return t.listener.Accept()
} | [
"func",
"(",
"t",
"*",
"TCPStreamLayer",
")",
"Accept",
"(",
")",
"(",
"c",
"net",
".",
"Conn",
",",
"err",
"error",
")",
"{",
"return",
"t",
".",
"listener",
".",
"Accept",
"(",
")",
"\n",
"}"
] | // Accept implements the net.Listener interface. | [
"Accept",
"implements",
"the",
"net",
".",
"Listener",
"interface",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/tcp_transport.go#L100-L102 | test |
hashicorp/raft | tcp_transport.go | Addr | func (t *TCPStreamLayer) Addr() net.Addr {
// Use an advertise addr if provided
if t.advertise != nil {
return t.advertise
}
return t.listener.Addr()
} | go | func (t *TCPStreamLayer) Addr() net.Addr {
// Use an advertise addr if provided
if t.advertise != nil {
return t.advertise
}
return t.listener.Addr()
} | [
"func",
"(",
"t",
"*",
"TCPStreamLayer",
")",
"Addr",
"(",
")",
"net",
".",
"Addr",
"{",
"if",
"t",
".",
"advertise",
"!=",
"nil",
"{",
"return",
"t",
".",
"advertise",
"\n",
"}",
"\n",
"return",
"t",
".",
"listener",
".",
"Addr",
"(",
")",
"\n",... | // Addr implements the net.Listener interface. | [
"Addr",
"implements",
"the",
"net",
".",
"Listener",
"interface",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/tcp_transport.go#L110-L116 | test |
hashicorp/raft | api.go | restoreSnapshot | func (r *Raft) restoreSnapshot() error {
snapshots, err := r.snapshots.List()
if err != nil {
r.logger.Error(fmt.Sprintf("Failed to list snapshots: %v", err))
return err
}
// Try to load in order of newest to oldest
for _, snapshot := range snapshots {
_, source, err := r.snapshots.Open(snapshot.ID)
if er... | go | func (r *Raft) restoreSnapshot() error {
snapshots, err := r.snapshots.List()
if err != nil {
r.logger.Error(fmt.Sprintf("Failed to list snapshots: %v", err))
return err
}
// Try to load in order of newest to oldest
for _, snapshot := range snapshots {
_, source, err := r.snapshots.Open(snapshot.ID)
if er... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"restoreSnapshot",
"(",
")",
"error",
"{",
"snapshots",
",",
"err",
":=",
"r",
".",
"snapshots",
".",
"List",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"r",
".",
"logger",
".",
"Error",
"(",
"fmt",
".",
... | // restoreSnapshot attempts to restore the latest snapshots, and fails if none
// of them can be restored. This is called at initialization time, and is
// completely unsafe to call at any other time. | [
"restoreSnapshot",
"attempts",
"to",
"restore",
"the",
"latest",
"snapshots",
"and",
"fails",
"if",
"none",
"of",
"them",
"can",
"be",
"restored",
".",
"This",
"is",
"called",
"at",
"initialization",
"time",
"and",
"is",
"completely",
"unsafe",
"to",
"call",
... | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/api.go#L519-L572 | test |
hashicorp/raft | api.go | BootstrapCluster | func (r *Raft) BootstrapCluster(configuration Configuration) Future {
bootstrapReq := &bootstrapFuture{}
bootstrapReq.init()
bootstrapReq.configuration = configuration
select {
case <-r.shutdownCh:
return errorFuture{ErrRaftShutdown}
case r.bootstrapCh <- bootstrapReq:
return bootstrapReq
}
} | go | func (r *Raft) BootstrapCluster(configuration Configuration) Future {
bootstrapReq := &bootstrapFuture{}
bootstrapReq.init()
bootstrapReq.configuration = configuration
select {
case <-r.shutdownCh:
return errorFuture{ErrRaftShutdown}
case r.bootstrapCh <- bootstrapReq:
return bootstrapReq
}
} | [
"func",
"(",
"r",
"*",
"Raft",
")",
"BootstrapCluster",
"(",
"configuration",
"Configuration",
")",
"Future",
"{",
"bootstrapReq",
":=",
"&",
"bootstrapFuture",
"{",
"}",
"\n",
"bootstrapReq",
".",
"init",
"(",
")",
"\n",
"bootstrapReq",
".",
"configuration",
... | // BootstrapCluster is equivalent to non-member BootstrapCluster but can be
// called on an un-bootstrapped Raft instance after it has been created. This
// should only be called at the beginning of time for the cluster, and you
// absolutely must make sure that you call it with the same configuration on all
// the Vot... | [
"BootstrapCluster",
"is",
"equivalent",
"to",
"non",
"-",
"member",
"BootstrapCluster",
"but",
"can",
"be",
"called",
"on",
"an",
"un",
"-",
"bootstrapped",
"Raft",
"instance",
"after",
"it",
"has",
"been",
"created",
".",
"This",
"should",
"only",
"be",
"ca... | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/api.go#L580-L590 | test |
hashicorp/raft | api.go | Leader | func (r *Raft) Leader() ServerAddress {
r.leaderLock.RLock()
leader := r.leader
r.leaderLock.RUnlock()
return leader
} | go | func (r *Raft) Leader() ServerAddress {
r.leaderLock.RLock()
leader := r.leader
r.leaderLock.RUnlock()
return leader
} | [
"func",
"(",
"r",
"*",
"Raft",
")",
"Leader",
"(",
")",
"ServerAddress",
"{",
"r",
".",
"leaderLock",
".",
"RLock",
"(",
")",
"\n",
"leader",
":=",
"r",
".",
"leader",
"\n",
"r",
".",
"leaderLock",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"leader"... | // Leader is used to return the current leader of the cluster.
// It may return empty string if there is no current leader
// or the leader is unknown. | [
"Leader",
"is",
"used",
"to",
"return",
"the",
"current",
"leader",
"of",
"the",
"cluster",
".",
"It",
"may",
"return",
"empty",
"string",
"if",
"there",
"is",
"no",
"current",
"leader",
"or",
"the",
"leader",
"is",
"unknown",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/api.go#L595-L600 | test |
hashicorp/raft | api.go | Apply | func (r *Raft) Apply(cmd []byte, timeout time.Duration) ApplyFuture {
metrics.IncrCounter([]string{"raft", "apply"}, 1)
var timer <-chan time.Time
if timeout > 0 {
timer = time.After(timeout)
}
// Create a log future, no index or term yet
logFuture := &logFuture{
log: Log{
Type: LogCommand,
Data: cmd,
... | go | func (r *Raft) Apply(cmd []byte, timeout time.Duration) ApplyFuture {
metrics.IncrCounter([]string{"raft", "apply"}, 1)
var timer <-chan time.Time
if timeout > 0 {
timer = time.After(timeout)
}
// Create a log future, no index or term yet
logFuture := &logFuture{
log: Log{
Type: LogCommand,
Data: cmd,
... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"Apply",
"(",
"cmd",
"[",
"]",
"byte",
",",
"timeout",
"time",
".",
"Duration",
")",
"ApplyFuture",
"{",
"metrics",
".",
"IncrCounter",
"(",
"[",
"]",
"string",
"{",
"\"raft\"",
",",
"\"apply\"",
"}",
",",
"1",
"... | // Apply is used to apply a command to the FSM in a highly consistent
// manner. This returns a future that can be used to wait on the application.
// An optional timeout can be provided to limit the amount of time we wait
// for the command to be started. This must be run on the leader or it
// will fail. | [
"Apply",
"is",
"used",
"to",
"apply",
"a",
"command",
"to",
"the",
"FSM",
"in",
"a",
"highly",
"consistent",
"manner",
".",
"This",
"returns",
"a",
"future",
"that",
"can",
"be",
"used",
"to",
"wait",
"on",
"the",
"application",
".",
"An",
"optional",
... | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/api.go#L607-L631 | test |
hashicorp/raft | api.go | Barrier | func (r *Raft) Barrier(timeout time.Duration) Future {
metrics.IncrCounter([]string{"raft", "barrier"}, 1)
var timer <-chan time.Time
if timeout > 0 {
timer = time.After(timeout)
}
// Create a log future, no index or term yet
logFuture := &logFuture{
log: Log{
Type: LogBarrier,
},
}
logFuture.init()
... | go | func (r *Raft) Barrier(timeout time.Duration) Future {
metrics.IncrCounter([]string{"raft", "barrier"}, 1)
var timer <-chan time.Time
if timeout > 0 {
timer = time.After(timeout)
}
// Create a log future, no index or term yet
logFuture := &logFuture{
log: Log{
Type: LogBarrier,
},
}
logFuture.init()
... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"Barrier",
"(",
"timeout",
"time",
".",
"Duration",
")",
"Future",
"{",
"metrics",
".",
"IncrCounter",
"(",
"[",
"]",
"string",
"{",
"\"raft\"",
",",
"\"barrier\"",
"}",
",",
"1",
")",
"\n",
"var",
"timer",
"<-",
... | // Barrier is used to issue a command that blocks until all preceeding
// operations have been applied to the FSM. It can be used to ensure the
// FSM reflects all queued writes. An optional timeout can be provided to
// limit the amount of time we wait for the command to be started. This
// must be run on the leader o... | [
"Barrier",
"is",
"used",
"to",
"issue",
"a",
"command",
"that",
"blocks",
"until",
"all",
"preceeding",
"operations",
"have",
"been",
"applied",
"to",
"the",
"FSM",
".",
"It",
"can",
"be",
"used",
"to",
"ensure",
"the",
"FSM",
"reflects",
"all",
"queued",
... | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/api.go#L638-L661 | test |
hashicorp/raft | api.go | VerifyLeader | func (r *Raft) VerifyLeader() Future {
metrics.IncrCounter([]string{"raft", "verify_leader"}, 1)
verifyFuture := &verifyFuture{}
verifyFuture.init()
select {
case <-r.shutdownCh:
return errorFuture{ErrRaftShutdown}
case r.verifyCh <- verifyFuture:
return verifyFuture
}
} | go | func (r *Raft) VerifyLeader() Future {
metrics.IncrCounter([]string{"raft", "verify_leader"}, 1)
verifyFuture := &verifyFuture{}
verifyFuture.init()
select {
case <-r.shutdownCh:
return errorFuture{ErrRaftShutdown}
case r.verifyCh <- verifyFuture:
return verifyFuture
}
} | [
"func",
"(",
"r",
"*",
"Raft",
")",
"VerifyLeader",
"(",
")",
"Future",
"{",
"metrics",
".",
"IncrCounter",
"(",
"[",
"]",
"string",
"{",
"\"raft\"",
",",
"\"verify_leader\"",
"}",
",",
"1",
")",
"\n",
"verifyFuture",
":=",
"&",
"verifyFuture",
"{",
"}... | // VerifyLeader is used to ensure the current node is still
// the leader. This can be done to prevent stale reads when a
// new leader has potentially been elected. | [
"VerifyLeader",
"is",
"used",
"to",
"ensure",
"the",
"current",
"node",
"is",
"still",
"the",
"leader",
".",
"This",
"can",
"be",
"done",
"to",
"prevent",
"stale",
"reads",
"when",
"a",
"new",
"leader",
"has",
"potentially",
"been",
"elected",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/api.go#L666-L676 | test |
hashicorp/raft | api.go | AddVoter | func (r *Raft) AddVoter(id ServerID, address ServerAddress, prevIndex uint64, timeout time.Duration) IndexFuture {
if r.protocolVersion < 2 {
return errorFuture{ErrUnsupportedProtocol}
}
return r.requestConfigChange(configurationChangeRequest{
command: AddStaging,
serverID: id,
serverAddress: add... | go | func (r *Raft) AddVoter(id ServerID, address ServerAddress, prevIndex uint64, timeout time.Duration) IndexFuture {
if r.protocolVersion < 2 {
return errorFuture{ErrUnsupportedProtocol}
}
return r.requestConfigChange(configurationChangeRequest{
command: AddStaging,
serverID: id,
serverAddress: add... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"AddVoter",
"(",
"id",
"ServerID",
",",
"address",
"ServerAddress",
",",
"prevIndex",
"uint64",
",",
"timeout",
"time",
".",
"Duration",
")",
"IndexFuture",
"{",
"if",
"r",
".",
"protocolVersion",
"<",
"2",
"{",
"retur... | // AddVoter will add the given server to the cluster as a staging server. If the
// server is already in the cluster as a voter, this updates the server's address.
// This must be run on the leader or it will fail. The leader will promote the
// staging server to a voter once that server is ready. If nonzero, prevIndex... | [
"AddVoter",
"will",
"add",
"the",
"given",
"server",
"to",
"the",
"cluster",
"as",
"a",
"staging",
"server",
".",
"If",
"the",
"server",
"is",
"already",
"in",
"the",
"cluster",
"as",
"a",
"voter",
"this",
"updates",
"the",
"server",
"s",
"address",
".",... | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/api.go#L732-L743 | test |
hashicorp/raft | api.go | RemoveServer | func (r *Raft) RemoveServer(id ServerID, prevIndex uint64, timeout time.Duration) IndexFuture {
if r.protocolVersion < 2 {
return errorFuture{ErrUnsupportedProtocol}
}
return r.requestConfigChange(configurationChangeRequest{
command: RemoveServer,
serverID: id,
prevIndex: prevIndex,
}, timeout)
} | go | func (r *Raft) RemoveServer(id ServerID, prevIndex uint64, timeout time.Duration) IndexFuture {
if r.protocolVersion < 2 {
return errorFuture{ErrUnsupportedProtocol}
}
return r.requestConfigChange(configurationChangeRequest{
command: RemoveServer,
serverID: id,
prevIndex: prevIndex,
}, timeout)
} | [
"func",
"(",
"r",
"*",
"Raft",
")",
"RemoveServer",
"(",
"id",
"ServerID",
",",
"prevIndex",
"uint64",
",",
"timeout",
"time",
".",
"Duration",
")",
"IndexFuture",
"{",
"if",
"r",
".",
"protocolVersion",
"<",
"2",
"{",
"return",
"errorFuture",
"{",
"ErrU... | // RemoveServer will remove the given server from the cluster. If the current
// leader is being removed, it will cause a new election to occur. This must be
// run on the leader or it will fail. For prevIndex and timeout, see AddVoter. | [
"RemoveServer",
"will",
"remove",
"the",
"given",
"server",
"from",
"the",
"cluster",
".",
"If",
"the",
"current",
"leader",
"is",
"being",
"removed",
"it",
"will",
"cause",
"a",
"new",
"election",
"to",
"occur",
".",
"This",
"must",
"be",
"run",
"on",
"... | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/api.go#L766-L776 | test |
hashicorp/raft | api.go | Shutdown | func (r *Raft) Shutdown() Future {
r.shutdownLock.Lock()
defer r.shutdownLock.Unlock()
if !r.shutdown {
close(r.shutdownCh)
r.shutdown = true
r.setState(Shutdown)
return &shutdownFuture{r}
}
// avoid closing transport twice
return &shutdownFuture{nil}
} | go | func (r *Raft) Shutdown() Future {
r.shutdownLock.Lock()
defer r.shutdownLock.Unlock()
if !r.shutdown {
close(r.shutdownCh)
r.shutdown = true
r.setState(Shutdown)
return &shutdownFuture{r}
}
// avoid closing transport twice
return &shutdownFuture{nil}
} | [
"func",
"(",
"r",
"*",
"Raft",
")",
"Shutdown",
"(",
")",
"Future",
"{",
"r",
".",
"shutdownLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"shutdownLock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"!",
"r",
".",
"shutdown",
"{",
"close",
"(",
... | // Shutdown is used to stop the Raft background routines.
// This is not a graceful operation. Provides a future that
// can be used to block until all background routines have exited. | [
"Shutdown",
"is",
"used",
"to",
"stop",
"the",
"Raft",
"background",
"routines",
".",
"This",
"is",
"not",
"a",
"graceful",
"operation",
".",
"Provides",
"a",
"future",
"that",
"can",
"be",
"used",
"to",
"block",
"until",
"all",
"background",
"routines",
"... | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/api.go#L798-L811 | test |
hashicorp/raft | api.go | Snapshot | func (r *Raft) Snapshot() SnapshotFuture {
future := &userSnapshotFuture{}
future.init()
select {
case r.userSnapshotCh <- future:
return future
case <-r.shutdownCh:
future.respond(ErrRaftShutdown)
return future
}
} | go | func (r *Raft) Snapshot() SnapshotFuture {
future := &userSnapshotFuture{}
future.init()
select {
case r.userSnapshotCh <- future:
return future
case <-r.shutdownCh:
future.respond(ErrRaftShutdown)
return future
}
} | [
"func",
"(",
"r",
"*",
"Raft",
")",
"Snapshot",
"(",
")",
"SnapshotFuture",
"{",
"future",
":=",
"&",
"userSnapshotFuture",
"{",
"}",
"\n",
"future",
".",
"init",
"(",
")",
"\n",
"select",
"{",
"case",
"r",
".",
"userSnapshotCh",
"<-",
"future",
":",
... | // Snapshot is used to manually force Raft to take a snapshot. Returns a future
// that can be used to block until complete, and that contains a function that
// can be used to open the snapshot. | [
"Snapshot",
"is",
"used",
"to",
"manually",
"force",
"Raft",
"to",
"take",
"a",
"snapshot",
".",
"Returns",
"a",
"future",
"that",
"can",
"be",
"used",
"to",
"block",
"until",
"complete",
"and",
"that",
"contains",
"a",
"function",
"that",
"can",
"be",
"... | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/api.go#L816-L826 | test |
hashicorp/raft | api.go | Restore | func (r *Raft) Restore(meta *SnapshotMeta, reader io.Reader, timeout time.Duration) error {
metrics.IncrCounter([]string{"raft", "restore"}, 1)
var timer <-chan time.Time
if timeout > 0 {
timer = time.After(timeout)
}
// Perform the restore.
restore := &userRestoreFuture{
meta: meta,
reader: reader,
}
... | go | func (r *Raft) Restore(meta *SnapshotMeta, reader io.Reader, timeout time.Duration) error {
metrics.IncrCounter([]string{"raft", "restore"}, 1)
var timer <-chan time.Time
if timeout > 0 {
timer = time.After(timeout)
}
// Perform the restore.
restore := &userRestoreFuture{
meta: meta,
reader: reader,
}
... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"Restore",
"(",
"meta",
"*",
"SnapshotMeta",
",",
"reader",
"io",
".",
"Reader",
",",
"timeout",
"time",
".",
"Duration",
")",
"error",
"{",
"metrics",
".",
"IncrCounter",
"(",
"[",
"]",
"string",
"{",
"\"raft\"",
... | // Restore is used to manually force Raft to consume an external snapshot, such
// as if restoring from a backup. We will use the current Raft configuration,
// not the one from the snapshot, so that we can restore into a new cluster. We
// will also use the higher of the index of the snapshot, or the current index,
//... | [
"Restore",
"is",
"used",
"to",
"manually",
"force",
"Raft",
"to",
"consume",
"an",
"external",
"snapshot",
"such",
"as",
"if",
"restoring",
"from",
"a",
"backup",
".",
"We",
"will",
"use",
"the",
"current",
"Raft",
"configuration",
"not",
"the",
"one",
"fr... | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/api.go#L842-L885 | test |
hashicorp/raft | api.go | String | func (r *Raft) String() string {
return fmt.Sprintf("Node at %s [%v]", r.localAddr, r.getState())
} | go | func (r *Raft) String() string {
return fmt.Sprintf("Node at %s [%v]", r.localAddr, r.getState())
} | [
"func",
"(",
"r",
"*",
"Raft",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"Node at %s [%v]\"",
",",
"r",
".",
"localAddr",
",",
"r",
".",
"getState",
"(",
")",
")",
"\n",
"}"
] | // String returns a string representation of this Raft node. | [
"String",
"returns",
"a",
"string",
"representation",
"of",
"this",
"Raft",
"node",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/api.go#L901-L903 | test |
hashicorp/raft | api.go | LastContact | func (r *Raft) LastContact() time.Time {
r.lastContactLock.RLock()
last := r.lastContact
r.lastContactLock.RUnlock()
return last
} | go | func (r *Raft) LastContact() time.Time {
r.lastContactLock.RLock()
last := r.lastContact
r.lastContactLock.RUnlock()
return last
} | [
"func",
"(",
"r",
"*",
"Raft",
")",
"LastContact",
"(",
")",
"time",
".",
"Time",
"{",
"r",
".",
"lastContactLock",
".",
"RLock",
"(",
")",
"\n",
"last",
":=",
"r",
".",
"lastContact",
"\n",
"r",
".",
"lastContactLock",
".",
"RUnlock",
"(",
")",
"\... | // LastContact returns the time of last contact by a leader.
// This only makes sense if we are currently a follower. | [
"LastContact",
"returns",
"the",
"time",
"of",
"last",
"contact",
"by",
"a",
"leader",
".",
"This",
"only",
"makes",
"sense",
"if",
"we",
"are",
"currently",
"a",
"follower",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/api.go#L907-L912 | test |
hashicorp/raft | fuzzy/cluster.go | Logf | func (a *LoggerAdapter) Logf(s string, v ...interface{}) {
a.log.Printf(s, v...)
} | go | func (a *LoggerAdapter) Logf(s string, v ...interface{}) {
a.log.Printf(s, v...)
} | [
"func",
"(",
"a",
"*",
"LoggerAdapter",
")",
"Logf",
"(",
"s",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"a",
".",
"log",
".",
"Printf",
"(",
"s",
",",
"v",
"...",
")",
"\n",
"}"
] | // Logf will record a formatted message to the contained debug log | [
"Logf",
"will",
"record",
"a",
"formatted",
"message",
"to",
"the",
"contained",
"debug",
"log"
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/fuzzy/cluster.go#L50-L52 | test |
hashicorp/raft | fuzzy/cluster.go | containsNode | func containsNode(nodes []*raftNode, n *raftNode) bool {
for _, rn := range nodes {
if rn == n {
return true
}
}
return false
} | go | func containsNode(nodes []*raftNode, n *raftNode) bool {
for _, rn := range nodes {
if rn == n {
return true
}
}
return false
} | [
"func",
"containsNode",
"(",
"nodes",
"[",
"]",
"*",
"raftNode",
",",
"n",
"*",
"raftNode",
")",
"bool",
"{",
"for",
"_",
",",
"rn",
":=",
"range",
"nodes",
"{",
"if",
"rn",
"==",
"n",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
... | // containsNode returns true if the slice 'nodes' contains 'n' | [
"containsNode",
"returns",
"true",
"if",
"the",
"slice",
"nodes",
"contains",
"n"
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/fuzzy/cluster.go#L133-L140 | test |
hashicorp/raft | fuzzy/cluster.go | LeaderPlus | func (c *cluster) LeaderPlus(n int) []*raftNode {
r := make([]*raftNode, 0, n+1)
ldr := c.Leader(time.Second)
if ldr != nil {
r = append(r, ldr)
}
if len(r) >= n {
return r
}
for _, node := range c.nodes {
if !containsNode(r, node) {
r = append(r, node)
if len(r) >= n {
return r
}
}
}
retu... | go | func (c *cluster) LeaderPlus(n int) []*raftNode {
r := make([]*raftNode, 0, n+1)
ldr := c.Leader(time.Second)
if ldr != nil {
r = append(r, ldr)
}
if len(r) >= n {
return r
}
for _, node := range c.nodes {
if !containsNode(r, node) {
r = append(r, node)
if len(r) >= n {
return r
}
}
}
retu... | [
"func",
"(",
"c",
"*",
"cluster",
")",
"LeaderPlus",
"(",
"n",
"int",
")",
"[",
"]",
"*",
"raftNode",
"{",
"r",
":=",
"make",
"(",
"[",
"]",
"*",
"raftNode",
",",
"0",
",",
"n",
"+",
"1",
")",
"\n",
"ldr",
":=",
"c",
".",
"Leader",
"(",
"ti... | // LeaderPlus returns the leader + n additional nodes from the cluster
// the leader is always the first node in the returned slice. | [
"LeaderPlus",
"returns",
"the",
"leader",
"+",
"n",
"additional",
"nodes",
"from",
"the",
"cluster",
"the",
"leader",
"is",
"always",
"the",
"first",
"node",
"in",
"the",
"returned",
"slice",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/fuzzy/cluster.go#L144-L162 | test |
hashicorp/raft | fuzzy/cluster.go | WaitTilUptoDate | func (c *cluster) WaitTilUptoDate(t *testing.T, maxWait time.Duration) {
idx := c.lastApplySuccess.Index()
start := time.Now()
for true {
allAtIdx := true
for i := 0; i < len(c.nodes); i++ {
nodeAppliedIdx := c.nodes[i].raft.AppliedIndex()
if nodeAppliedIdx < idx {
allAtIdx = false
break
} else ... | go | func (c *cluster) WaitTilUptoDate(t *testing.T, maxWait time.Duration) {
idx := c.lastApplySuccess.Index()
start := time.Now()
for true {
allAtIdx := true
for i := 0; i < len(c.nodes); i++ {
nodeAppliedIdx := c.nodes[i].raft.AppliedIndex()
if nodeAppliedIdx < idx {
allAtIdx = false
break
} else ... | [
"func",
"(",
"c",
"*",
"cluster",
")",
"WaitTilUptoDate",
"(",
"t",
"*",
"testing",
".",
"T",
",",
"maxWait",
"time",
".",
"Duration",
")",
"{",
"idx",
":=",
"c",
".",
"lastApplySuccess",
".",
"Index",
"(",
")",
"\n",
"start",
":=",
"time",
".",
"N... | // WaitTilUptoDate blocks until all nodes in the cluster have gotten their
// commitedIndex upto the Index from the last successful call to Apply | [
"WaitTilUptoDate",
"blocks",
"until",
"all",
"nodes",
"in",
"the",
"cluster",
"have",
"gotten",
"their",
"commitedIndex",
"upto",
"the",
"Index",
"from",
"the",
"last",
"successful",
"call",
"to",
"Apply"
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/fuzzy/cluster.go#L173-L198 | test |
hashicorp/raft | fuzzy/cluster.go | assertLogEntryEqual | func assertLogEntryEqual(t *testing.T, node string, exp *raft.Log, act *raft.Log) bool {
res := true
if exp.Term != act.Term {
t.Errorf("Log Entry at Index %d for node %v has mismatched terms %d/%d", exp.Index, node, exp.Term, act.Term)
res = false
}
if exp.Index != act.Index {
t.Errorf("Node %v, Log Entry sh... | go | func assertLogEntryEqual(t *testing.T, node string, exp *raft.Log, act *raft.Log) bool {
res := true
if exp.Term != act.Term {
t.Errorf("Log Entry at Index %d for node %v has mismatched terms %d/%d", exp.Index, node, exp.Term, act.Term)
res = false
}
if exp.Index != act.Index {
t.Errorf("Node %v, Log Entry sh... | [
"func",
"assertLogEntryEqual",
"(",
"t",
"*",
"testing",
".",
"T",
",",
"node",
"string",
",",
"exp",
"*",
"raft",
".",
"Log",
",",
"act",
"*",
"raft",
".",
"Log",
")",
"bool",
"{",
"res",
":=",
"true",
"\n",
"if",
"exp",
".",
"Term",
"!=",
"act"... | // assertLogEntryEqual compares the 2 raft Log entries and reports any differences to the supplied testing.T instance
// it return true if the 2 entries are equal, false otherwise. | [
"assertLogEntryEqual",
"compares",
"the",
"2",
"raft",
"Log",
"entries",
"and",
"reports",
"any",
"differences",
"to",
"the",
"supplied",
"testing",
".",
"T",
"instance",
"it",
"return",
"true",
"if",
"the",
"2",
"entries",
"are",
"equal",
"false",
"otherwise"... | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/fuzzy/cluster.go#L369-L388 | test |
hashicorp/raft | fsm.go | runFSM | func (r *Raft) runFSM() {
var lastIndex, lastTerm uint64
commit := func(req *commitTuple) {
// Apply the log if a command
var resp interface{}
if req.log.Type == LogCommand {
start := time.Now()
resp = r.fsm.Apply(req.log)
metrics.MeasureSince([]string{"raft", "fsm", "apply"}, start)
}
// Update ... | go | func (r *Raft) runFSM() {
var lastIndex, lastTerm uint64
commit := func(req *commitTuple) {
// Apply the log if a command
var resp interface{}
if req.log.Type == LogCommand {
start := time.Now()
resp = r.fsm.Apply(req.log)
metrics.MeasureSince([]string{"raft", "fsm", "apply"}, start)
}
// Update ... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"runFSM",
"(",
")",
"{",
"var",
"lastIndex",
",",
"lastTerm",
"uint64",
"\n",
"commit",
":=",
"func",
"(",
"req",
"*",
"commitTuple",
")",
"{",
"var",
"resp",
"interface",
"{",
"}",
"\n",
"if",
"req",
".",
"log",... | // runFSM is a long running goroutine responsible for applying logs
// to the FSM. This is done async of other logs since we don't want
// the FSM to block our internal operations. | [
"runFSM",
"is",
"a",
"long",
"running",
"goroutine",
"responsible",
"for",
"applying",
"logs",
"to",
"the",
"FSM",
".",
"This",
"is",
"done",
"async",
"of",
"other",
"logs",
"since",
"we",
"don",
"t",
"want",
"the",
"FSM",
"to",
"block",
"our",
"internal... | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/fsm.go#L49-L136 | test |
hashicorp/raft | configuration.go | Clone | func (c *Configuration) Clone() (copy Configuration) {
copy.Servers = append(copy.Servers, c.Servers...)
return
} | go | func (c *Configuration) Clone() (copy Configuration) {
copy.Servers = append(copy.Servers, c.Servers...)
return
} | [
"func",
"(",
"c",
"*",
"Configuration",
")",
"Clone",
"(",
")",
"(",
"copy",
"Configuration",
")",
"{",
"copy",
".",
"Servers",
"=",
"append",
"(",
"copy",
".",
"Servers",
",",
"c",
".",
"Servers",
"...",
")",
"\n",
"return",
"\n",
"}"
] | // Clone makes a deep copy of a Configuration. | [
"Clone",
"makes",
"a",
"deep",
"copy",
"of",
"a",
"Configuration",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/configuration.go#L60-L63 | test |
hashicorp/raft | configuration.go | Clone | func (c *configurations) Clone() (copy configurations) {
copy.committed = c.committed.Clone()
copy.committedIndex = c.committedIndex
copy.latest = c.latest.Clone()
copy.latestIndex = c.latestIndex
return
} | go | func (c *configurations) Clone() (copy configurations) {
copy.committed = c.committed.Clone()
copy.committedIndex = c.committedIndex
copy.latest = c.latest.Clone()
copy.latestIndex = c.latestIndex
return
} | [
"func",
"(",
"c",
"*",
"configurations",
")",
"Clone",
"(",
")",
"(",
"copy",
"configurations",
")",
"{",
"copy",
".",
"committed",
"=",
"c",
".",
"committed",
".",
"Clone",
"(",
")",
"\n",
"copy",
".",
"committedIndex",
"=",
"c",
".",
"committedIndex"... | // Clone makes a deep copy of a configurations object. | [
"Clone",
"makes",
"a",
"deep",
"copy",
"of",
"a",
"configurations",
"object",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/configuration.go#L137-L143 | test |
hashicorp/raft | configuration.go | hasVote | func hasVote(configuration Configuration, id ServerID) bool {
for _, server := range configuration.Servers {
if server.ID == id {
return server.Suffrage == Voter
}
}
return false
} | go | func hasVote(configuration Configuration, id ServerID) bool {
for _, server := range configuration.Servers {
if server.ID == id {
return server.Suffrage == Voter
}
}
return false
} | [
"func",
"hasVote",
"(",
"configuration",
"Configuration",
",",
"id",
"ServerID",
")",
"bool",
"{",
"for",
"_",
",",
"server",
":=",
"range",
"configuration",
".",
"Servers",
"{",
"if",
"server",
".",
"ID",
"==",
"id",
"{",
"return",
"server",
".",
"Suffr... | // hasVote returns true if the server identified by 'id' is a Voter in the
// provided Configuration. | [
"hasVote",
"returns",
"true",
"if",
"the",
"server",
"identified",
"by",
"id",
"is",
"a",
"Voter",
"in",
"the",
"provided",
"Configuration",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/configuration.go#L147-L154 | test |
hashicorp/raft | configuration.go | checkConfiguration | func checkConfiguration(configuration Configuration) error {
idSet := make(map[ServerID]bool)
addressSet := make(map[ServerAddress]bool)
var voters int
for _, server := range configuration.Servers {
if server.ID == "" {
return fmt.Errorf("Empty ID in configuration: %v", configuration)
}
if server.Address =... | go | func checkConfiguration(configuration Configuration) error {
idSet := make(map[ServerID]bool)
addressSet := make(map[ServerAddress]bool)
var voters int
for _, server := range configuration.Servers {
if server.ID == "" {
return fmt.Errorf("Empty ID in configuration: %v", configuration)
}
if server.Address =... | [
"func",
"checkConfiguration",
"(",
"configuration",
"Configuration",
")",
"error",
"{",
"idSet",
":=",
"make",
"(",
"map",
"[",
"ServerID",
"]",
"bool",
")",
"\n",
"addressSet",
":=",
"make",
"(",
"map",
"[",
"ServerAddress",
"]",
"bool",
")",
"\n",
"var",... | // checkConfiguration tests a cluster membership configuration for common
// errors. | [
"checkConfiguration",
"tests",
"a",
"cluster",
"membership",
"configuration",
"for",
"common",
"errors",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/configuration.go#L158-L185 | test |
hashicorp/raft | configuration.go | nextConfiguration | func nextConfiguration(current Configuration, currentIndex uint64, change configurationChangeRequest) (Configuration, error) {
if change.prevIndex > 0 && change.prevIndex != currentIndex {
return Configuration{}, fmt.Errorf("Configuration changed since %v (latest is %v)", change.prevIndex, currentIndex)
}
configu... | go | func nextConfiguration(current Configuration, currentIndex uint64, change configurationChangeRequest) (Configuration, error) {
if change.prevIndex > 0 && change.prevIndex != currentIndex {
return Configuration{}, fmt.Errorf("Configuration changed since %v (latest is %v)", change.prevIndex, currentIndex)
}
configu... | [
"func",
"nextConfiguration",
"(",
"current",
"Configuration",
",",
"currentIndex",
"uint64",
",",
"change",
"configurationChangeRequest",
")",
"(",
"Configuration",
",",
"error",
")",
"{",
"if",
"change",
".",
"prevIndex",
">",
"0",
"&&",
"change",
".",
"prevInd... | // nextConfiguration generates a new Configuration from the current one and a
// configuration change request. It's split from appendConfigurationEntry so
// that it can be unit tested easily. | [
"nextConfiguration",
"generates",
"a",
"new",
"Configuration",
"from",
"the",
"current",
"one",
"and",
"a",
"configuration",
"change",
"request",
".",
"It",
"s",
"split",
"from",
"appendConfigurationEntry",
"so",
"that",
"it",
"can",
"be",
"unit",
"tested",
"eas... | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/configuration.go#L190-L275 | test |
hashicorp/raft | configuration.go | encodePeers | func encodePeers(configuration Configuration, trans Transport) []byte {
// Gather up all the voters, other suffrage types are not supported by
// this data format.
var encPeers [][]byte
for _, server := range configuration.Servers {
if server.Suffrage == Voter {
encPeers = append(encPeers, trans.EncodePeer(ser... | go | func encodePeers(configuration Configuration, trans Transport) []byte {
// Gather up all the voters, other suffrage types are not supported by
// this data format.
var encPeers [][]byte
for _, server := range configuration.Servers {
if server.Suffrage == Voter {
encPeers = append(encPeers, trans.EncodePeer(ser... | [
"func",
"encodePeers",
"(",
"configuration",
"Configuration",
",",
"trans",
"Transport",
")",
"[",
"]",
"byte",
"{",
"var",
"encPeers",
"[",
"]",
"[",
"]",
"byte",
"\n",
"for",
"_",
",",
"server",
":=",
"range",
"configuration",
".",
"Servers",
"{",
"if"... | // encodePeers is used to serialize a Configuration into the old peers format.
// This is here for backwards compatibility when operating with a mix of old
// servers and should be removed once we deprecate support for protocol version 1. | [
"encodePeers",
"is",
"used",
"to",
"serialize",
"a",
"Configuration",
"into",
"the",
"old",
"peers",
"format",
".",
"This",
"is",
"here",
"for",
"backwards",
"compatibility",
"when",
"operating",
"with",
"a",
"mix",
"of",
"old",
"servers",
"and",
"should",
"... | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/configuration.go#L280-L297 | test |
hashicorp/raft | configuration.go | decodePeers | func decodePeers(buf []byte, trans Transport) Configuration {
// Decode the buffer first.
var encPeers [][]byte
if err := decodeMsgPack(buf, &encPeers); err != nil {
panic(fmt.Errorf("failed to decode peers: %v", err))
}
// Deserialize each peer.
var servers []Server
for _, enc := range encPeers {
p := tran... | go | func decodePeers(buf []byte, trans Transport) Configuration {
// Decode the buffer first.
var encPeers [][]byte
if err := decodeMsgPack(buf, &encPeers); err != nil {
panic(fmt.Errorf("failed to decode peers: %v", err))
}
// Deserialize each peer.
var servers []Server
for _, enc := range encPeers {
p := tran... | [
"func",
"decodePeers",
"(",
"buf",
"[",
"]",
"byte",
",",
"trans",
"Transport",
")",
"Configuration",
"{",
"var",
"encPeers",
"[",
"]",
"[",
"]",
"byte",
"\n",
"if",
"err",
":=",
"decodeMsgPack",
"(",
"buf",
",",
"&",
"encPeers",
")",
";",
"err",
"!=... | // decodePeers is used to deserialize an old list of peers into a Configuration.
// This is here for backwards compatibility with old log entries and snapshots;
// it should be removed eventually. | [
"decodePeers",
"is",
"used",
"to",
"deserialize",
"an",
"old",
"list",
"of",
"peers",
"into",
"a",
"Configuration",
".",
"This",
"is",
"here",
"for",
"backwards",
"compatibility",
"with",
"old",
"log",
"entries",
"and",
"snapshots",
";",
"it",
"should",
"be"... | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/configuration.go#L302-L323 | test |
hashicorp/raft | configuration.go | encodeConfiguration | func encodeConfiguration(configuration Configuration) []byte {
buf, err := encodeMsgPack(configuration)
if err != nil {
panic(fmt.Errorf("failed to encode configuration: %v", err))
}
return buf.Bytes()
} | go | func encodeConfiguration(configuration Configuration) []byte {
buf, err := encodeMsgPack(configuration)
if err != nil {
panic(fmt.Errorf("failed to encode configuration: %v", err))
}
return buf.Bytes()
} | [
"func",
"encodeConfiguration",
"(",
"configuration",
"Configuration",
")",
"[",
"]",
"byte",
"{",
"buf",
",",
"err",
":=",
"encodeMsgPack",
"(",
"configuration",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"failed t... | // encodeConfiguration serializes a Configuration using MsgPack, or panics on
// errors. | [
"encodeConfiguration",
"serializes",
"a",
"Configuration",
"using",
"MsgPack",
"or",
"panics",
"on",
"errors",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/configuration.go#L327-L333 | test |
hashicorp/raft | configuration.go | decodeConfiguration | func decodeConfiguration(buf []byte) Configuration {
var configuration Configuration
if err := decodeMsgPack(buf, &configuration); err != nil {
panic(fmt.Errorf("failed to decode configuration: %v", err))
}
return configuration
} | go | func decodeConfiguration(buf []byte) Configuration {
var configuration Configuration
if err := decodeMsgPack(buf, &configuration); err != nil {
panic(fmt.Errorf("failed to decode configuration: %v", err))
}
return configuration
} | [
"func",
"decodeConfiguration",
"(",
"buf",
"[",
"]",
"byte",
")",
"Configuration",
"{",
"var",
"configuration",
"Configuration",
"\n",
"if",
"err",
":=",
"decodeMsgPack",
"(",
"buf",
",",
"&",
"configuration",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(... | // decodeConfiguration deserializes a Configuration using MsgPack, or panics on
// errors. | [
"decodeConfiguration",
"deserializes",
"a",
"Configuration",
"using",
"MsgPack",
"or",
"panics",
"on",
"errors",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/configuration.go#L337-L343 | test |
hashicorp/raft | state.go | goFunc | func (r *raftState) goFunc(f func()) {
r.routinesGroup.Add(1)
go func() {
defer r.routinesGroup.Done()
f()
}()
} | go | func (r *raftState) goFunc(f func()) {
r.routinesGroup.Add(1)
go func() {
defer r.routinesGroup.Done()
f()
}()
} | [
"func",
"(",
"r",
"*",
"raftState",
")",
"goFunc",
"(",
"f",
"func",
"(",
")",
")",
"{",
"r",
".",
"routinesGroup",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"defer",
"r",
".",
"routinesGroup",
".",
"Done",
"(",
")",
"\n",
... | // Start a goroutine and properly handle the race between a routine
// starting and incrementing, and exiting and decrementing. | [
"Start",
"a",
"goroutine",
"and",
"properly",
"handle",
"the",
"race",
"between",
"a",
"routine",
"starting",
"and",
"incrementing",
"and",
"exiting",
"and",
"decrementing",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/state.go#L142-L148 | test |
hashicorp/raft | state.go | getLastIndex | func (r *raftState) getLastIndex() uint64 {
r.lastLock.Lock()
defer r.lastLock.Unlock()
return max(r.lastLogIndex, r.lastSnapshotIndex)
} | go | func (r *raftState) getLastIndex() uint64 {
r.lastLock.Lock()
defer r.lastLock.Unlock()
return max(r.lastLogIndex, r.lastSnapshotIndex)
} | [
"func",
"(",
"r",
"*",
"raftState",
")",
"getLastIndex",
"(",
")",
"uint64",
"{",
"r",
".",
"lastLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"lastLock",
".",
"Unlock",
"(",
")",
"\n",
"return",
"max",
"(",
"r",
".",
"lastLogIndex",
",",
... | // getLastIndex returns the last index in stable storage.
// Either from the last log or from the last snapshot. | [
"getLastIndex",
"returns",
"the",
"last",
"index",
"in",
"stable",
"storage",
".",
"Either",
"from",
"the",
"last",
"log",
"or",
"from",
"the",
"last",
"snapshot",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/state.go#L156-L160 | test |
hashicorp/raft | state.go | getLastEntry | func (r *raftState) getLastEntry() (uint64, uint64) {
r.lastLock.Lock()
defer r.lastLock.Unlock()
if r.lastLogIndex >= r.lastSnapshotIndex {
return r.lastLogIndex, r.lastLogTerm
}
return r.lastSnapshotIndex, r.lastSnapshotTerm
} | go | func (r *raftState) getLastEntry() (uint64, uint64) {
r.lastLock.Lock()
defer r.lastLock.Unlock()
if r.lastLogIndex >= r.lastSnapshotIndex {
return r.lastLogIndex, r.lastLogTerm
}
return r.lastSnapshotIndex, r.lastSnapshotTerm
} | [
"func",
"(",
"r",
"*",
"raftState",
")",
"getLastEntry",
"(",
")",
"(",
"uint64",
",",
"uint64",
")",
"{",
"r",
".",
"lastLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"lastLock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"r",
".",
"lastLogIn... | // getLastEntry returns the last index and term in stable storage.
// Either from the last log or from the last snapshot. | [
"getLastEntry",
"returns",
"the",
"last",
"index",
"and",
"term",
"in",
"stable",
"storage",
".",
"Either",
"from",
"the",
"last",
"log",
"or",
"from",
"the",
"last",
"snapshot",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/state.go#L164-L171 | test |
hashicorp/raft | raft.go | checkRPCHeader | func (r *Raft) checkRPCHeader(rpc RPC) error {
// Get the header off the RPC message.
wh, ok := rpc.Command.(WithRPCHeader)
if !ok {
return fmt.Errorf("RPC does not have a header")
}
header := wh.GetRPCHeader()
// First check is to just make sure the code can understand the
// protocol at all.
if header.Prot... | go | func (r *Raft) checkRPCHeader(rpc RPC) error {
// Get the header off the RPC message.
wh, ok := rpc.Command.(WithRPCHeader)
if !ok {
return fmt.Errorf("RPC does not have a header")
}
header := wh.GetRPCHeader()
// First check is to just make sure the code can understand the
// protocol at all.
if header.Prot... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"checkRPCHeader",
"(",
"rpc",
"RPC",
")",
"error",
"{",
"wh",
",",
"ok",
":=",
"rpc",
".",
"Command",
".",
"(",
"WithRPCHeader",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"RPC does n... | // checkRPCHeader houses logic about whether this instance of Raft can process
// the given RPC message. | [
"checkRPCHeader",
"houses",
"logic",
"about",
"whether",
"this",
"instance",
"of",
"Raft",
"can",
"process",
"the",
"given",
"RPC",
"message",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/raft.go#L35-L61 | test |
hashicorp/raft | raft.go | setLeader | func (r *Raft) setLeader(leader ServerAddress) {
r.leaderLock.Lock()
oldLeader := r.leader
r.leader = leader
r.leaderLock.Unlock()
if oldLeader != leader {
r.observe(LeaderObservation{leader: leader})
}
} | go | func (r *Raft) setLeader(leader ServerAddress) {
r.leaderLock.Lock()
oldLeader := r.leader
r.leader = leader
r.leaderLock.Unlock()
if oldLeader != leader {
r.observe(LeaderObservation{leader: leader})
}
} | [
"func",
"(",
"r",
"*",
"Raft",
")",
"setLeader",
"(",
"leader",
"ServerAddress",
")",
"{",
"r",
".",
"leaderLock",
".",
"Lock",
"(",
")",
"\n",
"oldLeader",
":=",
"r",
".",
"leader",
"\n",
"r",
".",
"leader",
"=",
"leader",
"\n",
"r",
".",
"leaderL... | // setLeader is used to modify the current leader of the cluster | [
"setLeader",
"is",
"used",
"to",
"modify",
"the",
"current",
"leader",
"of",
"the",
"cluster"
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/raft.go#L89-L97 | test |
hashicorp/raft | raft.go | requestConfigChange | func (r *Raft) requestConfigChange(req configurationChangeRequest, timeout time.Duration) IndexFuture {
var timer <-chan time.Time
if timeout > 0 {
timer = time.After(timeout)
}
future := &configurationChangeFuture{
req: req,
}
future.init()
select {
case <-timer:
return errorFuture{ErrEnqueueTimeout}
ca... | go | func (r *Raft) requestConfigChange(req configurationChangeRequest, timeout time.Duration) IndexFuture {
var timer <-chan time.Time
if timeout > 0 {
timer = time.After(timeout)
}
future := &configurationChangeFuture{
req: req,
}
future.init()
select {
case <-timer:
return errorFuture{ErrEnqueueTimeout}
ca... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"requestConfigChange",
"(",
"req",
"configurationChangeRequest",
",",
"timeout",
"time",
".",
"Duration",
")",
"IndexFuture",
"{",
"var",
"timer",
"<-",
"chan",
"time",
".",
"Time",
"\n",
"if",
"timeout",
">",
"0",
"{",
... | // requestConfigChange is a helper for the above functions that make
// configuration change requests. 'req' describes the change. For timeout,
// see AddVoter. | [
"requestConfigChange",
"is",
"a",
"helper",
"for",
"the",
"above",
"functions",
"that",
"make",
"configuration",
"change",
"requests",
".",
"req",
"describes",
"the",
"change",
".",
"For",
"timeout",
"see",
"AddVoter",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/raft.go#L102-L119 | test |
hashicorp/raft | raft.go | run | func (r *Raft) run() {
for {
// Check if we are doing a shutdown
select {
case <-r.shutdownCh:
// Clear the leader to prevent forwarding
r.setLeader("")
return
default:
}
// Enter into a sub-FSM
switch r.getState() {
case Follower:
r.runFollower()
case Candidate:
r.runCandidate()
ca... | go | func (r *Raft) run() {
for {
// Check if we are doing a shutdown
select {
case <-r.shutdownCh:
// Clear the leader to prevent forwarding
r.setLeader("")
return
default:
}
// Enter into a sub-FSM
switch r.getState() {
case Follower:
r.runFollower()
case Candidate:
r.runCandidate()
ca... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"run",
"(",
")",
"{",
"for",
"{",
"select",
"{",
"case",
"<-",
"r",
".",
"shutdownCh",
":",
"r",
".",
"setLeader",
"(",
"\"\"",
")",
"\n",
"return",
"\n",
"default",
":",
"}",
"\n",
"switch",
"r",
".",
"getSt... | // run is a long running goroutine that runs the Raft FSM. | [
"run",
"is",
"a",
"long",
"running",
"goroutine",
"that",
"runs",
"the",
"Raft",
"FSM",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/raft.go#L122-L143 | test |
hashicorp/raft | raft.go | runFollower | func (r *Raft) runFollower() {
didWarn := false
r.logger.Info(fmt.Sprintf("%v entering Follower state (Leader: %q)", r, r.Leader()))
metrics.IncrCounter([]string{"raft", "state", "follower"}, 1)
heartbeatTimer := randomTimeout(r.conf.HeartbeatTimeout)
for {
select {
case rpc := <-r.rpcCh:
r.processRPC(rpc)
... | go | func (r *Raft) runFollower() {
didWarn := false
r.logger.Info(fmt.Sprintf("%v entering Follower state (Leader: %q)", r, r.Leader()))
metrics.IncrCounter([]string{"raft", "state", "follower"}, 1)
heartbeatTimer := randomTimeout(r.conf.HeartbeatTimeout)
for {
select {
case rpc := <-r.rpcCh:
r.processRPC(rpc)
... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"runFollower",
"(",
")",
"{",
"didWarn",
":=",
"false",
"\n",
"r",
".",
"logger",
".",
"Info",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"%v entering Follower state (Leader: %q)\"",
",",
"r",
",",
"r",
".",
"Leader",
"(",
"... | // runFollower runs the FSM for a follower. | [
"runFollower",
"runs",
"the",
"FSM",
"for",
"a",
"follower",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/raft.go#L146-L215 | test |
hashicorp/raft | raft.go | liveBootstrap | func (r *Raft) liveBootstrap(configuration Configuration) error {
// Use the pre-init API to make the static updates.
err := BootstrapCluster(&r.conf, r.logs, r.stable, r.snapshots,
r.trans, configuration)
if err != nil {
return err
}
// Make the configuration live.
var entry Log
if err := r.logs.GetLog(1, ... | go | func (r *Raft) liveBootstrap(configuration Configuration) error {
// Use the pre-init API to make the static updates.
err := BootstrapCluster(&r.conf, r.logs, r.stable, r.snapshots,
r.trans, configuration)
if err != nil {
return err
}
// Make the configuration live.
var entry Log
if err := r.logs.GetLog(1, ... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"liveBootstrap",
"(",
"configuration",
"Configuration",
")",
"error",
"{",
"err",
":=",
"BootstrapCluster",
"(",
"&",
"r",
".",
"conf",
",",
"r",
".",
"logs",
",",
"r",
".",
"stable",
",",
"r",
".",
"snapshots",
",... | // liveBootstrap attempts to seed an initial configuration for the cluster. See
// the Raft object's member BootstrapCluster for more details. This must only be
// called on the main thread, and only makes sense in the follower state. | [
"liveBootstrap",
"attempts",
"to",
"seed",
"an",
"initial",
"configuration",
"for",
"the",
"cluster",
".",
"See",
"the",
"Raft",
"object",
"s",
"member",
"BootstrapCluster",
"for",
"more",
"details",
".",
"This",
"must",
"only",
"be",
"called",
"on",
"the",
... | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/raft.go#L220-L237 | test |
hashicorp/raft | raft.go | runCandidate | func (r *Raft) runCandidate() {
r.logger.Info(fmt.Sprintf("%v entering Candidate state in term %v", r, r.getCurrentTerm()+1))
metrics.IncrCounter([]string{"raft", "state", "candidate"}, 1)
// Start vote for us, and set a timeout
voteCh := r.electSelf()
electionTimer := randomTimeout(r.conf.ElectionTimeout)
// T... | go | func (r *Raft) runCandidate() {
r.logger.Info(fmt.Sprintf("%v entering Candidate state in term %v", r, r.getCurrentTerm()+1))
metrics.IncrCounter([]string{"raft", "state", "candidate"}, 1)
// Start vote for us, and set a timeout
voteCh := r.electSelf()
electionTimer := randomTimeout(r.conf.ElectionTimeout)
// T... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"runCandidate",
"(",
")",
"{",
"r",
".",
"logger",
".",
"Info",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"%v entering Candidate state in term %v\"",
",",
"r",
",",
"r",
".",
"getCurrentTerm",
"(",
")",
"+",
"1",
")",
")",
... | // runCandidate runs the FSM for a candidate. | [
"runCandidate",
"runs",
"the",
"FSM",
"for",
"a",
"candidate",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/raft.go#L240-L315 | test |
hashicorp/raft | raft.go | runLeader | func (r *Raft) runLeader() {
r.logger.Info(fmt.Sprintf("%v entering Leader state", r))
metrics.IncrCounter([]string{"raft", "state", "leader"}, 1)
// Notify that we are the leader
asyncNotifyBool(r.leaderCh, true)
// Push to the notify channel if given
if notify := r.conf.NotifyCh; notify != nil {
select {
... | go | func (r *Raft) runLeader() {
r.logger.Info(fmt.Sprintf("%v entering Leader state", r))
metrics.IncrCounter([]string{"raft", "state", "leader"}, 1)
// Notify that we are the leader
asyncNotifyBool(r.leaderCh, true)
// Push to the notify channel if given
if notify := r.conf.NotifyCh; notify != nil {
select {
... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"runLeader",
"(",
")",
"{",
"r",
".",
"logger",
".",
"Info",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"%v entering Leader state\"",
",",
"r",
")",
")",
"\n",
"metrics",
".",
"IncrCounter",
"(",
"[",
"]",
"string",
"{",
... | // runLeader runs the FSM for a leader. Do the setup here and drop into
// the leaderLoop for the hot loop. | [
"runLeader",
"runs",
"the",
"FSM",
"for",
"a",
"leader",
".",
"Do",
"the",
"setup",
"here",
"and",
"drop",
"into",
"the",
"leaderLoop",
"for",
"the",
"hot",
"loop",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/raft.go#L319-L420 | test |
hashicorp/raft | raft.go | startStopReplication | func (r *Raft) startStopReplication() {
inConfig := make(map[ServerID]bool, len(r.configurations.latest.Servers))
lastIdx := r.getLastIndex()
// Start replication goroutines that need starting
for _, server := range r.configurations.latest.Servers {
if server.ID == r.localID {
continue
}
inConfig[server.I... | go | func (r *Raft) startStopReplication() {
inConfig := make(map[ServerID]bool, len(r.configurations.latest.Servers))
lastIdx := r.getLastIndex()
// Start replication goroutines that need starting
for _, server := range r.configurations.latest.Servers {
if server.ID == r.localID {
continue
}
inConfig[server.I... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"startStopReplication",
"(",
")",
"{",
"inConfig",
":=",
"make",
"(",
"map",
"[",
"ServerID",
"]",
"bool",
",",
"len",
"(",
"r",
".",
"configurations",
".",
"latest",
".",
"Servers",
")",
")",
"\n",
"lastIdx",
":="... | // startStopReplication will set up state and start asynchronous replication to
// new peers, and stop replication to removed peers. Before removing a peer,
// it'll instruct the replication routines to try to replicate to the current
// index. This must only be called from the main thread. | [
"startStopReplication",
"will",
"set",
"up",
"state",
"and",
"start",
"asynchronous",
"replication",
"to",
"new",
"peers",
"and",
"stop",
"replication",
"to",
"removed",
"peers",
".",
"Before",
"removing",
"a",
"peer",
"it",
"ll",
"instruct",
"the",
"replication... | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/raft.go#L426-L467 | test |
hashicorp/raft | raft.go | configurationChangeChIfStable | func (r *Raft) configurationChangeChIfStable() chan *configurationChangeFuture {
// Have to wait until:
// 1. The latest configuration is committed, and
// 2. This leader has committed some entry (the noop) in this term
// https://groups.google.com/forum/#!msg/raft-dev/t4xj6dJTP6E/d2D9LrWRza8J
if r.configuratio... | go | func (r *Raft) configurationChangeChIfStable() chan *configurationChangeFuture {
// Have to wait until:
// 1. The latest configuration is committed, and
// 2. This leader has committed some entry (the noop) in this term
// https://groups.google.com/forum/#!msg/raft-dev/t4xj6dJTP6E/d2D9LrWRza8J
if r.configuratio... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"configurationChangeChIfStable",
"(",
")",
"chan",
"*",
"configurationChangeFuture",
"{",
"if",
"r",
".",
"configurations",
".",
"latestIndex",
"==",
"r",
".",
"configurations",
".",
"committedIndex",
"&&",
"r",
".",
"getCom... | // configurationChangeChIfStable returns r.configurationChangeCh if it's safe
// to process requests from it, or nil otherwise. This must only be called
// from the main thread.
//
// Note that if the conditions here were to change outside of leaderLoop to take
// this from nil to non-nil, we would need leaderLoop to b... | [
"configurationChangeChIfStable",
"returns",
"r",
".",
"configurationChangeCh",
"if",
"it",
"s",
"safe",
"to",
"process",
"requests",
"from",
"it",
"or",
"nil",
"otherwise",
".",
"This",
"must",
"only",
"be",
"called",
"from",
"the",
"main",
"thread",
".",
"Not... | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/raft.go#L475-L485 | test |
hashicorp/raft | raft.go | verifyLeader | func (r *Raft) verifyLeader(v *verifyFuture) {
// Current leader always votes for self
v.votes = 1
// Set the quorum size, hot-path for single node
v.quorumSize = r.quorumSize()
if v.quorumSize == 1 {
v.respond(nil)
return
}
// Track this request
v.notifyCh = r.verifyCh
r.leaderState.notify[v] = struct{}... | go | func (r *Raft) verifyLeader(v *verifyFuture) {
// Current leader always votes for self
v.votes = 1
// Set the quorum size, hot-path for single node
v.quorumSize = r.quorumSize()
if v.quorumSize == 1 {
v.respond(nil)
return
}
// Track this request
v.notifyCh = r.verifyCh
r.leaderState.notify[v] = struct{}... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"verifyLeader",
"(",
"v",
"*",
"verifyFuture",
")",
"{",
"v",
".",
"votes",
"=",
"1",
"\n",
"v",
".",
"quorumSize",
"=",
"r",
".",
"quorumSize",
"(",
")",
"\n",
"if",
"v",
".",
"quorumSize",
"==",
"1",
"{",
"... | // verifyLeader must be called from the main thread for safety.
// Causes the followers to attempt an immediate heartbeat. | [
"verifyLeader",
"must",
"be",
"called",
"from",
"the",
"main",
"thread",
"for",
"safety",
".",
"Causes",
"the",
"followers",
"to",
"attempt",
"an",
"immediate",
"heartbeat",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/raft.go#L642-L664 | test |
hashicorp/raft | raft.go | checkLeaderLease | func (r *Raft) checkLeaderLease() time.Duration {
// Track contacted nodes, we can always contact ourself
contacted := 1
// Check each follower
var maxDiff time.Duration
now := time.Now()
for peer, f := range r.leaderState.replState {
diff := now.Sub(f.LastContact())
if diff <= r.conf.LeaderLeaseTimeout {
... | go | func (r *Raft) checkLeaderLease() time.Duration {
// Track contacted nodes, we can always contact ourself
contacted := 1
// Check each follower
var maxDiff time.Duration
now := time.Now()
for peer, f := range r.leaderState.replState {
diff := now.Sub(f.LastContact())
if diff <= r.conf.LeaderLeaseTimeout {
... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"checkLeaderLease",
"(",
")",
"time",
".",
"Duration",
"{",
"contacted",
":=",
"1",
"\n",
"var",
"maxDiff",
"time",
".",
"Duration",
"\n",
"now",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"for",
"peer",
",",
"f",... | // checkLeaderLease is used to check if we can contact a quorum of nodes
// within the last leader lease interval. If not, we need to step down,
// as we may have lost connectivity. Returns the maximum duration without
// contact. This must only be called from the main thread. | [
"checkLeaderLease",
"is",
"used",
"to",
"check",
"if",
"we",
"can",
"contact",
"a",
"quorum",
"of",
"nodes",
"within",
"the",
"last",
"leader",
"lease",
"interval",
".",
"If",
"not",
"we",
"need",
"to",
"step",
"down",
"as",
"we",
"may",
"have",
"lost",
... | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/raft.go#L670-L703 | test |
hashicorp/raft | raft.go | restoreUserSnapshot | func (r *Raft) restoreUserSnapshot(meta *SnapshotMeta, reader io.Reader) error {
defer metrics.MeasureSince([]string{"raft", "restoreUserSnapshot"}, time.Now())
// Sanity check the version.
version := meta.Version
if version < SnapshotVersionMin || version > SnapshotVersionMax {
return fmt.Errorf("unsupported sn... | go | func (r *Raft) restoreUserSnapshot(meta *SnapshotMeta, reader io.Reader) error {
defer metrics.MeasureSince([]string{"raft", "restoreUserSnapshot"}, time.Now())
// Sanity check the version.
version := meta.Version
if version < SnapshotVersionMin || version > SnapshotVersionMax {
return fmt.Errorf("unsupported sn... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"restoreUserSnapshot",
"(",
"meta",
"*",
"SnapshotMeta",
",",
"reader",
"io",
".",
"Reader",
")",
"error",
"{",
"defer",
"metrics",
".",
"MeasureSince",
"(",
"[",
"]",
"string",
"{",
"\"raft\"",
",",
"\"restoreUserSnapsh... | // restoreUserSnapshot is used to manually consume an external snapshot, such
// as if restoring from a backup. We will use the current Raft configuration,
// not the one from the snapshot, so that we can restore into a new cluster. We
// will also use the higher of the index of the snapshot, or the current index,
// a... | [
"restoreUserSnapshot",
"is",
"used",
"to",
"manually",
"consume",
"an",
"external",
"snapshot",
"such",
"as",
"if",
"restoring",
"from",
"a",
"backup",
".",
"We",
"will",
"use",
"the",
"current",
"Raft",
"configuration",
"not",
"the",
"one",
"from",
"the",
"... | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/raft.go#L726-L812 | test |
hashicorp/raft | raft.go | appendConfigurationEntry | func (r *Raft) appendConfigurationEntry(future *configurationChangeFuture) {
configuration, err := nextConfiguration(r.configurations.latest, r.configurations.latestIndex, future.req)
if err != nil {
future.respond(err)
return
}
r.logger.Info(fmt.Sprintf("Updating configuration with %s (%v, %v) to %+v",
futu... | go | func (r *Raft) appendConfigurationEntry(future *configurationChangeFuture) {
configuration, err := nextConfiguration(r.configurations.latest, r.configurations.latestIndex, future.req)
if err != nil {
future.respond(err)
return
}
r.logger.Info(fmt.Sprintf("Updating configuration with %s (%v, %v) to %+v",
futu... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"appendConfigurationEntry",
"(",
"future",
"*",
"configurationChangeFuture",
")",
"{",
"configuration",
",",
"err",
":=",
"nextConfiguration",
"(",
"r",
".",
"configurations",
".",
"latest",
",",
"r",
".",
"configurations",
... | // appendConfigurationEntry changes the configuration and adds a new
// configuration entry to the log. This must only be called from the
// main thread. | [
"appendConfigurationEntry",
"changes",
"the",
"configuration",
"and",
"adds",
"a",
"new",
"configuration",
"entry",
"to",
"the",
"log",
".",
"This",
"must",
"only",
"be",
"called",
"from",
"the",
"main",
"thread",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/raft.go#L817-L852 | test |
hashicorp/raft | raft.go | dispatchLogs | func (r *Raft) dispatchLogs(applyLogs []*logFuture) {
now := time.Now()
defer metrics.MeasureSince([]string{"raft", "leader", "dispatchLog"}, now)
term := r.getCurrentTerm()
lastIndex := r.getLastIndex()
n := len(applyLogs)
logs := make([]*Log, n)
metrics.SetGauge([]string{"raft", "leader", "dispatchNumLogs"},... | go | func (r *Raft) dispatchLogs(applyLogs []*logFuture) {
now := time.Now()
defer metrics.MeasureSince([]string{"raft", "leader", "dispatchLog"}, now)
term := r.getCurrentTerm()
lastIndex := r.getLastIndex()
n := len(applyLogs)
logs := make([]*Log, n)
metrics.SetGauge([]string{"raft", "leader", "dispatchNumLogs"},... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"dispatchLogs",
"(",
"applyLogs",
"[",
"]",
"*",
"logFuture",
")",
"{",
"now",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"defer",
"metrics",
".",
"MeasureSince",
"(",
"[",
"]",
"string",
"{",
"\"raft\"",
",",
"\"... | // dispatchLog is called on the leader to push a log to disk, mark it
// as inflight and begin replication of it. | [
"dispatchLog",
"is",
"called",
"on",
"the",
"leader",
"to",
"push",
"a",
"log",
"to",
"disk",
"mark",
"it",
"as",
"inflight",
"and",
"begin",
"replication",
"of",
"it",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/raft.go#L856-L894 | test |
hashicorp/raft | raft.go | processLogs | func (r *Raft) processLogs(index uint64, future *logFuture) {
// Reject logs we've applied already
lastApplied := r.getLastApplied()
if index <= lastApplied {
r.logger.Warn(fmt.Sprintf("Skipping application of old log: %d", index))
return
}
// Apply all the preceding logs
for idx := r.getLastApplied() + 1; i... | go | func (r *Raft) processLogs(index uint64, future *logFuture) {
// Reject logs we've applied already
lastApplied := r.getLastApplied()
if index <= lastApplied {
r.logger.Warn(fmt.Sprintf("Skipping application of old log: %d", index))
return
}
// Apply all the preceding logs
for idx := r.getLastApplied() + 1; i... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"processLogs",
"(",
"index",
"uint64",
",",
"future",
"*",
"logFuture",
")",
"{",
"lastApplied",
":=",
"r",
".",
"getLastApplied",
"(",
")",
"\n",
"if",
"index",
"<=",
"lastApplied",
"{",
"r",
".",
"logger",
".",
"... | // processLogs is used to apply all the committed entries that haven't been
// applied up to the given index limit.
// This can be called from both leaders and followers.
// Followers call this from AppendEntries, for n entries at a time, and always
// pass future=nil.
// Leaders call this once per inflight when entrie... | [
"processLogs",
"is",
"used",
"to",
"apply",
"all",
"the",
"committed",
"entries",
"that",
"haven",
"t",
"been",
"applied",
"up",
"to",
"the",
"given",
"index",
"limit",
".",
"This",
"can",
"be",
"called",
"from",
"both",
"leaders",
"and",
"followers",
".",... | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/raft.go#L903-L928 | test |
hashicorp/raft | raft.go | processLog | func (r *Raft) processLog(l *Log, future *logFuture) {
switch l.Type {
case LogBarrier:
// Barrier is handled by the FSM
fallthrough
case LogCommand:
// Forward to the fsm handler
select {
case r.fsmMutateCh <- &commitTuple{l, future}:
case <-r.shutdownCh:
if future != nil {
future.respond(ErrRaf... | go | func (r *Raft) processLog(l *Log, future *logFuture) {
switch l.Type {
case LogBarrier:
// Barrier is handled by the FSM
fallthrough
case LogCommand:
// Forward to the fsm handler
select {
case r.fsmMutateCh <- &commitTuple{l, future}:
case <-r.shutdownCh:
if future != nil {
future.respond(ErrRaf... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"processLog",
"(",
"l",
"*",
"Log",
",",
"future",
"*",
"logFuture",
")",
"{",
"switch",
"l",
".",
"Type",
"{",
"case",
"LogBarrier",
":",
"fallthrough",
"\n",
"case",
"LogCommand",
":",
"select",
"{",
"case",
"r",... | // processLog is invoked to process the application of a single committed log entry. | [
"processLog",
"is",
"invoked",
"to",
"process",
"the",
"application",
"of",
"a",
"single",
"committed",
"log",
"entry",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/raft.go#L931-L965 | test |
hashicorp/raft | raft.go | processRPC | func (r *Raft) processRPC(rpc RPC) {
if err := r.checkRPCHeader(rpc); err != nil {
rpc.Respond(nil, err)
return
}
switch cmd := rpc.Command.(type) {
case *AppendEntriesRequest:
r.appendEntries(rpc, cmd)
case *RequestVoteRequest:
r.requestVote(rpc, cmd)
case *InstallSnapshotRequest:
r.installSnapshot(rp... | go | func (r *Raft) processRPC(rpc RPC) {
if err := r.checkRPCHeader(rpc); err != nil {
rpc.Respond(nil, err)
return
}
switch cmd := rpc.Command.(type) {
case *AppendEntriesRequest:
r.appendEntries(rpc, cmd)
case *RequestVoteRequest:
r.requestVote(rpc, cmd)
case *InstallSnapshotRequest:
r.installSnapshot(rp... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"processRPC",
"(",
"rpc",
"RPC",
")",
"{",
"if",
"err",
":=",
"r",
".",
"checkRPCHeader",
"(",
"rpc",
")",
";",
"err",
"!=",
"nil",
"{",
"rpc",
".",
"Respond",
"(",
"nil",
",",
"err",
")",
"\n",
"return",
"\n... | // processRPC is called to handle an incoming RPC request. This must only be
// called from the main thread. | [
"processRPC",
"is",
"called",
"to",
"handle",
"an",
"incoming",
"RPC",
"request",
".",
"This",
"must",
"only",
"be",
"called",
"from",
"the",
"main",
"thread",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/raft.go#L969-L986 | test |
hashicorp/raft | raft.go | processHeartbeat | func (r *Raft) processHeartbeat(rpc RPC) {
defer metrics.MeasureSince([]string{"raft", "rpc", "processHeartbeat"}, time.Now())
// Check if we are shutdown, just ignore the RPC
select {
case <-r.shutdownCh:
return
default:
}
// Ensure we are only handling a heartbeat
switch cmd := rpc.Command.(type) {
case ... | go | func (r *Raft) processHeartbeat(rpc RPC) {
defer metrics.MeasureSince([]string{"raft", "rpc", "processHeartbeat"}, time.Now())
// Check if we are shutdown, just ignore the RPC
select {
case <-r.shutdownCh:
return
default:
}
// Ensure we are only handling a heartbeat
switch cmd := rpc.Command.(type) {
case ... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"processHeartbeat",
"(",
"rpc",
"RPC",
")",
"{",
"defer",
"metrics",
".",
"MeasureSince",
"(",
"[",
"]",
"string",
"{",
"\"raft\"",
",",
"\"rpc\"",
",",
"\"processHeartbeat\"",
"}",
",",
"time",
".",
"Now",
"(",
")",... | // processHeartbeat is a special handler used just for heartbeat requests
// so that they can be fast-pathed if a transport supports it. This must only
// be called from the main thread. | [
"processHeartbeat",
"is",
"a",
"special",
"handler",
"used",
"just",
"for",
"heartbeat",
"requests",
"so",
"that",
"they",
"can",
"be",
"fast",
"-",
"pathed",
"if",
"a",
"transport",
"supports",
"it",
".",
"This",
"must",
"only",
"be",
"called",
"from",
"t... | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/raft.go#L991-L1009 | test |
hashicorp/raft | raft.go | setLastContact | func (r *Raft) setLastContact() {
r.lastContactLock.Lock()
r.lastContact = time.Now()
r.lastContactLock.Unlock()
} | go | func (r *Raft) setLastContact() {
r.lastContactLock.Lock()
r.lastContact = time.Now()
r.lastContactLock.Unlock()
} | [
"func",
"(",
"r",
"*",
"Raft",
")",
"setLastContact",
"(",
")",
"{",
"r",
".",
"lastContactLock",
".",
"Lock",
"(",
")",
"\n",
"r",
".",
"lastContact",
"=",
"time",
".",
"Now",
"(",
")",
"\n",
"r",
".",
"lastContactLock",
".",
"Unlock",
"(",
")",
... | // setLastContact is used to set the last contact time to now | [
"setLastContact",
"is",
"used",
"to",
"set",
"the",
"last",
"contact",
"time",
"to",
"now"
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/raft.go#L1380-L1384 | test |
hashicorp/raft | raft.go | persistVote | func (r *Raft) persistVote(term uint64, candidate []byte) error {
if err := r.stable.SetUint64(keyLastVoteTerm, term); err != nil {
return err
}
if err := r.stable.Set(keyLastVoteCand, candidate); err != nil {
return err
}
return nil
} | go | func (r *Raft) persistVote(term uint64, candidate []byte) error {
if err := r.stable.SetUint64(keyLastVoteTerm, term); err != nil {
return err
}
if err := r.stable.Set(keyLastVoteCand, candidate); err != nil {
return err
}
return nil
} | [
"func",
"(",
"r",
"*",
"Raft",
")",
"persistVote",
"(",
"term",
"uint64",
",",
"candidate",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"err",
":=",
"r",
".",
"stable",
".",
"SetUint64",
"(",
"keyLastVoteTerm",
",",
"term",
")",
";",
"err",
"!=",
"n... | // persistVote is used to persist our vote for safety. | [
"persistVote",
"is",
"used",
"to",
"persist",
"our",
"vote",
"for",
"safety",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/raft.go#L1455-L1463 | test |
hashicorp/raft | raft.go | setCurrentTerm | func (r *Raft) setCurrentTerm(t uint64) {
// Persist to disk first
if err := r.stable.SetUint64(keyCurrentTerm, t); err != nil {
panic(fmt.Errorf("failed to save current term: %v", err))
}
r.raftState.setCurrentTerm(t)
} | go | func (r *Raft) setCurrentTerm(t uint64) {
// Persist to disk first
if err := r.stable.SetUint64(keyCurrentTerm, t); err != nil {
panic(fmt.Errorf("failed to save current term: %v", err))
}
r.raftState.setCurrentTerm(t)
} | [
"func",
"(",
"r",
"*",
"Raft",
")",
"setCurrentTerm",
"(",
"t",
"uint64",
")",
"{",
"if",
"err",
":=",
"r",
".",
"stable",
".",
"SetUint64",
"(",
"keyCurrentTerm",
",",
"t",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"... | // setCurrentTerm is used to set the current term in a durable manner. | [
"setCurrentTerm",
"is",
"used",
"to",
"set",
"the",
"current",
"term",
"in",
"a",
"durable",
"manner",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/raft.go#L1466-L1472 | test |
hashicorp/raft | raft.go | setState | func (r *Raft) setState(state RaftState) {
r.setLeader("")
oldState := r.raftState.getState()
r.raftState.setState(state)
if oldState != state {
r.observe(state)
}
} | go | func (r *Raft) setState(state RaftState) {
r.setLeader("")
oldState := r.raftState.getState()
r.raftState.setState(state)
if oldState != state {
r.observe(state)
}
} | [
"func",
"(",
"r",
"*",
"Raft",
")",
"setState",
"(",
"state",
"RaftState",
")",
"{",
"r",
".",
"setLeader",
"(",
"\"\"",
")",
"\n",
"oldState",
":=",
"r",
".",
"raftState",
".",
"getState",
"(",
")",
"\n",
"r",
".",
"raftState",
".",
"setState",
"(... | // setState is used to update the current state. Any state
// transition causes the known leader to be cleared. This means
// that leader should be set only after updating the state. | [
"setState",
"is",
"used",
"to",
"update",
"the",
"current",
"state",
".",
"Any",
"state",
"transition",
"causes",
"the",
"known",
"leader",
"to",
"be",
"cleared",
".",
"This",
"means",
"that",
"leader",
"should",
"be",
"set",
"only",
"after",
"updating",
"... | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/raft.go#L1477-L1484 | test |
hashicorp/raft | commitment.go | getCommitIndex | func (c *commitment) getCommitIndex() uint64 {
c.Lock()
defer c.Unlock()
return c.commitIndex
} | go | func (c *commitment) getCommitIndex() uint64 {
c.Lock()
defer c.Unlock()
return c.commitIndex
} | [
"func",
"(",
"c",
"*",
"commitment",
")",
"getCommitIndex",
"(",
")",
"uint64",
"{",
"c",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"Unlock",
"(",
")",
"\n",
"return",
"c",
".",
"commitIndex",
"\n",
"}"
] | // Called by leader after commitCh is notified | [
"Called",
"by",
"leader",
"after",
"commitCh",
"is",
"notified"
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/commitment.go#L64-L68 | test |
hashicorp/raft | commitment.go | recalculate | func (c *commitment) recalculate() {
if len(c.matchIndexes) == 0 {
return
}
matched := make([]uint64, 0, len(c.matchIndexes))
for _, idx := range c.matchIndexes {
matched = append(matched, idx)
}
sort.Sort(uint64Slice(matched))
quorumMatchIndex := matched[(len(matched)-1)/2]
if quorumMatchIndex > c.commit... | go | func (c *commitment) recalculate() {
if len(c.matchIndexes) == 0 {
return
}
matched := make([]uint64, 0, len(c.matchIndexes))
for _, idx := range c.matchIndexes {
matched = append(matched, idx)
}
sort.Sort(uint64Slice(matched))
quorumMatchIndex := matched[(len(matched)-1)/2]
if quorumMatchIndex > c.commit... | [
"func",
"(",
"c",
"*",
"commitment",
")",
"recalculate",
"(",
")",
"{",
"if",
"len",
"(",
"c",
".",
"matchIndexes",
")",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n",
"matched",
":=",
"make",
"(",
"[",
"]",
"uint64",
",",
"0",
",",
"len",
"(",
"c"... | // Internal helper to calculate new commitIndex from matchIndexes.
// Must be called with lock held. | [
"Internal",
"helper",
"to",
"calculate",
"new",
"commitIndex",
"from",
"matchIndexes",
".",
"Must",
"be",
"called",
"with",
"lock",
"held",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/commitment.go#L85-L101 | test |
hashicorp/raft | util.go | randomTimeout | func randomTimeout(minVal time.Duration) <-chan time.Time {
if minVal == 0 {
return nil
}
extra := (time.Duration(rand.Int63()) % minVal)
return time.After(minVal + extra)
} | go | func randomTimeout(minVal time.Duration) <-chan time.Time {
if minVal == 0 {
return nil
}
extra := (time.Duration(rand.Int63()) % minVal)
return time.After(minVal + extra)
} | [
"func",
"randomTimeout",
"(",
"minVal",
"time",
".",
"Duration",
")",
"<-",
"chan",
"time",
".",
"Time",
"{",
"if",
"minVal",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"extra",
":=",
"(",
"time",
".",
"Duration",
"(",
"rand",
".",
"Int63",
... | // randomTimeout returns a value that is between the minVal and 2x minVal. | [
"randomTimeout",
"returns",
"a",
"value",
"that",
"is",
"between",
"the",
"minVal",
"and",
"2x",
"minVal",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/util.go#L31-L37 | test |
hashicorp/raft | util.go | generateUUID | func generateUUID() string {
buf := make([]byte, 16)
if _, err := crand.Read(buf); err != nil {
panic(fmt.Errorf("failed to read random bytes: %v", err))
}
return fmt.Sprintf("%08x-%04x-%04x-%04x-%12x",
buf[0:4],
buf[4:6],
buf[6:8],
buf[8:10],
buf[10:16])
} | go | func generateUUID() string {
buf := make([]byte, 16)
if _, err := crand.Read(buf); err != nil {
panic(fmt.Errorf("failed to read random bytes: %v", err))
}
return fmt.Sprintf("%08x-%04x-%04x-%04x-%12x",
buf[0:4],
buf[4:6],
buf[6:8],
buf[8:10],
buf[10:16])
} | [
"func",
"generateUUID",
"(",
")",
"string",
"{",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"16",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"crand",
".",
"Read",
"(",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Er... | // generateUUID is used to generate a random UUID. | [
"generateUUID",
"is",
"used",
"to",
"generate",
"a",
"random",
"UUID",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/util.go#L56-L68 | test |
hashicorp/raft | util.go | decodeMsgPack | func decodeMsgPack(buf []byte, out interface{}) error {
r := bytes.NewBuffer(buf)
hd := codec.MsgpackHandle{}
dec := codec.NewDecoder(r, &hd)
return dec.Decode(out)
} | go | func decodeMsgPack(buf []byte, out interface{}) error {
r := bytes.NewBuffer(buf)
hd := codec.MsgpackHandle{}
dec := codec.NewDecoder(r, &hd)
return dec.Decode(out)
} | [
"func",
"decodeMsgPack",
"(",
"buf",
"[",
"]",
"byte",
",",
"out",
"interface",
"{",
"}",
")",
"error",
"{",
"r",
":=",
"bytes",
".",
"NewBuffer",
"(",
"buf",
")",
"\n",
"hd",
":=",
"codec",
".",
"MsgpackHandle",
"{",
"}",
"\n",
"dec",
":=",
"codec... | // Decode reverses the encode operation on a byte slice input. | [
"Decode",
"reverses",
"the",
"encode",
"operation",
"on",
"a",
"byte",
"slice",
"input",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/util.go#L100-L105 | test |
hashicorp/raft | util.go | encodeMsgPack | func encodeMsgPack(in interface{}) (*bytes.Buffer, error) {
buf := bytes.NewBuffer(nil)
hd := codec.MsgpackHandle{}
enc := codec.NewEncoder(buf, &hd)
err := enc.Encode(in)
return buf, err
} | go | func encodeMsgPack(in interface{}) (*bytes.Buffer, error) {
buf := bytes.NewBuffer(nil)
hd := codec.MsgpackHandle{}
enc := codec.NewEncoder(buf, &hd)
err := enc.Encode(in)
return buf, err
} | [
"func",
"encodeMsgPack",
"(",
"in",
"interface",
"{",
"}",
")",
"(",
"*",
"bytes",
".",
"Buffer",
",",
"error",
")",
"{",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"nil",
")",
"\n",
"hd",
":=",
"codec",
".",
"MsgpackHandle",
"{",
"}",
"\n",
"enc... | // Encode writes an encoded object to a new bytes buffer. | [
"Encode",
"writes",
"an",
"encoded",
"object",
"to",
"a",
"new",
"bytes",
"buffer",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/util.go#L108-L114 | test |
hashicorp/raft | util.go | backoff | func backoff(base time.Duration, round, limit uint64) time.Duration {
power := min(round, limit)
for power > 2 {
base *= 2
power--
}
return base
} | go | func backoff(base time.Duration, round, limit uint64) time.Duration {
power := min(round, limit)
for power > 2 {
base *= 2
power--
}
return base
} | [
"func",
"backoff",
"(",
"base",
"time",
".",
"Duration",
",",
"round",
",",
"limit",
"uint64",
")",
"time",
".",
"Duration",
"{",
"power",
":=",
"min",
"(",
"round",
",",
"limit",
")",
"\n",
"for",
"power",
">",
"2",
"{",
"base",
"*=",
"2",
"\n",
... | // backoff is used to compute an exponential backoff
// duration. Base time is scaled by the current round,
// up to some maximum scale factor. | [
"backoff",
"is",
"used",
"to",
"compute",
"an",
"exponential",
"backoff",
"duration",
".",
"Base",
"time",
"is",
"scaled",
"by",
"the",
"current",
"round",
"up",
"to",
"some",
"maximum",
"scale",
"factor",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/util.go#L119-L126 | test |
hashicorp/raft | fuzzy/apply_src.go | newApplySource | func newApplySource(seed string) *applySource {
h := fnv.New32()
h.Write([]byte(seed))
s := &applySource{seed: int64(h.Sum32())}
s.reset()
return s
} | go | func newApplySource(seed string) *applySource {
h := fnv.New32()
h.Write([]byte(seed))
s := &applySource{seed: int64(h.Sum32())}
s.reset()
return s
} | [
"func",
"newApplySource",
"(",
"seed",
"string",
")",
"*",
"applySource",
"{",
"h",
":=",
"fnv",
".",
"New32",
"(",
")",
"\n",
"h",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"seed",
")",
")",
"\n",
"s",
":=",
"&",
"applySource",
"{",
"seed",
":",... | // newApplySource will create a new source, any source created with the same seed will generate the same sequence of data. | [
"newApplySource",
"will",
"create",
"a",
"new",
"source",
"any",
"source",
"created",
"with",
"the",
"same",
"seed",
"will",
"generate",
"the",
"same",
"sequence",
"of",
"data",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/fuzzy/apply_src.go#L16-L22 | test |
hashicorp/raft | fuzzy/apply_src.go | reset | func (a *applySource) reset() {
a.rnd = rand.New(rand.NewSource(a.seed))
} | go | func (a *applySource) reset() {
a.rnd = rand.New(rand.NewSource(a.seed))
} | [
"func",
"(",
"a",
"*",
"applySource",
")",
"reset",
"(",
")",
"{",
"a",
".",
"rnd",
"=",
"rand",
".",
"New",
"(",
"rand",
".",
"NewSource",
"(",
"a",
".",
"seed",
")",
")",
"\n",
"}"
] | // reset this source back to its initial state, it'll generate the same sequence of data it initially did | [
"reset",
"this",
"source",
"back",
"to",
"its",
"initial",
"state",
"it",
"ll",
"generate",
"the",
"same",
"sequence",
"of",
"data",
"it",
"initially",
"did"
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/fuzzy/apply_src.go#L25-L27 | test |
hashicorp/raft | config.go | DefaultConfig | func DefaultConfig() *Config {
return &Config{
ProtocolVersion: ProtocolVersionMax,
HeartbeatTimeout: 1000 * time.Millisecond,
ElectionTimeout: 1000 * time.Millisecond,
CommitTimeout: 50 * time.Millisecond,
MaxAppendEntries: 64,
ShutdownOnRemove: true,
TrailingLogs: 10240,
Snapsh... | go | func DefaultConfig() *Config {
return &Config{
ProtocolVersion: ProtocolVersionMax,
HeartbeatTimeout: 1000 * time.Millisecond,
ElectionTimeout: 1000 * time.Millisecond,
CommitTimeout: 50 * time.Millisecond,
MaxAppendEntries: 64,
ShutdownOnRemove: true,
TrailingLogs: 10240,
Snapsh... | [
"func",
"DefaultConfig",
"(",
")",
"*",
"Config",
"{",
"return",
"&",
"Config",
"{",
"ProtocolVersion",
":",
"ProtocolVersionMax",
",",
"HeartbeatTimeout",
":",
"1000",
"*",
"time",
".",
"Millisecond",
",",
"ElectionTimeout",
":",
"1000",
"*",
"time",
".",
"... | // DefaultConfig returns a Config with usable defaults. | [
"DefaultConfig",
"returns",
"a",
"Config",
"with",
"usable",
"defaults",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/config.go#L205-L219 | test |
hashicorp/raft | config.go | ValidateConfig | func ValidateConfig(config *Config) error {
// We don't actually support running as 0 in the library any more, but
// we do understand it.
protocolMin := ProtocolVersionMin
if protocolMin == 0 {
protocolMin = 1
}
if config.ProtocolVersion < protocolMin ||
config.ProtocolVersion > ProtocolVersionMax {
return... | go | func ValidateConfig(config *Config) error {
// We don't actually support running as 0 in the library any more, but
// we do understand it.
protocolMin := ProtocolVersionMin
if protocolMin == 0 {
protocolMin = 1
}
if config.ProtocolVersion < protocolMin ||
config.ProtocolVersion > ProtocolVersionMax {
return... | [
"func",
"ValidateConfig",
"(",
"config",
"*",
"Config",
")",
"error",
"{",
"protocolMin",
":=",
"ProtocolVersionMin",
"\n",
"if",
"protocolMin",
"==",
"0",
"{",
"protocolMin",
"=",
"1",
"\n",
"}",
"\n",
"if",
"config",
".",
"ProtocolVersion",
"<",
"protocolM... | // ValidateConfig is used to validate a sane configuration | [
"ValidateConfig",
"is",
"used",
"to",
"validate",
"a",
"sane",
"configuration"
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/config.go#L222-L265 | test |
hashicorp/raft | snapshot.go | runSnapshots | func (r *Raft) runSnapshots() {
for {
select {
case <-randomTimeout(r.conf.SnapshotInterval):
// Check if we should snapshot
if !r.shouldSnapshot() {
continue
}
// Trigger a snapshot
if _, err := r.takeSnapshot(); err != nil {
r.logger.Error(fmt.Sprintf("Failed to take snapshot: %v", err))
... | go | func (r *Raft) runSnapshots() {
for {
select {
case <-randomTimeout(r.conf.SnapshotInterval):
// Check if we should snapshot
if !r.shouldSnapshot() {
continue
}
// Trigger a snapshot
if _, err := r.takeSnapshot(); err != nil {
r.logger.Error(fmt.Sprintf("Failed to take snapshot: %v", err))
... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"runSnapshots",
"(",
")",
"{",
"for",
"{",
"select",
"{",
"case",
"<-",
"randomTimeout",
"(",
"r",
".",
"conf",
".",
"SnapshotInterval",
")",
":",
"if",
"!",
"r",
".",
"shouldSnapshot",
"(",
")",
"{",
"continue",
... | // runSnapshots is a long running goroutine used to manage taking
// new snapshots of the FSM. It runs in parallel to the FSM and
// main goroutines, so that snapshots do not block normal operation. | [
"runSnapshots",
"is",
"a",
"long",
"running",
"goroutine",
"used",
"to",
"manage",
"taking",
"new",
"snapshots",
"of",
"the",
"FSM",
".",
"It",
"runs",
"in",
"parallel",
"to",
"the",
"FSM",
"and",
"main",
"goroutines",
"so",
"that",
"snapshots",
"do",
"not... | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/snapshot.go#L69-L99 | test |
hashicorp/raft | snapshot.go | shouldSnapshot | func (r *Raft) shouldSnapshot() bool {
// Check the last snapshot index
lastSnap, _ := r.getLastSnapshot()
// Check the last log index
lastIdx, err := r.logs.LastIndex()
if err != nil {
r.logger.Error(fmt.Sprintf("Failed to get last log index: %v", err))
return false
}
// Compare the delta to the threshold... | go | func (r *Raft) shouldSnapshot() bool {
// Check the last snapshot index
lastSnap, _ := r.getLastSnapshot()
// Check the last log index
lastIdx, err := r.logs.LastIndex()
if err != nil {
r.logger.Error(fmt.Sprintf("Failed to get last log index: %v", err))
return false
}
// Compare the delta to the threshold... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"shouldSnapshot",
"(",
")",
"bool",
"{",
"lastSnap",
",",
"_",
":=",
"r",
".",
"getLastSnapshot",
"(",
")",
"\n",
"lastIdx",
",",
"err",
":=",
"r",
".",
"logs",
".",
"LastIndex",
"(",
")",
"\n",
"if",
"err",
"!... | // shouldSnapshot checks if we meet the conditions to take
// a new snapshot. | [
"shouldSnapshot",
"checks",
"if",
"we",
"meet",
"the",
"conditions",
"to",
"take",
"a",
"new",
"snapshot",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/snapshot.go#L103-L117 | test |
hashicorp/raft | snapshot.go | takeSnapshot | func (r *Raft) takeSnapshot() (string, error) {
defer metrics.MeasureSince([]string{"raft", "snapshot", "takeSnapshot"}, time.Now())
// Create a request for the FSM to perform a snapshot.
snapReq := &reqSnapshotFuture{}
snapReq.init()
// Wait for dispatch or shutdown.
select {
case r.fsmSnapshotCh <- snapReq:
... | go | func (r *Raft) takeSnapshot() (string, error) {
defer metrics.MeasureSince([]string{"raft", "snapshot", "takeSnapshot"}, time.Now())
// Create a request for the FSM to perform a snapshot.
snapReq := &reqSnapshotFuture{}
snapReq.init()
// Wait for dispatch or shutdown.
select {
case r.fsmSnapshotCh <- snapReq:
... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"takeSnapshot",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"defer",
"metrics",
".",
"MeasureSince",
"(",
"[",
"]",
"string",
"{",
"\"raft\"",
",",
"\"snapshot\"",
",",
"\"takeSnapshot\"",
"}",
",",
"time",
".",... | // takeSnapshot is used to take a new snapshot. This must only be called from
// the snapshot thread, never the main thread. This returns the ID of the new
// snapshot, along with an error. | [
"takeSnapshot",
"is",
"used",
"to",
"take",
"a",
"new",
"snapshot",
".",
"This",
"must",
"only",
"be",
"called",
"from",
"the",
"snapshot",
"thread",
"never",
"the",
"main",
"thread",
".",
"This",
"returns",
"the",
"ID",
"of",
"the",
"new",
"snapshot",
"... | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/snapshot.go#L122-L207 | test |
hashicorp/raft | snapshot.go | compactLogs | func (r *Raft) compactLogs(snapIdx uint64) error {
defer metrics.MeasureSince([]string{"raft", "compactLogs"}, time.Now())
// Determine log ranges to compact
minLog, err := r.logs.FirstIndex()
if err != nil {
return fmt.Errorf("failed to get first log index: %v", err)
}
// Check if we have enough logs to trunc... | go | func (r *Raft) compactLogs(snapIdx uint64) error {
defer metrics.MeasureSince([]string{"raft", "compactLogs"}, time.Now())
// Determine log ranges to compact
minLog, err := r.logs.FirstIndex()
if err != nil {
return fmt.Errorf("failed to get first log index: %v", err)
}
// Check if we have enough logs to trunc... | [
"func",
"(",
"r",
"*",
"Raft",
")",
"compactLogs",
"(",
"snapIdx",
"uint64",
")",
"error",
"{",
"defer",
"metrics",
".",
"MeasureSince",
"(",
"[",
"]",
"string",
"{",
"\"raft\"",
",",
"\"compactLogs\"",
"}",
",",
"time",
".",
"Now",
"(",
")",
")",
"\... | // compactLogs takes the last inclusive index of a snapshot
// and trims the logs that are no longer needed. | [
"compactLogs",
"takes",
"the",
"last",
"inclusive",
"index",
"of",
"a",
"snapshot",
"and",
"trims",
"the",
"logs",
"that",
"are",
"no",
"longer",
"needed",
"."
] | 773bcaa2009bf059c5c06457b9fccd156d5e91e7 | https://github.com/hashicorp/raft/blob/773bcaa2009bf059c5c06457b9fccd156d5e91e7/snapshot.go#L211-L239 | test |
gobuffalo/buffalo | buffalo/cmd/fix/webpack.go | WebpackCheck | func WebpackCheck(r *Runner) error {
fmt.Println("~~~ Checking webpack.config.js ~~~")
if !r.App.WithWebpack {
return nil
}
box := webpack.Templates
f, err := box.FindString("webpack.config.js.tmpl")
if err != nil {
return err
}
tmpl, err := template.New("webpack").Parse(f)
if err != nil {
return err... | go | func WebpackCheck(r *Runner) error {
fmt.Println("~~~ Checking webpack.config.js ~~~")
if !r.App.WithWebpack {
return nil
}
box := webpack.Templates
f, err := box.FindString("webpack.config.js.tmpl")
if err != nil {
return err
}
tmpl, err := template.New("webpack").Parse(f)
if err != nil {
return err... | [
"func",
"WebpackCheck",
"(",
"r",
"*",
"Runner",
")",
"error",
"{",
"fmt",
".",
"Println",
"(",
"\"~~~ Checking webpack.config.js ~~~\"",
")",
"\n",
"if",
"!",
"r",
".",
"App",
".",
"WithWebpack",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"box",
":=",
"webp... | // WebpackCheck will compare the current default Buffalo
// webpack.config.js against the applications webpack.config.js. If they are
// different you have the option to overwrite the existing webpack.config.js
// file with the new one. | [
"WebpackCheck",
"will",
"compare",
"the",
"current",
"default",
"Buffalo",
"webpack",
".",
"config",
".",
"js",
"against",
"the",
"applications",
"webpack",
".",
"config",
".",
"js",
".",
"If",
"they",
"are",
"different",
"you",
"have",
"the",
"option",
"to"... | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/buffalo/cmd/fix/webpack.go#L17-L69 | test |
gobuffalo/buffalo | genny/vcs/vcs.go | New | func New(opts *Options) (*genny.Generator, error) {
g := genny.New()
if err := opts.Validate(); err != nil {
return g, err
}
if opts.Provider == "none" {
return g, nil
}
box := packr.New("buffalo:genny:vcs", "../vcs/templates")
s, err := box.FindString("ignore.tmpl")
if err != nil {
return g, err
}
... | go | func New(opts *Options) (*genny.Generator, error) {
g := genny.New()
if err := opts.Validate(); err != nil {
return g, err
}
if opts.Provider == "none" {
return g, nil
}
box := packr.New("buffalo:genny:vcs", "../vcs/templates")
s, err := box.FindString("ignore.tmpl")
if err != nil {
return g, err
}
... | [
"func",
"New",
"(",
"opts",
"*",
"Options",
")",
"(",
"*",
"genny",
".",
"Generator",
",",
"error",
")",
"{",
"g",
":=",
"genny",
".",
"New",
"(",
")",
"\n",
"if",
"err",
":=",
"opts",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
... | // New generator for adding VCS to an application | [
"New",
"generator",
"for",
"adding",
"VCS",
"to",
"an",
"application"
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/genny/vcs/vcs.go#L12-L42 | test |
gobuffalo/buffalo | servers/listener.go | UnixSocket | func UnixSocket(addr string) (*Listener, error) {
listener, err := net.Listen("unix", addr)
if err != nil {
return nil, err
}
return &Listener{
Server: &http.Server{},
Listener: listener,
}, nil
} | go | func UnixSocket(addr string) (*Listener, error) {
listener, err := net.Listen("unix", addr)
if err != nil {
return nil, err
}
return &Listener{
Server: &http.Server{},
Listener: listener,
}, nil
} | [
"func",
"UnixSocket",
"(",
"addr",
"string",
")",
"(",
"*",
"Listener",
",",
"error",
")",
"{",
"listener",
",",
"err",
":=",
"net",
".",
"Listen",
"(",
"\"unix\"",
",",
"addr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",... | // UnixSocket returns a new Listener on that address | [
"UnixSocket",
"returns",
"a",
"new",
"Listener",
"on",
"that",
"address"
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/servers/listener.go#L29-L38 | test |
gobuffalo/buffalo | errors.go | Get | func (e ErrorHandlers) Get(status int) ErrorHandler {
if eh, ok := e[status]; ok {
return eh
}
if eh, ok := e[0]; ok {
return eh
}
return defaultErrorHandler
} | go | func (e ErrorHandlers) Get(status int) ErrorHandler {
if eh, ok := e[status]; ok {
return eh
}
if eh, ok := e[0]; ok {
return eh
}
return defaultErrorHandler
} | [
"func",
"(",
"e",
"ErrorHandlers",
")",
"Get",
"(",
"status",
"int",
")",
"ErrorHandler",
"{",
"if",
"eh",
",",
"ok",
":=",
"e",
"[",
"status",
"]",
";",
"ok",
"{",
"return",
"eh",
"\n",
"}",
"\n",
"if",
"eh",
",",
"ok",
":=",
"e",
"[",
"0",
... | // Get a registered ErrorHandler for this status code. If
// no ErrorHandler has been registered, a default one will
// be returned. | [
"Get",
"a",
"registered",
"ErrorHandler",
"for",
"this",
"status",
"code",
".",
"If",
"no",
"ErrorHandler",
"has",
"been",
"registered",
"a",
"default",
"one",
"will",
"be",
"returned",
"."
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/errors.go#L48-L56 | test |
gobuffalo/buffalo | errors.go | PanicHandler | func (a *App) PanicHandler(next Handler) Handler {
return func(c Context) error {
defer func() { //catch or finally
r := recover()
var err error
if r != nil { //catch
switch t := r.(type) {
case error:
err = t
case string:
err = errors.New(t)
default:
err = errors.New(fmt.Spri... | go | func (a *App) PanicHandler(next Handler) Handler {
return func(c Context) error {
defer func() { //catch or finally
r := recover()
var err error
if r != nil { //catch
switch t := r.(type) {
case error:
err = t
case string:
err = errors.New(t)
default:
err = errors.New(fmt.Spri... | [
"func",
"(",
"a",
"*",
"App",
")",
"PanicHandler",
"(",
"next",
"Handler",
")",
"Handler",
"{",
"return",
"func",
"(",
"c",
"Context",
")",
"error",
"{",
"defer",
"func",
"(",
")",
"{",
"r",
":=",
"recover",
"(",
")",
"\n",
"var",
"err",
"error",
... | // PanicHandler recovers from panics gracefully and calls
// the error handling code for a 500 error. | [
"PanicHandler",
"recovers",
"from",
"panics",
"gracefully",
"and",
"calls",
"the",
"error",
"handling",
"code",
"for",
"a",
"500",
"error",
"."
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/errors.go#L70-L97 | test |
gobuffalo/buffalo | render/template.go | partialFeeder | func (s templateRenderer) partialFeeder(name string) (string, error) {
ct := strings.ToLower(s.contentType)
d, f := filepath.Split(name)
name = filepath.Join(d, "_"+f)
name = fixExtension(name, ct)
return s.TemplatesBox.FindString(name)
} | go | func (s templateRenderer) partialFeeder(name string) (string, error) {
ct := strings.ToLower(s.contentType)
d, f := filepath.Split(name)
name = filepath.Join(d, "_"+f)
name = fixExtension(name, ct)
return s.TemplatesBox.FindString(name)
} | [
"func",
"(",
"s",
"templateRenderer",
")",
"partialFeeder",
"(",
"name",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"ct",
":=",
"strings",
".",
"ToLower",
"(",
"s",
".",
"contentType",
")",
"\n",
"d",
",",
"f",
":=",
"filepath",
".",
"Spli... | // partialFeeder returns template string for the name from `TemplateBox`.
// It should be registered as helper named `partialFeeder` so plush can
// find it with the name. | [
"partialFeeder",
"returns",
"template",
"string",
"for",
"the",
"name",
"from",
"TemplateBox",
".",
"It",
"should",
"be",
"registered",
"as",
"helper",
"named",
"partialFeeder",
"so",
"plush",
"can",
"find",
"it",
"with",
"the",
"name",
"."
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/render/template.go#L56-L64 | test |
gobuffalo/buffalo | render/render.go | New | func New(opts Options) *Engine {
if opts.Helpers == nil {
opts.Helpers = map[string]interface{}{}
}
if opts.TemplateEngines == nil {
opts.TemplateEngines = map[string]TemplateEngine{}
}
if _, ok := opts.TemplateEngines["html"]; !ok {
opts.TemplateEngines["html"] = plush.BuffaloRenderer
}
if _, ok := opts.... | go | func New(opts Options) *Engine {
if opts.Helpers == nil {
opts.Helpers = map[string]interface{}{}
}
if opts.TemplateEngines == nil {
opts.TemplateEngines = map[string]TemplateEngine{}
}
if _, ok := opts.TemplateEngines["html"]; !ok {
opts.TemplateEngines["html"] = plush.BuffaloRenderer
}
if _, ok := opts.... | [
"func",
"New",
"(",
"opts",
"Options",
")",
"*",
"Engine",
"{",
"if",
"opts",
".",
"Helpers",
"==",
"nil",
"{",
"opts",
".",
"Helpers",
"=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"if",
"opts",
".",
"Template... | // New render.Engine ready to go with your Options
// and some defaults we think you might like. | [
"New",
"render",
".",
"Engine",
"ready",
"to",
"go",
"with",
"your",
"Options",
"and",
"some",
"defaults",
"we",
"think",
"you",
"might",
"like",
"."
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/render/render.go#L17-L52 | test |
gobuffalo/buffalo | mail/internal/mail/writeto.go | WriteTo | func (m *Message) WriteTo(w io.Writer) (int64, error) {
mw := &messageWriter{w: w}
mw.writeMessage(m)
return mw.n, mw.err
} | go | func (m *Message) WriteTo(w io.Writer) (int64, error) {
mw := &messageWriter{w: w}
mw.writeMessage(m)
return mw.n, mw.err
} | [
"func",
"(",
"m",
"*",
"Message",
")",
"WriteTo",
"(",
"w",
"io",
".",
"Writer",
")",
"(",
"int64",
",",
"error",
")",
"{",
"mw",
":=",
"&",
"messageWriter",
"{",
"w",
":",
"w",
"}",
"\n",
"mw",
".",
"writeMessage",
"(",
"m",
")",
"\n",
"return... | // WriteTo implements io.WriterTo. It dumps the whole message into w. | [
"WriteTo",
"implements",
"io",
".",
"WriterTo",
".",
"It",
"dumps",
"the",
"whole",
"message",
"into",
"w",
"."
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/mail/internal/mail/writeto.go#L15-L19 | test |
gobuffalo/buffalo | mail/smtp_sender.go | Send | func (sm SMTPSender) Send(message Message) error {
gm := gomail.NewMessage()
gm.SetHeader("From", message.From)
gm.SetHeader("To", message.To...)
gm.SetHeader("Subject", message.Subject)
gm.SetHeader("Cc", message.CC...)
gm.SetHeader("Bcc", message.Bcc...)
sm.addBodies(message, gm)
sm.addAttachments(message, ... | go | func (sm SMTPSender) Send(message Message) error {
gm := gomail.NewMessage()
gm.SetHeader("From", message.From)
gm.SetHeader("To", message.To...)
gm.SetHeader("Subject", message.Subject)
gm.SetHeader("Cc", message.CC...)
gm.SetHeader("Bcc", message.Bcc...)
sm.addBodies(message, gm)
sm.addAttachments(message, ... | [
"func",
"(",
"sm",
"SMTPSender",
")",
"Send",
"(",
"message",
"Message",
")",
"error",
"{",
"gm",
":=",
"gomail",
".",
"NewMessage",
"(",
")",
"\n",
"gm",
".",
"SetHeader",
"(",
"\"From\"",
",",
"message",
".",
"From",
")",
"\n",
"gm",
".",
"SetHeade... | //Send a message using SMTP configuration or returns an error if something goes wrong. | [
"Send",
"a",
"message",
"using",
"SMTP",
"configuration",
"or",
"returns",
"an",
"error",
"if",
"something",
"goes",
"wrong",
"."
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/mail/smtp_sender.go#L18-L41 | test |
gobuffalo/buffalo | mail/smtp_sender.go | NewSMTPSender | func NewSMTPSender(host string, port string, user string, password string) (SMTPSender, error) {
iport, err := strconv.Atoi(port)
if err != nil {
return SMTPSender{}, errors.New("invalid port for the SMTP mail")
}
dialer := &gomail.Dialer{
Host: host,
Port: iport,
}
if user != "" {
dialer.Username = us... | go | func NewSMTPSender(host string, port string, user string, password string) (SMTPSender, error) {
iport, err := strconv.Atoi(port)
if err != nil {
return SMTPSender{}, errors.New("invalid port for the SMTP mail")
}
dialer := &gomail.Dialer{
Host: host,
Port: iport,
}
if user != "" {
dialer.Username = us... | [
"func",
"NewSMTPSender",
"(",
"host",
"string",
",",
"port",
"string",
",",
"user",
"string",
",",
"password",
"string",
")",
"(",
"SMTPSender",
",",
"error",
")",
"{",
"iport",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"port",
")",
"\n",
"if",
... | //NewSMTPSender builds a SMTP mail based in passed config. | [
"NewSMTPSender",
"builds",
"a",
"SMTP",
"mail",
"based",
"in",
"passed",
"config",
"."
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/mail/smtp_sender.go#L76-L96 | test |
gobuffalo/buffalo | default_context.go | Param | func (d *DefaultContext) Param(key string) string {
return d.Params().Get(key)
} | go | func (d *DefaultContext) Param(key string) string {
return d.Params().Get(key)
} | [
"func",
"(",
"d",
"*",
"DefaultContext",
")",
"Param",
"(",
"key",
"string",
")",
"string",
"{",
"return",
"d",
".",
"Params",
"(",
")",
".",
"Get",
"(",
"key",
")",
"\n",
"}"
] | // Param returns a param, either named or query string,
// based on the key. | [
"Param",
"returns",
"a",
"param",
"either",
"named",
"or",
"query",
"string",
"based",
"on",
"the",
"key",
"."
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/default_context.go#L64-L66 | test |
gobuffalo/buffalo | default_context.go | Set | func (d *DefaultContext) Set(key string, value interface{}) {
d.moot.Lock()
d.data[key] = value
d.moot.Unlock()
} | go | func (d *DefaultContext) Set(key string, value interface{}) {
d.moot.Lock()
d.data[key] = value
d.moot.Unlock()
} | [
"func",
"(",
"d",
"*",
"DefaultContext",
")",
"Set",
"(",
"key",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"d",
".",
"moot",
".",
"Lock",
"(",
")",
"\n",
"d",
".",
"data",
"[",
"key",
"]",
"=",
"value",
"\n",
"d",
".",
"moot",
... | // Set a value onto the Context. Any value set onto the Context
// will be automatically available in templates. | [
"Set",
"a",
"value",
"onto",
"the",
"Context",
".",
"Any",
"value",
"set",
"onto",
"the",
"Context",
"will",
"be",
"automatically",
"available",
"in",
"templates",
"."
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/default_context.go#L70-L74 | test |
gobuffalo/buffalo | default_context.go | Value | func (d *DefaultContext) Value(key interface{}) interface{} {
if k, ok := key.(string); ok {
d.moot.RLock()
defer d.moot.RUnlock()
if v, ok := d.data[k]; ok {
return v
}
}
return d.Context.Value(key)
} | go | func (d *DefaultContext) Value(key interface{}) interface{} {
if k, ok := key.(string); ok {
d.moot.RLock()
defer d.moot.RUnlock()
if v, ok := d.data[k]; ok {
return v
}
}
return d.Context.Value(key)
} | [
"func",
"(",
"d",
"*",
"DefaultContext",
")",
"Value",
"(",
"key",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"if",
"k",
",",
"ok",
":=",
"key",
".",
"(",
"string",
")",
";",
"ok",
"{",
"d",
".",
"moot",
".",
"RLock",
"(",
")",
"... | // Value that has previously stored on the context. | [
"Value",
"that",
"has",
"previously",
"stored",
"on",
"the",
"context",
"."
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/default_context.go#L77-L86 | test |
gobuffalo/buffalo | default_context.go | Redirect | func (d *DefaultContext) Redirect(status int, url string, args ...interface{}) error {
d.Flash().persist(d.Session())
if strings.HasSuffix(url, "Path()") {
if len(args) > 1 {
return fmt.Errorf("you must pass only a map[string]interface{} to a route path: %T", args)
}
var m map[string]interface{}
if len(ar... | go | func (d *DefaultContext) Redirect(status int, url string, args ...interface{}) error {
d.Flash().persist(d.Session())
if strings.HasSuffix(url, "Path()") {
if len(args) > 1 {
return fmt.Errorf("you must pass only a map[string]interface{} to a route path: %T", args)
}
var m map[string]interface{}
if len(ar... | [
"func",
"(",
"d",
"*",
"DefaultContext",
")",
"Redirect",
"(",
"status",
"int",
",",
"url",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"d",
".",
"Flash",
"(",
")",
".",
"persist",
"(",
"d",
".",
"Session",
"(",
")",
"... | // Redirect a request with the given status to the given URL. | [
"Redirect",
"a",
"request",
"with",
"the",
"given",
"status",
"to",
"the",
"given",
"URL",
"."
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/default_context.go#L189-L221 | test |
gobuffalo/buffalo | default_context.go | File | func (d *DefaultContext) File(name string) (binding.File, error) {
req := d.Request()
if err := req.ParseMultipartForm(5 * 1024 * 1024); err != nil {
return binding.File{}, err
}
f, h, err := req.FormFile(name)
bf := binding.File{
File: f,
FileHeader: h,
}
if err != nil {
return bf, err
}
return ... | go | func (d *DefaultContext) File(name string) (binding.File, error) {
req := d.Request()
if err := req.ParseMultipartForm(5 * 1024 * 1024); err != nil {
return binding.File{}, err
}
f, h, err := req.FormFile(name)
bf := binding.File{
File: f,
FileHeader: h,
}
if err != nil {
return bf, err
}
return ... | [
"func",
"(",
"d",
"*",
"DefaultContext",
")",
"File",
"(",
"name",
"string",
")",
"(",
"binding",
".",
"File",
",",
"error",
")",
"{",
"req",
":=",
"d",
".",
"Request",
"(",
")",
"\n",
"if",
"err",
":=",
"req",
".",
"ParseMultipartForm",
"(",
"5",
... | // File returns an uploaded file by name, or an error | [
"File",
"returns",
"an",
"uploaded",
"file",
"by",
"name",
"or",
"an",
"error"
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/default_context.go#L248-L262 | test |
gobuffalo/buffalo | default_context.go | MarshalJSON | func (d *DefaultContext) MarshalJSON() ([]byte, error) {
m := map[string]interface{}{}
data := d.Data()
for k, v := range data {
// don't try and marshal ourself
if _, ok := v.(*DefaultContext); ok {
continue
}
if _, err := json.Marshal(v); err == nil {
// it can be marshaled, so add it:
m[k] = v
... | go | func (d *DefaultContext) MarshalJSON() ([]byte, error) {
m := map[string]interface{}{}
data := d.Data()
for k, v := range data {
// don't try and marshal ourself
if _, ok := v.(*DefaultContext); ok {
continue
}
if _, err := json.Marshal(v); err == nil {
// it can be marshaled, so add it:
m[k] = v
... | [
"func",
"(",
"d",
"*",
"DefaultContext",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"m",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"data",
":=",
"d",
".",
"Data",
"(",
")",
"\n",
... | // MarshalJSON implements json marshaling for the context | [
"MarshalJSON",
"implements",
"json",
"marshaling",
"for",
"the",
"context"
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/default_context.go#L265-L279 | test |
gobuffalo/buffalo | genny/newapp/api/api.go | New | func New(opts *Options) (*genny.Group, error) {
if err := opts.Validate(); err != nil {
return nil, err
}
gg, err := core.New(opts.Options)
if err != nil {
return gg, err
}
g := genny.New()
data := map[string]interface{}{
"opts": opts,
}
helpers := template.FuncMap{}
t := gogen.TemplateTransformer(d... | go | func New(opts *Options) (*genny.Group, error) {
if err := opts.Validate(); err != nil {
return nil, err
}
gg, err := core.New(opts.Options)
if err != nil {
return gg, err
}
g := genny.New()
data := map[string]interface{}{
"opts": opts,
}
helpers := template.FuncMap{}
t := gogen.TemplateTransformer(d... | [
"func",
"New",
"(",
"opts",
"*",
"Options",
")",
"(",
"*",
"genny",
".",
"Group",
",",
"error",
")",
"{",
"if",
"err",
":=",
"opts",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"gg",
... | // New generator for creating a Buffalo API application | [
"New",
"generator",
"for",
"creating",
"a",
"Buffalo",
"API",
"application"
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/genny/newapp/api/api.go#L13-L37 | test |
gobuffalo/buffalo | app.go | New | func New(opts Options) *App {
LoadPlugins()
envy.Load()
opts = optionsWithDefaults(opts)
a := &App{
Options: opts,
ErrorHandlers: ErrorHandlers{
404: defaultErrorHandler,
500: defaultErrorHandler,
},
router: mux.NewRouter(),
moot: &sync.RWMutex{},
routes: RouteList{},
children: []*App{}... | go | func New(opts Options) *App {
LoadPlugins()
envy.Load()
opts = optionsWithDefaults(opts)
a := &App{
Options: opts,
ErrorHandlers: ErrorHandlers{
404: defaultErrorHandler,
500: defaultErrorHandler,
},
router: mux.NewRouter(),
moot: &sync.RWMutex{},
routes: RouteList{},
children: []*App{}... | [
"func",
"New",
"(",
"opts",
"Options",
")",
"*",
"App",
"{",
"LoadPlugins",
"(",
")",
"\n",
"envy",
".",
"Load",
"(",
")",
"\n",
"opts",
"=",
"optionsWithDefaults",
"(",
"opts",
")",
"\n",
"a",
":=",
"&",
"App",
"{",
"Options",
":",
"opts",
",",
... | // New returns a new instance of App and adds some sane, and useful, defaults. | [
"New",
"returns",
"a",
"new",
"instance",
"of",
"App",
"and",
"adds",
"some",
"sane",
"and",
"useful",
"defaults",
"."
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/app.go#L35-L74 | test |
gobuffalo/buffalo | buffalo/cmd/fix/deprecations.go | DeprecrationsCheck | func DeprecrationsCheck(r *Runner) error {
fmt.Println("~~~ Checking for deprecations ~~~")
b, err := ioutil.ReadFile("main.go")
if err != nil {
return err
}
if bytes.Contains(b, []byte("app.Start")) {
r.Warnings = append(r.Warnings, "app.Start has been removed in v0.11.0. Use app.Serve Instead. [main.go]")
}... | go | func DeprecrationsCheck(r *Runner) error {
fmt.Println("~~~ Checking for deprecations ~~~")
b, err := ioutil.ReadFile("main.go")
if err != nil {
return err
}
if bytes.Contains(b, []byte("app.Start")) {
r.Warnings = append(r.Warnings, "app.Start has been removed in v0.11.0. Use app.Serve Instead. [main.go]")
}... | [
"func",
"DeprecrationsCheck",
"(",
"r",
"*",
"Runner",
")",
"error",
"{",
"fmt",
".",
"Println",
"(",
"\"~~~ Checking for deprecations ~~~\"",
")",
"\n",
"b",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"\"main.go\"",
")",
"\n",
"if",
"err",
"!=",
"n... | // DeprecrationsCheck will either log, or fix, deprecated items in the application | [
"DeprecrationsCheck",
"will",
"either",
"log",
"or",
"fix",
"deprecated",
"items",
"in",
"the",
"application"
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/buffalo/cmd/fix/deprecations.go#L12-L58 | test |
gobuffalo/buffalo | resource.go | List | func (v BaseResource) List(c Context) error {
return c.Error(404, errors.New("resource not implemented"))
} | go | func (v BaseResource) List(c Context) error {
return c.Error(404, errors.New("resource not implemented"))
} | [
"func",
"(",
"v",
"BaseResource",
")",
"List",
"(",
"c",
"Context",
")",
"error",
"{",
"return",
"c",
".",
"Error",
"(",
"404",
",",
"errors",
".",
"New",
"(",
"\"resource not implemented\"",
")",
")",
"\n",
"}"
] | // List default implementation. Returns a 404 | [
"List",
"default",
"implementation",
".",
"Returns",
"a",
"404"
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/resource.go#L51-L53 | test |
gobuffalo/buffalo | render/func.go | Render | func (s funcRenderer) Render(w io.Writer, data Data) error {
return s.renderFunc(w, data)
} | go | func (s funcRenderer) Render(w io.Writer, data Data) error {
return s.renderFunc(w, data)
} | [
"func",
"(",
"s",
"funcRenderer",
")",
"Render",
"(",
"w",
"io",
".",
"Writer",
",",
"data",
"Data",
")",
"error",
"{",
"return",
"s",
".",
"renderFunc",
"(",
"w",
",",
"data",
")",
"\n",
"}"
] | // Render the provided Data to the provider Writer using the
// RendererFunc provide. | [
"Render",
"the",
"provided",
"Data",
"to",
"the",
"provider",
"Writer",
"using",
"the",
"RendererFunc",
"provide",
"."
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/render/func.go#L22-L24 | test |
gobuffalo/buffalo | session.go | Save | func (s *Session) Save() error {
return s.Session.Save(s.req, s.res)
} | go | func (s *Session) Save() error {
return s.Session.Save(s.req, s.res)
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"Save",
"(",
")",
"error",
"{",
"return",
"s",
".",
"Session",
".",
"Save",
"(",
"s",
".",
"req",
",",
"s",
".",
"res",
")",
"\n",
"}"
] | // Save the current session. | [
"Save",
"the",
"current",
"session",
"."
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/session.go#L18-L20 | test |
gobuffalo/buffalo | session.go | GetOnce | func (s *Session) GetOnce(name interface{}) interface{} {
if x, ok := s.Session.Values[name]; ok {
s.Delete(name)
return x
}
return nil
} | go | func (s *Session) GetOnce(name interface{}) interface{} {
if x, ok := s.Session.Values[name]; ok {
s.Delete(name)
return x
}
return nil
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"GetOnce",
"(",
"name",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"if",
"x",
",",
"ok",
":=",
"s",
".",
"Session",
".",
"Values",
"[",
"name",
"]",
";",
"ok",
"{",
"s",
".",
"Delete",
"(",
... | // GetOnce gets a value from the current session and then deletes it. | [
"GetOnce",
"gets",
"a",
"value",
"from",
"the",
"current",
"session",
"and",
"then",
"deletes",
"it",
"."
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/session.go#L28-L34 | test |
gobuffalo/buffalo | session.go | Set | func (s *Session) Set(name, value interface{}) {
s.Session.Values[name] = value
} | go | func (s *Session) Set(name, value interface{}) {
s.Session.Values[name] = value
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"Set",
"(",
"name",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"s",
".",
"Session",
".",
"Values",
"[",
"name",
"]",
"=",
"value",
"\n",
"}"
] | // Set a value onto the current session. If a value with that name
// already exists it will be overridden with the new value. | [
"Set",
"a",
"value",
"onto",
"the",
"current",
"session",
".",
"If",
"a",
"value",
"with",
"that",
"name",
"already",
"exists",
"it",
"will",
"be",
"overridden",
"with",
"the",
"new",
"value",
"."
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/session.go#L38-L40 | test |
gobuffalo/buffalo | session.go | Clear | func (s *Session) Clear() {
for k := range s.Session.Values {
s.Delete(k)
}
} | go | func (s *Session) Clear() {
for k := range s.Session.Values {
s.Delete(k)
}
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"Clear",
"(",
")",
"{",
"for",
"k",
":=",
"range",
"s",
".",
"Session",
".",
"Values",
"{",
"s",
".",
"Delete",
"(",
"k",
")",
"\n",
"}",
"\n",
"}"
] | // Clear the current session | [
"Clear",
"the",
"current",
"session"
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/session.go#L48-L52 | test |
gobuffalo/buffalo | session.go | getSession | func (a *App) getSession(r *http.Request, w http.ResponseWriter) *Session {
if a.root != nil {
return a.root.getSession(r, w)
}
session, _ := a.SessionStore.Get(r, a.SessionName)
return &Session{
Session: session,
req: r,
res: w,
}
} | go | func (a *App) getSession(r *http.Request, w http.ResponseWriter) *Session {
if a.root != nil {
return a.root.getSession(r, w)
}
session, _ := a.SessionStore.Get(r, a.SessionName)
return &Session{
Session: session,
req: r,
res: w,
}
} | [
"func",
"(",
"a",
"*",
"App",
")",
"getSession",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"w",
"http",
".",
"ResponseWriter",
")",
"*",
"Session",
"{",
"if",
"a",
".",
"root",
"!=",
"nil",
"{",
"return",
"a",
".",
"root",
".",
"getSession",
"(... | // Get a session using a request and response. | [
"Get",
"a",
"session",
"using",
"a",
"request",
"and",
"response",
"."
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/session.go#L55-L65 | test |
gobuffalo/buffalo | genny/grift/grift.go | New | func New(opts *Options) (*genny.Generator, error) {
g := genny.New()
if err := opts.Validate(); err != nil {
return g, err
}
data := map[string]interface{}{
"opts": opts,
}
t := gogen.TemplateTransformer(data, template.FuncMap{})
g.Transformer(t)
g.RunFn(func(r *genny.Runner) error {
return genFile(r, ... | go | func New(opts *Options) (*genny.Generator, error) {
g := genny.New()
if err := opts.Validate(); err != nil {
return g, err
}
data := map[string]interface{}{
"opts": opts,
}
t := gogen.TemplateTransformer(data, template.FuncMap{})
g.Transformer(t)
g.RunFn(func(r *genny.Runner) error {
return genFile(r, ... | [
"func",
"New",
"(",
"opts",
"*",
"Options",
")",
"(",
"*",
"genny",
".",
"Generator",
",",
"error",
")",
"{",
"g",
":=",
"genny",
".",
"New",
"(",
")",
"\n",
"if",
"err",
":=",
"opts",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
... | // New generator to create a grift task | [
"New",
"generator",
"to",
"create",
"a",
"grift",
"task"
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/genny/grift/grift.go#L12-L29 | test |
gobuffalo/buffalo | genny/assets/webpack/webpack.go | New | func New(opts *Options) (*genny.Generator, error) {
g := genny.New()
if err := opts.Validate(); err != nil {
return g, err
}
g.RunFn(func(r *genny.Runner) error {
if _, err := r.LookPath("npm"); err != nil {
return errors.New("could not find npm executable")
}
return nil
})
g.Box(Templates)
data :... | go | func New(opts *Options) (*genny.Generator, error) {
g := genny.New()
if err := opts.Validate(); err != nil {
return g, err
}
g.RunFn(func(r *genny.Runner) error {
if _, err := r.LookPath("npm"); err != nil {
return errors.New("could not find npm executable")
}
return nil
})
g.Box(Templates)
data :... | [
"func",
"New",
"(",
"opts",
"*",
"Options",
")",
"(",
"*",
"genny",
".",
"Generator",
",",
"error",
")",
"{",
"g",
":=",
"genny",
".",
"New",
"(",
")",
"\n",
"if",
"err",
":=",
"opts",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
... | // New generator for creating webpack asset files | [
"New",
"generator",
"for",
"creating",
"webpack",
"asset",
"files"
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/genny/assets/webpack/webpack.go#L29-L57 | test |
gobuffalo/buffalo | genny/refresh/refresh.go | New | func New(opts *Options) (*genny.Generator, error) {
g := genny.New()
if err := opts.Validate(); err != nil {
return g, err
}
g.Box(packr.New("buffalo:genny:refresh", "../refresh/templates"))
ctx := plush.NewContext()
ctx.Set("app", opts.App)
g.Transformer(plushgen.Transformer(ctx))
g.Transformer(genny.Dot())... | go | func New(opts *Options) (*genny.Generator, error) {
g := genny.New()
if err := opts.Validate(); err != nil {
return g, err
}
g.Box(packr.New("buffalo:genny:refresh", "../refresh/templates"))
ctx := plush.NewContext()
ctx.Set("app", opts.App)
g.Transformer(plushgen.Transformer(ctx))
g.Transformer(genny.Dot())... | [
"func",
"New",
"(",
"opts",
"*",
"Options",
")",
"(",
"*",
"genny",
".",
"Generator",
",",
"error",
")",
"{",
"g",
":=",
"genny",
".",
"New",
"(",
")",
"\n",
"if",
"err",
":=",
"opts",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
... | // New generator to generate refresh templates | [
"New",
"generator",
"to",
"generate",
"refresh",
"templates"
] | 7f360181f4ccd79dcc9dcea2c904a4801f194f04 | https://github.com/gobuffalo/buffalo/blob/7f360181f4ccd79dcc9dcea2c904a4801f194f04/genny/refresh/refresh.go#L11-L23 | test |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.