func (i *info) MarkAvailable() {
	i.m.Lock()
	ch := i.available
	i.available = nil
	close(ch)
	i.m.Unlock()
}
MarkAvailable will mark this region as available again, by closing the struct
returned by AvailabilityChan
package region
import (
	"bytes"
	"context"
	"encoding/binary"
	"fmt"
	"sync"
	"github.com/tsuna/gohbase/hrpc"
	"github.com/tsuna/gohbase/pb"
	"google.golang.org/protobuf/proto"
)
var defaultNamespace = []byte("default")
type OfflineRegionError struct {
	n string
}
func (e OfflineRegionError) Error() string {
	return fmt.Sprintf("region %s is offline", e.n)
}
type info struct {
	id        uint64  
	namespace []byte
	table     []byte
	name      []byte
	startKey  []byte
	stopKey   []byte
	ctx       context.Context
	cancel    context.CancelFunc
	m sync.RWMutex
	client hrpc.RegionClient
	available chan struct{}
}
func NewInfo(id uint64, namespace, table, name, startKey, stopKey []byte) hrpc.RegionInfo {
	ctx, cancel := context.WithCancel(context.Background())
	return &info{
		id:        id,
		ctx:       ctx,
		cancel:    cancel,
		namespace: namespace,
		table:     table,
		name:      name,
		startKey:  startKey,
		stopKey:   stopKey,
	}
}
func infoFromCell(cell *hrpc.Cell) (hrpc.RegionInfo, error) {
	value := cell.Value
	if len(value) == 0 {
		return nil, fmt.Errorf("empty value in %q", cell)
	} else if value[0] != 'P' {
		return nil, fmt.Errorf("unsupported region info version %d in %q", value[0], cell)
	}
	const pbufMagic = 1346524486  
	magic := binary.BigEndian.Uint32(value[:4])
	if magic != pbufMagic {
		return nil, fmt.Errorf("invalid magic number in %q", cell)
	}
	var regInfo pb.RegionInfo
	err := proto.Unmarshal(value[4:], &regInfo)
	if err != nil {
		return nil, fmt.Errorf("failed to decode %q: %s", cell, err)
	}
	if regInfo.GetOffline() {
		return nil, OfflineRegionError{n: string(cell.Row)}
	}
	var namespace []byte
	if !bytes.Equal(regInfo.TableName.Namespace, defaultNamespace) {
		namespace = regInfo.TableName.Namespace
	}
	return NewInfo(
		regInfo.GetRegionId(),
		namespace,
		regInfo.TableName.Qualifier,
		cell.Row,
		regInfo.StartKey,
		regInfo.EndKey,
	), nil
}
func ParseRegionInfo(metaRow *hrpc.Result) (hrpc.RegionInfo, string, error) {
	var reg hrpc.RegionInfo
	var addr string
	for _, cell := range metaRow.Cells {
		switch string(cell.Qualifier) {
		case "regioninfo":
			var err error
			reg, err = infoFromCell(cell)
			if err != nil {
				return nil, "", err
			}
		case "server":
			value := cell.Value
			if len(value) == 0 {
				continue  
			}
			addr = string(value)
		default:
		}
	}
	if reg == nil {
		return nil, "", fmt.Errorf("meta seems to be broken, there was no region in %v", metaRow)
	}
	if len(addr) == 0 {
		return nil, "", fmt.Errorf("meta doesn't have a server location in %v", metaRow)
	}
	return reg, addr, nil
}
func (i *info) IsUnavailable() bool {
	i.m.RLock()
	res := i.available != nil
	i.m.RUnlock()
	return res
}
func (i *info) AvailabilityChan() <-chan struct{} {
	i.m.RLock()
	ch := i.available
	i.m.RUnlock()
	return ch
}
func (i *info) MarkUnavailable() bool {
	created := false
	i.m.Lock()
	if i.available == nil {
		i.available = make(chan struct{})
		created = true
	}
	i.m.Unlock()
	return created
}