本文整理汇总了Golang中github.com/janelia-flyem/dvid/dvid.Criticalf函数的典型用法代码示例。如果您正苦于以下问题:Golang Criticalf函数的具体用法?Golang Criticalf怎么用?Golang Criticalf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Criticalf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: deleteBlock
func (d *Data) deleteBlock(ctx *datastore.VersionedCtx, block labels.DeleteBlock, batcher storage.KeyValueBatcher) {
batch := batcher.NewBatch(ctx)
// Iterate through this block of labels and get set of labels.
blockBytes := len(block.Data)
if blockBytes != int(d.BlockSize.Prod())*8 {
dvid.Criticalf("Deserialized label block %d bytes, not uint64 size times %d block elements\n",
blockBytes, d.BlockSize.Prod())
return
}
labelSet := make(map[uint64]struct{})
for i := 0; i < blockBytes; i += 8 {
label := binary.LittleEndian.Uint64(block.Data[i : i+8])
if label != 0 {
labelSet[label] = struct{}{}
}
}
// Go through all non-zero labels and delete the corresponding labelvol k/v pair.
zyx := block.Index.ToIZYXString()
for label := range labelSet {
tk := NewTKey(label, zyx)
batch.Delete(tk)
}
if err := batch.Commit(); err != nil {
dvid.Criticalf("Bad sync in labelvol. Couldn't commit block %s\n", zyx.Print())
}
return
}
示例2: recoverHandler
// Middleware that recovers from panics, sends email if a notification email
// has been provided, and log issues.
func recoverHandler(c *web.C, h http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
reqID := middleware.GetReqID(*c)
defer func() {
if err := recover(); err != nil {
buf := make([]byte, 1<<16)
size := runtime.Stack(buf, false)
stackTrace := string(buf[0:size])
message := fmt.Sprintf("Panic detected on request %s:\n%+v\nIP: %v, URL: %s\nStack trace:\n%s\n",
reqID, err, r.RemoteAddr, r.URL.Path, stackTrace)
dvid.Criticalf("%s\n", message)
if err := SendNotification(message, nil); err != nil {
dvid.Criticalf("Couldn't send email notifcation: %v\n", err)
}
http.Error(w, http.StatusText(500), 500)
}
}()
h.ServeHTTP(w, r)
}
return http.HandlerFunc(fn)
}
示例3: splitBlock
// Goroutine that handles splits across a lot of blocks for one label.
func (d *Data) splitBlock(ctx *datastore.VersionedCtx, op splitOp) {
defer d.MutDone(op.mutID)
store, err := d.GetOrderedKeyValueDB()
if err != nil {
dvid.Errorf("Data type labelblk had error initializing store: %v\n", err)
return
}
// Read the block.
tk := NewTKeyByCoord(op.block)
data, err := store.Get(ctx, tk)
if err != nil {
dvid.Errorf("Error on GET of labelblk with coord string %v\n", []byte(op.block))
return
}
if data == nil {
dvid.Errorf("nil label block where split was done, coord %v\n", []byte(op.block))
return
}
blockData, _, err := dvid.DeserializeData(data, true)
if err != nil {
dvid.Criticalf("unable to deserialize label block in '%s' key %v: %v\n", d.DataName(), []byte(op.block), err)
return
}
blockBytes := int(d.BlockSize().Prod() * 8)
if len(blockData) != blockBytes {
dvid.Criticalf("splitBlock: coord %v got back %d bytes, expected %d bytes\n", []byte(op.block), len(blockData), blockBytes)
return
}
// Modify the block using either voxel-level changes or coarser block-level mods.
if op.rles != nil {
if err := d.storeRLEs(blockData, op.newLabel, op.block, op.rles); err != nil {
dvid.Errorf("can't store label %d RLEs into block %s: %v\n", op.newLabel, op.block, err)
return
}
} else {
// We are doing coarse split and will replace all
if err := d.replaceLabel(blockData, op.oldLabel, op.newLabel); err != nil {
dvid.Errorf("can't replace label %d with %d in block %s: %v\n", op.oldLabel, op.newLabel, op.block, err)
return
}
}
// Write the modified block.
serialization, err := dvid.SerializeData(blockData, d.Compression(), d.Checksum())
if err != nil {
dvid.Criticalf("Unable to serialize block %s in %q: %v\n", op.block, d.DataName(), err)
return
}
if err := store.Put(ctx, tk, serialization); err != nil {
dvid.Errorf("Error in putting key %v: %v\n", tk, err)
}
// Notify any downstream downres instance.
d.publishBlockChange(ctx.VersionID(), op.mutID, op.block, blockData)
}
示例4: DeleteRange
// DeleteRange removes all key-value pairs with keys in the given range.
func (db *LevelDB) DeleteRange(ctx storage.Context, kStart, kEnd storage.TKey) error {
if ctx == nil {
return fmt.Errorf("Received nil context in DeleteRange()")
}
// For leveldb, we just iterate over keys in range and delete each one using batch.
const BATCH_SIZE = 10000
batch := db.NewBatch(ctx).(*goBatch)
ch := make(chan errorableKV)
// Run the keys-only range query in a goroutine.
go func() {
if ctx == nil || !ctx.Versioned() {
db.unversionedRange(ctx, kStart, kEnd, ch, true)
} else {
db.versionedRange(ctx.(storage.VersionedCtx), kStart, kEnd, ch, true)
}
}()
// Consume the key-value pairs.
numKV := 0
for {
result := <-ch
if result.KeyValue == nil {
break
}
if result.error != nil {
return result.error
}
// The key coming down channel is not index but full key, so no need to construct key using context.
// If versioned, write a tombstone using current version id since we don't want to delete locked ancestors.
// If unversioned, just delete.
tk, err := ctx.TKeyFromKey(result.KeyValue.K)
if err != nil {
return err
}
batch.Delete(tk)
if (numKV+1)%BATCH_SIZE == 0 {
if err := batch.Commit(); err != nil {
dvid.Criticalf("Error on batch commit of DeleteRange at key-value pair %d: %v\n", numKV, err)
return fmt.Errorf("Error on batch commit of DeleteRange at key-value pair %d: %v\n", numKV, err)
}
batch = db.NewBatch(ctx).(*goBatch)
}
numKV++
}
if numKV%BATCH_SIZE != 0 {
if err := batch.Commit(); err != nil {
dvid.Criticalf("Error on last batch commit of DeleteRange: %v\n", err)
return fmt.Errorf("Error on last batch commit of DeleteRange: %v\n", err)
}
}
dvid.Debugf("Deleted %d key-value pairs via delete range for %s.\n", numKV, ctx)
return nil
}
示例5: mergeBlock
// Goroutine that handles relabeling of blocks during a merge operation.
// Since the same block coordinate always gets mapped to the same goroutine, we handle
// concurrency by serializing GET/PUT for a particular block coordinate.
func (d *Data) mergeBlock(in <-chan mergeOp) {
store, err := storage.MutableStore()
if err != nil {
dvid.Errorf("Data type labelblk had error initializing store: %v\n", err)
return
}
blockBytes := int(d.BlockSize().Prod() * 8)
for op := range in {
tk := NewTKeyByCoord(op.izyx)
data, err := store.Get(op.ctx, tk)
if err != nil {
dvid.Errorf("Error on GET of labelblk with coord string %q\n", op.izyx)
op.wg.Done()
continue
}
if data == nil {
dvid.Errorf("nil label block where merge was done!\n")
op.wg.Done()
continue
}
blockData, _, err := dvid.DeserializeData(data, true)
if err != nil {
dvid.Criticalf("unable to deserialize label block in '%s': %v\n", d.DataName(), err)
op.wg.Done()
continue
}
if len(blockData) != blockBytes {
dvid.Criticalf("After labelblk deserialization got back %d bytes, expected %d bytes\n", len(blockData), blockBytes)
op.wg.Done()
continue
}
// Iterate through this block of labels and relabel if label in merge.
for i := 0; i < blockBytes; i += 8 {
label := binary.LittleEndian.Uint64(blockData[i : i+8])
if _, merged := op.Merged[label]; merged {
binary.LittleEndian.PutUint64(blockData[i:i+8], op.Target)
}
}
// Store this block.
serialization, err := dvid.SerializeData(blockData, d.Compression(), d.Checksum())
if err != nil {
dvid.Criticalf("Unable to serialize block in %q: %v\n", d.DataName(), err)
op.wg.Done()
continue
}
if err := store.Put(op.ctx, tk, serialization); err != nil {
dvid.Errorf("Error in putting key %v: %v\n", tk, err)
}
op.wg.Done()
}
}
示例6: mergeBlock
// handles relabeling of blocks during a merge operation.
func (d *Data) mergeBlock(ctx *datastore.VersionedCtx, op mergeOp) {
defer d.MutDone(op.mutID)
store, err := d.GetKeyValueDB()
if err != nil {
dvid.Errorf("Data type labelblk had error initializing store: %v\n", err)
return
}
tk := NewTKeyByCoord(op.block)
data, err := store.Get(ctx, tk)
if err != nil {
dvid.Errorf("Error on GET of labelblk with coord string %q\n", op.block)
return
}
if data == nil {
dvid.Errorf("nil label block where merge was done!\n")
return
}
blockData, _, err := dvid.DeserializeData(data, true)
if err != nil {
dvid.Criticalf("unable to deserialize label block in '%s': %v\n", d.DataName(), err)
return
}
blockBytes := int(d.BlockSize().Prod() * 8)
if len(blockData) != blockBytes {
dvid.Criticalf("After labelblk deserialization got back %d bytes, expected %d bytes\n", len(blockData), blockBytes)
return
}
// Iterate through this block of labels and relabel if label in merge.
for i := 0; i < blockBytes; i += 8 {
label := binary.LittleEndian.Uint64(blockData[i : i+8])
if _, merged := op.Merged[label]; merged {
binary.LittleEndian.PutUint64(blockData[i:i+8], op.Target)
}
}
// Store this block.
serialization, err := dvid.SerializeData(blockData, d.Compression(), d.Checksum())
if err != nil {
dvid.Criticalf("Unable to serialize block in %q: %v\n", d.DataName(), err)
return
}
if err := store.Put(ctx, tk, serialization); err != nil {
dvid.Errorf("Error in putting key %v: %v\n", tk, err)
}
// Notify any downstream downres instance.
d.publishBlockChange(ctx.VersionID(), op.mutID, op.block, blockData)
}
示例7: Put
// Put writes a value with given key.
func (db *LevelDB) Put(ctx storage.Context, tk storage.TKey, v []byte) error {
if ctx == nil {
return fmt.Errorf("Received nil context in Put()")
}
wo := db.options.WriteOptions
var err error
key := ctx.ConstructKey(tk)
if !ctx.Versioned() {
dvid.StartCgo()
err = db.ldb.Put(wo, key, v)
dvid.StopCgo()
} else {
vctx, ok := ctx.(storage.VersionedCtx)
if !ok {
return fmt.Errorf("Non-versioned context that says it's versioned received in Put(): %v", ctx)
}
tombstoneKey := vctx.TombstoneKey(tk)
batch := db.NewBatch(vctx).(*goBatch)
batch.WriteBatch.Delete(tombstoneKey)
batch.WriteBatch.Put(key, v)
if err = batch.Commit(); err != nil {
dvid.Criticalf("Error on batch commit of Put: %v\n", err)
err = fmt.Errorf("Error on batch commit of Put: %v", err)
}
}
storage.StoreKeyBytesWritten <- len(key)
storage.StoreValueBytesWritten <- len(v)
return err
}
示例8: NewBatch
// NewBatch returns an implementation that allows batch writes
func (db *BigTable) NewBatch(ctx storage.Context) storage.Batch {
if ctx == nil {
dvid.Criticalf("Received nil context in NewBatch()")
return nil
}
return &goBatch{db, ctx, []storage.TKeyValue{}}
}
示例9: publishDownresCommit
func (d *Data) publishDownresCommit(v dvid.VersionID, mutID uint64) {
evt := datastore.SyncEvent{Data: d.DataUUID(), Event: DownsizeCommitEvent}
msg := datastore.SyncMessage{Event: DownsizeCommitEvent, Version: v, Delta: mutID}
if err := datastore.NotifySubscribers(evt, msg); err != nil {
dvid.Criticalf("unable to notify subscribers of event %s: %v\n", evt, err)
}
}
示例10: handleBlockEvent
// Processes each change as we get it.
// TODO -- accumulate larger # of changes before committing to prevent
// excessive compaction time? This assumes LSM storage engine, which
// might not always hold in future, so stick with incremental update
// until proven to be a bottleneck.
func (d *Data) handleBlockEvent(in <-chan datastore.SyncMessage, done <-chan struct{}) {
store, err := storage.SmallDataStore()
if err != nil {
dvid.Errorf("Data type labelvol had error initializing store: %v\n", err)
return
}
batcher, ok := store.(storage.KeyValueBatcher)
if !ok {
dvid.Errorf("Data type labelvol requires batch-enabled store, which %q is not\n", store)
return
}
for msg := range in {
select {
case <-done:
return
default:
ctx := datastore.NewVersionedCtx(d, msg.Version)
switch delta := msg.Delta.(type) {
case imageblk.Block:
d.ingestBlock(ctx, delta, batcher)
case labels.DeleteBlock:
d.deleteBlock(ctx, delta, batcher)
default:
dvid.Criticalf("Cannot sync labelvol from block event. Got unexpected delta: %v\n", msg)
}
}
}
}
示例11: syncSplit
func (d *Data) syncSplit(name dvid.InstanceName, in <-chan datastore.SyncMessage, done <-chan struct{}) {
// Start N goroutines to process blocks. Don't need transactional support for
// GET-PUT combo if each spatial coordinate (block) is only handled serially by a one goroutine.
const numprocs = 32
const splitBufSize = 10
var pch [numprocs]chan splitOp
for i := 0; i < numprocs; i++ {
pch[i] = make(chan splitOp, splitBufSize)
go d.splitBlock(pch[i])
}
for msg := range in {
select {
case <-done:
for i := 0; i < numprocs; i++ {
close(pch[i])
}
return
default:
switch delta := msg.Delta.(type) {
case labels.DeltaSplit:
ctx := datastore.NewVersionedCtx(d, msg.Version)
n := delta.OldLabel % numprocs
pch[n] <- splitOp{delta, *ctx}
case labels.DeltaSplitStart:
// Mark the old label is under transition
iv := dvid.InstanceVersion{name, msg.Version}
splitCache.Incr(iv, delta.OldLabel)
default:
dvid.Criticalf("bad delta in split event: %v\n", delta)
continue
}
}
}
}
示例12: Serve
// Serve starts HTTP and RPC servers.
func Serve() {
// Use defaults if not set via TOML config file.
if tc.Server.Host == "" {
tc.Server.Host = DefaultHost
}
if tc.Server.HTTPAddress == "" {
tc.Server.HTTPAddress = DefaultWebAddress
}
if tc.Server.RPCAddress == "" {
tc.Server.RPCAddress = DefaultRPCAddress
}
dvid.Infof("------------------\n")
dvid.Infof("DVID code version: %s\n", gitVersion)
dvid.Infof("Serving HTTP on %s (host alias %q)\n", tc.Server.HTTPAddress, tc.Server.Host)
dvid.Infof("Serving command-line use via RPC %s\n", tc.Server.RPCAddress)
dvid.Infof("Using web client files from %s\n", tc.Server.WebClient)
dvid.Infof("Using %d of %d logical CPUs for DVID.\n", dvid.NumCPU, runtime.NumCPU())
// Launch the web server
go serveHTTP()
// Launch the rpc server
go func() {
if err := rpc.StartServer(tc.Server.RPCAddress); err != nil {
dvid.Criticalf("Could not start RPC server: %v\n", err)
}
}()
<-shutdownCh
}
示例13: Delete
// Delete removes a value with given key.
func (db *LevelDB) Delete(ctx storage.Context, tk storage.TKey) error {
if db == nil {
return fmt.Errorf("Can't call Delete on nil LevelDB")
}
if ctx == nil {
return fmt.Errorf("Received nil context in Delete()")
}
wo := db.options.WriteOptions
var err error
key := ctx.ConstructKey(tk)
if !ctx.Versioned() {
dvid.StartCgo()
err = db.ldb.Delete(wo, key)
dvid.StopCgo()
} else {
vctx, ok := ctx.(storage.VersionedCtx)
if !ok {
return fmt.Errorf("Non-versioned context that says it's versioned received in Delete(): %v", ctx)
}
tombstoneKey := vctx.TombstoneKey(tk)
batch := db.NewBatch(vctx).(*goBatch)
batch.WriteBatch.Delete(key)
batch.WriteBatch.Put(tombstoneKey, dvid.EmptyValue())
if err = batch.Commit(); err != nil {
dvid.Criticalf("Error on batch commit of Delete: %v\n", err)
err = fmt.Errorf("Error on batch commit of Delete: %v", err)
}
}
return err
}
示例14: downsizeAdd
// Handle upstream mods on a labelblk we are downresing.
func (d *Data) downsizeAdd(v dvid.VersionID, delta deltaBlock) {
defer d.MutDone(delta.mutID)
lobuf, err := d.getLoresCache(v, delta.block)
if err != nil {
dvid.Criticalf("unable to initialize block cache for labelblk %q: %v\n", d.DataName(), err)
return
}
// Offsets from corner of 2x2x2 voxel neighborhood to neighbor in highres block.
blockSize := d.BlockSize()
bx := blockSize.Value(0) * 8
bxy := blockSize.Value(1) * bx
var off [8]int32
off[0] = 0
off[1] = 8
off[2] = bx
off[3] = bx + 8
off[4] = bxy
off[5] = bxy + off[1]
off[6] = bxy + off[2]
off[7] = bxy + off[3]
var lo int32 // lores byte offset
for z := int32(0); z < blockSize.Value(2); z += 2 {
for y := int32(0); y < blockSize.Value(1); y += 2 {
hi := z*bxy + y*bx // hires byte offset to 2^3 neighborhood corner
for x := int32(0); x < blockSize.Value(0); x += 2 {
counts := make(map[uint64]int)
for n := 0; n < 8; n++ {
i := hi + off[n]
label := binary.LittleEndian.Uint64(delta.data[i : i+8])
counts[label]++
}
// get best label and if there's a tie use smaller label
var most int
var best uint64
for label, count := range counts {
if count > most {
best = label
most = count
} else if count == most && label > best {
best = label
}
}
// store into downres cache
//dvid.Infof("Data %q: best %d for (%d,%d,%d)\n", d.DataName(), best, x/2, y/2, z/2)
binary.LittleEndian.PutUint64(lobuf[lo:lo+8], best)
// Move to next corner of 8 block voxels
lo += 8
hi += 16 // 2 * label byte size
}
}
}
}
示例15: StopUpdate
func (u *Updater) StopUpdate() {
u.Lock()
u.updates--
if u.updates < 0 {
dvid.Criticalf("StopUpdate() called more than StartUpdate(). Issue with data instance code.\n")
}
u.Unlock()
}