コード例 #1
0
ファイル: hbase_test.go プロジェクト: xiaoma20082008/bfs
func TestHbase(t *testing.T) {
	var (
		err  error
		m, n *meta.Needle
	)
	if err = Init("172.16.13.90:9090", 5*time.Second, 10, 10); err != nil {
		t.Errorf("Init failed")
		t.FailNow()
	}

	h := NewHBaseClient()
	m = new(meta.Needle)
	m.Key = 445
	m.Vid = 55
	m.Cookie = 5
	n = new(meta.Needle)
	if err = h.Put(m); err != nil {
		t.Errorf("error: %v", err)
		t.FailNow()
	}
	if n, err = h.Get(m.Key); err != nil {
		t.Errorf("error: %v", err)
		t.FailNow()
	}
	fmt.Println("Get success", n)
	if err = h.Del(m.Key); err != nil {
		t.Errorf("error:%v", err)
		t.FailNow()
	}
	if n, err = h.Get(m.Key); err != nil {
		t.Errorf("error: %v", err)
		t.FailNow()
	}
	fmt.Println("Get success", n)
}
コード例 #2
0
ファイル: directory.go プロジェクト: xiaoma20082008/bfs
// UploadStores get writable stores for http upload
func (d *Directory) UploadStores(numKeys int) (keys []KeyCookie, vid int32, stores []string, err error) {
	var (
		i         int
		key       int64
		kc        KeyCookie
		n         meta.Needle
		svrs      []string
		store     string
		storeMeta *meta.Store
		ok        bool
	)
	if numKeys > d.config.MaxNum {
		err = errors.ErrUploadMaxFile
		return
	}
	if vid, err = d.dispatcher.VolumeId(d.group, d.storeVolume); err != nil {
		log.Errorf("dispatcher.VolumeId error(%v)", err)
		err = errors.ErrStoreNotAvailable
		return
	}
	svrs = d.volumeStore[vid]
	stores = make([]string, 0, len(svrs))
	for _, store = range svrs {
		if storeMeta, ok = d.store[store]; !ok {
			err = errors.ErrZookeeperDataError
			return
		}
		stores = append(stores, storeMeta.Api)
	}
	keys = make([]KeyCookie, numKeys)
	for i = 0; i < numKeys; i++ {
		if key, err = d.genkey.Getkey(); err != nil {
			log.Errorf("genkey.Getkey() error(%v)", err)
			err = errors.ErrIdNotAvailable
			return
		}
		keys[i].Key = key
		keys[i].Cookie = d.cookie()
	}
	for _, kc = range keys {
		n.Key = kc.Key
		n.Vid = vid
		n.Cookie = kc.Cookie
		if err = d.hbase.Put(&n); err != nil {
			log.Errorf("hbase.Put error(%v)", err)
			err = errors.ErrHbase
			return //puted keys will be ignored
		}
	}
	return
}