本文整理汇总了Golang中github.com/cockroachdb/cockroach/pkg/util/log.Fatalf函数的典型用法代码示例。如果您正苦于以下问题:Golang Fatalf函数的具体用法?Golang Fatalf怎么用?Golang Fatalf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Fatalf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: initNodeID
// initNodeID updates the internal NodeDescriptor with the given ID. If zero is
// supplied, a new NodeID is allocated with the first invocation. For all other
// values, the supplied ID is stored into the descriptor (unless one has been
// set previously, in which case a fatal error occurs).
//
// Upon setting a new NodeID, the descriptor is gossiped and the NodeID is
// stored into the gossip instance.
func (n *Node) initNodeID(id roachpb.NodeID) {
ctx := n.AnnotateCtx(context.TODO())
if id < 0 {
log.Fatalf(ctx, "NodeID must not be negative")
}
if o := n.Descriptor.NodeID; o > 0 {
if id == 0 {
return
}
log.Fatalf(ctx, "cannot initialize NodeID to %d, already have %d", id, o)
}
var err error
if id == 0 {
ctxWithSpan, span := n.AnnotateCtxWithSpan(ctx, "alloc-node-id")
id, err = allocateNodeID(ctxWithSpan, n.storeCfg.DB)
if err != nil {
log.Fatal(ctxWithSpan, err)
}
log.Infof(ctxWithSpan, "new node allocated ID %d", id)
if id == 0 {
log.Fatal(ctxWithSpan, "new node allocated illegal ID 0")
}
span.Finish()
n.storeCfg.Gossip.NodeID.Set(ctx, id)
} else {
log.Infof(ctx, "node ID %d initialized", id)
}
// Gossip the node descriptor to make this node addressable by node ID.
n.Descriptor.NodeID = id
if err = n.storeCfg.Gossip.SetNodeDescriptor(&n.Descriptor); err != nil {
log.Fatalf(ctx, "couldn't gossip descriptor for node %d: %s", n.Descriptor.NodeID, err)
}
}
开发者ID:knz,项目名称:cockroach,代码行数:41,代码来源:node.go
示例2: verify
func (z *zeroSum) verify(d time.Duration) {
for {
time.Sleep(d)
// Grab the count of accounts from committed transactions first. The number
// of accounts found by the SELECT should be at least this number.
committedAccounts := uint64(z.accountsLen())
q := `SELECT count(*), sum(balance) FROM accounts`
var accounts uint64
var total int64
db := z.DB[z.RandNode(rand.Intn)]
if err := db.QueryRow(q).Scan(&accounts, &total); err != nil {
z.maybeLogError(err)
continue
}
if total != 0 {
log.Fatalf(context.Background(), "unexpected total balance %d", total)
}
if accounts < committedAccounts {
log.Fatalf(context.Background(), "expected at least %d accounts, but found %d",
committedAccounts, accounts)
}
}
}
开发者ID:knz,项目名称:cockroach,代码行数:25,代码来源:main.go
示例3: isReplicated
func (c *Cluster) isReplicated() (bool, string) {
db := c.Clients[0]
rows, err := db.Scan(context.Background(), keys.Meta2Prefix, keys.Meta2Prefix.PrefixEnd(), 100000)
if err != nil {
if IsUnavailableError(err) {
return false, ""
}
log.Fatalf(context.Background(), "scan failed: %s\n", err)
}
var buf bytes.Buffer
tw := tabwriter.NewWriter(&buf, 2, 1, 2, ' ', 0)
done := true
for _, row := range rows {
desc := &roachpb.RangeDescriptor{}
if err := row.ValueProto(desc); err != nil {
log.Fatalf(context.Background(), "%s: unable to unmarshal range descriptor\n", row.Key)
continue
}
var storeIDs []roachpb.StoreID
for _, replica := range desc.Replicas {
storeIDs = append(storeIDs, replica.StoreID)
}
fmt.Fprintf(tw, "\t%s\t%s\t[%d]\t%d\n",
desc.StartKey, desc.EndKey, desc.RangeID, storeIDs)
if len(desc.Replicas) != 3 {
done = false
}
}
_ = tw.Flush()
return done, buf.String()
}
开发者ID:knz,项目名称:cockroach,代码行数:33,代码来源:localcluster.go
示例4: Start
// Start starts a node.
func (n *Node) Start() {
n.Lock()
defer n.Unlock()
if n.cmd != nil {
return
}
n.cmd = exec.Command(n.args[0], n.args[1:]...)
n.cmd.Env = os.Environ()
n.cmd.Env = append(n.cmd.Env, n.env...)
stdoutPath := filepath.Join(n.logDir, "stdout")
stdout, err := os.OpenFile(stdoutPath,
os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf(context.Background(), "unable to open file %s: %s", stdoutPath, err)
}
n.cmd.Stdout = stdout
stderrPath := filepath.Join(n.logDir, "stderr")
stderr, err := os.OpenFile(stderrPath,
os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf(context.Background(), "unable to open file %s: %s", stderrPath, err)
}
n.cmd.Stderr = stderr
err = n.cmd.Start()
if n.cmd.Process != nil {
log.Infof(context.Background(), "process %d started: %s",
n.cmd.Process.Pid, strings.Join(n.args, " "))
}
if err != nil {
log.Infof(context.Background(), "%v", err)
_ = stdout.Close()
_ = stderr.Close()
return
}
go func(cmd *exec.Cmd) {
if err := cmd.Wait(); err != nil {
log.Errorf(context.Background(), "waiting for command: %v", err)
}
_ = stdout.Close()
_ = stderr.Close()
ps := cmd.ProcessState
sy := ps.Sys().(syscall.WaitStatus)
log.Infof(context.Background(), "Process %d exited with status %d",
ps.Pid(), sy.ExitStatus())
log.Infof(context.Background(), ps.String())
n.Lock()
n.cmd = nil
n.Unlock()
}(n.cmd)
}
开发者ID:knz,项目名称:cockroach,代码行数:60,代码来源:localcluster.go
示例5: main
func main() {
// Seed the random number generator for non-determinism across
// multiple runs.
randutil.SeedForTests()
if f := flag.Lookup("alsologtostderr"); f != nil {
fmt.Println("Starting simulation. Add -alsologtostderr to see progress.")
}
flag.Parse()
dirName, err := ioutil.TempDir("", "gossip-simulation-")
if err != nil {
log.Fatalf(context.TODO(), "could not create temporary directory for gossip simulation output: %s", err)
}
// Simulation callbacks to run the simulation for cycleCount
// cycles. At each cycle % outputEvery, a dot file showing the
// state of the network graph is output.
nodeCount := 3
switch *size {
case "tiny":
// Use default parameters.
case "small":
nodeCount = 10
case "medium":
nodeCount = 25
case "large":
nodeCount = 50
case "huge":
nodeCount = 100
case "ginormous":
nodeCount = 250
default:
log.Fatalf(context.TODO(), "unknown simulation size: %s", *size)
}
edgeSet := make(map[string]edge)
stopper := stop.NewStopper()
defer stopper.Stop()
n := simulation.NewNetwork(stopper, nodeCount, true)
n.SimulateNetwork(
func(cycle int, network *simulation.Network) bool {
// Output dot graph.
dotFN := fmt.Sprintf("%s/sim-cycle-%03d.dot", dirName, cycle)
_, quiescent := outputDotFile(dotFN, cycle, network, edgeSet)
// Run until network has quiesced.
return !quiescent
},
)
// Output instructions for viewing graphs.
fmt.Printf("To view simulation graph output run (you must install graphviz):\n\nfor f in %s/*.dot ; do circo $f -Tpng -o $f.png ; echo $f.png ; done\n", dirName)
}
开发者ID:knz,项目名称:cockroach,代码行数:55,代码来源:main.go
示例6: Set
// Set sets the current node ID. If it is already set, the value must match.
func (n *NodeIDContainer) Set(ctx context.Context, val roachpb.NodeID) {
if val <= 0 {
log.Fatalf(ctx, "trying to set invalid NodeID: %d", val)
}
oldVal := atomic.SwapInt32(&n.nodeID, int32(val))
if oldVal == 0 {
log.Infof(ctx, "NodeID set to %d", val)
} else if oldVal != int32(val) {
log.Fatalf(ctx, "different NodeIDs set: %d, then %d", oldVal, val)
}
}
开发者ID:knz,项目名称:cockroach,代码行数:12,代码来源:node_id.go
示例7: makeClient
func (c *Cluster) makeClient(nodeIdx int) *client.DB {
sender, err := client.NewSender(c.rpcCtx, c.RPCAddr(nodeIdx))
if err != nil {
log.Fatalf(context.Background(), "failed to initialize KV client: %s", err)
}
return client.NewDB(sender)
}
开发者ID:knz,项目名称:cockroach,代码行数:7,代码来源:localcluster.go
示例8: Batch
// Batch implements the roachpb.InternalServer interface.
func (n *Node) Batch(
ctx context.Context, args *roachpb.BatchRequest,
) (*roachpb.BatchResponse, error) {
growStack()
ctx = n.AnnotateCtx(ctx)
br, err := n.batchInternal(ctx, args)
// We always return errors via BatchResponse.Error so structure is
// preserved; plain errors are presumed to be from the RPC
// framework and not from cockroach.
if err != nil {
if br == nil {
br = &roachpb.BatchResponse{}
}
if br.Error != nil {
log.Fatalf(
ctx, "attempting to return both a plain error (%s) and roachpb.Error (%s)", err, br.Error,
)
}
br.Error = roachpb.NewError(err)
}
return br, nil
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:26,代码来源:node.go
示例9: makeStatus
func (c *Cluster) makeStatus(nodeIdx int) serverpb.StatusClient {
conn, err := c.rpcCtx.GRPCDial(c.RPCAddr(nodeIdx))
if err != nil {
log.Fatalf(context.Background(), "failed to initialize status client: %s", err)
}
return serverpb.NewStatusClient(conn)
}
开发者ID:knz,项目名称:cockroach,代码行数:7,代码来源:localcluster.go
示例10: Example_user_insecure
func Example_user_insecure() {
s, err := serverutils.StartServerRaw(
base.TestServerArgs{Insecure: true})
if err != nil {
log.Fatalf(context.Background(), "Could not start server: %v", err)
}
defer s.Stopper().Stop()
c := cliTest{TestServer: s.(*server.TestServer), cleanupFunc: func() {}}
// Since util.IsolatedTestAddr is used on Linux in insecure test clusters,
// we have to reset the advertiseHost so that the value from previous
// tests is not used to construct an incorrect postgres URL by the client.
advertiseHost = ""
// No prompting for password in insecure mode.
c.Run("user set foo")
c.Run("user ls --pretty")
// Output:
// user set foo
// INSERT 1
// user ls --pretty
// +----------+
// | username |
// +----------+
// | foo |
// +----------+
// (1 row)
}
开发者ID:bdarnell,项目名称:cockroach,代码行数:29,代码来源:cli_test.go
示例11: NewNetwork
// NewNetwork creates nodeCount gossip nodes.
func NewNetwork(stopper *stop.Stopper, nodeCount int, createResolvers bool) *Network {
log.Infof(context.TODO(), "simulating gossip network with %d nodes", nodeCount)
n := &Network{
Nodes: []*Node{},
Stopper: stopper,
}
n.rpcContext = rpc.NewContext(
log.AmbientContext{},
&base.Config{Insecure: true},
hlc.NewClock(hlc.UnixNano, time.Nanosecond),
n.Stopper,
)
var err error
n.tlsConfig, err = n.rpcContext.GetServerTLSConfig()
if err != nil {
log.Fatal(context.TODO(), err)
}
for i := 0; i < nodeCount; i++ {
node, err := n.CreateNode()
if err != nil {
log.Fatal(context.TODO(), err)
}
// Build a resolver for each instance or we'll get data races.
if createResolvers {
r, err := resolver.NewResolverFromAddress(n.Nodes[0].Addr())
if err != nil {
log.Fatalf(context.TODO(), "bad gossip address %s: %s", n.Nodes[0].Addr(), err)
}
node.Gossip.SetResolvers([]resolver.Resolver{r})
}
}
return n
}
开发者ID:hvaara,项目名称:cockroach,代码行数:36,代码来源:network.go
示例12: Example_node
func Example_node() {
c, err := newCLITest(nil, false)
if err != nil {
panic(err)
}
defer c.stop(true)
// Refresh time series data, which is required to retrieve stats.
if err := c.WriteSummaries(); err != nil {
log.Fatalf(context.Background(), "Couldn't write stats summaries: %s", err)
}
c.Run("node ls")
c.Run("node ls --pretty")
c.Run("node status 10000")
// Output:
// node ls
// 1 row
// id
// 1
// node ls --pretty
// +----+
// | id |
// +----+
// | 1 |
// +----+
// (1 row)
// node status 10000
// Error: node 10000 doesn't exist
}
开发者ID:veteranlu,项目名称:cockroach,代码行数:31,代码来源:cli_test.go
示例13: Freeze
// Freeze freezes (or thaws) the cluster. The freeze request is sent to the
// specified node.
func (c *Cluster) Freeze(nodeIdx int, freeze bool) {
addr := c.RPCAddr(nodeIdx)
conn, err := c.rpcCtx.GRPCDial(addr)
if err != nil {
log.Fatalf(context.Background(), "unable to dial: %s: %v", addr, err)
}
adminClient := serverpb.NewAdminClient(conn)
stream, err := adminClient.ClusterFreeze(
context.Background(), &serverpb.ClusterFreezeRequest{Freeze: freeze})
if err != nil {
log.Fatal(context.Background(), err)
}
for {
resp, err := stream.Recv()
if err != nil {
if err == io.EOF {
break
}
log.Fatal(context.Background(), err)
}
fmt.Println(resp.Message)
}
fmt.Println("ok")
}
开发者ID:knz,项目名称:cockroach,代码行数:27,代码来源:localcluster.go
示例14: createDefaultZoneConfig
// Create the key/value pairs for the default zone config entry.
func createDefaultZoneConfig() []roachpb.KeyValue {
var ret []roachpb.KeyValue
value := roachpb.Value{}
desc := config.DefaultZoneConfig()
if err := value.SetProto(&desc); err != nil {
log.Fatalf(context.TODO(), "could not marshal %v", desc)
}
ret = append(ret, roachpb.KeyValue{
Key: MakeZoneKey(keys.RootNamespaceID),
Value: value,
})
return ret
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:14,代码来源:system.go
示例15: HandleRaftResponse
func (s channelServer) HandleRaftResponse(
ctx context.Context, resp *storage.RaftMessageResponse,
) error {
// Mimic the logic in (*Store).HandleRaftResponse without requiring an
// entire Store object to be pulled into these tests.
if val, ok := resp.Union.GetValue().(*roachpb.Error); ok {
if err, ok := val.GetDetail().(*roachpb.StoreNotFoundError); ok {
return err
}
}
log.Fatalf(ctx, "unexpected raft response: %s", resp)
return nil
}
开发者ID:hvaara,项目名称:cockroach,代码行数:13,代码来源:raft_transport_test.go
示例16: GetInitialValues
// GetInitialValues returns the set of initial K/V values which should be added to
// a bootstrapping CockroachDB cluster in order to create the tables contained
// in the schema.
func (ms MetadataSchema) GetInitialValues() []roachpb.KeyValue {
var ret []roachpb.KeyValue
// Save the ID generator value, which will generate descriptor IDs for user
// objects.
value := roachpb.Value{}
value.SetInt(int64(keys.MaxReservedDescID + 1))
ret = append(ret, roachpb.KeyValue{
Key: keys.DescIDGenerator,
Value: value,
})
// addDescriptor generates the needed KeyValue objects to install a
// descriptor on a new cluster.
addDescriptor := func(parentID ID, desc DescriptorProto) {
// Create name metadata key.
value := roachpb.Value{}
value.SetInt(int64(desc.GetID()))
ret = append(ret, roachpb.KeyValue{
Key: MakeNameMetadataKey(parentID, desc.GetName()),
Value: value,
})
// Create descriptor metadata key.
value = roachpb.Value{}
wrappedDesc := WrapDescriptor(desc)
if err := value.SetProto(wrappedDesc); err != nil {
log.Fatalf(context.TODO(), "could not marshal %v", desc)
}
ret = append(ret, roachpb.KeyValue{
Key: MakeDescMetadataKey(desc.GetID()),
Value: value,
})
}
// Generate initial values for system databases and tables, which have
// static descriptors that were generated elsewhere.
for _, sysObj := range ms.descs {
addDescriptor(sysObj.parentID, sysObj.desc)
}
// Other key/value generation that doesn't fit into databases and
// tables. This can be used to add initial entries to a table.
ret = append(ret, ms.otherKV...)
// Sort returned key values; this is valuable because it matches the way the
// objects would be sorted if read from the engine.
sort.Sort(roachpb.KeyValueByKey(ret))
return ret
}
开发者ID:knz,项目名称:cockroach,代码行数:53,代码来源:metadata.go
示例17: chaos
func (z *zeroSum) chaos() {
switch z.chaosType {
case "none":
// nothing to do
case "simple":
go z.chaosSimple()
case "flappy":
go z.chaosFlappy()
case "freeze":
go z.chaosFreeze()
default:
log.Fatalf(context.Background(), "unknown chaos type: %s", z.chaosType)
}
}
开发者ID:knz,项目名称:cockroach,代码行数:14,代码来源:main.go
示例18: connectGossip
// connectGossip connects to gossip network and reads cluster ID. If
// this node is already part of a cluster, the cluster ID is verified
// for a match. If not part of a cluster, the cluster ID is set. The
// node's address is gossiped with node ID as the gossip key.
func (n *Node) connectGossip(ctx context.Context) {
log.Infof(ctx, "connecting to gossip network to verify cluster ID...")
// No timeout or stop condition is needed here. Log statements should be
// sufficient for diagnosing this type of condition.
<-n.storeCfg.Gossip.Connected
uuidBytes, err := n.storeCfg.Gossip.GetInfo(gossip.KeyClusterID)
if err != nil {
log.Fatalf(ctx, "unable to ascertain cluster ID from gossip network: %s", err)
}
gossipClusterID, err := uuid.FromBytes(uuidBytes)
if err != nil {
log.Fatalf(ctx, "unable to ascertain cluster ID from gossip network: %s", err)
}
if n.ClusterID == (uuid.UUID{}) {
n.ClusterID = gossipClusterID
} else if n.ClusterID != gossipClusterID {
log.Fatalf(ctx, "node %d belongs to cluster %q but is attempting to connect to a gossip network for cluster %q",
n.Descriptor.NodeID, n.ClusterID, gossipClusterID)
}
log.Infof(ctx, "node connected via gossip and verified as part of cluster %q", gossipClusterID)
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:27,代码来源:node.go
示例19: ExampleNewClock
// ExampleNewClock shows how to create a new
// hybrid logical clock based on the local machine's
// physical clock. The sanity checks in this example
// will, of course, not fail and the output will be
// the age of the Unix epoch in nanoseconds.
func ExampleNewClock() {
// Initialize a new clock, using the local
// physical clock.
c := NewClock(UnixNano)
// Update the state of the hybrid clock.
s := c.Now()
time.Sleep(50 * time.Nanosecond)
t := Timestamp{WallTime: UnixNano()}
// The sanity checks below will usually never be triggered.
if s.Less(t) || !t.Less(s) {
log.Fatalf(context.Background(), "The later timestamp is smaller than the earlier one")
}
if t.WallTime-s.WallTime > 0 {
log.Fatalf(context.Background(), "HLC timestamp %d deviates from physical clock %d", s, t)
}
if s.Logical > 0 {
log.Fatalf(context.Background(), "Trivial timestamp has logical component")
}
fmt.Printf("The Unix Epoch is now approximately %dns old.\n", t.WallTime)
}
开发者ID:knz,项目名称:cockroach,代码行数:29,代码来源:hlc_test.go
示例20: newCLITest
func newCLITest() cliTest {
// Reset the client context for each test. We don't reset the
// pointer (because they are tied into the flags), but instead
// overwrite the existing struct's values.
baseCfg.InitDefaults()
cliCtx.InitCLIDefaults()
osStderr = os.Stdout
s, err := serverutils.StartServerRaw(base.TestServerArgs{})
if err != nil {
log.Fatalf(context.Background(), "Could not start server: %s", err)
}
tempDir, err := ioutil.TempDir("", "cli-test")
if err != nil {
log.Fatal(context.Background(), err)
}
// Copy these assets to disk from embedded strings, so this test can
// run from a standalone binary.
// Disable embedded certs, or the security library will try to load
// our real files as embedded assets.
security.ResetReadFileFn()
assets := []string{
filepath.Join(security.EmbeddedCertsDir, security.EmbeddedCACert),
filepath.Join(security.EmbeddedCertsDir, security.EmbeddedCAKey),
filepath.Join(security.EmbeddedCertsDir, security.EmbeddedNodeCert),
filepath.Join(security.EmbeddedCertsDir, security.EmbeddedNodeKey),
filepath.Join(security.EmbeddedCertsDir, security.EmbeddedRootCert),
filepath.Join(security.EmbeddedCertsDir, security.EmbeddedRootKey),
}
for _, a := range assets {
securitytest.RestrictedCopy(nil, a, tempDir, filepath.Base(a))
}
return cliTest{
TestServer: s.(*server.TestServer),
certsDir: tempDir,
cleanupFunc: func() {
if err := os.RemoveAll(tempDir); err != nil {
log.Fatal(context.Background(), err)
}
},
}
}
开发者ID:knz,项目名称:cockroach,代码行数:48,代码来源:cli_test.go
注:本文中的github.com/cockroachdb/cockroach/pkg/util/log.Fatalf函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论