本文整理汇总了Golang中github.com/cockroachdb/cockroach/pkg/util/log.Fatal函数的典型用法代码示例。如果您正苦于以下问题:Golang Fatal函数的具体用法?Golang Fatal怎么用?Golang Fatal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Fatal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: 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)
}
}
示例3: setup
func (z *zeroSum) setup() uint32 {
db := z.DB[0]
if _, err := db.Exec("CREATE DATABASE IF NOT EXISTS zerosum"); err != nil {
log.Fatal(context.Background(), err)
}
accounts := `
CREATE TABLE IF NOT EXISTS accounts (
id INT PRIMARY KEY,
balance INT NOT NULL
)
`
if _, err := db.Exec(accounts); err != nil {
log.Fatal(context.Background(), err)
}
tableIDQuery := `
SELECT tables.id FROM system.namespace tables
JOIN system.namespace dbs ON dbs.id = tables.parentid
WHERE dbs.name = $1 AND tables.name = $2
`
var tableID uint32
if err := db.QueryRow(tableIDQuery, "zerosum", "accounts").Scan(&tableID); err != nil {
log.Fatal(context.Background(), err)
}
return tableID
}
示例4: 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")
}
示例5: UpdateZoneConfig
// UpdateZoneConfig updates the default zone config for the cluster.
func (c *Cluster) UpdateZoneConfig(rangeMinBytes, rangeMaxBytes int64) {
zone := config.DefaultZoneConfig()
zone.RangeMinBytes = rangeMinBytes
zone.RangeMaxBytes = rangeMaxBytes
buf, err := protoutil.Marshal(&zone)
if err != nil {
log.Fatal(context.Background(), err)
}
_, err = c.DB[0].Exec(`UPSERT INTO system.zones (id, config) VALUES (0, $1)`, buf)
if err != nil {
log.Fatal(context.Background(), err)
}
}
示例6: 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)
}
},
}
}
示例7: makeNode
func (c *Cluster) makeNode(nodeIdx int, extraArgs, extraEnv []string) *Node {
name := fmt.Sprintf("%d", nodeIdx+1)
dir := filepath.Join(dataDir, name)
logDir := filepath.Join(dir, "logs")
if err := os.MkdirAll(logDir, 0755); err != nil {
log.Fatal(context.Background(), err)
}
args := []string{
cockroachBin,
"start",
"--insecure",
fmt.Sprintf("--port=%d", c.RPCPort(nodeIdx)),
fmt.Sprintf("--http-port=%d", c.HTTPPort(nodeIdx)),
fmt.Sprintf("--store=%s", dir),
fmt.Sprintf("--cache=256MiB"),
fmt.Sprintf("--logtostderr"),
}
if nodeIdx > 0 {
args = append(args, fmt.Sprintf("--join=localhost:%d", c.RPCPort(0)))
}
args = append(args, extraArgs...)
node := &Node{
logDir: logDir,
args: args,
env: extraEnv,
}
node.Start()
return node
}
示例8: setup
func (a *allocSim) setup() {
db := a.DB[0]
if _, err := db.Exec("CREATE DATABASE IF NOT EXISTS allocsim"); err != nil {
log.Fatal(context.Background(), err)
}
blocks := `
CREATE TABLE IF NOT EXISTS blocks (
id INT NOT NULL,
num INT NOT NULL,
data BYTES NOT NULL,
PRIMARY KEY (id, num)
)
`
if _, err := db.Exec(blocks); err != nil {
log.Fatal(context.Background(), err)
}
}
示例9: SimulateNetwork
// SimulateNetwork runs until the simCallback returns false.
//
// At each cycle, every node gossips a key equal to its address (unique)
// with the cycle as the value. The received cycle value can be used
// to determine the aging of information between any two nodes in the
// network.
//
// At each cycle of the simulation, node 0 gossips the sentinel.
//
// The simulation callback receives the cycle and the network as arguments.
func (n *Network) SimulateNetwork(simCallback func(cycle int, network *Network) bool) {
n.Start()
nodes := n.Nodes
for cycle := 1; ; cycle++ {
// Node 0 gossips sentinel & cluster ID every cycle.
if err := nodes[0].Gossip.AddInfo(
gossip.KeySentinel,
encoding.EncodeUint64Ascending(nil, uint64(cycle)),
time.Hour,
); err != nil {
log.Fatal(context.TODO(), err)
}
if err := nodes[0].Gossip.AddInfo(
gossip.KeyClusterID,
encoding.EncodeUint64Ascending(nil, uint64(cycle)),
0*time.Second,
); err != nil {
log.Fatal(context.TODO(), err)
}
// Every node gossips every cycle.
for _, node := range nodes {
if err := node.Gossip.AddInfo(
node.Addr().String(),
encoding.EncodeUint64Ascending(nil, uint64(cycle)),
time.Hour,
); err != nil {
log.Fatal(context.TODO(), err)
}
node.Gossip.SimulationCycle()
}
// If the simCallback returns false, we're done with the
// simulation; exit the loop. This condition is tested here
// instead of in the for statement in order to guarantee
// we run at least one iteration of this loop in order to
// gossip the cluster ID and sentinel.
if !simCallback(cycle, n) {
break
}
time.Sleep(5 * time.Millisecond)
}
log.Infof(context.TODO(), "gossip network simulation: total infos sent=%d, received=%d", n.infosSent(), n.infosReceived())
}
示例10: Start
// Start starts all gossip nodes.
// TODO(spencer): make all methods in Network return errors instead of
// fatal logging.
func (n *Network) Start() {
if n.started {
return
}
n.started = true
for _, node := range n.Nodes {
if err := n.StartNode(node); err != nil {
log.Fatal(context.TODO(), err)
}
}
}
示例11: RestrictedCopy
// RestrictedCopy creates an on-disk copy of the embedded security asset
// with the provided path. The copy will be created in the provided directory.
// Returns the path of the file and a cleanup function that will delete the file.
//
// The file will have restrictive file permissions (0600), making it
// appropriate for usage by libraries that require security assets to have such
// restrictive permissions.
func RestrictedCopy(t util.Tester, path, tempdir, name string) string {
contents, err := Asset(path)
if err != nil {
if t == nil {
log.Fatal(context.TODO(), err)
} else {
t.Fatal(err)
}
}
return util.CreateRestrictedFile(t, contents, tempdir, name)
}
示例12: CreateRestrictedFile
// CreateRestrictedFile creates a file on disk which contains the
// supplied byte string as its content. The resulting file will have restrictive
// permissions; specifically, u=rw (0600). Returns the path of the created file
// along with a function that will delete the created file.
//
// This is needed for some Go libraries (e.g. postgres SQL driver) which will
// refuse to open certificate files that have overly permissive permissions.
func CreateRestrictedFile(t Tester, contents []byte, tempdir, name string) string {
tempPath := filepath.Join(tempdir, name)
if err := ioutil.WriteFile(tempPath, contents, 0600); err != nil {
if t == nil {
log.Fatal(context.TODO(), err)
} else {
t.Fatal(err)
}
}
return tempPath
}
示例13: bootstrapStores
// bootstrapStores bootstraps uninitialized stores once the cluster
// and node IDs have been established for this node. Store IDs are
// allocated via a sequence id generator stored at a system key per
// node.
func (n *Node) bootstrapStores(
ctx context.Context, bootstraps []*storage.Store, stopper *stop.Stopper,
) {
if n.ClusterID == *uuid.EmptyUUID {
panic("ClusterID missing during store bootstrap of auxiliary store")
}
// Bootstrap all waiting stores by allocating a new store id for
// each and invoking store.Bootstrap() to persist.
inc := int64(len(bootstraps))
firstID, err := allocateStoreIDs(ctx, n.Descriptor.NodeID, inc, n.storeCfg.DB)
if err != nil {
log.Fatal(ctx, err)
}
sIdent := roachpb.StoreIdent{
ClusterID: n.ClusterID,
NodeID: n.Descriptor.NodeID,
StoreID: firstID,
}
for _, s := range bootstraps {
if err := s.Bootstrap(sIdent); err != nil {
log.Fatal(ctx, err)
}
if err := s.Start(ctx, stopper); err != nil {
log.Fatal(ctx, err)
}
n.addStore(s)
sIdent.StoreID++
log.Infof(ctx, "bootstrapped store %s", s)
// Done regularly in Node.startGossip, but this cuts down the time
// until this store is used for range allocations.
if err := s.GossipStore(ctx); err != nil {
log.Warningf(ctx, "error doing initial gossiping: %s", err)
}
}
// write a new status summary after all stores have been bootstrapped; this
// helps the UI remain responsive when new nodes are added.
if err := n.writeSummaries(ctx); err != nil {
log.Warningf(ctx, "error writing node summary after store bootstrap: %s", err)
}
}
示例14: rangeInfo
func (a *allocSim) rangeInfo() (total int, replicas []int, leases []int) {
replicas = make([]int, len(a.Nodes))
leases = make([]int, len(a.Nodes))
// Retrieve the metrics for each node and extract the replica and leaseholder
// counts.
var wg sync.WaitGroup
wg.Add(len(a.Status))
for i := range a.Status {
go func(i int) {
defer wg.Done()
resp, err := a.Status[i].Metrics(context.Background(), &serverpb.MetricsRequest{
NodeId: fmt.Sprintf("%d", i+1),
})
if err != nil {
log.Fatal(context.Background(), err)
}
var metrics map[string]interface{}
if err := json.Unmarshal(resp.Data, &metrics); err != nil {
log.Fatal(context.Background(), err)
}
stores := metrics["stores"].(map[string]interface{})
for _, v := range stores {
storeMetrics := v.(map[string]interface{})
if v, ok := storeMetrics["replicas"]; ok {
replicas[i] += int(v.(float64))
}
if v, ok := storeMetrics["replicas.leaseholders"]; ok {
leases[i] += int(v.(float64))
}
}
}(i)
}
wg.Wait()
for _, v := range replicas {
total += v
}
return total, replicas, leases
}
示例15: makeDB
func (c *Cluster) makeDB(nodeIdx, numWorkers int, dbName string) *gosql.DB {
url := fmt.Sprintf("postgresql://[email protected]:%d/%s?sslmode=disable",
c.RPCPort(nodeIdx), dbName)
conn, err := gosql.Open("postgres", url)
if err != nil {
log.Fatal(context.Background(), err)
}
if numWorkers == 0 {
numWorkers = 1
}
conn.SetMaxOpenConns(numWorkers)
conn.SetMaxIdleConns(numWorkers)
return conn
}