github.com/janelia-flyem/dvid@v1.0.0/datatype/labelmap/sync.go (about)

     1  /*
     2  	This file supports interactive syncing between data instances.  It is different
     3  	from ingestion syncs that can more effectively batch changes.
     4  */
     5  
     6  package labelmap
     7  
     8  import (
     9  	"sync"
    10  	"time"
    11  
    12  	"github.com/janelia-flyem/dvid/datastore"
    13  	"github.com/janelia-flyem/dvid/datatype/common/downres"
    14  	"github.com/janelia-flyem/dvid/datatype/common/labels"
    15  	"github.com/janelia-flyem/dvid/dvid"
    16  )
    17  
    18  const (
    19  	numLabelHandlers = 256 // goroutines used to do get/put tx on label indices
    20  )
    21  
    22  // IngestedBlock is the unit of delta for a IngestBlockEvent.
    23  type IngestedBlock struct {
    24  	MutID  uint64
    25  	BCoord dvid.IZYXString
    26  	Data   *labels.Block
    27  }
    28  
    29  // MutatedBlock tracks previous and updated block data.
    30  // It is the unit of delta for a MutateBlockEvent.
    31  type MutatedBlock struct {
    32  	MutID  uint64
    33  	BCoord dvid.IZYXString
    34  	Prev   *labels.Block
    35  	Data   *labels.Block
    36  }
    37  
    38  type procMsg struct {
    39  	v  dvid.VersionID
    40  	op interface{}
    41  }
    42  
    43  type downresOp struct {
    44  	mutID  uint64
    45  	bcoord dvid.IZYXString // the high-res block coord corresponding to the Block
    46  	block  *labels.Block
    47  }
    48  
    49  type mergeOp struct {
    50  	labels.MergeOp
    51  	mutID      uint64
    52  	bcoord     dvid.IZYXString
    53  	downresMut *downres.Mutation
    54  }
    55  
    56  type splitSupervoxelOp struct {
    57  	labels.SplitSupervoxelOp
    58  	mutID      uint64
    59  	bcoord     dvid.IZYXString
    60  	downresMut *downres.Mutation
    61  }
    62  
    63  // InitDataHandlers launches goroutines to handle each labelmap instance's syncs.
    64  func (d *Data) InitDataHandlers() error {
    65  	return nil
    66  }
    67  
    68  // Shutdown terminates blocks until syncs are done then terminates background goroutines processing data.
    69  func (d *Data) Shutdown(wg *sync.WaitGroup) {
    70  	var elapsed int
    71  	for {
    72  		if d.Updating() {
    73  			if elapsed >= datastore.DataShutdownTime {
    74  				dvid.Infof("Timed out after %d seconds waiting for data %q updating", elapsed, d.DataName())
    75  				break
    76  			}
    77  			dvid.Infof("After %d seconds, data %q is still updating", elapsed, d.DataName())
    78  			time.Sleep(1 * time.Second)
    79  			elapsed++
    80  		} else {
    81  			break
    82  		}
    83  	}
    84  	if indexCache != nil {
    85  		var hitrate float64
    86  		if metaAttempts > 0 {
    87  			hitrate = (float64(metaHits) / float64(metaAttempts)) * 100.0
    88  		}
    89  		dvid.Infof("Cache for data %q: got %d meta cache hits on %d attempts (%5.2f)\n", d.DataName(), metaHits, metaAttempts, hitrate)
    90  	}
    91  	wg.Done()
    92  }