示例#1
0
func (s *server) CompactBlock(ctx context.Context, request *oproto.CompactBlockRequest) (*oproto.CompactBlockResponse, error) {
	logCtx := openinstrument.LogContext(ctx)
	block, err := s.ds.GetBlock(request.Block.Id, request.Block.EndKey)
	if err != nil {
		return nil, err
	}
	if err = block.Compact(logCtx); err != nil {
		return nil, err
	}
	log.Printf("Log:\n%s", openinstrument.StringLog(logCtx))
	return &oproto.CompactBlockResponse{Block: block.ToProto()}, nil
}
示例#2
0
func (ds *Datastore) background(ctx context.Context) {
	// Background processing of blocks
	flush_tick := time.Tick(5 * time.Second)
	compact_tick := time.Tick(1 * time.Minute)
	for {
		select {
		case <-ctx.Done():
			log.Println("Context complete, closing background goroutine")
			return
		case <-flush_tick:
			ds.Flush()
		case <-compact_tick:
			logCtx, l := openinstrument.GetContextWithLog(ctx)
			for _, block := range ds.Blocks() {
				// Compact any blocks that need it
				if block.CompactRequired(logCtx) {
					if err := block.Compact(logCtx); err != nil {
						openinstrument.Logf(logCtx, "Error compacting block: %s\n", err)
					}
				}

				// Split any blocks that need it
				if block.SplitRequired(logCtx) {
					if _, _, err := ds.SplitBlock(logCtx, block); err != nil {
						openinstrument.Logf(logCtx, "Error splitting block: %s\n", err)
					}
					openinstrument.Logf(logCtx, "Finished splitting block %s", block)
				}
			}

			if len(l.Log) > 0 {
				log.Printf("Compact tick log:\n%s", openinstrument.StringLog(logCtx))
			}
		}
	}
}