本文整理汇总了Golang中github.com/cockroachdb/cockroach/util/log.Errorf函数的典型用法代码示例。如果您正苦于以下问题:Golang Errorf函数的具体用法?Golang Errorf怎么用?Golang Errorf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Errorf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: runGetZone
// runGetZone retrieves the zone config for a given object id,
// and if present, outputs its YAML representation.
// TODO(marc): accept db/table names rather than IDs.
func runGetZone(cmd *cobra.Command, args []string) {
if len(args) != 1 {
mustUsage(cmd)
return
}
id, err := strconv.Atoi(args[0])
if err != nil {
log.Errorf("could not parse object ID %s", args[0])
return
}
db, _ := makeSQLClient()
defer func() { _ = db.Close() }()
// TODO(marc): switch to placeholders once they work with pgwire.
_, rows, err := runQueryWithFormat(db, fmtMap{"config": formatZone},
fmt.Sprintf(`SELECT * FROM system.zones WHERE id=%d`, id))
if err != nil {
log.Error(err)
return
}
if len(rows) == 0 {
log.Errorf("Object %d: no zone config found", id)
return
}
fmt.Println(rows[0][1])
}
示例2: runStart
// runStart starts the cockroach node using -stores as the list of
// storage devices ("stores") on this machine and -gossip as the list
// of "well-known" hosts used to join this node to the cockroach
// cluster via the gossip network.
func runStart(cmd *commander.Command, args []string) {
log.Info("Starting cockroach cluster")
s, err := newServer()
if err != nil {
log.Errorf("Failed to start Cockroach server: %v", err)
return
}
// Init engines from -stores.
engines, err := initEngines(*stores)
if err != nil {
log.Errorf("Failed to initialize engines from -stores=%q: %v", *stores, err)
return
}
if len(engines) == 0 {
log.Errorf("No valid engines specified after initializing from -stores=%q", *stores)
return
}
err = s.start(engines, false)
defer s.stop()
if err != nil {
log.Errorf("Cockroach server exited with error: %v", err)
return
}
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill)
// Block until one of the signals above is received.
<-c
}
示例3: runInit
func runInit(cmd *commander.Command, args []string) {
// Initialize the engine based on the first argument and
// then verify it's not in-memory.
err := Context.Init()
if err != nil {
log.Errorf("Failed to initialize context: %v", err)
return
}
e := Context.Engines[0]
if _, ok := e.(*engine.InMem); ok {
log.Errorf("Cannot initialize a cluster using an in-memory store")
return
}
// Generate a new UUID for cluster ID and bootstrap the cluster.
clusterID := uuid.New()
localDB, err := server.BootstrapCluster(clusterID, e)
if err != nil {
log.Errorf("Failed to bootstrap cluster: %v", err)
return
}
// Close localDB and bootstrap engine.
localDB.Close()
e.Stop()
fmt.Printf("Cockroach cluster %s has been initialized\n", clusterID)
if Context.BootstrapOnly {
fmt.Printf("To start the cluster, run \"cockroach start\"\n")
return
}
runStart(cmd, args)
}
示例4: runInit
func runInit(cmd *commander.Command, args []string) {
// Initialize the engine based on the first argument and
// then verify it's not in-memory.
engines, err := initEngines(*stores)
if err != nil {
log.Errorf("Failed to initialize engines from -stores=%s: %v", *stores, err)
return
}
if len(engines) == 0 {
log.Errorf("No valid engines specified after initializing from -stores=%s", *stores)
return
}
e := engines[0]
if _, ok := e.(*engine.InMem); ok {
log.Errorf("Cannot initialize a cluster using an in-memory store")
return
}
// Generate a new UUID for cluster ID and bootstrap the cluster.
clusterID := uuid.New()
localDB, err := BootstrapCluster(clusterID, e)
if err != nil {
log.Errorf("Failed to bootstrap cluster: %v", err)
return
}
// Close localDB and bootstrap engine.
localDB.Close()
e.Stop()
fmt.Printf("Cockroach cluster %s has been initialized\n", clusterID)
if *bootstrapOnly {
fmt.Printf("To start the cluster, run \"cockroach start\"\n")
return
}
runStart(cmd, args)
}
示例5: computeSplitKeys
// computeSplitKeys returns an array of keys at which the supplied
// range should be split, as computed by intersecting the range with
// accounting and zone config map boundaries.
func computeSplitKeys(g *gossip.Gossip, rng *Range) []proto.Key {
// Now split the range into pieces by intersecting it with the
// boundaries of the config map.
splitKeys := proto.KeySlice{}
for _, configKey := range []string{gossip.KeyConfigAccounting, gossip.KeyConfigZone} {
info, err := g.GetInfo(configKey)
if err != nil {
log.Errorf("unable to fetch %s config from gossip: %s", configKey, err)
continue
}
configMap := info.(PrefixConfigMap)
splits, err := configMap.SplitRangeByPrefixes(rng.Desc().StartKey, rng.Desc().EndKey)
if err != nil {
log.Errorf("unable to split %s by prefix map %s", rng, configMap)
continue
}
// Gather new splits.
for _, split := range splits {
if split.end.Less(rng.Desc().EndKey) {
splitKeys = append(splitKeys, split.end)
}
}
}
// Sort and unique the combined split keys from intersections with
// both the accounting and zone config maps.
sort.Sort(splitKeys)
var unique []proto.Key
for i, key := range splitKeys {
if i == 0 || !key.Equal(splitKeys[i-1]) {
unique = append(unique, key)
}
}
return unique
}
示例6: runStart
// runStart starts the cockroach node using -stores as the list of
// storage devices ("stores") on this machine and -gossip as the list
// of "well-known" hosts used to join this node to the cockroach
// cluster via the gossip network.
func runStart(cmd *commander.Command, args []string) {
info := util.GetBuildInfo()
log.Infof("Build Vers: %s", info.Vers)
log.Infof("Build Tag: %s", info.Tag)
log.Infof("Build Time: %s", info.Time)
log.Infof("Build Deps: %s", info.Deps)
log.Info("Starting cockroach cluster")
s, err := server.NewServer(Context)
if err != nil {
log.Errorf("Failed to start Cockroach server: %v", err)
return
}
err = Context.Init()
if err != nil {
log.Errorf("Failed to initialize context: %v", err)
return
}
err = s.Start(false)
defer s.Stop()
if err != nil {
log.Errorf("Cockroach server exited with error: %v", err)
return
}
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill)
// Block until one of the signals above is received.
<-c
}
示例7: verifyChecksumTrigger
func (r *Replica) verifyChecksumTrigger(
ctx context.Context, args roachpb.VerifyChecksumRequest,
) {
id := args.ChecksumID
c, ok := r.getChecksum(ctx, id)
if !ok {
log.Errorf(ctx, "consistency check skipped: checksum for id = %v doesn't exist", id)
// Return success because a checksum might be missing only on
// this replica. A checksum might be missing because of a
// number of reasons: GC-ed, server restart, and ComputeChecksum
// version incompatibility.
return
}
if c.checksum != nil && !bytes.Equal(c.checksum, args.Checksum) {
// Replication consistency problem!
logFunc := log.Errorf
// Collect some more debug information.
if args.Snapshot == nil {
// No debug information; run another consistency check to deliver
// more debug information.
if err := r.store.stopper.RunAsyncTask(func() {
log.Errorf(ctx, "%s: consistency check failed; fetching details", r)
desc := r.Desc()
startKey := desc.StartKey.AsRawKey()
// Can't use a start key less than LocalMax.
if bytes.Compare(startKey, keys.LocalMax) < 0 {
startKey = keys.LocalMax
}
if err := r.store.db.CheckConsistency(startKey, desc.EndKey.AsRawKey(), true /* withDiff */); err != nil {
log.Errorf(ctx, "couldn't rerun consistency check: %s", err)
}
}); err != nil {
log.Error(ctx, errors.Wrap(err, "could not rerun consistency check"))
}
} else {
// Compute diff.
diff := diffRange(args.Snapshot, c.snapshot)
if diff != nil {
for _, d := range diff {
l := "leader"
if d.LeaseHolder {
l = "replica"
}
log.Errorf(ctx, "consistency check failed: k:v = (%s (%x), %s, %x) not present on %s",
d.Key, d.Key, d.Timestamp, d.Value, l)
}
}
if r.store.ctx.ConsistencyCheckPanicOnFailure {
if p := r.store.ctx.TestingKnobs.BadChecksumPanic; p != nil {
p(diff)
} else {
logFunc = log.Fatalf
}
}
}
logFunc(ctx, "consistency check failed on replica: %s, checksum mismatch: e = %x, v = %x", args.Checksum, c.checksum)
}
}
示例8: runStart
// runStart starts the cockroach node using --stores as the list of
// storage devices ("stores") on this machine and --gossip as the list
// of "well-known" hosts used to join this node to the cockroach
// cluster via the gossip network.
func runStart(cmd *cobra.Command, args []string) {
info := util.GetBuildInfo()
log.Infof("build Vers: %s", info.Vers)
log.Infof("build Tag: %s", info.Tag)
log.Infof("build Time: %s", info.Time)
log.Infof("build Deps: %s", info.Deps)
// Default user for servers.
Context.User = security.NodeUser
// First initialize the Context as it is used in other places.
err := Context.Init("start")
if err != nil {
log.Errorf("failed to initialize context: %s", err)
return
}
log.Info("starting cockroach cluster")
stopper := util.NewStopper()
stopper.AddWorker()
s, err := server.NewServer(Context, stopper)
if err != nil {
log.Errorf("failed to start Cockroach server: %s", err)
return
}
err = s.Start(false)
if err != nil {
log.Errorf("cockroach server exited with error: %s", err)
return
}
signalCh := make(chan os.Signal, 1)
signal.Notify(signalCh, os.Interrupt, os.Kill)
// TODO(spencer): move this behind a build tag.
signal.Notify(signalCh, syscall.SIGTERM)
// Block until one of the signals above is received or the stopper
// is stopped externally (for example, via the quit endpoint).
select {
case <-stopper.ShouldStop():
stopper.SetStopped()
case <-signalCh:
log.Infof("initiating graceful shutdown of server")
stopper.SetStopped()
go func() {
s.Stop()
}()
}
select {
case <-signalCh:
log.Warningf("second signal received, initiating hard shutdown")
case <-time.After(time.Minute):
log.Warningf("time limit reached, initiating hard shutdown")
return
case <-stopper.IsStopped():
log.Infof("server drained and shutdown completed")
}
log.Flush()
}
示例9: runGetZone
// runGetZone retrieves the zone config for a given object id,
// and if present, outputs its YAML representation.
// TODO(marc): accept db/table names rather than IDs.
func runGetZone(cmd *cobra.Command, args []string) {
if len(args) != 1 {
mustUsage(cmd)
return
}
id, err := strconv.Atoi(args[0])
if err != nil {
log.Errorf("could not parse object ID %s", args[0])
return
}
db := makeSQLClient()
_, rows, err := runQueryWithFormat(db, fmtMap{"config": formatZone},
`SELECT * FROM system.zones WHERE id=$1`, id)
if err != nil {
log.Error(err)
return
}
if len(rows) == 0 {
log.Errorf("Object %d: no zone config found", id)
return
}
fmt.Fprintln(osStdout, rows[0][1])
}
示例10: TestStoreRangeMergeDistantRanges
// TestStoreRangeMergeDistantRanges attempts to merge two ranges
// that are not not next to each other.
func TestStoreRangeMergeDistantRanges(t *testing.T) {
store := createTestStore(t)
defer store.Stop()
// Split into 3 ranges
argsSplit, replySplit := adminSplitArgs(engine.KeyMin, []byte("d"), 1, store.StoreID())
if err := store.ExecuteCmd(proto.AdminSplit, argsSplit, replySplit); err != nil {
t.Fatalf("Can't split range %s", err)
}
argsSplit, replySplit = adminSplitArgs(engine.KeyMin, []byte("b"), 1, store.StoreID())
if err := store.ExecuteCmd(proto.AdminSplit, argsSplit, replySplit); err != nil {
t.Fatalf("Can't split range %s", err)
}
rangeA := store.LookupRange([]byte("a"), nil)
rangeB := store.LookupRange([]byte("c"), nil)
rangeC := store.LookupRange([]byte("e"), nil)
if bytes.Equal(rangeA.Desc().StartKey, rangeB.Desc().StartKey) {
log.Errorf("split ranges keys are equal %q!=%q", rangeA.Desc().StartKey, rangeB.Desc().StartKey)
}
if bytes.Equal(rangeB.Desc().StartKey, rangeC.Desc().StartKey) {
log.Errorf("split ranges keys are equal %q!=%q", rangeB.Desc().StartKey, rangeC.Desc().StartKey)
}
if bytes.Equal(rangeA.Desc().StartKey, rangeC.Desc().StartKey) {
log.Errorf("split ranges keys are equal %q!=%q", rangeA.Desc().StartKey, rangeC.Desc().StartKey)
}
argsMerge, replyMerge := adminMergeArgs(rangeC.Desc().StartKey, *rangeC.Desc(), 1, store.StoreID())
rangeA.AdminMerge(argsMerge, replyMerge)
if replyMerge.Error == nil {
t.Fatal("Should not be able to merge two ranges that are not adjacent.")
}
}
示例11: runAddNodes
func runAddNodes(cmd *cobra.Command, args []string) {
if len(args) != 1 {
cmd.Usage()
return
}
numNodes, err := strconv.Atoi(args[0])
if err != nil || numNodes < 1 {
log.Errorf("argument %s must be an integer > 0", args)
return
}
driver, err := NewDriver(Context)
if err != nil {
log.Errorf("could not create driver: %v", err)
return
}
for i := 1; i <= numNodes; i++ {
log.Infof("adding node %d of %d", i, numNodes)
err := AddOneNode(driver)
if err != nil {
log.Errorf("problem adding node: %v", err)
return
}
}
}
示例12: computeSplitKeys
// computeSplitKeys returns an array of keys at which the supplied
// range should be split, as computed by intersecting the range with
// zone config map boundaries.
func computeSplitKeys(g *gossip.Gossip, repl *Replica) []proto.Key {
// Now split the range into pieces by intersecting it with the
// boundaries of the config map.
configMap, err := repl.rm.Gossip().GetZoneConfig()
if err != nil {
log.Errorf("unable to fetch zone config from gossip: %s", err)
return nil
}
desc := repl.Desc()
splits, err := configMap.SplitRangeByPrefixes(desc.StartKey, desc.EndKey)
if err != nil {
log.Errorf("unable to split %s by prefix map %s", repl, configMap)
return nil
}
// Gather new splits.
var splitKeys proto.KeySlice
for _, split := range splits {
if split.End.Less(desc.EndKey) {
splitKeys = append(splitKeys, split.End)
}
}
// Sort and unique the combined split keys from intersections with
// the zone config maps.
sort.Sort(splitKeys)
var unique []proto.Key
for i, key := range splitKeys {
if i == 0 || !key.Equal(splitKeys[i-1]) {
unique = append(unique, key)
}
}
return unique
}
示例13: writeSummaries
// writeSummaries retrieves status summaries from the supplied
// NodeStatusRecorder and persists them to the cockroach data store.
func (s *Server) writeSummaries() error {
nodeStatus, storeStatuses := s.recorder.GetStatusSummaries()
if nodeStatus != nil {
key := keys.NodeStatusKey(int32(nodeStatus.Desc.NodeID))
if err := s.db.Put(key, nodeStatus); err != nil {
return err
}
if log.V(1) {
statusJSON, err := json.Marshal(nodeStatus)
if err != nil {
log.Errorf("error marshaling nodeStatus to json: %s", err)
}
log.Infof("node %d status: %s", nodeStatus.Desc.NodeID, statusJSON)
}
}
for _, ss := range storeStatuses {
key := keys.StoreStatusKey(int32(ss.Desc.StoreID))
if err := s.db.Put(key, &ss); err != nil {
return err
}
if log.V(1) {
statusJSON, err := json.Marshal(&ss)
if err != nil {
log.Errorf("error marshaling storeStatus to json: %s", err)
}
log.Infof("store %d status: %s", ss.Desc.StoreID, statusJSON)
}
}
return nil
}
示例14: runExterminate
// runExterminate destroys the data held in the specified stores.
func runExterminate(cmd *cobra.Command, args []string) {
if err := context.InitStores(); err != nil {
log.Errorf("failed to initialize context: %s", err)
return
}
// First attempt to shutdown the server. Note that an error of EOF just
// means the HTTP server shutdown before the request to quit returned.
admin := client.NewAdminClient(&context.Context, context.Addr, client.Quit)
body, err := admin.Get()
if err != nil {
log.Infof("shutdown node %s: %s", context.Addr, err)
} else {
log.Infof("shutdown node in anticipation of data extermination: %s", body)
}
// Exterminate all data held in specified stores.
for _, e := range context.Engines {
if rocksdb, ok := e.(*engine.RocksDB); ok {
log.Infof("exterminating data from store %s", e)
if err := rocksdb.Destroy(); err != nil {
log.Errorf("unable to destroy store %s: %s", e, err)
osExit(1)
}
}
}
log.Infof("exterminated all data from stores %s", context.Engines)
}
示例15: runInit
// runInit.
func runInit(cmd *commander.Command, args []string) {
if len(args) != 1 {
cmd.Usage()
return
}
// Initialize the engine based on the first argument and
// then verify it's not in-memory.
engines, err := initEngines(args[0])
if err != nil {
log.Errorf("Failed to initialize engine %q: %v", args[0], err)
return
}
e := engines[0]
if _, ok := e.(*engine.InMem); ok {
log.Errorf("Cannot initialize a cluster using an in-memory store")
return
}
// Generate a new UUID for cluster ID and bootstrap the cluster.
clusterID := uuid.New()
localDB, err := BootstrapCluster(clusterID, e)
if err != nil {
log.Errorf("Failed to bootstrap cluster: %v", err)
return
}
defer localDB.Close()
fmt.Fprintf(os.Stdout, "Cockroach cluster %s has been initialized\n", clusterID)
fmt.Fprintf(os.Stdout, "To start the cluster, run \"cockroach start\"\n")
}