本文整理汇总了Golang中github.com/cockroachdb/cockroach/pkg/util/log.Fatal函数的典型用法代码示例。如果您正苦于以下问题:Golang Fatal函数的具体用法?Golang Fatal怎么用?Golang Fatal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Fatal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:hvaara,项目名称:cockroach,代码行数:36,代码来源:network.go
示例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)
}
}
开发者ID:knz,项目名称:cockroach,代码行数:41,代码来源:node.go
示例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
}
开发者ID:knz,项目名称:cockroach,代码行数:27,代码来源:main.go
示例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")
}
开发者ID:knz,项目名称:cockroach,代码行数:27,代码来源:localcluster.go
示例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)
}
}
开发者ID:knz,项目名称:cockroach,代码行数:15,代码来源:localcluster.go
示例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)
}
},
}
}
开发者ID:knz,项目名称:cockroach,代码行数:48,代码来源:cli_test.go
示例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
}
开发者ID:knz,项目名称:cockroach,代码行数:31,代码来源:localcluster.go
示例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)
}
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:18,代码来源:main.go
示例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())
}
开发者ID:hvaara,项目名称:cockroach,代码行数:52,代码来源:network.go
示例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)
}
}
}
开发者ID:hvaara,项目名称:cockroach,代码行数:14,代码来源:network.go
示例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)
}
开发者ID:knz,项目名称:cockroach,代码行数:18,代码来源:securitytest.go
示例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
}
开发者ID:knz,项目名称:cockroach,代码行数:18,代码来源:testing.go
示例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)
}
}
开发者ID:knz,项目名称:cockroach,代码行数:45,代码来源:node.go
示例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
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:40,代码来源:main.go
示例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
}
开发者ID:knz,项目名称:cockroach,代码行数:14,代码来源:localcluster.go
示例16: worker
func (z *zeroSum) worker() {
r := newRand()
zipf := z.accountDistribution(r)
for {
from := zipf.Uint64()
to := zipf.Uint64()
if from == to {
continue
}
db := z.DB[z.RandNode(r.Intn)]
err := crdb.ExecuteTx(db, func(tx *gosql.Tx) error {
rows, err := tx.Query(`SELECT id, balance FROM accounts WHERE id IN ($1, $2)`, from, to)
if err != nil {
return err
}
var fromBalance, toBalance int64
for rows.Next() {
var id uint64
var balance int64
if err = rows.Scan(&id, &balance); err != nil {
log.Fatal(context.Background(), err)
}
switch id {
case from:
fromBalance = balance
case to:
toBalance = balance
default:
panic(fmt.Sprintf("got unexpected account %d", id))
}
}
upsert := `UPSERT INTO accounts VALUES ($1, $3), ($2, $4)`
_, err = tx.Exec(upsert, to, from, toBalance+1, fromBalance-1)
return err
})
if err != nil {
z.maybeLogError(err)
} else {
atomic.AddUint64(&z.stats.ops, 1)
z.accounts.Lock()
z.accounts.m[from] = struct{}{}
z.accounts.m[to] = struct{}{}
z.accounts.Unlock()
}
}
}
开发者ID:knz,项目名称:cockroach,代码行数:50,代码来源:main.go
示例17: NewExecutor
// NewExecutor creates an Executor and registers a callback on the
// system config.
func NewExecutor(
cfg ExecutorConfig, stopper *stop.Stopper, startupMemMetrics *MemoryMetrics,
) *Executor {
exec := &Executor{
cfg: cfg,
reCache: parser.NewRegexpCache(512),
Latency: metric.NewLatency(MetaLatency, cfg.MetricsSampleInterval),
TxnBeginCount: metric.NewCounter(MetaTxnBegin),
TxnCommitCount: metric.NewCounter(MetaTxnCommit),
TxnAbortCount: metric.NewCounter(MetaTxnAbort),
TxnRollbackCount: metric.NewCounter(MetaTxnRollback),
SelectCount: metric.NewCounter(MetaSelect),
UpdateCount: metric.NewCounter(MetaUpdate),
InsertCount: metric.NewCounter(MetaInsert),
DeleteCount: metric.NewCounter(MetaDelete),
DdlCount: metric.NewCounter(MetaDdl),
MiscCount: metric.NewCounter(MetaMisc),
QueryCount: metric.NewCounter(MetaQuery),
}
exec.systemConfigCond = sync.NewCond(exec.systemConfigMu.RLocker())
gossipUpdateC := cfg.Gossip.RegisterSystemConfigChannel()
stopper.RunWorker(func() {
for {
select {
case <-gossipUpdateC:
sysCfg, _ := cfg.Gossip.GetSystemConfig()
exec.updateSystemConfig(sysCfg)
case <-stopper.ShouldStop():
return
}
}
})
ctx := log.WithLogTag(context.Background(), "startup", nil)
startupSession := NewSession(ctx, SessionArgs{}, exec, nil, startupMemMetrics)
if err := exec.virtualSchemas.init(&startupSession.planner); err != nil {
log.Fatal(ctx, err)
}
startupSession.Finish(exec)
return exec
}
开发者ID:hvaara,项目名称:cockroach,代码行数:47,代码来源:executor.go
示例18: TestAllocateWithStopper
func TestAllocateWithStopper(t *testing.T) {
defer leaktest.AfterTest(t)()
store, _, stopper := createTestStore(t)
idAlloc, err := newIDAllocator(
log.AmbientContext{}, keys.RangeIDGenerator, store.cfg.DB, 2, 10, stopper,
)
if err != nil {
log.Fatal(context.Background(), err)
}
stopper.Stop()
if _, err := idAlloc.Allocate(); err == nil {
t.Errorf("unexpected success")
} else if !strings.Contains(err.Error(), "system is draining") {
t.Errorf("unexpected error: %s", err)
}
}
开发者ID:hvaara,项目名称:cockroach,代码行数:18,代码来源:id_alloc_test.go
示例19: hasImage
func hasImage(l *LocalCluster, ref string) bool {
name := strings.Split(ref, ":")[0]
images, err := l.client.ImageList(context.Background(), types.ImageListOptions{MatchName: name})
if err != nil {
log.Fatal(context.TODO(), err)
}
for _, image := range images {
for _, repoTag := range image.RepoTags {
// The Image.RepoTags field contains strings of the form <repo>:<tag>.
if ref == repoTag {
return true
}
}
}
for _, image := range images {
for _, tag := range image.RepoTags {
log.Infof(context.TODO(), "ImageList %s %s", tag, image.ID)
}
}
return false
}
开发者ID:hvaara,项目名称:cockroach,代码行数:21,代码来源:docker.go
示例20: MakeServer
// MakeServer constructs a Server that tracks active connections, closing them
// when signalled by stopper.
func MakeServer(stopper *stop.Stopper, tlsConfig *tls.Config, handler http.Handler) Server {
var mu syncutil.Mutex
activeConns := make(map[net.Conn]struct{})
server := Server{
Server: &http.Server{
Handler: handler,
TLSConfig: tlsConfig,
ConnState: func(conn net.Conn, state http.ConnState) {
mu.Lock()
switch state {
case http.StateNew:
activeConns[conn] = struct{}{}
case http.StateClosed:
delete(activeConns, conn)
}
mu.Unlock()
},
ErrorLog: httpLogger,
},
}
// net/http.(*Server).Serve/http2.ConfigureServer are not thread safe with
// respect to net/http.(*Server).TLSConfig, so we call it synchronously here.
if err := http2.ConfigureServer(server.Server, nil); err != nil {
log.Fatal(context.TODO(), err)
}
stopper.RunWorker(func() {
<-stopper.ShouldStop()
mu.Lock()
for conn := range activeConns {
conn.Close()
}
mu.Unlock()
})
return server
}
开发者ID:knz,项目名称:cockroach,代码行数:41,代码来源:net.go
注:本文中的github.com/cockroachdb/cockroach/pkg/util/log.Fatal函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论