Example #1
0
// NewClient creates a new HBase client.
func NewClient(zkquorum string, options ...Option) *Client {
	log.WithFields(log.Fields{
		"Host": zkquorum,
	}).Debug("Creating new client.")
	c := &Client{
		clientType: StandardClient,
		regions:    keyRegionCache{regions: b.TreeNew(regioninfo.CompareGeneric)},
		clients: regionClientCache{
			clients:        make(map[*regioninfo.Info]*region.Client),
			clientsToInfos: make(map[*region.Client][]*regioninfo.Info),
		},
		zkquorum:      zkquorum,
		rpcQueueSize:  100,
		flushInterval: 20 * time.Millisecond,
		metaRegionInfo: &regioninfo.Info{
			Table:      []byte("hbase:meta"),
			RegionName: []byte("hbase:meta,,1"),
			StopKey:    []byte{},
		},
		adminRegionInfo: &regioninfo.Info{},
	}
	for _, option := range options {
		option(c)
	}
	return c
}
Example #2
0
func New(mo store.MergeOperator, config map[string]interface{}) (store.KVStore, error) {
	s := &Store{
		t:  b.TreeNew(itemCompare),
		mo: mo,
	}
	return s, nil
}
func BenchmarkIterate(b *testing.B) {
	tree := btree.TreeNew(cznicCmp)
	for i := 0; i < len(fixture.TestData); i++ {
		tree.Set(fixture.TestData[i].Key, fixture.TestData[i].Value)
	}
	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		// only errors on empty trees; meh api
		iter, err := tree.SeekFirst()
		if err != nil {
			b.Fatalf("tree.SeekFirst: %v", err)
		}
		for {
			k, v, err := iter.Next()
			if err == io.EOF {
				break
			}
			if err != nil {
				b.Fatalf("iter.Next: %v", err)
			}

			_ = k.(fixture.Key)
			_ = v.(fixture.Value)
		}
		iter.Close()
	}
}
func BenchmarkSortedInsert(b *testing.B) {
	for i := 0; i < b.N; i++ {
		tree := btree.TreeNew(cznicCmp)
		for i := 0; i < len(fixture.SortedTestData); i++ {
			tree.Set(fixture.SortedTestData[i].Key, fixture.SortedTestData[i].Value)
		}
	}
}
Example #5
0
func StoreConstructor(config map[string]interface{}) (store.KVStore, error) {
	s := &Store{
		t:                b.TreeNew(itemCompare),
		availableWriters: make(chan bool, MAX_CONCURRENT_WRITERS),
	}
	for i := 0; i < MAX_CONCURRENT_WRITERS; i++ {
		s.availableWriters <- true
	}
	return s, nil
}
Example #6
0
func New(mo store.MergeOperator, config map[string]interface{}) (store.KVStore, error) {
	path, ok := config["path"].(string)
	if !ok {
		return nil, fmt.Errorf("must specify path")
	}
	if path != "" {
		return nil, os.ErrInvalid
	}
	s := &Store{
		t:  b.TreeNew(itemCompare),
		mo: mo,
	}
	return s, nil
}
Example #7
0
// Import the import data file into the BTree
func processDataFile(inputFile string) {

	file, err := os.Open(inputFile)
	if err != nil {
		log.Fatal("Error opening the data file: %v", err)
	}
	defer file.Close()

	// String array used when importing from a CSV file
	var parts []string

	logger.Info("Starting import")

	// Initialise the BTree structure
	bTree = b.TreeNew(cmp)

	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		if opt.CsvField > -1 {
			parts = strings.Split(scanner.Text(), opt.CsvDelimiter)

			if opt.CsvField > len(parts) {
				logger.Error("CSV field index is greater than the length of the split parts: %v", scanner.Text())
				continue
			}

			if opt.RemoveQuotes == true {
				bTree.Set(strings.ToUpper(parts[opt.CsvField][1:len(parts[opt.CsvField])-1]), nil)
			} else {
				bTree.Set(strings.ToUpper(parts[opt.CsvField]), nil)
			}
		} else {
			if opt.RemoveQuotes == true {
				bTree.Set(strings.ToUpper(scanner.Text()[1:len(scanner.Text())-1]), nil)
			} else {
				bTree.Set(strings.ToUpper(scanner.Text()), nil)
			}
		}
	}

	logger.Info("Import complete")

	if err := scanner.Err(); err != nil {
		logger.Fatal(err)
	}
}
Example #8
0
func newLRUItems() *lruItems {
	return &lruItems{b.TreeNew(func(_a, _b interface{}) int {
		a := _a.(ItemInfo)
		b := _b.(ItemInfo)
		if a.Accessed != b.Accessed {
			if a.Accessed.Before(b.Accessed) {
				return -1
			} else {
				return 1
			}
		}
		if a.Path == b.Path {
			return 0
		}
		if a.Path < b.Path {
			return -1
		}
		return 1
	})}
}
Example #9
0
File: book.go Project: ikravets/ev
func NewOptionSideStateDeep(side packet.MarketSide) optionSideState {
	ComparePrice := func(lhs, rhs interface{}) int {
		l, r := lhs.(int), rhs.(int)
		return l - r
	}
	ComparePriceRev := func(lhs, rhs interface{}) int {
		l, r := lhs.(int), rhs.(int)
		return r - l
	}

	var cmp b.Cmp
	switch side {
	case packet.MarketSideBid:
		cmp = ComparePriceRev
	case packet.MarketSideAsk:
		cmp = ComparePrice
	default:
		log.Fatal("unexpected market side ", side)
	}
	s := &optionSideStateDeep{
		levels: b.TreeNew(cmp),
	}
	return s
}
Example #10
0
func newClient(zkquorum string, options ...Option) *client {
	log.WithFields(log.Fields{
		"Host": zkquorum,
	}).Debug("Creating new client.")
	c := &client{
		clientType: standardClient,
		regions:    keyRegionCache{regions: b.TreeNew(region.CompareGeneric)},
		clients: clientRegionCache{
			regions: make(map[hrpc.RegionClient][]hrpc.RegionInfo),
		},
		zkquorum:      zkquorum,
		rpcQueueSize:  100,
		flushInterval: 20 * time.Millisecond,
		metaRegionInfo: region.NewInfo(
			[]byte("hbase:meta"),
			[]byte("hbase:meta,,1"),
			nil,
			nil),
		adminRegionInfo: region.NewInfo(
			nil,
			nil,
			nil,
			nil),
		zkClient: zk.NewClient(zkquorum),
	}
	for _, option := range options {
		option(c)
	}
	if c.master == (zk.ResourceName)("") {
		c.master = zk.ResourceName("/hbase/master")
	}
	if c.meta == (zk.ResourceName)("") {
		c.meta = zk.ResourceName("/hbase/meta-region-server")
	}
	return c
}